parent
59c9ba2f8d
commit
c9a08a593b
|
@ -53,12 +53,3 @@ find_package (Threads)
|
|||
# Execute external commands as root
|
||||
kpm_test(testexternalcommand testexternalcommand.cpp)
|
||||
add_test(NAME testexternalcommand COMMAND testexternalcommand ${BACKEND})
|
||||
|
||||
# Including SMART files reference
|
||||
set(SMARTPARSER ${CMAKE_SOURCE_DIR}/src/core/smartdiskinformation.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/smartattributeparseddata.cpp
|
||||
${CMAKE_SOURCE_DIR}/src/core/smartparser.cpp)
|
||||
|
||||
# Test SMART support
|
||||
kpm_test(testsmart testsmart.cpp ${SMARTPARSER})
|
||||
add_test(NAME testsmart COMMAND testsmart ${BACKEND})
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
#include "helpers.h"
|
||||
|
||||
#include "util/externalcommand.h"
|
||||
#include "backend/corebackend.h"
|
||||
#include "backend/corebackendmanager.h"
|
||||
#include "core/smartstatus.h"
|
||||
#include "core/smartparser.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
|
||||
static QString getDefaultDevicePath();
|
||||
static bool testSmartStatus();
|
||||
static bool testSmartParser();
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
KPMCoreInitializer i;
|
||||
|
||||
if (argc == 2)
|
||||
i = KPMCoreInitializer(argv[1]);
|
||||
|
||||
if (!i.isValid())
|
||||
return 1;
|
||||
|
||||
CoreBackend *backend = CoreBackendManager::self()->backend();
|
||||
|
||||
if (!backend)
|
||||
{
|
||||
qWarning() << "Couldn't get backend.";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!testSmartStatus() || !testSmartParser())
|
||||
return 1;
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
static QString getDefaultDevicePath()
|
||||
{
|
||||
// Getting default home partition using 'df -P /home | awk 'END{print $1}'' command
|
||||
ExternalCommand command(QStringLiteral("df"), { QStringLiteral("-P"), QStringLiteral("/home"), QStringLiteral("|"),
|
||||
QStringLiteral("awk"), QStringLiteral("\'END{print $1}\'") });
|
||||
|
||||
if (command.run() && command.exitCode() == 0) {
|
||||
QString output = command.output();
|
||||
return output;
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
static bool testSmartStatus()
|
||||
{
|
||||
QString devicePath = getDefaultDevicePath();
|
||||
|
||||
SmartStatus smart(devicePath);
|
||||
|
||||
if (smart.devicePath() != devicePath)
|
||||
return false;
|
||||
|
||||
if (!smart.status())
|
||||
return false;
|
||||
|
||||
if (smart.modelName() == QString())
|
||||
return false;
|
||||
|
||||
if (smart.firmware() == QString())
|
||||
return false;
|
||||
|
||||
if (smart.serial() == QString())
|
||||
return false;
|
||||
|
||||
if (smart.selfTestStatus() != SmartStatus::SelfTestStatus::Success)
|
||||
return false;
|
||||
|
||||
if (!smart.isValid())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool testSmartParser()
|
||||
{
|
||||
QString devicePath = getDefaultDevicePath();
|
||||
|
||||
SmartParser parser(devicePath);
|
||||
|
||||
if (!parser.init())
|
||||
return false;
|
||||
|
||||
if (parser.devicePath() != devicePath)
|
||||
return false;
|
||||
|
||||
if (!parser.diskInformation())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Reference in New Issue