Add JSON unit test, fix ring count output.
Shockingly there were no unit tests that did a simple write-then-read. This is important because it's easy to forget details such as trailing commas and the fact that uint8_t is a char.
This commit is contained in:
Binary file not shown.
@@ -140,7 +140,11 @@ void AutomationEngine::applySettings(const char* json, size_t jsonLength, View*
|
||||
MaterialInstance* const* materials, size_t materialCount, IndirectLight* ibl,
|
||||
utils::Entity sunlight, LightManager* lm, Scene* scene, Renderer* renderer) {
|
||||
JsonSerializer serializer;
|
||||
serializer.readJson(json, jsonLength, mSettings);
|
||||
if (!serializer.readJson(json, jsonLength, mSettings)) {
|
||||
std::string jsonWithTerminator(json, json + jsonLength);
|
||||
slog.e << "Badly formed JSON:\n" << jsonWithTerminator.c_str() << io::endl;
|
||||
return;
|
||||
}
|
||||
viewer::applySettings(mSettings->view, view);
|
||||
for (size_t i = 0; i < materialCount; i++) {
|
||||
viewer::applySettings(mSettings->material, materials[i]);
|
||||
|
||||
@@ -1205,9 +1205,9 @@ static std::ostream& operator<<(std::ostream& out, const DepthOfFieldOptions& in
|
||||
<< "\"enabled\": " << to_string(in.enabled) << ",\n"
|
||||
<< "\"filter\": " << (in.filter) << ",\n"
|
||||
<< "\"nativeResolution\": " << (in.nativeResolution) << ",\n"
|
||||
<< "\"foregroundRingCount\": " << (in.foregroundRingCount) << ",\n"
|
||||
<< "\"backgroundRingCount\": " << (in.backgroundRingCount) << ",\n"
|
||||
<< "\"fastGatherRingCount\": " << (in.fastGatherRingCount) << ",\n"
|
||||
<< "\"foregroundRingCount\": " << int(in.foregroundRingCount) << ",\n"
|
||||
<< "\"backgroundRingCount\": " << int(in.backgroundRingCount) << ",\n"
|
||||
<< "\"fastGatherRingCount\": " << int(in.fastGatherRingCount) << ",\n"
|
||||
<< "\"maxForegroundCOC\": " << (in.maxForegroundCOC) << ",\n"
|
||||
<< "\"maxBackgroundCOC\": " << (in.maxBackgroundCOC) << "\n"
|
||||
<< "}";
|
||||
@@ -1330,7 +1330,6 @@ bool JsonSerializer::readJson(const char* jsonChunk, size_t size, Settings* out)
|
||||
|
||||
int tokenCount = jsmn_parse(&parser, jsonChunk, size, nullptr, 0);
|
||||
if (tokenCount <= 0) {
|
||||
slog.e << "Badly formed JSON." << io::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1342,7 +1341,6 @@ bool JsonSerializer::readJson(const char* jsonChunk, size_t size, Settings* out)
|
||||
|
||||
if (tokenCount <= 0) {
|
||||
free(tokens);
|
||||
slog.e << "Badly formed JSON." << io::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,23 @@ TEST_F(ViewSettingsTest, JsonTestDefaults) {
|
||||
ASSERT_EQ(serializer.writeJson(settings2), serializer.writeJson(settings3));
|
||||
}
|
||||
|
||||
TEST_F(ViewSettingsTest, JsonTestSerialization) {
|
||||
auto canParse = [](bool parseResult, std::string json) {
|
||||
if (parseResult) {
|
||||
return testing::AssertionSuccess() << "Settings can be serialized.";
|
||||
} else {
|
||||
return testing::AssertionFailure() << "JSON has errors:\n" << json.c_str() << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
JsonSerializer serializer;
|
||||
Settings outSettings = {};
|
||||
std::string jsonstr = serializer.writeJson(outSettings);
|
||||
Settings inSettings = {};
|
||||
bool result = serializer.readJson(jsonstr.c_str(), jsonstr.size(), &inSettings);
|
||||
ASSERT_TRUE(canParse(result, jsonstr));
|
||||
}
|
||||
|
||||
TEST_F(ViewSettingsTest, JsonTestMaterial) {
|
||||
JsonSerializer serializer;
|
||||
Settings settings = {0};
|
||||
|
||||
Reference in New Issue
Block a user