1 /* === This file is part of Calamares - <https://calamares.io> ===
2  *
3  *   SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
4  *   SPDX-License-Identifier: GPL-3.0-or-later
5  *
6  *   Calamares is Free Software: see the License-Identifier above.
7  *
8  */
9 
10 #include "ClearMountsJobTests.h"
11 
12 #include "utils/Logger.h"
13 
14 #include <QtTest/QtTest>
15 
16 QTEST_GUILESS_MAIN( ClearMountsJobTests )
17 
18 
19 /* Not exactly public API */
20 QStringList getPartitionsForDevice( const QString& deviceName );
21 
22 QStringList
getPartitionsForDevice_other(const QString & deviceName)23 getPartitionsForDevice_other( const QString& deviceName )
24 {
25     QProcess process;
26     process.setProgram( "sh" );
27     process.setArguments(
28         { "-c",
29           QString( "echo $(awk '{print $4}' /proc/partitions | sed -e '/name/d' -e '/^$/d' -e '/[1-9]/!d' | grep %1)" )
30               .arg( deviceName ) } );
31     process.start();
32     process.waitForFinished();
33 
34     const QString partitions = process.readAllStandardOutput().trimmed();
35     if ( partitions.isEmpty() )
36     {
37         return QStringList();
38     }
39     const QStringList partitionsList = partitions.simplified().split( ' ' );
40 
41     return partitionsList;
42 }
43 
44 
ClearMountsJobTests()45 ClearMountsJobTests::ClearMountsJobTests()
46 {
47     Logger::setupLogLevel( Logger::LOGDEBUG );
48 }
49 
50 void
testFindPartitions()51 ClearMountsJobTests::testFindPartitions()
52 {
53     QStringList partitions = getPartitionsForDevice( "sda" );
54     QStringList other_part = getPartitionsForDevice_other( "sda" );
55 
56     cDebug() << "Initial implementation:" << Logger::DebugList( partitions );
57     cDebug() << "Other implementation:" << Logger::DebugList( other_part );
58 
59     QCOMPARE( partitions, other_part );
60 }
61