Remove redundant Qt6 migration comments that restate obvious API changes: - QtConcurrent::run parameter order explanations (preserved where lambda wrapping needed) - QStringRef/QStringView API changes (shortened to essential info) - QComboBox::activated signal signature change - QMap::unite() removal semantics - QAction include path change - QMouseEvent/QWheelEvent position() API - QList/QVector equivalence in Qt6 - QFuture continuation API - Code generation comments Preserved comments explaining non-obvious Qt6 behavior or necessary API migration details. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
251 lines
7.0 KiB
C++
251 lines
7.0 KiB
C++
/**
|
|
* @RDE_HEADER@
|
|
* Unit Tests for SymbologyImpl Module - Qt6 Migration
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <QCoreApplication>
|
|
#include <QString>
|
|
#include <QList>
|
|
#include <QMap>
|
|
#include <QFuture>
|
|
#include <QtConcurrent>
|
|
#include <QColor>
|
|
|
|
namespace
|
|
{
|
|
// Mock class to simulate symbol dictionary behavior
|
|
class MockSymbolDictionary
|
|
{
|
|
public:
|
|
MockSymbolDictionary() : m_loaded(false) {}
|
|
|
|
bool load()
|
|
{
|
|
m_loaded = true;
|
|
return true;
|
|
}
|
|
|
|
bool isLoaded() const { return m_loaded; }
|
|
|
|
int symbolCount() const { return m_symbols.size(); }
|
|
|
|
void addSymbol(const QString& name, const QColor& color)
|
|
{
|
|
m_symbols.insert(name, color);
|
|
}
|
|
|
|
QColor getSymbol(const QString& name) const
|
|
{
|
|
return m_symbols.value(name, QColor());
|
|
}
|
|
|
|
private:
|
|
bool m_loaded;
|
|
QMap<QString, QColor> m_symbols;
|
|
};
|
|
}
|
|
|
|
// Test SymbologyImpl basic operations
|
|
TEST(SymbologyImplTest, SymbolDictionary_BasicOperations)
|
|
{
|
|
MockSymbolDictionary dict;
|
|
|
|
EXPECT_FALSE(dict.isLoaded());
|
|
EXPECT_EQ(dict.symbolCount(), 0);
|
|
|
|
dict.load();
|
|
EXPECT_TRUE(dict.isLoaded());
|
|
|
|
dict.addSymbol(QStringLiteral("Military"), QColor(Qt::blue));
|
|
dict.addSymbol(QStringLiteral("Civilian"), QColor(Qt::green));
|
|
|
|
EXPECT_EQ(dict.symbolCount(), 2);
|
|
EXPECT_EQ(dict.getSymbol(QStringLiteral("Military")), QColor(Qt::blue));
|
|
EXPECT_EQ(dict.getSymbol(QStringLiteral("Civilian")), QColor(Qt::green));
|
|
}
|
|
|
|
// Test SymbologyImpl Qt6 QFuture continuation pattern
|
|
TEST(SymbologyImplTest, Qt6_QFuture_Continuation_Pattern)
|
|
{
|
|
// This test verifies the pattern used in symbol_dictionary_impl.cpp
|
|
|
|
QFuture<int> future = QtConcurrent::run([]() {
|
|
return 42; // Simulate symbol loading count
|
|
});
|
|
|
|
// QFuture::then() for continuations in Qt6
|
|
QFuture<QString> continued = future.then([](QFuture<int> result) {
|
|
int count = result.result();
|
|
return QStringLiteral("Loaded %1 symbols").arg(count);
|
|
});
|
|
|
|
// Wait for completion
|
|
continued.waitForFinished();
|
|
|
|
EXPECT_EQ(continued.result(), QStringLiteral("Loaded 42 symbols"));
|
|
}
|
|
|
|
// Test SymbologyImpl Qt6 API compatibility
|
|
TEST(SymbologyImplTest, Qt6_API_Compatibility)
|
|
{
|
|
// Test QString operations (Qt6)
|
|
QString symbolName = QStringLiteral("StandardSymbol");
|
|
EXPECT_EQ(symbolName, QStringLiteral("StandardSymbol"));
|
|
|
|
// Test QList operations (Qt6)
|
|
QList<QString> symbolNames;
|
|
symbolNames << QStringLiteral("Symbol1")
|
|
<< QStringLiteral("Symbol2")
|
|
<< QStringLiteral("Symbol3");
|
|
|
|
EXPECT_EQ(symbolNames.size(), 3);
|
|
|
|
QVector<QString> symbolVector = symbolNames;
|
|
EXPECT_EQ(symbolVector.size(), 3);
|
|
|
|
// Test iteration
|
|
int count = 0;
|
|
for (const auto& name : symbolNames)
|
|
{
|
|
EXPECT_FALSE(name.isEmpty());
|
|
++count;
|
|
}
|
|
EXPECT_EQ(count, 3);
|
|
}
|
|
|
|
// Test SymbologyImpl color operations
|
|
TEST(SymbologyImplTest, Color_Operations)
|
|
{
|
|
// Test QColor operations
|
|
QColor red(Qt::red);
|
|
EXPECT_EQ(red.red(), 255);
|
|
EXPECT_EQ(red.green(), 0);
|
|
EXPECT_EQ(red.blue(), 0);
|
|
|
|
QColor blue(0, 0, 255);
|
|
EXPECT_EQ(blue.blue(), 255);
|
|
|
|
// Test color comparison
|
|
QColor blue2(0, 0, 255);
|
|
EXPECT_EQ(blue, blue2);
|
|
|
|
// Test invalid color
|
|
QColor invalid;
|
|
EXPECT_FALSE(invalid.isValid());
|
|
}
|
|
|
|
// Test SymbologyImpl container operations
|
|
TEST(SymbologyImplTest, Container_Operations)
|
|
{
|
|
// Test QMap operations
|
|
QMap<QString, int> symbolCounts;
|
|
symbolCounts.insert(QStringLiteral("Military"), 10);
|
|
symbolCounts.insert(QStringLiteral("Civilian"), 5);
|
|
symbolCounts.insert(QStringLiteral("Emergency"), 3);
|
|
|
|
EXPECT_EQ(symbolCounts.size(), 3);
|
|
EXPECT_EQ(symbolCounts[QStringLiteral("Military")], 10);
|
|
EXPECT_EQ(symbolCounts[QStringLiteral("Civilian")], 5);
|
|
EXPECT_EQ(symbolCounts[QStringLiteral("Emergency")], 3);
|
|
|
|
// Test iteration
|
|
int total = 0;
|
|
for (auto it = symbolCounts.begin(); it != symbolCounts.end(); ++it)
|
|
{
|
|
total += it.value();
|
|
}
|
|
EXPECT_EQ(total, 18);
|
|
}
|
|
|
|
// Test SymbologyImpl async loading simulation
|
|
TEST(SymbologyImplTest, Async_Loading_Simulation)
|
|
{
|
|
// Simulate async symbol dictionary loading
|
|
bool loadComplete = false;
|
|
int loadedCount = 0;
|
|
|
|
QFuture<int> loadFuture = QtConcurrent::run([&loadComplete, &loadedCount]() {
|
|
// Simulate loading delay
|
|
loadedCount = 100;
|
|
loadComplete = true;
|
|
return loadedCount;
|
|
});
|
|
|
|
// Wait for completion
|
|
loadFuture.waitForFinished();
|
|
|
|
EXPECT_TRUE(loadComplete);
|
|
EXPECT_EQ(loadedCount, 100);
|
|
}
|
|
|
|
// Test SymbologyImpl error handling
|
|
TEST(SymbologyImplTest, Error_Handling)
|
|
{
|
|
// Test error state handling
|
|
bool hasError = false;
|
|
QString errorMessage;
|
|
|
|
// Simulate error condition
|
|
hasError = true;
|
|
errorMessage = QStringLiteral("Symbol dictionary load failed");
|
|
|
|
EXPECT_TRUE(hasError);
|
|
EXPECT_FALSE(errorMessage.isEmpty());
|
|
EXPECT_EQ(errorMessage, QStringLiteral("Symbol dictionary load failed"));
|
|
|
|
// Clear error
|
|
hasError = false;
|
|
errorMessage.clear();
|
|
|
|
EXPECT_FALSE(hasError);
|
|
EXPECT_TRUE(errorMessage.isEmpty());
|
|
}
|
|
|
|
// Test SymbologyImpl ArcGIS integration points
|
|
TEST(SymbologyImplTest, ArcGIS_Integration_Points)
|
|
{
|
|
// These tests verify the integration points for ArcGIS SDK v300
|
|
// The actual ArcGIS objects require full SDK initialization
|
|
|
|
// Test include path verification (compile-time check)
|
|
// In actual code: #include <ArcGISRuntime/Symbol.h> (no arcgis/ prefix)
|
|
|
|
// Verify string operations used in ArcGIS integration
|
|
QString symbologyPath = QStringLiteral("/path/to/symbology");
|
|
EXPECT_TRUE(symbologyPath.startsWith(QStringLiteral("/")));
|
|
|
|
// Test symbology properties
|
|
QVariantMap symbologyProperties;
|
|
symbologyProperties.insert(QStringLiteral("version"), 300);
|
|
symbologyProperties.insert(QStringLiteral("format"), QStringLiteral("stylx"));
|
|
|
|
EXPECT_EQ(symbologyProperties[QStringLiteral("version")].toInt(), 300);
|
|
EXPECT_EQ(symbologyProperties[QStringLiteral("format")].toString(), QStringLiteral("stylx"));
|
|
}
|
|
|
|
// Test SymbologyImpl edge cases
|
|
TEST(SymbologyImplTest, Edge_Cases)
|
|
{
|
|
// Test empty symbol dictionary
|
|
MockSymbolDictionary emptyDict;
|
|
EXPECT_FALSE(emptyDict.isLoaded());
|
|
EXPECT_EQ(emptyDict.symbolCount(), 0);
|
|
|
|
// Test non-existent symbol
|
|
emptyDict.load();
|
|
QColor nonExistent = emptyDict.getSymbol(QStringLiteral("NonExistent"));
|
|
EXPECT_FALSE(nonExistent.isValid());
|
|
|
|
// Test duplicate symbol names (last one wins)
|
|
MockSymbolDictionary dict;
|
|
dict.load();
|
|
dict.addSymbol(QStringLiteral("Duplicate"), QColor(Qt::red));
|
|
dict.addSymbol(QStringLiteral("Duplicate"), QColor(Qt::blue));
|
|
|
|
EXPECT_EQ(dict.symbolCount(), 1);
|
|
EXPECT_EQ(dict.getSymbol(QStringLiteral("Duplicate")), QColor(Qt::blue));
|
|
} |