|
71 | 71 | #include "core/objects/object.h" |
72 | 72 | #include "core/objects/text_object.h" |
73 | 73 | #include "core/symbols/area_symbol.h" |
74 | | -#include "core/symbols/symbol.h" |
75 | 74 | #include "core/symbols/line_symbol.h" |
| 75 | +#include "core/symbols/symbol.h" |
| 76 | +#include "core/symbols/text_symbol.h" |
76 | 77 | #include "fileformats/file_format.h" |
77 | 78 | #include "fileformats/file_format_registry.h" |
78 | 79 | #include "fileformats/file_import_export.h" |
79 | 80 | #include "fileformats/iof_course_export.h" |
80 | 81 | #include "fileformats/kml_course_export.h" |
81 | 82 | #include "fileformats/ocd_file_export.h" |
82 | | -#include "fileformats/ocd_file_import.h" |
83 | 83 | #include "fileformats/ocd_file_format.h" |
| 84 | +#include "fileformats/ocd_file_import.h" |
84 | 85 | #include "fileformats/ocd_types.h" |
85 | 86 | #include "fileformats/ocd_types_v8.h" |
86 | 87 | #include "fileformats/ocd_types_v12.h" |
@@ -143,7 +144,7 @@ namespace QTest |
143 | 144 | ba += ", overprinting"; |
144 | 145 | return qstrdup(ba.data()); |
145 | 146 | } |
146 | | -} |
| 147 | +} // namespace QTest |
147 | 148 |
|
148 | 149 | #endif |
149 | 150 |
|
@@ -1787,6 +1788,102 @@ void FileFormatTest::ocdAreaSymbolTest() |
1787 | 1788 | } |
1788 | 1789 | } |
1789 | 1790 |
|
| 1791 | +void FileFormatTest::ocdTextSymbolTest_data() |
| 1792 | +{ |
| 1793 | + QTest::addColumn<int>("format_version"); |
| 1794 | + |
| 1795 | +#ifndef MAPPER_BIG_ENDIAN |
| 1796 | + static struct { int version; const char* id; } const tests[] = { |
| 1797 | + { 8, "OCD8" }, |
| 1798 | + { 9, "OCD9" }, |
| 1799 | + { 10, "OCD10" }, |
| 1800 | + { 11, "OCD11" }, |
| 1801 | + { 12, "OCD12" }, |
| 1802 | + }; |
| 1803 | + for (auto& t : tests) |
| 1804 | + { |
| 1805 | + QTest::newRow(t.id) << t.version; |
| 1806 | + } |
| 1807 | +#endif |
| 1808 | +} |
| 1809 | + |
| 1810 | +void FileFormatTest::ocdTextSymbolTest() |
| 1811 | +{ |
| 1812 | + QFETCH(int, format_version); |
| 1813 | + |
| 1814 | + auto* format_id = QTest::currentDataTag(); |
| 1815 | + const auto* format = FileFormats.findFormat(format_id); |
| 1816 | + QVERIFY(format); |
| 1817 | + |
| 1818 | + static const auto filepath = QString::fromLatin1("data:text-symbol.omap"); |
| 1819 | + QVERIFY(QFileInfo::exists(filepath)); |
| 1820 | + |
| 1821 | + // Load the test map |
| 1822 | + auto expected = std::make_unique<Map>(); |
| 1823 | + QVERIFY(expected->loadFrom(filepath)); |
| 1824 | + |
| 1825 | + // Save and load the map |
| 1826 | + auto actual = saveAndLoadMap(*expected, format); |
| 1827 | + QVERIFY2(actual, "Exception while importing / exporting."); |
| 1828 | + QCOMPARE(actual->property(OcdFileFormat::versionProperty()), format_version); |
| 1829 | + |
| 1830 | + // Symbols |
| 1831 | + QCOMPARE(actual->getNumSymbols(), expected->getNumSymbols()); |
| 1832 | + for (int i = 0; i < actual->getNumSymbols(); ++i) |
| 1833 | + { |
| 1834 | + auto* expected_symbol = expected->getSymbol(i); |
| 1835 | + if (expected_symbol->getType() != Symbol::Text) // actually redundant for the given test data |
| 1836 | + continue; |
| 1837 | + |
| 1838 | + auto* actual_symbol = actual->getSymbol(i); |
| 1839 | + QCOMPARE(actual_symbol->getType(), Symbol::Text); |
| 1840 | + |
| 1841 | + COMPARE_SYMBOL_PROPERTY(actual_symbol->getNumberComponent(0), expected_symbol->getNumberComponent(0), *expected_symbol); |
| 1842 | + // OCD limitation: always two number components |
| 1843 | + if (expected_symbol->getNumberComponent(1) != -1) |
| 1844 | + COMPARE_SYMBOL_PROPERTY(actual_symbol->getNumberComponent(1), expected_symbol->getNumberComponent(1), *expected_symbol); |
| 1845 | + |
| 1846 | + QVERIFY(expected_symbol->stateEquals(actual_symbol)); |
| 1847 | + |
| 1848 | + auto* expected_text_symbol = expected_symbol->asText(); |
| 1849 | + auto* actual_text_symbol = actual_symbol->asText(); |
| 1850 | + |
| 1851 | + COMPARE_SYMBOL_PROPERTY(bool(actual_text_symbol->getColor()), bool(expected_text_symbol->getColor()), *expected_text_symbol); |
| 1852 | + if (expected_text_symbol->getColor()) |
| 1853 | + COMPARE_SYMBOL_PROPERTY(actual_text_symbol->getColor()->operator QRgb(), expected_text_symbol->getColor()->operator QRgb(), *expected_text_symbol); |
| 1854 | + COMPARE_SYMBOL_PROPERTY(bool(actual_text_symbol->getFramingColor()), bool(expected_text_symbol->getFramingColor()), *expected_text_symbol); |
| 1855 | + if (expected_text_symbol->getFramingColor()) |
| 1856 | + COMPARE_SYMBOL_PROPERTY(actual_text_symbol->getFramingColor()->operator QRgb(), expected_text_symbol->getFramingColor()->operator QRgb(), *expected_text_symbol); |
| 1857 | + COMPARE_SYMBOL_PROPERTY(bool(actual_text_symbol->getLineBelowColor()), bool(expected_text_symbol->getLineBelowColor()), *expected_text_symbol); |
| 1858 | + if (expected_text_symbol->getLineBelowColor()) |
| 1859 | + COMPARE_SYMBOL_PROPERTY(actual_text_symbol->getLineBelowColor()->operator QRgb(), expected_text_symbol->getLineBelowColor()->operator QRgb(), *expected_text_symbol); |
| 1860 | + |
| 1861 | + COMPARE_SYMBOL_PROPERTY(actual_text_symbol->getFramingMode(), expected_text_symbol->getFramingMode(), *expected_text_symbol); |
| 1862 | + if (expected_text_symbol->getFramingMode() == TextSymbol::FramingMode::ShadowFraming) |
| 1863 | + { |
| 1864 | + COMPARE_SYMBOL_PROPERTY(actual_text_symbol->getFramingShadowYOffset(), expected_text_symbol->getFramingShadowYOffset(), *expected_text_symbol); |
| 1865 | + COMPARE_SYMBOL_PROPERTY(actual_text_symbol->getFramingShadowXOffset(), expected_text_symbol->getFramingShadowXOffset(), *expected_text_symbol); |
| 1866 | + } |
| 1867 | + if (expected_text_symbol->getFramingMode() == TextSymbol::FramingMode::LineFraming) |
| 1868 | + { |
| 1869 | + COMPARE_SYMBOL_PROPERTY(actual_text_symbol->getFramingLineHalfWidth(), expected_text_symbol->getFramingLineHalfWidth(), *expected_text_symbol); |
| 1870 | + } |
| 1871 | + |
| 1872 | + if (expected_text_symbol->hasLineBelow()) |
| 1873 | + { |
| 1874 | + COMPARE_SYMBOL_PROPERTY(actual_text_symbol->getLineBelowWidth(), expected_text_symbol->getLineBelowWidth(), *expected_text_symbol); |
| 1875 | + COMPARE_SYMBOL_PROPERTY(actual_text_symbol->getLineBelowDistance(), expected_text_symbol->getLineBelowDistance(), *expected_text_symbol); |
| 1876 | + } |
| 1877 | + |
| 1878 | + COMPARE_SYMBOL_PROPERTY(actual_text_symbol->getNumCustomTabs(), expected_text_symbol->getNumCustomTabs(), *expected_text_symbol); |
| 1879 | + if (expected_text_symbol->getNumCustomTabs()) |
| 1880 | + { |
| 1881 | + for (int i = 0; i < expected_text_symbol->getNumCustomTabs(); ++i) |
| 1882 | + COMPARE_SYMBOL_PROPERTY(actual_text_symbol->getCustomTab(i), expected_text_symbol->getCustomTab(i), *expected_text_symbol); |
| 1883 | + } |
| 1884 | + } |
| 1885 | +} |
| 1886 | + |
1790 | 1887 |
|
1791 | 1888 | /* |
1792 | 1889 | * We don't need a real GUI window. |
|
0 commit comments