- Created 139 test files covering all Lts/Common module components - Includes tests for CodeGen, LtsAppDescriptor, LtsAppManager, LtsCoordTrans, LtsElevation, LtsLicence, LtsLogin, LtsMultiMonitor, LtsNotification, LtsPluginManager, LtsProtocol, LtsProjection, VNC, and CustomViews - Updated tests/CMakeLists.txt with dynamic file(GLOB) for test collection - Moved coordTransTests from CommonUnitTestsPlaceholder/ to tests/ - All tests follow policy naming conventions (test_<name>.cpp) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
113 lines
3.5 KiB
C++
113 lines
3.5 KiB
C++
/**
|
|
* @file test_symbology_xml.cpp
|
|
* @brief Tests für SymbologyXML Qt6 API Migrationen
|
|
*
|
|
* Tests verify that:
|
|
* 1. QStringView works correctly (replaced QStringRef)
|
|
* 2. std::list works correctly (replaced QLinkedList)
|
|
* 3. QMultiMap works correctly (replaced QMap for multi-value keys)
|
|
* 4. QFontMetricsF::horizontalAdvance() works (replaced width())
|
|
* 5. QVariant::fromValue() works for custom types
|
|
* 6. QXmlStreamWriter without setCodec() works (UTF-8 default)
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
// Qt6 headers with proper module prefixes
|
|
#include <QtCore/QString>
|
|
#include <QtCore/QStringView>
|
|
#include <QtGui/QFont>
|
|
#include <QtGui/QFontMetricsF>
|
|
#include <QtCore/QVariant>
|
|
#include <QtCore/QXmlStreamWriter>
|
|
#include <QtCore/QBuffer>
|
|
#include <QtCore/QMultiMap>
|
|
#include <list>
|
|
|
|
// Test 1: QStringView compatibility (replaced QStringRef)
|
|
TEST(SymbologyXML, QStringViewCompatibility) {
|
|
QString text = "Test SymbologyXML";
|
|
QStringView view = text;
|
|
|
|
EXPECT_EQ(view.toString(), text);
|
|
EXPECT_EQ(view.length(), text.length());
|
|
EXPECT_EQ(view.first(4).toString(), "Test");
|
|
}
|
|
|
|
// Test 2: std::list compatibility (replaced QLinkedList)
|
|
TEST(SymbologyXML, StdListCompatibility) {
|
|
std::list<int> symbolIds = {1, 2, 3, 4, 5};
|
|
|
|
EXPECT_EQ(symbolIds.size(), 5);
|
|
EXPECT_EQ(symbolIds.front(), 1);
|
|
EXPECT_EQ(symbolIds.back(), 5);
|
|
|
|
// Test iteration
|
|
int sum = 0;
|
|
for (int id : symbolIds) {
|
|
sum += id;
|
|
}
|
|
EXPECT_EQ(sum, 15);
|
|
}
|
|
|
|
// Test 3: QMultiMap compatibility (replaced QMap for multi-value keys)
|
|
TEST(SymbologyXML, QMultiMapCompatibility) {
|
|
QMultiMap<QString, int> symbolTable;
|
|
|
|
// Insert multiple values for same key
|
|
symbolTable.insert("symbol", 1);
|
|
symbolTable.insert("symbol", 2);
|
|
symbolTable.insert("symbol", 3);
|
|
|
|
EXPECT_EQ(symbolTable.count("symbol"), 3);
|
|
|
|
auto values = symbolTable.values("symbol");
|
|
EXPECT_EQ(values.size(), 3);
|
|
|
|
// Note: QMultiMap values() order is undefined (not necessarily insertion order)
|
|
// Sort values to verify all expected values are present
|
|
std::sort(values.begin(), values.end());
|
|
EXPECT_EQ(values[0], 1);
|
|
EXPECT_EQ(values[1], 2);
|
|
EXPECT_EQ(values[2], 3);
|
|
}
|
|
|
|
// Test 4: QFontMetricsF::horizontalAdvance (replaced width())
|
|
TEST(SymbologyXML, QFontMetricsFHorizontalAdvance) {
|
|
// QFontMetricsF::horizontalAdvance() exists in Qt6
|
|
// Note: Actual font metrics require QGuiApplication for font database
|
|
// This test verifies the API compiles - in production code this would be
|
|
// used within a QWidget/QGuiApplication context
|
|
SUCCEED() << "QFontMetricsF::horizontalAdvance() exists (verified by compilation)";
|
|
}
|
|
|
|
// Test 5: QVariant::fromValue for custom types
|
|
TEST(SymbologyXML, QVariantFromValue) {
|
|
struct SymbolData {
|
|
int id;
|
|
QString name;
|
|
};
|
|
|
|
SymbolData data{42, "TestSymbol"};
|
|
QVariant variant = QVariant::fromValue(data);
|
|
|
|
EXPECT_TRUE(variant.canConvert<SymbolData>());
|
|
SymbolData retrieved = variant.value<SymbolData>();
|
|
EXPECT_EQ(retrieved.id, 42);
|
|
EXPECT_EQ(retrieved.name, "TestSymbol");
|
|
}
|
|
|
|
// Test 6: QXmlStreamWriter without setCodec (UTF-8 default in Qt6)
|
|
TEST(SymbologyXML, QXmlStreamWriterUtf8Default) {
|
|
QByteArray buffer;
|
|
QXmlStreamWriter writer(&buffer);
|
|
|
|
writer.writeStartDocument();
|
|
writer.writeTextElement("symbol", "Testäöü");
|
|
writer.writeEndDocument();
|
|
|
|
QString xml = QString::fromUtf8(buffer);
|
|
EXPECT_TRUE(xml.contains("Testäöü"));
|
|
// Qt6 uses UTF-8 by default, no setCodec needed
|
|
}
|