[machineid] Turn back the change in tests

- the *mount* module inserts a rootMountPoint without trailing /
   into global storage, so we can't assume that here. On the other
   hand, the paths passed in to the Worker functions are absolute
   paths -- adjust the tests to follow that.
main
Adriaan de Groot 5 years ago
parent dd47201f27
commit 12107b3113

@ -50,12 +50,16 @@ MachineIdTests::initTestCase()
void
MachineIdTests::testCopyFile()
{
QTemporaryDir d( QDir::tempPath() + QStringLiteral( "/test-XXXXXX" ) );
QTemporaryDir tempRoot( QDir::tempPath() + QStringLiteral( "/test-root-XXXXXX" ) );
cDebug() << "Temporary files as" << QDir::tempPath();
cDebug() << "Temp dir file at " << d.path();
QVERIFY( !d.path().isEmpty() );
cDebug() << "Temp dir file at " << tempRoot.path();
QVERIFY( !tempRoot.path().isEmpty() );
QFile source( d.filePath( "example" ) );
// This will pretend to be the host system
QTemporaryDir tempISOdir( QDir::tempPath() + QStringLiteral( "/test-live-XXXXXX" ) );
QVERIFY( QDir( tempRoot.path() ).mkpath( tempRoot.path() + tempISOdir.path() ) );
QFile source( tempRoot.filePath( "example" ) );
QVERIFY( !source.exists() );
source.open( QIODevice::WriteOnly );
source.write( "Derp" );
@ -63,17 +67,20 @@ MachineIdTests::testCopyFile()
QCOMPARE( source.size(), 4 );
QVERIFY( source.exists() );
QString root = d.path() + '/';
// This should fail since "example" isn't standard in our test directory
auto r0 = MachineId::copyFile( root, "example" );
auto r0 = MachineId::copyFile( tempRoot.path(), "example" );
QVERIFY( !r0 );
if ( QFile::exists( "CMakeCache.txt" ) )
const QString sampleFile = QStringLiteral( "CMakeCache.txt" );
if ( QFile::exists( sampleFile ) )
{
auto r1 = MachineId::copyFile( root, "CMakeCache.txt" );
QVERIFY( r1 );
QVERIFY( QFile::exists( d.filePath( "CMakeCache.txt" ) ) );
auto r1 = MachineId::copyFile( tempRoot.path(), sampleFile );
// Also fail, because it's not an absolute path
QVERIFY( !r1 );
QVERIFY( QFile::copy( sampleFile, tempISOdir.path() + '/' + sampleFile ) );
auto r2 = MachineId::copyFile( tempRoot.path(), tempISOdir.path() + '/' + sampleFile );
QVERIFY( r2 );
}
}

Loading…
Cancel
Save