Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nmc/add new unit test files #5867

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/gui/folderman.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class TestShareModel;
class ShareTestHelper;
class EndToEndTestHelper;
class TestSyncConflictsModel;
class TestFolderWizard;
class TestSettingsDialog;
class TestGeneralSettings;

namespace OCC {

Expand Down Expand Up @@ -396,6 +399,9 @@ private slots:
friend class ::TestCfApiShellExtensionsIPC;
friend class ::ShareTestHelper;
friend class ::EndToEndTestHelper;
friend class ::TestFolderWizard;
friend class ::TestSettingsDialog;
friend class ::TestGeneralSettings;
};

} // namespace OCC
Expand Down
2 changes: 2 additions & 0 deletions src/gui/folderstatusmodel.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/folderstatusmodel.h

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/folderstatusmodel.h

File src/gui/folderstatusmodel.h (lines 157): Code does not conform to Custom style guidelines.
* Copyright (C) by Klaas Freitag <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -23,6 +23,7 @@
#include <QPointer>

class QNetworkReply;
class TestFolderStatusModel;
namespace OCC {

Q_DECLARE_LOGGING_CATEGORY(lcFolderStatus)
Expand Down Expand Up @@ -153,6 +154,7 @@
bool _dirty = false; // If the selective sync checkboxes were changed

bool _isSyncRunningForAwhile = false;
friend class:: TestFolderStatusModel;// for Unit Test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
friend class:: TestFolderStatusModel;// for Unit Test
friend class ::TestFolderStatusModel; // for Unit Test


/**
* Keeps track of items that are fetching data from the server.
Expand Down
18 changes: 18 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ nextcloud_add_test(RemoteWipe)

nextcloud_add_test(OAuth)

nextcloud_add_test(UserModel)
nextcloud_add_test(ConfigFile)
nextcloud_add_test(FolderWizard)
nextcloud_add_test(OwncloudWizard)
nextcloud_add_test(SettingsDialog)
nextcloud_add_test(Flow2AuthWidget)
nextcloud_add_test(AccountSettings)
nextcloud_add_test(GeneralSettings)
nextcloud_add_test(FolderStatusModel)
nextcloud_add_test(OwncloudSetupPage)
nextcloud_add_test(FolderStatusDelegate)
nextcloud_add_test(OwncloudAdvancedSetupPage)

nextcloud_add_test(Window)
nextcloud_add_test(Welcome)
nextcloud_add_test(UserLine)
nextcloud_add_test(HeaderButton)

configure_file(test_journal.db "${PROJECT_BINARY_DIR}/bin/test_journal.db" COPYONLY)

find_package(CMocka)
Expand Down
6 changes: 5 additions & 1 deletion test/nextcloud_add_test.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
find_package(Qt5 COMPONENTS Core Test Xml Network Qml Quick REQUIRED)
get_property(nextcloudCoreName TARGET nextcloudCore PROPERTY NAME)
set(nextcloudCoreAutogenInclude ${CMAKE_BINARY_DIR}/src/gui/${nextcloudCoreName}_autogen/include)

macro(nextcloud_build_test test_class)
set(CMAKE_AUTOMOC TRUE)
Expand Down Expand Up @@ -32,6 +34,7 @@ macro(nextcloud_build_test test_class)

target_include_directories(${OWNCLOUD_TEST_CLASS}Test PRIVATE
"${CMAKE_SOURCE_DIR}/test/"
${nextcloudCoreAutogenInclude}
${CMAKE_SOURCE_DIR}/src/3rdparty/qtokenizer
)
set_target_properties(${OWNCLOUD_TEST_CLASS}Test PROPERTIES FOLDER Tests)
Expand Down Expand Up @@ -81,8 +84,9 @@ macro(nextcloud_add_test test_class)
target_include_directories(${OWNCLOUD_TEST_CLASS}Test
PRIVATE
"${CMAKE_SOURCE_DIR}/test/"
${nextcloudCoreAutogenInclude}
${CMAKE_SOURCE_DIR}/src/3rdparty/qtokenizer
)
)
set_target_properties(${OWNCLOUD_TEST_CLASS}Test PROPERTIES FOLDER Tests)
endmacro()

Expand Down
24 changes: 24 additions & 0 deletions test/testaccountsettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*

Check notice on line 1 in test/testaccountsettings.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on test/testaccountsettings.cpp

File test/testaccountsettings.cpp (lines 10, 15, 19): Code does not conform to Custom style guidelines.
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*
*/

#include <QtTest>

#include "ui_accountsettings.h"
#include "accountsettings.h"

using namespace OCC;

class TestAccountSettings: public QObject
{
Q_OBJECT

private slots:

};

QTEST_MAIN(TestAccountSettings)
#include "testaccountsettings.moc"
22 changes: 22 additions & 0 deletions test/testconfigfile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*

Check notice on line 1 in test/testconfigfile.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on test/testconfigfile.cpp

File test/testconfigfile.cpp (lines 8, 13, 17): Code does not conform to Custom style guidelines.
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*
*/

#include <QtTest>
#include "configfile.h"

using namespace OCC;

class TestConfigFile: public QObject
{
Q_OBJECT

private slots:

};

QTEST_MAIN(TestConfigFile)
#include "testconfigfile.moc"
22 changes: 22 additions & 0 deletions test/testflow2authwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*

Check notice on line 1 in test/testflow2authwidget.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on test/testflow2authwidget.cpp

File test/testflow2authwidget.cpp (lines 8, 13, 17): Code does not conform to Custom style guidelines.
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*
*/

#include <QtTest>
#include "wizard/flow2authwidget.h"

using namespace OCC;

class TestFlow2AuthWidget: public QObject
{
Q_OBJECT

private slots:

};

QTEST_MAIN(TestFlow2AuthWidget)
#include "testflow2authwidget.moc"
5 changes: 2 additions & 3 deletions test/testfolderman.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/*

Check notice on line 1 in test/testfolderman.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on test/testfolderman.cpp

File test/testfolderman.cpp (lines 8): Code does not conform to Custom style guidelines.
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*
*/

#include <qglobal.h>
#include <QtGlobal>
#include <QTemporaryDir>
#include <QtTest>

#include "QtTest/qtestcase.h"
#include "common/utility.h"
#include "folderman.h"
#include "account.h"
#include "accountstate.h"
#include <accountmanager.h>
#include "accountmanager.h"
#include "configfile.h"
#include "syncenginetestutils.h"
#include "testhelper.h"
Expand Down
27 changes: 27 additions & 0 deletions test/testfolderstatusdelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*

Check notice on line 1 in test/testfolderstatusdelegate.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on test/testfolderstatusdelegate.cpp

File test/testfolderstatusdelegate.cpp (lines 8, 18, 22): Code does not conform to Custom style guidelines.
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*
*/

#include <QtTest>
#include <QPainter>

#include "folderstatusmodel.h"
#define private public
#include "folderstatusdelegate.h"
#undef private
Comment on lines +12 to +14
Copy link
Collaborator

@mgallien mgallien Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this "trick" will work because we are using a static library
if we would have been using a shared library (DLL on windows) I think that would fail because the symbol mangling is different for private/public class members (see https://en.wikiversity.org/wiki/Visual_C%2B%2B_name_mangling#Complex_Type_(union,_struct,_class,_coclass,_cointerface) and https://www.qt.io/blog/2009/08/12/some-thoughts-on-binary-compatibility)
I would not block this PR only based on that but

  • we would be unable to keep using that if our code was moved to a shared library (DLL)
  • I am not convinced of automated tests using private interfaces
  • That creates heavy coupling of the tests to the current internal implementation

why not "just" make your test a friend of the class you are testing ? That would also be more in line with the current state of the automated tests of the desktop client ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, friend class is very simple and easy solution, I avoided this because of only data/member privacy concern.
but if this is not major concern then I will apply the same.


using namespace OCC;

class TestFolderStatusDelegate: public QObject
{
Q_OBJECT

private slots:

};

QTEST_MAIN(TestFolderStatusDelegate)
#include "testfolderstatusdelegate.moc"
34 changes: 34 additions & 0 deletions test/testfolderstatusmodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*

Check notice on line 1 in test/testfolderstatusmodel.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on test/testfolderstatusmodel.cpp

File test/testfolderstatusmodel.cpp (lines 10, 17, 25, 29): Code does not conform to Custom style guidelines.
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*
*/

#include <QtTest>

#include "localdiscoverytracker.h"
#include "folderstatusmodel.h"
#include "syncrunfilelog.h"
#include "syncengine.h"
#include "account.h"

#define private public
#include "accountstate.h"
#include "syncresult.h"
#include "folder.h"
#include "theme.h"
#undef private
Comment on lines +16 to +21
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment


using namespace OCC;

class TestFolderStatusModel: public QObject
{
Q_OBJECT

private slots:

};

QTEST_GUILESS_MAIN(TestFolderStatusModel)
#include "testfolderstatusmodel.moc"
29 changes: 29 additions & 0 deletions test/testfolderwizard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*

Check notice on line 1 in test/testfolderwizard.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on test/testfolderwizard.cpp

File test/testfolderwizard.cpp (lines 11, 20, 24): Code does not conform to Custom style guidelines.
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*
*/

#include <QWizardPage>
#include <QtTest>

#include "creds/abstractcredentials.h"
#include "folderwizard.h"
#include "accountstate.h"
#include "testhelper.h"
#include "folderman.h"
#include "account.h"

using namespace OCC;

class TestFolderWizard: public QObject
{
Q_OBJECT

private slots:

};

QTEST_MAIN(TestFolderWizard)
#include "testfolderwizard.moc"
29 changes: 29 additions & 0 deletions test/testgeneralsettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*

Check notice on line 1 in test/testgeneralsettings.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on test/testgeneralsettings.cpp

File test/testgeneralsettings.cpp (lines 10, 20, 24): Code does not conform to Custom style guidelines.
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*
*/

#include <QtTest>

#include "theme.h"
#include "folderman.h"
#include "configfile.h"
#define private public
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

#include "generalsettings.h"
#undef private
#include "ui_generalsettings.h"

using namespace OCC;

class TestGeneralSettings: public QObject
{
Q_OBJECT

private slots:

};

QTEST_MAIN(TestGeneralSettings)
#include "testgeneralsettings.moc"
28 changes: 28 additions & 0 deletions test/testheaderbutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*

Check notice on line 1 in test/testheaderbutton.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on test/testheaderbutton.cpp

File test/testheaderbutton.cpp (lines 17, 21, 23): Code does not conform to Custom style guidelines.
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*
*/

#include <QQmlEngine>
#include <QQuickItem>
#include <QQuickView>
#include <QtTest>

#include "theme.h"

using namespace OCC;

class TestHeaderButton: public QObject
{
Q_OBJECT

public:

private slots:

};

QTEST_MAIN(TestHeaderButton)
#include "testheaderbutton.moc"
24 changes: 24 additions & 0 deletions test/testowncloudadvancedsetuppage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*
*/

#include <QtTest>

#include "wizard/owncloudadvancedsetuppage.h"
#include "wizard/owncloudwizard.h"

using namespace OCC;

class TestOwncloudAdvancedSetupPage: public QWidget
{
Q_OBJECT

private slots:

};

QTEST_MAIN(TestOwncloudAdvancedSetupPage)
#include "testowncloudadvancedsetuppage.moc"
23 changes: 23 additions & 0 deletions test/testowncloudsetuppage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* This software is in the public domain, furnished "as is", without technical
* support, and with no warranty, express or implied, as to its usefulness for
* any purpose.
*
*/

#include <QtTest>

#include "wizard/owncloudsetuppage.h"

using namespace OCC;

class TestOwncloudSetupPage: public QWidget
{
Q_OBJECT

private slots:

};

QTEST_MAIN(TestOwncloudSetupPage)
#include "testowncloudsetuppage.moc"
Loading
Loading