diff --git a/map/style_tests/style_symbols_consistency_test.cpp b/map/style_tests/style_symbols_consistency_test.cpp new file mode 100644 index 0000000000..9e1d927cd2 --- /dev/null +++ b/map/style_tests/style_symbols_consistency_test.cpp @@ -0,0 +1,118 @@ +#include "testing/testing.hpp" + +#include "indexer/classificator_loader.hpp" +#include "indexer/drawing_rules.hpp" +#include "indexer/drules_include.hpp" +#include "indexer/map_style_reader.hpp" + +#include "coding/reader.hpp" +#include "coding/parse_xml.hpp" + +#include "base/logging.hpp" + +#include "std/array.hpp" +#include "std/string.hpp" +#include "std/unordered_set.hpp" + +namespace +{ + +class SdfParsingDispatcher +{ +public: + SdfParsingDispatcher(unordered_set & symbols) + : m_symbols(symbols) + {} + + bool Push(string const &) { return true; } + void Pop(string const &) {} + void CharData(string const &) {} + void AddAttr(string const & attribute, string const & value) + { + if (attribute == "name") + m_symbols.insert(value); + } + +private: + unordered_set & m_symbols; +}; + +unordered_set GetSymbolsSetFromDrawingRule() +{ + unordered_set symbols; + drule::rules().ForEachRule([&symbols](int, int, int, drule::BaseRule const * rule) + { + SymbolRuleProto const * const symbol = rule->GetSymbol(); + if (nullptr != symbol && symbol->has_name()) + symbols.insert(symbol->name()); + }); + return symbols; +} + +unordered_set GetSymbolsSetFromResourcesFile(string const & density) +{ + unordered_set symbols; + SdfParsingDispatcher dispatcher(symbols); + ReaderPtr reader = GetStyleReader().GetResourceReader("symbols.sdf", density); + ReaderSource > source(reader); + ParseXML(source, dispatcher); + return symbols; +} + +// returns s1 - s2 +unordered_set Subtract(unordered_set const & s1, unordered_set const & s2) +{ + unordered_set res(s1); + for (auto const & s : s2) + res.erase(s); + return res; +} + +array g_styles = +{{ + MapStyleLight, + MapStyleDark, + MapStyleClear +}}; + +array g_densities = +{{ + "ldpi", + "mdpi", + "hdpi", + "xhdpi", + "xxhdpi", + "6plus" +}}; + +} // namespace + +UNIT_TEST(Test_SymbolsConsistency) +{ + bool res = true; + + for (auto const style : g_styles) + { + GetStyleReader().SetCurrentStyle(style); + classificator::Load(); + + unordered_set const drawingRuleSymbols = GetSymbolsSetFromDrawingRule(); + + for (auto const & density : g_densities) + { + unordered_set const resourceStyles = GetSymbolsSetFromResourcesFile(density); + + unordered_set const s = Subtract(drawingRuleSymbols, resourceStyles); + + vector const missed(s.begin(), s.end()); + + if (!missed.empty()) + { + LOG(LINFO, ("Symbols mismatch: style", style, ", density", density, ", missed", missed)); + res = false; + } + } + } + + TEST(res, ()); +} diff --git a/map/style_tests/style_tests.pro b/map/style_tests/style_tests.pro new file mode 100644 index 0000000000..25763f9b5b --- /dev/null +++ b/map/style_tests/style_tests.pro @@ -0,0 +1,19 @@ +TARGET = style_tests +CONFIG += console warn_on +CONFIG -= app_bundle +TEMPLATE = app + +INCLUDEPATH += ../../3party/protobuf/src + +ROOT_DIR = ../.. +DEPENDENCIES = map indexer platform geometry coding base expat protobuf + +macx-*: LIBS *= "-framework IOKit" + +include($$ROOT_DIR/common.pri) + +QT *= core + +SOURCES += \ + ../../testing/testingmain.cpp \ + style_symbols_consistency_test.cpp \ diff --git a/omim.pro b/omim.pro index 6a538e1f5b..c2e6ed1e8a 100644 --- a/omim.pro +++ b/omim.pro @@ -79,7 +79,7 @@ CONFIG(desktop) { SUBDIRS += render/render_tests SUBDIRS += storage/storage_tests SUBDIRS += search/search_tests - SUBDIRS += map/map_tests map/benchmark_tool map/mwm_tests + SUBDIRS += map/map_tests map/benchmark_tool map/mwm_tests map/style_tests SUBDIRS += routing/routing_integration_tests SUBDIRS += routing/routing_tests SUBDIRS += generator/generator_tests