Skip to content
This repository was archived by the owner on Oct 20, 2026. It is now read-only.
Merged
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
11 changes: 3 additions & 8 deletions src/plugins/preferences/common/basemodelbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "commonitem.h"

#include <QDate>
#include <QDateTime>
#include <QString>

namespace preferences
Expand Down Expand Up @@ -99,17 +99,12 @@ class BaseModelBuilder
template<typename T>
T createRootElement(const std::string &guid)
{
QString dateOfChange(QDate::currentDate().toString(Qt::ISODate) + " "
+ QTime::currentTime().toString("hh:mm:ss"));

return T(guid, dateOfChange.toStdString(), "");
return T(guid, createDateOfChange(), "");
}

std::string createDateOfChange()
{
QString dateOfChange(QDate::currentDate().toString(Qt::ISODate) + " "
+ QTime::currentTime().toString("hh:mm:ss"));
return dateOfChange.toStdString();
return QDateTime::currentDateTimeUtc().toString("yyyy-MM-dd hh:mm:ss").toStdString();
}
};

Expand Down
1 change: 1 addition & 0 deletions tests/auto/plugins/preferences/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(common/basemodelbuilder)
32 changes: 2 additions & 30 deletions tests/auto/plugins/preferences/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,2 @@
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets Test REQUIRED)

find_package(XercesC REQUIRED)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
preferencesdialogtest.cpp
../../../../../src/plugins/preferences/shortcuts/shortcutswidget.cpp
../../../../../src/plugins/preferences/shortcuts/shortcutsschema.cpp
../../../../../src/plugins/preferences/shortcuts/modelbuilder.cpp
)

set(UI_FORMS
../../../../../src/plugins/preferences/common/preferencesdialog.ui
../../../../../src/plugins/preferences/shortcuts/shortcutswidget.ui
)

set(MOC_HEADERS
preferencesdialogtest.h
../../../../../src/plugins/preferences/common/preferencesdialog.h
../../../../../src/plugins/preferences/shortcuts/shortcutswidget.h
)

qt_wrap_ui(UI_SOURCES ${UI_FORMS})
qt_wrap_cpp(MOC_SOURCES ${MOC_HEADERS})

add_executable(preferencesdialogtest ${SOURCES} ${MOC_SOURCES} ${UI_SOURCES})
target_link_libraries(preferencesdialogtest ${GPUI_LIBRARIES} preferences-common Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Test XercesC::XercesC)
add_gpui_test(plugins.preferencesdialogtest preferencesdialogtest)
add_subdirectory(basemodelbuilder)
add_subdirectory(preferencesdialog)
Comment thread
august-alt marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Test REQUIRED)

qt_wrap_cpp(MOC_SOURCES basemodelbuildertest.h)

