File indexing completed on 2024-04-14 04:35:56

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include <datatypes.h>
0008 
0009 #include <QTest>
0010 
0011 class OsmTypeTest : public QObject
0012 {
0013     Q_OBJECT
0014 private Q_SLOTS:
0015     void testZIndex_data()
0016     {
0017         QTest::addColumn<double>("lon");
0018         QTest::addColumn<double>("lat");
0019         QTest::addColumn<qulonglong>("z");
0020 
0021         QTest::newRow("-180,-90") << -180.0 << -90.0 << 0ull;
0022         QTest::newRow("-179,-90") << -179.0 << -90.0 << 143488451117056ull;
0023         QTest::newRow("-180,-89") << -180.0 << -89.0 << 71744225558528ull;
0024         QTest::newRow("0,0") << 0.0 << 0.0 << 3286330935456890880ull;
0025         QTest::newRow("180,90") << 180.0 << 90.0 << 13145323741827563520ull;
0026     }
0027 
0028     void testZIndex()
0029     {
0030         QFETCH(double, lat);
0031         QFETCH(double, lon);
0032         QFETCH(qulonglong, z);
0033 
0034         OSM::Coordinate coord(lat, lon);
0035         QCOMPARE(coord.z(), z);
0036 
0037         OSM::Coordinate coord2(z);
0038         QCOMPARE(coord2.latitude, coord.latitude);
0039         QCOMPARE(coord2.longitude, coord.longitude);
0040     }
0041 
0042     void testTagKeys()
0043     {
0044         OSM::DataSet ds;
0045 
0046         OSM::TagKey nullKey;
0047         QCOMPARE(nullKey, ds.tagKey("akey"));
0048         QCOMPARE(nullKey.isNull(), true);
0049 
0050         const auto key1 = ds.makeTagKey("akey", OSM::StringMemory::Persistent);
0051         QCOMPARE(key1, ds.makeTagKey("akey", OSM::StringMemory::Persistent));
0052         QCOMPARE(key1, ds.tagKey("akey"));
0053         QCOMPARE(key1.isNull(), false);
0054         QCOMPARE(key1.name(), "akey");
0055         QVERIFY(key1 != nullKey);
0056 
0057         const auto key2 = ds.makeTagKey("bkey", OSM::StringMemory::Transient);
0058         QVERIFY(key1 != key2);
0059         QCOMPARE(key2, ds.makeTagKey("bkey", OSM::StringMemory::Transient));
0060 
0061         OSM::Node node;
0062         OSM::setTagValue(node, key1, "avalue");
0063         OSM::setTagValue(node, key2, "bvalue-1");
0064         OSM::setTagValue(node, key2, "bvalue");
0065 
0066         QCOMPARE(OSM::tagValue(node, key1), "avalue");
0067         QCOMPARE(OSM::tagValue(node, key2), "bvalue");
0068 
0069         QCOMPARE(OSM::tagValue(node, "bkey"), "bvalue");
0070         QCOMPARE(OSM::tagValue(node, "akey"), "avalue");
0071     }
0072 };
0073 
0074 QTEST_GUILESS_MAIN(OsmTypeTest)
0075 
0076 #include "osmtypetest.moc"