Commit 6d2f9cb4 by Gert Wollny Committed by Commit Bot

JsonSerializer: add method to store only a hash for vectors

This can be used to make the Json comaprison less noisy. Bug: angleproject:5856 Change-Id: I57df41eed3926647aaf8bcf97a7aea050e1c3d51 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2822255 Commit-Queue: Gert Wollny <gert.wollny@collabora.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 58eabfd7
...@@ -91,6 +91,12 @@ class JsonSerializer : public angle::NonCopyable ...@@ -91,6 +91,12 @@ class JsonSerializer : public angle::NonCopyable
mGroupValueStack.top()->AddMember(tag, array, mAllocator); mGroupValueStack.top()->AddMember(tag, array, mAllocator);
} }
template <typename T>
void addVectorAsHash(const std::string &name, const std::vector<T> &value)
{
addBlob(name, reinterpret_cast<const uint8_t *>(&value[0]), value.size() * sizeof(T));
}
private: private:
using ValuePointer = std::unique_ptr<rapidjson::Value>; using ValuePointer = std::unique_ptr<rapidjson::Value>;
......
...@@ -133,6 +133,39 @@ TEST_F(JsonSerializerTest, IntVectorValue) ...@@ -133,6 +133,39 @@ TEST_F(JsonSerializerTest, IntVectorValue)
check(expect); check(expect);
} }
// Test writing one vector of integer values
TEST_F(JsonSerializerTest, IntVectorAsBlobValue)
{
std::vector<int> v = {0, 1, -1};
js.addVectorAsHash("test2", v);
const std::string expect =
R"({
"context": {
"test2": "SHA1:6216A439C16A113E2F1E53AB63FB88877D3597F5"
}
})";
check(expect);
}
// Test writing one vector of short integer values
TEST_F(JsonSerializerTest, ShortVectorAsBlobValue)
{
std::vector<short> v = {0, 1, -1};
js.addVectorAsHash("test2", v);
const std::string expect =
R"({
"context": {
"test2": "SHA1:0BA7C0DE700CE0F8018D084B8CF447B150A9465D"
}
})";
check(expect);
}
// Test writing boolean values // Test writing boolean values
TEST_F(JsonSerializerTest, NamedBoolValues) TEST_F(JsonSerializerTest, NamedBoolValues)
{ {
......
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