add_executable(basemodelbuildertest basemodelbuildertest.cpp ${MOC_SOURCES})
target_include_directories(basemodelbuildertest PRIVATE ${CMAKE_SOURCE_DIR}/src/plugins/preferences/common)
target_link_libraries(basemodelbuildertest preferences_static Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Test)
add_gpui_test(plugins.basemodelbuildertest basemodelbuildertest)
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/***********************************************************************************************************************
**
** Copyright (C) 2026 BaseALT Ltd. <org@basealt.ru>
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/

#include "basemodelbuildertest.h"

#include "basemodelbuilder.h"

#include <string>

#include <QtGlobal>
#include <QtTest>
#include <QTimeZone>

#ifdef Q_OS_UNIX
# include <time.h>
#endif

namespace {
const QString timestampFormat = "yyyy-MM-dd hh:mm:ss";

class TestModelBuilder : public preferences::BaseModelBuilder
{
public:
using BaseModelBuilder::createDateOfChange;
using BaseModelBuilder::createRootElement;
};

struct TestRootElement
{
TestRootElement(const std::string &guidValue, const std::string &changedValue,
const std::string &descriptionValue)
: guid(guidValue), changed(changedValue), description(descriptionValue)
{
}

std::string guid;
std::string changed;
std::string description;
};

void updateSystemTimeZone()
{
#ifdef Q_OS_UNIX
tzset();
#endif
}

} // namespace

namespace tests {
void BaseModelBuilderTest::initTestCase()
{
originalTimeZone = qgetenv("TZ");
hadOriginalTimeZone = qEnvironmentVariableIsSet("TZ");

QVERIFY(qputenv("TZ", "Europe/Saratov"));
updateSystemTimeZone();

QVERIFY(QDateTime::currentDateTime().offsetFromUtc() != 0);
}

void BaseModelBuilderTest::cleanupTestCase()
{
if (hadOriginalTimeZone) {
qputenv("TZ", originalTimeZone);
} else {
qunsetenv("TZ");
}
updateSystemTimeZone();
}

void BaseModelBuilderTest::createDateOfChangeUsesUtc()
{
TestModelBuilder builder;

const QDateTime before = QDateTime::currentDateTimeUtc();
const QString timestamp = QString::fromStdString(builder.createDateOfChange());
const QDateTime after = QDateTime::currentDateTimeUtc();

verifyUtcTimestamp(timestamp, before, after);
}

void BaseModelBuilderTest::createRootElementUsesUtc()
{
TestModelBuilder builder;

const QDateTime before = QDateTime::currentDateTimeUtc();
const TestRootElement root = builder.createRootElement<TestRootElement>("test-guid");
const QDateTime after = QDateTime::currentDateTimeUtc();

QCOMPARE(QString::fromStdString(root.guid), QString("test-guid"));
QCOMPARE(QString::fromStdString(root.description), QString());
verifyUtcTimestamp(QString::fromStdString(root.changed), before, after);
}

void BaseModelBuilderTest::verifyUtcTimestamp(const QString &timestamp, const QDateTime &before,
const QDateTime &after)
{
QVERIFY(timestamp.size() == 19);

QDateTime parsedTimestamp = QDateTime::fromString(timestamp, timestampFormat);
QVERIFY(parsedTimestamp.isValid());
QCOMPARE(parsedTimestamp.toString(timestampFormat), timestamp);

parsedTimestamp.setTimeZone(QTimeZone::utc());
QVERIFY(parsedTimestamp >= before.addSecs(-1));
QVERIFY(parsedTimestamp <= after);
}

} // namespace tests

QTEST_APPLESS_MAIN(tests::BaseModelBuilderTest)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/***********************************************************************************************************************
**
** Copyright (C) 2026 BaseALT Ltd. <org@basealt.ru>
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/

#ifndef GPUI_BASE_MODEL_BUILDER_TEST_H
#define GPUI_BASE_MODEL_BUILDER_TEST_H

#include <QByteArray>
#include <QDateTime>
#include <QObject>

namespace tests {
class BaseModelBuilderTest : public QObject
{
Q_OBJECT

private slots:
void initTestCase();
void cleanupTestCase();

void createDateOfChangeUsesUtc();
void createRootElementUsesUtc();

private:
void verifyUtcTimestamp(const QString &timestamp, const QDateTime &before,
const QDateTime &after);

QByteArray originalTimeZone;
bool hadOriginalTimeZone = false;
};

} // namespace tests

#endif // GPUI_BASE_MODEL_BUILDER_TEST_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets Test REQUIRED)

find_package(XercesC REQUIRED)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SOURCES
preferencesdialogtest.cpp
../../../../../../src/plugins/preferences/shortcuts/shortcutswidget.cpp
../../../../../../src/plugins/preferences/shortcuts/shortcutsschema.cpp
../../../../../../src/plugins/preferences/shortcuts/modelbuilder.cpp
)

set(UI_FORMS
../../../../../../src/plugins/preferences/common/preferencesdialog.ui
../../../../../../src/plugins/preferences/shortcuts/shortcutswidget.ui
)

set(MOC_HEADERS
preferencesdialogtest.h
../../../../../../src/plugins/preferences/common/preferencesdialog.h
../../../../../../src/plugins/preferences/shortcuts/shortcutswidget.h
)

qt_wrap_ui(UI_SOURCES ${UI_FORMS})
qt_wrap_cpp(MOC_SOURCES ${MOC_HEADERS})

add_executable(preferencesdialogtest ${SOURCES} ${MOC_SOURCES} ${UI_SOURCES})
target_link_libraries(preferencesdialogtest ${GPUI_LIBRARIES} preferences-common Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Test XercesC::XercesC)
add_gpui_test(plugins.preferencesdialogtest preferencesdialogtest)
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

#include <fstream>

#include "../../../../../src/plugins/preferences/shortcuts/modelbuilder.h"
#include "../../../../../src/plugins/preferences/shortcuts/shortcutroles.h"
#include "../../../../../src/plugins/preferences/shortcuts/shortcutsschema.h"
#include "../../../../../src/plugins/preferences/shortcuts/shortcutswidget.h"
#include "../../../../../../src/plugins/preferences/shortcuts/modelbuilder.h"
#include "../../../../../../src/plugins/preferences/shortcuts/shortcutroles.h"
#include "../../../../../../src/plugins/preferences/shortcuts/shortcutsschema.h"
#include "../../../../../../src/plugins/preferences/shortcuts/shortcutswidget.h"

#include "../../../../../src/plugins/preferences/common/preferencesdialog.h"
#include "../../../../../../src/plugins/preferences/common/preferencesdialog.h"

const std::string dataPath = "../../../../data/";
const std::string dataPath = "../../../../../data/";

namespace tests {

Expand Down