kpmcore/test/testexternalcommand.cpp

71 lines
2.3 KiB
C++
Raw Normal View History

/*************************************************************************
* Copyright 2017 by Andrius Štikonas <andrius@stikonas.eu> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
*************************************************************************/
// SPDX-License-Identifier: GPL-3.0+
#include "helpers.h"
#include "backend/corebackendmanager.h"
#include "util/externalcommand.h"
2018-03-31 16:30:53 +01:00
#include <QCoreApplication>
#include <QDebug>
#include <QThread>
2019-05-23 12:05:27 +01:00
class runcmd : public QThread
{
2019-05-23 12:05:27 +01:00
public:
void run() override
{
ExternalCommand blkidCmd(QStringLiteral("blkid"), {});
2019-05-23 12:05:27 +01:00
// ExternalCommadHelper will refuse to run this or any other command which is not whitelisted.
// See src/util/externalcommand_whitelist.h for whitelisted commands.
blkidCmd.run();
qDebug().noquote() << blkidCmd.output();
}
};
2019-05-23 12:05:27 +01:00
class runcmd2 : public QThread
{
2019-05-23 12:05:27 +01:00
public:
void run() override
{
ExternalCommand lsblkCmd(QStringLiteral("lsblk"), { QStringLiteral("--nodeps"), QStringLiteral("--json") });
lsblkCmd.run();
qDebug().noquote() << lsblkCmd.output();
}
};
int main( int argc, char **argv )
{
2018-03-31 16:30:53 +01:00
QCoreApplication app(argc, argv);
KPMCoreInitializer i(QStringLiteral("pmsfdiskbackendplugin"));
runcmd a;
runcmd2 b;
2019-05-23 12:05:27 +01:00
a.start();
a.wait();
2019-05-23 12:05:27 +01:00
b.start();
b.wait();
return 0;
}