forked from qt-creator/qt-creator
Utils: Add unit tests for Id
Change-Id: Id471072f79ad0cdfbbc0197b437ac16e5d17386b Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
ba54e05e58
commit
8676397303
@@ -7,6 +7,7 @@ add_subdirectory(filepath)
|
|||||||
add_subdirectory(fileutils)
|
add_subdirectory(fileutils)
|
||||||
add_subdirectory(fsengine)
|
add_subdirectory(fsengine)
|
||||||
add_subdirectory(fuzzymatcher)
|
add_subdirectory(fuzzymatcher)
|
||||||
|
add_subdirectory(id)
|
||||||
add_subdirectory(indexedcontainerproxyconstiterator)
|
add_subdirectory(indexedcontainerproxyconstiterator)
|
||||||
add_subdirectory(mathutils)
|
add_subdirectory(mathutils)
|
||||||
add_subdirectory(multicursor)
|
add_subdirectory(multicursor)
|
||||||
|
4
tests/auto/utils/id/CMakeLists.txt
Normal file
4
tests/auto/utils/id/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
add_qtc_test(tst_utils_id
|
||||||
|
DEPENDS Utils
|
||||||
|
SOURCES tst_id.cpp
|
||||||
|
)
|
7
tests/auto/utils/id/id.qbs
Normal file
7
tests/auto/utils/id/id.qbs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import qbs
|
||||||
|
|
||||||
|
QtcAutotest {
|
||||||
|
name: "Id autotest"
|
||||||
|
Depends { name: "Utils" }
|
||||||
|
files: "tst_id.cpp"
|
||||||
|
}
|
79
tests/auto/utils/id/tst_id.cpp
Normal file
79
tests/auto/utils/id/tst_id.cpp
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
// Copyright (C) 2024 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
|
||||||
|
#include <utils/id.h>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
namespace QTest {
|
||||||
|
template<>
|
||||||
|
char *toString(const Utils::Id &id)
|
||||||
|
{
|
||||||
|
return qstrdup(id.name().constData());
|
||||||
|
}
|
||||||
|
} // namespace QTest
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace Utils {
|
||||||
|
|
||||||
|
class tst_id : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void isValid();
|
||||||
|
void withPrefix();
|
||||||
|
void withSuffix();
|
||||||
|
void compare();
|
||||||
|
void suffixAfter();
|
||||||
|
};
|
||||||
|
|
||||||
|
void tst_id::isValid()
|
||||||
|
{
|
||||||
|
QVERIFY(!Id().isValid());
|
||||||
|
QVERIFY(!Id::fromSetting("").isValid());
|
||||||
|
QVERIFY(Id::fromSetting("a").isValid());
|
||||||
|
QVERIFY(Id::generate().isValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_id::withPrefix()
|
||||||
|
{
|
||||||
|
QCOMPARE(Id("bar").withPrefix("foo"), Id("foobar"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_id::withSuffix()
|
||||||
|
{
|
||||||
|
Id id("foo");
|
||||||
|
QCOMPARE(id.withSuffix(42), Id("foo42"));
|
||||||
|
QCOMPARE(id.withSuffix('l'), Id("fool"));
|
||||||
|
QCOMPARE(id.withSuffix("lish"), Id("foolish"));
|
||||||
|
QCOMPARE(id.withSuffix(QStringView(QString("bar"))), Id("foobar"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_id::compare()
|
||||||
|
{
|
||||||
|
Id compId("blubb");
|
||||||
|
Id runId = Id::fromSetting("blubb");
|
||||||
|
QCOMPARE(compId, runId);
|
||||||
|
QCOMPARE(qHash(compId), qHash(runId));
|
||||||
|
QCOMPARE(compId.name(), "blubb");
|
||||||
|
QCOMPARE(runId, "blubb");
|
||||||
|
QVERIFY(compId == runId);
|
||||||
|
QVERIFY(compId == "blubb");
|
||||||
|
QVERIFY(runId == "blubb");
|
||||||
|
QVERIFY(Id("bar") < Id("foo"));
|
||||||
|
QVERIFY(Id("foo") > Id("bar"));
|
||||||
|
QVERIFY(!(Id("foo") < Id("bar")));
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_id::suffixAfter()
|
||||||
|
{
|
||||||
|
QCOMPARE(Id("foobar").suffixAfter(Id("foo")), "bar");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // Utils
|
||||||
|
|
||||||
|
QTEST_GUILESS_MAIN(Utils::tst_id)
|
||||||
|
|
||||||
|
#include "tst_id.moc"
|
@@ -12,6 +12,7 @@ Project {
|
|||||||
"fileutils/fileutils.qbs",
|
"fileutils/fileutils.qbs",
|
||||||
"fsengine/fsengine.qbs",
|
"fsengine/fsengine.qbs",
|
||||||
"fuzzymatcher/fuzzymatcher.qbs",
|
"fuzzymatcher/fuzzymatcher.qbs",
|
||||||
|
"id/id.qbs",
|
||||||
"indexedcontainerproxyconstiterator/indexedcontainerproxyconstiterator.qbs",
|
"indexedcontainerproxyconstiterator/indexedcontainerproxyconstiterator.qbs",
|
||||||
"mathutils/mathutils.qbs",
|
"mathutils/mathutils.qbs",
|
||||||
"multicursor/multicursor.qbs",
|
"multicursor/multicursor.qbs",
|
||||||
|
Reference in New Issue
Block a user