GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../test/cctest/test_traced_value.cc Lines: 53 53 100.0 %
Date: 2019-01-07 12:15:22 Branches: 10 20 50.0 %

Line Branch Exec Source
1
#include "tracing/traced_value.h"
2
3
#include <math.h>
4
#include <stddef.h>
5
#include <string.h>
6
7
#include "gtest/gtest.h"
8
9
using node::tracing::TracedValue;
10
11
5
TEST(TracedValue, Object) {
12
1
  auto traced_value = TracedValue::Create();
13
1
  traced_value->SetString("a", "b");
14
1
  traced_value->SetInteger("b", 1);
15
1
  traced_value->SetDouble("c", 1.234);
16
1
  traced_value->SetDouble("d", NAN);
17
1
  traced_value->SetDouble("e", INFINITY);
18
1
  traced_value->SetDouble("f", -INFINITY);
19
1
  traced_value->SetDouble("g", 1.23e7);
20
1
  traced_value->SetBoolean("h", false);
21
1
  traced_value->SetBoolean("i", true);
22
1
  traced_value->SetNull("j");
23
1
  traced_value->BeginDictionary("k");
24
1
  traced_value->SetString("l", "m");
25
1
  traced_value->EndDictionary();
26
27
2
  std::string string;
28
1
  traced_value->AppendAsTraceFormat(&string);
29
30
  static const char* check = "{\"a\":\"b\",\"b\":1,\"c\":1.234,\"d\":\"NaN\","
31
                             "\"e\":\"Infinity\",\"f\":\"-Infinity\",\"g\":"
32
                             "1.23e+07,\"h\":false,\"i\":true,\"j\":null,\"k\":"
33
                             "{\"l\":\"m\"}}";
34
35
2
  EXPECT_EQ(check, string);
36
1
}
37
38
5
TEST(TracedValue, Array) {
39
1
  auto traced_value = TracedValue::CreateArray();
40
1
  traced_value->AppendString("a");
41
1
  traced_value->AppendInteger(1);
42
1
  traced_value->AppendDouble(1.234);
43
1
  traced_value->AppendDouble(NAN);
44
1
  traced_value->AppendDouble(INFINITY);
45
1
  traced_value->AppendDouble(-INFINITY);
46
1
  traced_value->AppendDouble(1.23e7);
47
1
  traced_value->AppendBoolean(false);
48
1
  traced_value->AppendBoolean(true);
49
1
  traced_value->AppendNull();
50
1
  traced_value->BeginDictionary();
51
1
  traced_value->BeginArray("foo");
52
1
  traced_value->EndArray();
53
1
  traced_value->EndDictionary();
54
55
2
  std::string string;
56
1
  traced_value->AppendAsTraceFormat(&string);
57
58
  static const char* check = "[\"a\",1,1.234,\"NaN\",\"Infinity\","
59
                             "\"-Infinity\",1.23e+07,false,true,null,"
60
                             "{\"foo\":[]}]";
61
62
2
  EXPECT_EQ(check, string);
63
1
}
64
65
#define UTF8_SEQUENCE "1" "\xE2\x82\xAC" "23\"\x01\b\f\n\r\t\\"
66
#if defined(NODE_HAVE_I18N_SUPPORT)
67
# define UTF8_RESULT                                                          \
68
  "\"1\\u20AC23\\\"\\u0001\\b\\f\\n\\r\\t\\\\\""
69
#else
70
# define UTF8_RESULT                                                          \
71
  "\"1\\u00E2\\u0082\\u00AC23\\\"\\u0001\\b\\f\\n\\r\\t\\\\\""
72
#endif
73
74
5
TEST(TracedValue, EscapingObject) {
75
1
  auto traced_value = TracedValue::Create();
76
1
  traced_value->SetString("a", UTF8_SEQUENCE);
77
78
2
  std::string string;
79
1
  traced_value->AppendAsTraceFormat(&string);
80
81
  static const char* check = "{\"a\":" UTF8_RESULT "}";
82
83
2
  EXPECT_EQ(check, string);
84
1
}
85
86
5
TEST(TracedValue, EscapingArray) {
87
1
  auto traced_value = TracedValue::CreateArray();
88
1
  traced_value->AppendString(UTF8_SEQUENCE);
89
90
2
  std::string string;
91
1
  traced_value->AppendAsTraceFormat(&string);
92
93
  static const char* check = "[" UTF8_RESULT "]";
94
95
2
  EXPECT_EQ(check, string);
96

4
}