summaryrefslogtreecommitdiff
path: root/test/style/style_parser.test.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2016-09-28 11:45:33 +0200
committerKonstantin Käfer <mail@kkaefer.com>2016-09-28 16:34:22 +0200
commit3f3fc7b7723698e44427e2a14a2f4906832800bf (patch)
tree5acadfa4d77817c41f612c89c93925a149cbcfc0 /test/style/style_parser.test.cpp
parenta8b007daa0e85ea4b1a4898fd591d55d0117cc85 (diff)
downloadqtlocation-mapboxgl-3f3fc7b7723698e44427e2a14a2f4906832800bf.tar.gz
[test] add .test.cpp suffix to test case files
Diffstat (limited to 'test/style/style_parser.test.cpp')
-rw-r--r--test/style/style_parser.test.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/test/style/style_parser.test.cpp b/test/style/style_parser.test.cpp
new file mode 100644
index 0000000000..e3c1da582f
--- /dev/null
+++ b/test/style/style_parser.test.cpp
@@ -0,0 +1,104 @@
+#include <mbgl/test/util.hpp>
+#include <mbgl/test/fixture_log_observer.hpp>
+
+#include <mbgl/style/parser.hpp>
+#include <mbgl/util/io.hpp>
+#include <mbgl/util/enum.hpp>
+#include <mbgl/util/string.hpp>
+#include <mbgl/util/tileset.hpp>
+
+#include <rapidjson/document.h>
+
+#include <iostream>
+#include <fstream>
+
+#include <dirent.h>
+
+using namespace mbgl;
+
+typedef std::pair<uint32_t, std::string> Message;
+typedef std::vector<Message> Messages;
+
+class StyleParserTest : public ::testing::TestWithParam<std::string> {};
+
+TEST_P(StyleParserTest, ParseStyle) {
+ const std::string base = std::string("test/fixtures/style_parser/") + GetParam();
+
+ rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> infoDoc;
+ infoDoc.Parse<0>(util::read_file(base + ".info.json").c_str());
+ ASSERT_FALSE(infoDoc.HasParseError());
+ ASSERT_TRUE(infoDoc.IsObject());
+
+ auto observer = new FixtureLogObserver();
+ Log::setObserver(std::unique_ptr<Log::Observer>(observer));
+
+ style::Parser parser;
+ auto error = parser.parse(util::read_file(base + ".style.json"));
+
+ if (error) {
+ Log::Error(Event::ParseStyle, "Failed to parse style: %s", util::toString(error).c_str());
+ }
+
+ ASSERT_TRUE(infoDoc.IsObject());
+ for (const auto& property : infoDoc.GetObject()) {
+ const std::string name { property.name.GetString(), property.name.GetStringLength() };
+ const JSValue &value = property.value;
+ ASSERT_EQ(true, value.IsObject());
+
+ if (value.HasMember("log")) {
+ const JSValue &js_log = value["log"];
+ ASSERT_EQ(true, js_log.IsArray());
+ for (auto& js_entry : js_log.GetArray()) {
+ ASSERT_EQ(true, js_entry.IsArray());
+ ASSERT_GE(4u, js_entry.Size());
+
+ const uint32_t count = js_entry[rapidjson::SizeType(0)].GetUint();
+ const FixtureLogObserver::LogMessage message {
+ *Enum<EventSeverity>::toEnum(js_entry[rapidjson::SizeType(1)].GetString()),
+ *Enum<Event>::toEnum(js_entry[rapidjson::SizeType(2)].GetString()),
+ int64_t(-1),
+ js_entry[rapidjson::SizeType(3)].GetString()
+ };
+
+ EXPECT_EQ(count, observer->count(message)) << "Message: " << message << std::endl;
+ }
+ }
+
+ const auto &unchecked = observer->unchecked();
+ if (unchecked.size()) {
+ std::cerr << "Unchecked Log Messages (" << base << "/" << name << "): " << std::endl << unchecked;
+ }
+
+ ASSERT_EQ(0u, unchecked.size());
+ }
+}
+
+INSTANTIATE_TEST_CASE_P(StyleParser, StyleParserTest, ::testing::ValuesIn([] {
+ std::vector<std::string> names;
+ const std::string ending = ".info.json";
+
+ const std::string style_directory = "test/fixtures/style_parser";
+ DIR *dir = opendir(style_directory.c_str());
+ if (dir != nullptr) {
+ for (dirent *dp = nullptr; (dp = readdir(dir)) != nullptr;) {
+ const std::string name = dp->d_name;
+ if (name.length() >= ending.length() && name.compare(name.length() - ending.length(), ending.length(), ending) == 0) {
+ names.push_back(name.substr(0, name.length() - ending.length()));
+ }
+ }
+ closedir(dir);
+ }
+
+ EXPECT_GT(names.size(), 0u);
+ return names;
+}()));
+
+TEST(StyleParser, FontStacks) {
+ style::Parser parser;
+ parser.parse(util::read_file("test/fixtures/style_parser/font_stacks.json"));
+ auto result = parser.fontStacks();
+ ASSERT_EQ(3u, result.size());
+ ASSERT_EQ(FontStack({"a"}), result[0]);
+ ASSERT_EQ(FontStack({"a", "b"}), result[1]);
+ ASSERT_EQ(FontStack({"a", "b", "c"}), result[2]);
+}