| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/tracing/traced-value.h" | 5 #include "src/tracing/traced-value.h" |
| 6 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
| 7 | 7 |
| 8 using v8::tracing::TracedValue; | 8 using v8::tracing::TracedValue; |
| 9 | 9 |
| 10 TEST(FlatDictionary) { | 10 TEST(FlatDictionary) { |
| 11 auto value = TracedValue::Create(); | 11 auto value = TracedValue::Create(); |
| 12 value->SetInteger("int", 2014); | 12 value->SetInteger("int", 2014); |
| 13 value->SetDouble("double", 0.0); | 13 value->SetDouble("double", 0.0); |
| 14 value->SetBoolean("bool", true); | 14 value->SetBoolean("bool", true); |
| 15 value->SetString("string", "string"); | 15 value->SetString("string", "string"); |
| 16 std::string json = "PREFIX"; | 16 std::string json = "PREFIX"; |
| 17 value->AppendAsTraceFormat(&json); | 17 value->AppendAsTraceFormat(&json); |
| 18 CHECK_EQ( | 18 CHECK_EQ( |
| 19 "PREFIX{\"int\":2014,\"double\":0.000000,\"bool\":true,\"string\":" | 19 "PREFIX{\"int\":2014,\"double\":0,\"bool\":true,\"string\":" |
| 20 "\"string\"}", | 20 "\"string\"}", |
| 21 json); | 21 json); |
| 22 } | 22 } |
| 23 | 23 |
| 24 TEST(NoDotPathExpansion) { | 24 TEST(NoDotPathExpansion) { |
| 25 auto value = TracedValue::Create(); | 25 auto value = TracedValue::Create(); |
| 26 value->SetInteger("in.t", 2014); | 26 value->SetInteger("in.t", 2014); |
| 27 value->SetDouble("doub.le", 0.0); | 27 value->SetDouble("doub.le", -20.25); |
| 28 value->SetBoolean("bo.ol", true); | 28 value->SetBoolean("bo.ol", true); |
| 29 value->SetString("str.ing", "str.ing"); | 29 value->SetString("str.ing", "str.ing"); |
| 30 std::string json; | 30 std::string json; |
| 31 value->AppendAsTraceFormat(&json); | 31 value->AppendAsTraceFormat(&json); |
| 32 CHECK_EQ( | 32 CHECK_EQ( |
| 33 "{\"in.t\":2014,\"doub.le\":0.000000,\"bo.ol\":true,\"str.ing\":\"str." | 33 "{\"in.t\":2014,\"doub.le\":-20.25,\"bo.ol\":true,\"str.ing\":\"str." |
| 34 "ing\"}", | 34 "ing\"}", |
| 35 json); | 35 json); |
| 36 } | 36 } |
| 37 | 37 |
| 38 TEST(Hierarchy) { | 38 TEST(Hierarchy) { |
| 39 auto value = TracedValue::Create(); | 39 auto value = TracedValue::Create(); |
| 40 value->SetInteger("i0", 2014); | 40 value->SetInteger("i0", 2014); |
| 41 value->BeginDictionary("dict1"); | 41 value->BeginDictionary("dict1"); |
| 42 value->SetInteger("i1", 2014); | 42 value->SetInteger("i1", 2014); |
| 43 value->BeginDictionary("dict2"); | 43 value->BeginDictionary("dict2"); |
| 44 value->SetBoolean("b2", false); | 44 value->SetBoolean("b2", false); |
| 45 value->EndDictionary(); | 45 value->EndDictionary(); |
| 46 value->SetString("s1", "foo"); | 46 value->SetString("s1", "foo"); |
| 47 value->EndDictionary(); | 47 value->EndDictionary(); |
| 48 value->SetDouble("d0", 0.0); | 48 value->SetDouble("d0", 0.0); |
| 49 value->SetDouble("d1", 10.5); |
| 49 value->SetBoolean("b0", true); | 50 value->SetBoolean("b0", true); |
| 50 value->BeginArray("a1"); | 51 value->BeginArray("a1"); |
| 51 value->AppendInteger(1); | 52 value->AppendInteger(1); |
| 52 value->AppendBoolean(true); | 53 value->AppendBoolean(true); |
| 53 value->BeginDictionary(); | 54 value->BeginDictionary(); |
| 54 value->SetInteger("i2", 3); | 55 value->SetInteger("i2", 3); |
| 55 value->EndDictionary(); | 56 value->EndDictionary(); |
| 56 value->EndArray(); | 57 value->EndArray(); |
| 57 value->SetString("s0", "foo"); | 58 value->SetString("s0", "foo"); |
| 58 | 59 |
| 59 value->BeginArray("arr1"); | 60 value->BeginArray("arr1"); |
| 60 value->BeginDictionary(); | 61 value->BeginDictionary(); |
| 61 value->EndDictionary(); | 62 value->EndDictionary(); |
| 62 value->BeginArray(); | 63 value->BeginArray(); |
| 63 value->EndArray(); | 64 value->EndArray(); |
| 64 value->BeginDictionary(); | 65 value->BeginDictionary(); |
| 65 value->EndDictionary(); | 66 value->EndDictionary(); |
| 66 value->EndArray(); | 67 value->EndArray(); |
| 67 | 68 |
| 68 std::string json; | 69 std::string json; |
| 69 value->AppendAsTraceFormat(&json); | 70 value->AppendAsTraceFormat(&json); |
| 70 CHECK_EQ( | 71 CHECK_EQ( |
| 71 "{\"i0\":2014,\"dict1\":{\"i1\":2014,\"dict2\":{\"b2\":false}," | 72 "{\"i0\":2014,\"dict1\":{\"i1\":2014,\"dict2\":{\"b2\":false}," |
| 72 "\"s1\":\"foo\"},\"d0\":0.000000,\"b0\":true,\"a1\":[1,true,{\"i2\":3}]," | 73 "\"s1\":\"foo\"},\"d0\":0,\"d1\":10.5,\"b0\":true,\"a1\":[1,true,{\"i2\":" |
| 73 "\"s0\":\"foo\",\"arr1\":[{},[],{}]}", | 74 "3}],\"s0\":\"foo\",\"arr1\":[{},[],{}]}", |
| 74 json); | 75 json); |
| 75 } | 76 } |
| 76 | 77 |
| 77 TEST(LongStrings) { | 78 TEST(LongStrings) { |
| 78 std::string long_string = "supercalifragilisticexpialidocious"; | 79 std::string long_string = "supercalifragilisticexpialidocious"; |
| 79 std::string long_string2 = "0123456789012345678901234567890123456789"; | 80 std::string long_string2 = "0123456789012345678901234567890123456789"; |
| 80 char long_string3[4096]; | 81 char long_string3[4096]; |
| 81 for (size_t i = 0; i < sizeof(long_string3); ++i) | 82 for (size_t i = 0; i < sizeof(long_string3); ++i) |
| 82 long_string3[i] = static_cast<char>('a' + (i % 26)); | 83 long_string3[i] = static_cast<char>('a' + (i % 26)); |
| 83 long_string3[sizeof(long_string3) - 1] = '\0'; | 84 long_string3[sizeof(long_string3) - 1] = '\0'; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // as it fails to process # character on Windows. | 117 // as it fails to process # character on Windows. |
| 117 const char* expected = | 118 const char* expected = |
| 118 "{\"a\":\"abc\\\"\'\\\\\\\\x\\\"y\'z\\n\\t\\u0017\",\"b\":" | 119 "{\"a\":\"abc\\\"\'\\\\\\\\x\\\"y\'z\\n\\t\\u0017\",\"b\":" |
| 119 "\"\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\u0008\\t\\n\\u000B" | 120 "\"\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\u0008\\t\\n\\u000B" |
| 120 "\\u000C\\u000D\\u000E\\u000F\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\" | 121 "\\u000C\\u000D\\u000E\\u000F\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\" |
| 121 "u0016\\u0017\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F " | 122 "u0016\\u0017\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F " |
| 122 "!\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`" | 123 "!\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`" |
| 123 "abcdefghijklmnopqrstuvwxyz{|}~\177\"}"; | 124 "abcdefghijklmnopqrstuvwxyz{|}~\177\"}"; |
| 124 CHECK_EQ(expected, json); | 125 CHECK_EQ(expected, json); |
| 125 } | 126 } |
| OLD | NEW |