- Including SMART support test

- Adding export macro to SmartParser
This commit is contained in:
Caio Carvalho 2018-01-20 21:56:10 -03:00
parent b5303587e2
commit 49c0c39f4b
3 changed files with 109 additions and 1 deletions

View File

@ -18,6 +18,8 @@
#if !defined(KPMCORE_SMARTPARSER_H)
#define KPMCORE_SMARTPARSER_H
#include "util/libpartitionmanagerexport.h"
#include <QJsonDocument>
#include <QString>
@ -29,7 +31,7 @@ class SmartDiskInformation;
@author Caio Carvalho <caiojcarvalho@gmail.com>
*/
class SmartParser
class LIBKPMCORE_EXPORT SmartParser
{
public:
SmartParser(const QString &device_path);

View File

@ -52,3 +52,7 @@ find_package (Threads)
# Execute external commands as root
kpm_test(testexternalcommand testexternalcommand.cpp)
add_test(NAME testexternalcommand COMMAND testexternalcommand ${BACKEND})
# Test SMART support
kpm_test(testsmart testsmart.cpp)
add_test(NAME testsmart COMMAND testsmart ${BACKEND})

102
test/testsmart.cpp Normal file
View File

@ -0,0 +1,102 @@
#include "helpers.h"
#include "util/externalcommand.h"
#include "backend/corebackend.h"
#include "backend/corebackendmanager.h"
#include "core/smartstatus.h"
#include "core/smartparser.h"
#include <QApplication>
#include <QDebug>
static QString getDefaultDevicePath();
static bool testSmartStatus();
static bool testSmartParser();
int main(int argc, char **argv)
{
QApplication 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())
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;
}