forked from organicmaps/organicmaps
Added styles symbols consistency test
This commit is contained in:
parent
0dd108f117
commit
450d03b7a9
3 changed files with 138 additions and 1 deletions
118
map/style_tests/style_symbols_consistency_test.cpp
Normal file
118
map/style_tests/style_symbols_consistency_test.cpp
Normal file
|
@ -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<string> & 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<string> & m_symbols;
|
||||
};
|
||||
|
||||
unordered_set<string> GetSymbolsSetFromDrawingRule()
|
||||
{
|
||||
unordered_set<string> 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<string> GetSymbolsSetFromResourcesFile(string const & density)
|
||||
{
|
||||
unordered_set<string> symbols;
|
||||
SdfParsingDispatcher dispatcher(symbols);
|
||||
ReaderPtr<Reader> reader = GetStyleReader().GetResourceReader("symbols.sdf", density);
|
||||
ReaderSource<ReaderPtr<Reader> > source(reader);
|
||||
ParseXML(source, dispatcher);
|
||||
return symbols;
|
||||
}
|
||||
|
||||
// returns s1 - s2
|
||||
unordered_set<string> Subtract(unordered_set<string> const & s1, unordered_set<string> const & s2)
|
||||
{
|
||||
unordered_set<string> res(s1);
|
||||
for (auto const & s : s2)
|
||||
res.erase(s);
|
||||
return res;
|
||||
}
|
||||
|
||||
array<MapStyle, 3> g_styles =
|
||||
{{
|
||||
MapStyleLight,
|
||||
MapStyleDark,
|
||||
MapStyleClear
|
||||
}};
|
||||
|
||||
array<string, 6> 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<string> const drawingRuleSymbols = GetSymbolsSetFromDrawingRule();
|
||||
|
||||
for (auto const & density : g_densities)
|
||||
{
|
||||
unordered_set<string> const resourceStyles = GetSymbolsSetFromResourcesFile(density);
|
||||
|
||||
unordered_set<string> const s = Subtract(drawingRuleSymbols, resourceStyles);
|
||||
|
||||
vector<string> const missed(s.begin(), s.end());
|
||||
|
||||
if (!missed.empty())
|
||||
{
|
||||
LOG(LINFO, ("Symbols mismatch: style", style, ", density", density, ", missed", missed));
|
||||
res = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(res, ());
|
||||
}
|
19
map/style_tests/style_tests.pro
Normal file
19
map/style_tests/style_tests.pro
Normal file
|
@ -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 \
|
2
omim.pro
2
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
|
||||
|
|
Loading…
Add table
Reference in a new issue