Skip to content

Commit

Permalink
fix codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Oct 13, 2023
1 parent ba58b67 commit b444b90
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 44 deletions.
6 changes: 2 additions & 4 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()

Expand Down
2 changes: 1 addition & 1 deletion app/test/inputtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
59 changes: 32 additions & 27 deletions app/test/testmerginapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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() );
Expand All @@ -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() );
Expand All @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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 );
}


Expand All @@ -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();
Expand All @@ -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 );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down
22 changes: 11 additions & 11 deletions app/test/testutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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() );
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/test/testutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b444b90

Please sign in to comment.