diff --git a/src/core/smartparser.h b/src/core/smartparser.h index 3438e8d..ace6135 100644 --- a/src/core/smartparser.h +++ b/src/core/smartparser.h @@ -18,6 +18,8 @@ #if !defined(KPMCORE_SMARTPARSER_H) #define KPMCORE_SMARTPARSER_H +#include "util/libpartitionmanagerexport.h" + #include #include @@ -29,7 +31,7 @@ class SmartDiskInformation; @author Caio Carvalho */ -class SmartParser +class LIBKPMCORE_EXPORT SmartParser { public: SmartParser(const QString &device_path); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e81581e..67b9cea 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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}) diff --git a/test/testsmart.cpp b/test/testsmart.cpp new file mode 100644 index 0000000..ea5aa72 --- /dev/null +++ b/test/testsmart.cpp @@ -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 +#include + +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; +}