diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 7c631e35e..fe48ee1a2 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -220,10 +220,8 @@ if (ENABLE_TESTS) if (NOT USE_MM_SERVER_API_KEY) set_property( - SOURCE test/testmerginapi.cpp - PROPERTY COMPILE_DEFINITIONS - USE_MERGIN_DUMMY_API_KEY - ) + SOURCE test/testmerginapi.cpp PROPERTY COMPILE_DEFINITIONS USE_MERGIN_DUMMY_API_KEY + ) endif () endif () diff --git a/app/test/inputtests.cpp b/app/test/inputtests.cpp index 204f62ef4..eef9caccd 100644 --- a/app/test/inputtests.cpp +++ b/app/test/inputtests.cpp @@ -186,7 +186,7 @@ int InputTests::runTest() const { TestMerginApi merginApiTest( mApi ); QStringList args = mTestArgs; - if (!args.contains("-maxwarnings")) + if ( !args.contains( "-maxwarnings" ) ) { args << "-maxwarnings" << "0"; //show all debug output } diff --git a/app/test/testmerginapi.cpp b/app/test/testmerginapi.cpp index d1fd21ad0..c3923f8e8 100644 --- a/app/test/testmerginapi.cpp +++ b/app/test/testmerginapi.cpp @@ -59,9 +59,10 @@ void TestMerginApi::initTestCase() QString apiRoot, username, password, workspace; TestUtils::merginGetAuthCredentials( mApi, apiRoot, username, password ); - if (TestUtils::needsToAuthorizeAgain(mApi, username )) { - TestUtils::authorizeUser(mApi, username, password); - TestUtils::selectFirstWorkspace(mApi, workspace); + if ( TestUtils::needsToAuthorizeAgain( mApi, username ) ) + { + TestUtils::authorizeUser( mApi, username, password ); + TestUtils::selectFirstWorkspace( mApi, workspace ); } mUsername = username; // keep for later @@ -84,9 +85,10 @@ void TestMerginApi::initTestCase() mApiExtra = new MerginApi( *mLocalProjectsExtra ); mApiExtra->setApiRoot( mApi->apiRoot() ); - if (TestUtils::needsToAuthorizeAgain(mApiExtra, username )) { - TestUtils::authorizeUser(mApiExtra, username, password); - mApiExtra->userInfo()->setActiveWorkspace(mApi->userInfo()->activeWorkspaceId()); + if ( TestUtils::needsToAuthorizeAgain( mApiExtra, username ) ) + { + TestUtils::authorizeUser( mApiExtra, username, password ); + mApiExtra->userInfo()->setActiveWorkspace( mApi->userInfo()->activeWorkspaceId() ); } // Note: projects on the server are deleted in createRemoteProject function when needed @@ -215,7 +217,7 @@ void TestMerginApi::testDownloadProjectSpecChars() QString projectDir = mApi->projectsPath() + "/" + projectName + "/"; // First remove project on remote server (from previous test runs) - deleteRemoteProjectNow(mApi, projectNamespace, projectName); + deleteRemoteProjectNow( mApi, projectNamespace, projectName ); // create an empty project on the server QSignalSpy spy( mApi, &MerginApi::projectCreated ); @@ -304,7 +306,7 @@ void TestMerginApi::testCreateProjectTwice() QString projectNamespace = mWorkspaceName; // First remove project on remote server (from previous test runs) - deleteRemoteProjectNow(mApi, projectNamespace, projectName); + deleteRemoteProjectNow( mApi, projectNamespace, projectName ); MerginProjectsList projects = getProjectList(); QVERIFY( !_findProjectByName( projectNamespace, projectName, projects ).isValid() ); @@ -334,7 +336,7 @@ void TestMerginApi::testCreateProjectTwice() QCOMPARE( arguments.at( 1 ).toString(), QStringLiteral( "Mergin API error: createProject" ) ); //Clean created project - deleteRemoteProjectNow(mApi, projectNamespace, projectName); + deleteRemoteProjectNow( mApi, projectNamespace, projectName ); projects = getProjectList(); QVERIFY( !_findProjectByName( projectNamespace, projectName, projects ).isValid() ); @@ -366,7 +368,7 @@ void TestMerginApi::testCreateDeleteProject() QString projectNamespace = mWorkspaceName; // First remove project on remote server (from previous test runs) - deleteRemoteProjectNow(mApi, projectNamespace, projectName); + deleteRemoteProjectNow( mApi, projectNamespace, projectName ); MerginProjectsList projects = getProjectList(); QVERIFY( !_findProjectByName( projectNamespace, projectName, projects ).isValid() ); @@ -384,7 +386,7 @@ void TestMerginApi::testCreateDeleteProject() Q_ASSERT( _findProjectByName( projectNamespace, projectName, projects ).isValid() ); // Delete created project - deleteRemoteProjectNow(mApi, projectNamespace, projectName); + deleteRemoteProjectNow( mApi, projectNamespace, projectName ); projects = getProjectList(); QVERIFY( !_findProjectByName( projectNamespace, projectName, projects ).isValid() ); @@ -397,7 +399,7 @@ void TestMerginApi::testUploadProject() QString projectDir = mApi->projectsPath() + "/" + projectName; // clean leftovers from previous run first - deleteRemoteProjectNow(mApi, projectNamespace, projectName); + deleteRemoteProjectNow( mApi, projectNamespace, projectName ); QSignalSpy spy0( mApiExtra, &MerginApi::projectCreated ); mApiExtra->createProject( projectNamespace, projectName, true ); @@ -1449,7 +1451,7 @@ void TestMerginApi::testMigrateProject() QString projectName = "testMigrateProject"; // clean leftovers from previous tests - deleteRemoteProjectNow(mApi, mWorkspaceName, projectName); + deleteRemoteProjectNow( mApi, mWorkspaceName, projectName ); // make local copy of project QString projectDir = mApi->projectsPath() + "/" + projectName; @@ -1501,7 +1503,7 @@ void TestMerginApi::testMigrateProjectAndSync() QString projectDirExtra = mApiExtra->projectsPath() + "/" + projectName; // clean leftovers from previous tests - deleteRemoteProjectNow(mApi, mWorkspaceName, projectName); + deleteRemoteProjectNow( mApi, mWorkspaceName, projectName ); // step 1 createLocalProject( projectDir ); @@ -1555,7 +1557,7 @@ void TestMerginApi::testMigrateDetachProject() QString projectName = "testMigrateDetachProject"; // clean leftovers from previous tests - deleteRemoteProjectNow(mApi, mWorkspaceName, projectName); + deleteRemoteProjectNow( mApi, mWorkspaceName, projectName ); // make local copy of project QString projectDir = mApi->projectsPath() + "/" + projectName; @@ -2409,7 +2411,7 @@ void TestMerginApi::testAutosyncFailure() void TestMerginApi::testRegisterAndDelete() { #if defined(USE_MERGIN_DUMMY_API_KEY) - QSKIP("testRegisterAndDelete requires USE_MM_SERVER_API_KEY"); + QSKIP( "testRegisterAndDelete requires USE_MM_SERVER_API_KEY" ); #endif QString password = mApi->userAuth()->password(); @@ -2426,9 +2428,10 @@ void TestMerginApi::testRegisterAndDelete() QSignalSpy spy2( mApi, &MerginApi::registrationFailed ); mApi->registerUser( username, email, password, password, true ); bool success = spy.wait( TestUtils::LONG_REPLY ); - if (!success) { - qDebug() << "Failed registration" << spy2.takeFirst(); - QVERIFY( false ); + if ( !success ) + { + qDebug() << "Failed registration" << spy2.takeFirst(); + QVERIFY( false ); } @@ -2447,7 +2450,7 @@ void TestMerginApi::testRegisterAndDelete() void TestMerginApi::testCreateWorkspace() { #if defined(USE_MERGIN_DUMMY_API_KEY) - QSKIP("testCreateWorkspace requires USE_MM_SERVER_API_KEY"); + QSKIP( "testCreateWorkspace requires USE_MM_SERVER_API_KEY" ); #endif // we need to register new user for tests and assign its credentials to env vars QString username = TestUtils::generateUsername(); @@ -2460,9 +2463,10 @@ void TestMerginApi::testCreateWorkspace() QSignalSpy spy2( mApi, &MerginApi::registrationFailed ); mApi->registerUser( username, email, password, password, true ); bool success = spy.wait( TestUtils::LONG_REPLY ); - if (!success) { - qDebug() << "Failed registration" << spy2.takeFirst(); - QVERIFY( false ); + if ( !success ) + { + qDebug() << "Failed registration" << spy2.takeFirst(); + QVERIFY( false ); } QSignalSpy authSpy( mApi, &MerginApi::authChanged ); @@ -2584,9 +2588,9 @@ int TestMerginApi::serverVersionFromSpy( QSignalSpy &spy ) void TestMerginApi::createRemoteProject( MerginApi *api, const QString &projectNamespace, const QString &projectName, const QString &sourcePath, bool force ) { - if (force) + if ( force ) { - deleteRemoteProjectNow(api, projectNamespace, projectName); + deleteRemoteProjectNow( api, projectNamespace, projectName ); } // create a project @@ -2739,9 +2743,10 @@ void TestMerginApi::writeFileContent( const QString &filename, const QByteArray QByteArray TestMerginApi::readFileContent( const QString &filename ) { QFile f( filename ); - if (!f.exists()) { + if ( !f.exists() ) + { qDebug() << "Filename " << filename << " does not exist"; - Q_ASSERT(false); + Q_ASSERT( false ); } bool ok = f.open( QIODeviceBase::ReadOnly ); Q_ASSERT( ok ); diff --git a/app/test/testutils.cpp b/app/test/testutils.cpp index 6f16f8ce9..966e3cfb6 100644 --- a/app/test/testutils.cpp +++ b/app/test/testutils.cpp @@ -41,7 +41,7 @@ void TestUtils::merginGetAuthCredentials( MerginApi *api, QString &apiRoot, QStr password = ::getenv( "TEST_API_PASSWORD" ); } -void TestUtils::authorizeUser(MerginApi *api, const QString &username, const QString &password) +void TestUtils::authorizeUser( MerginApi *api, const QString &username, const QString &password ) { // Auth this user QSignalSpy spyExtra( api, &MerginApi::authChanged ); @@ -50,7 +50,7 @@ void TestUtils::authorizeUser(MerginApi *api, const QString &username, const QSt QCOMPARE( spyExtra.count(), 1 ); } -void TestUtils::selectFirstWorkspace(MerginApi *api, QString &workspace) +void TestUtils::selectFirstWorkspace( MerginApi *api, QString &workspace ) { // Gets his workspaces QSignalSpy spyExtraWs( api, &MerginApi::listWorkspacesFinished ); @@ -60,7 +60,7 @@ void TestUtils::selectFirstWorkspace(MerginApi *api, QString &workspace) // Sets active workspace Q_ASSERT( !api->userInfo()->workspaces().isEmpty() ); - api->userInfo()->setActiveWorkspace(api->userInfo()->workspaces().firstKey()); + api->userInfo()->setActiveWorkspace( api->userInfo()->workspaces().firstKey() ); // This user needs to have active workspace Q_ASSERT( !api->userInfo()->activeWorkspaceName().isEmpty() ); @@ -69,31 +69,31 @@ void TestUtils::selectFirstWorkspace(MerginApi *api, QString &workspace) } -bool TestUtils::needsToAuthorizeAgain(MerginApi *api, const QString &username) +bool TestUtils::needsToAuthorizeAgain( MerginApi *api, const QString &username ) { - Q_ASSERT(api); + Q_ASSERT( api ); // no auth at all if ( !api->userAuth()->hasAuthData() ) { - return true; + return true; } // wrong user - if ( api->userAuth()->username() != username) + if ( api->userAuth()->username() != username ) { - return true; + return true; } // no workspace - if (api->userInfo()->activeWorkspaceName().isEmpty()) + if ( api->userInfo()->activeWorkspaceName().isEmpty() ) { - return true; + return true; } // invalid token if ( api->userAuth()->authToken().isEmpty() || api->userAuth()->tokenExpiration() < QDateTime().currentDateTime().toUTC() ) { - return true; + return true; } // we are OK diff --git a/app/test/testutils.h b/app/test/testutils.h index 67c363d87..2f11654fc 100644 --- a/app/test/testutils.h +++ b/app/test/testutils.h @@ -33,7 +33,7 @@ namespace TestUtils void merginGetAuthCredentials( MerginApi *api, QString &apiRoot, QString &username, QString &password ); //! Whether we need to auth again - bool needsToAuthorizeAgain(MerginApi *api, const QString &username); + bool needsToAuthorizeAgain( MerginApi *api, const QString &username ); QString generateUsername(); QString generateEmail();