Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Unified Diff: test/cctest/test-traced-value.cc

Issue 2399463004: [tracing] Add support for TracedValue JSON serializer. (Closed)
Patch Set: addressing nits Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-traced-value.cc
diff --git a/test/cctest/test-traced-value.cc b/test/cctest/test-traced-value.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5a8b9ab9c498bf3009d563f8b6f458d9b45275e2
--- /dev/null
+++ b/test/cctest/test-traced-value.cc
@@ -0,0 +1,125 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/tracing/traced-value.h"
+#include "test/cctest/cctest.h"
+
+using v8::tracing::TracedValue;
+
+TEST(FlatDictionary) {
+ auto value = TracedValue::Create();
+ value->SetInteger("int", 2014);
+ value->SetDouble("double", 0.0);
+ value->SetBoolean("bool", true);
+ value->SetString("string", "string");
+ std::string json = "PREFIX";
+ value->AppendAsTraceFormat(&json);
+ CHECK_EQ(
+ "PREFIX{\"int\":2014,\"double\":0.000000,\"bool\":true,\"string\":"
+ "\"string\"}",
+ json);
+}
+
+TEST(NoDotPathExpansion) {
+ auto value = TracedValue::Create();
+ value->SetInteger("in.t", 2014);
+ value->SetDouble("doub.le", 0.0);
+ value->SetBoolean("bo.ol", true);
+ value->SetString("str.ing", "str.ing");
+ std::string json;
+ value->AppendAsTraceFormat(&json);
+ CHECK_EQ(
+ "{\"in.t\":2014,\"doub.le\":0.000000,\"bo.ol\":true,\"str.ing\":\"str."
+ "ing\"}",
+ json);
+}
+
+TEST(Hierarchy) {
+ auto value = TracedValue::Create();
+ value->SetInteger("i0", 2014);
+ value->BeginDictionary("dict1");
+ value->SetInteger("i1", 2014);
+ value->BeginDictionary("dict2");
+ value->SetBoolean("b2", false);
+ value->EndDictionary();
+ value->SetString("s1", "foo");
+ value->EndDictionary();
+ value->SetDouble("d0", 0.0);
+ value->SetBoolean("b0", true);
+ value->BeginArray("a1");
+ value->AppendInteger(1);
+ value->AppendBoolean(true);
+ value->BeginDictionary();
+ value->SetInteger("i2", 3);
+ value->EndDictionary();
+ value->EndArray();
+ value->SetString("s0", "foo");
+
+ value->BeginArray("arr1");
+ value->BeginDictionary();
+ value->EndDictionary();
+ value->BeginArray();
+ value->EndArray();
+ value->BeginDictionary();
+ value->EndDictionary();
+ value->EndArray();
+
+ std::string json;
+ value->AppendAsTraceFormat(&json);
+ CHECK_EQ(
+ "{\"i0\":2014,\"dict1\":{\"i1\":2014,\"dict2\":{\"b2\":false},"
+ "\"s1\":\"foo\"},\"d0\":0.000000,\"b0\":true,\"a1\":[1,true,{\"i2\":3}],"
+ "\"s0\":\"foo\",\"arr1\":[{},[],{}]}",
+ json);
+}
+
+TEST(LongStrings) {
+ std::string long_string = "supercalifragilisticexpialidocious";
+ std::string long_string2 = "0123456789012345678901234567890123456789";
+ char long_string3[4096];
+ for (size_t i = 0; i < sizeof(long_string3); ++i)
+ long_string3[i] = static_cast<char>('a' + (i % 26));
+ long_string3[sizeof(long_string3) - 1] = '\0';
+
+ auto value = TracedValue::Create();
+ value->SetString("a", "short");
+ value->SetString("b", long_string);
+ value->BeginArray("c");
+ value->AppendString(long_string2);
+ value->AppendString("");
+ value->BeginDictionary();
+ value->SetString("a", long_string3);
+ value->EndDictionary();
+ value->EndArray();
+
+ std::string json;
+ value->AppendAsTraceFormat(&json);
+ CHECK_EQ("{\"a\":\"short\",\"b\":\"" + long_string + "\",\"c\":[\"" +
+ long_string2 + "\",\"\",{\"a\":\"" + long_string3 + "\"}]}",
+ json);
+}
+
+TEST(Escaping) {
+ const char* string1 = "abc\"\'\\\\x\"y\'z\n\x09\x17";
+ std::string chars127;
+ for (int i = 1; i <= 127; ++i) {
+ chars127 += static_cast<char>(i);
+ }
+ auto value = TracedValue::Create();
+ value->SetString("a", string1);
+ value->SetString("b", chars127);
+
+ std::string json;
+ value->AppendAsTraceFormat(&json);
+ // Cannot use the expected value literal directly in CHECK_EQ
+ // as it fails to process # character on Windows.
+ const char* expected =
+ "{\"a\":\"abc\\\"\'\\\\\\\\x\\\"y\'z\\n\\t\\u0017\",\"b\":"
+ "\"\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\u0008\\t\\n\\u000B"
+ "\\u000C\\u000D\\u000E\\u000F\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\"
+ "u0016\\u0017\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F "
+ "!\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`"
+ "abcdefghijklmnopqrstuvwxyz{|}~\177\"}";
+ CHECK_EQ(expected, json);
+}
« no previous file with comments | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698