Commit 6362dcf1 by Gert Wollny Committed by Commit Bot

JsonSerializer: Add tests for sorting and non-unique keys

Bug: angleproject:5853 Change-Id: I85e64900a58a2706087b71769470bb33fb4e8522 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2824434 Commit-Queue: Gert Wollny <gert.wollny@collabora.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 212849e9
...@@ -139,7 +139,6 @@ TEST_F(JsonSerializerTest, IntVectorAsBlobValue) ...@@ -139,7 +139,6 @@ TEST_F(JsonSerializerTest, IntVectorAsBlobValue)
std::vector<int> v = {0, 1, -1}; std::vector<int> v = {0, 1, -1};
js.addVectorAsHash("test2", v); js.addVectorAsHash("test2", v);
const std::string expect = const std::string expect =
R"({ R"({
"context": { "context": {
...@@ -149,19 +148,49 @@ TEST_F(JsonSerializerTest, IntVectorAsBlobValue) ...@@ -149,19 +148,49 @@ TEST_F(JsonSerializerTest, IntVectorAsBlobValue)
check(expect); check(expect);
} }
// Test unsorted input gets sorted
TEST_F(JsonSerializerTest, SortValues1)
{
js.addScalar("b", 1.0);
js.addScalar("a", 2.0);
const std::string expect =
R"({
"context": {
"a": 2.0,
"b": 1.0
}
})";
check(expect);
}
// Test writing one vector of short integer values // Test writing one vector of short integer values
TEST_F(JsonSerializerTest, ShortVectorAsBlobValue) TEST_F(JsonSerializerTest, ShortVectorAsBlobValue)
{ {
std::vector<short> v = {0, 1, -1}; std::vector<short> v = {0, 1, -1};
js.addVectorAsHash("test2", v); js.addVectorAsHash("test2", v);
const std::string expect = const std::string expect =
R"({ R"({
"context": { "context": {
"test2": "SHA1:0BA7C0DE700CE0F8018D084B8CF447B150A9465D" "test2": "SHA1:0BA7C0DE700CE0F8018D084B8CF447B150A9465D"
} }
})"; })";
check(expect);
}
// Test adding the same key twice
TEST_F(JsonSerializerTest, KeyUsedTwice)
{
js.addScalar("a", 1.0);
js.addScalar("a", 1.0);
const std::string expect =
R"({
"context": {
"a": 1.0,
"a": 1.0
}
})";
check(expect); check(expect);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment