MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / TEST

Function TEST

data/config/ConfigSchemaValidationTest.cpp:47–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47TEST(ConfigSchemaValidationTest, BundledConfigsMatchSchema) {
48 std::unique_ptr<Runfiles> runfiles(Runfiles::CreateForTest());
49 ASSERT_NE(nullptr, runfiles);
50
51 // OPENCC_CONFIG_SCHEMA_TEST_FILE must be a workspace-relative path,
52 // e.g. "data/config/s2t.json" or "test/config_test/config_test.json".
53 const std::string configFile = OPENCC_CONFIG_SCHEMA_TEST_FILE;
54 const std::string schemaPath =
55 runfiles->Rlocation("_main/data/config/opencc_config.schema.json");
56 const std::string schemaJson = ReadFile(schemaPath);
57 rapidjson::Document schemaDoc;
58 schemaDoc.Parse(schemaJson.c_str());
59 ASSERT_FALSE(schemaDoc.HasParseError())
60 << "schema parse error at offset " << schemaDoc.GetErrorOffset() << ": "
61 << rapidjson::GetParseError_En(schemaDoc.GetParseError());
62 ASSERT_TRUE(schemaDoc.IsObject());
63 rapidjson::SchemaDocument schema(schemaDoc);
64
65 const std::string configPath = runfiles->Rlocation("_main/" + configFile);
66 const std::string configJson = ReadFile(configPath);
67 rapidjson::Document configDoc;
68 configDoc.Parse(configJson.c_str());
69 ASSERT_FALSE(configDoc.HasParseError())
70 << configFile << " parse error at offset " << configDoc.GetErrorOffset()
71 << ": " << rapidjson::GetParseError_En(configDoc.GetParseError());
72
73 rapidjson::SchemaValidator validator(schema);
74 EXPECT_TRUE(configDoc.Accept(validator))
75 << configFile << " violates schema at document path "
76 << StringifyPointer(validator.GetInvalidDocumentPointer())
77 << ", schema path "
78 << StringifyPointer(validator.GetInvalidSchemaPointer()) << ", keyword "
79 << validator.GetInvalidSchemaKeyword();
80}
81
82} // namespace
83} // namespace opencc

Callers

nothing calls this directly

Calls 9

StringifyPointerFunction · 0.85
GetParseErrorMethod · 0.80
ReadFileFunction · 0.70
ParseMethod · 0.45
HasParseErrorMethod · 0.45
GetErrorOffsetMethod · 0.45

Tested by

no test coverage detected