OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
siva
2015/06/16 15:42:31
2015
Cutch
2015/06/16 17:08:17
Done.
| |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #include "platform/assert.h" | |
6 | |
7 #include "vm/dart_api_impl.h" | |
8 #include "vm/dart_api_state.h" | |
9 #include "vm/globals.h" | |
10 #include "vm/timeline.h" | |
11 #include "vm/unit_test.h" | |
12 | |
13 namespace dart { | |
14 | |
15 TEST_CASE(TimelineEventIsValid) { | |
16 // Create a test stream. | |
17 TimelineStream stream; | |
18 stream.Init("testStream", true); | |
19 | |
20 TimelineEvent event; | |
21 | |
22 // Starts invalid. | |
23 EXPECT(!event.IsValid()); | |
24 | |
25 // Becomes valid. | |
26 event.Instant(&stream, "hello"); | |
27 EXPECT(event.IsValid()); | |
28 | |
29 // Becomes invalid. | |
30 event.Reset(); | |
31 EXPECT(!event.IsValid()); | |
32 } | |
33 | |
34 | |
35 TEST_CASE(TimelineEventDuration) { | |
36 // Create a test stream. | |
37 TimelineStream stream; | |
38 stream.Init("testStream", true); | |
39 | |
40 // Create a test event. | |
41 TimelineEvent event; | |
42 event.DurationBegin(&stream, "apple"); | |
43 // Measure the duration. | |
44 int64_t current_duration = event.TimeDuration(); | |
45 event.DurationEnd(); | |
46 // Verify that duration is larger. | |
47 EXPECT_GE(event.TimeDuration(), current_duration); | |
48 } | |
49 | |
50 | |
51 TEST_CASE(TimelineEventDurationPrintJSON) { | |
52 // Create a test stream. | |
53 TimelineStream stream; | |
54 stream.Init("testStream", true); | |
55 | |
56 // Create a test event. | |
57 TimelineEvent event; | |
58 event.DurationBegin(&stream, "apple"); | |
59 { | |
60 // Test printing to JSON. | |
61 JSONStream js; | |
62 event.PrintJSON(&js); | |
63 // Check category | |
64 EXPECT_SUBSTRING("\"cat\":\"testStream\"", js.ToCString()); | |
65 // Check name. | |
66 EXPECT_SUBSTRING("\"name\":\"apple\"", js.ToCString()); | |
67 // Check phase. | |
68 EXPECT_SUBSTRING("\"ph\":\"X\"", js.ToCString()); | |
69 // Check that ts key is present. | |
70 EXPECT_SUBSTRING("\"ts\":", js.ToCString()); | |
71 // Check that dur key is present. | |
72 EXPECT_SUBSTRING("\"dur\":", js.ToCString()); | |
73 } | |
74 event.DurationEnd(); | |
75 } | |
76 | |
77 | |
78 TEST_CASE(TimelineEventArguments) { | |
79 // Create a test stream. | |
80 TimelineStream stream; | |
81 stream.Init("testStream", true); | |
82 | |
83 // Create a test event. | |
84 TimelineEvent event; | |
85 | |
86 // Allocate room for four arguments. | |
87 event.SetNumArguments(4); | |
88 // Reset. | |
89 event.Reset(); | |
90 | |
91 event.DurationBegin(&stream, "apple"); | |
92 event.SetNumArguments(2); | |
93 event.CopyArgument(0, "arg1", "value1"); | |
94 event.CopyArgument(1, "arg2", "value2"); | |
95 event.DurationEnd(); | |
96 } | |
97 | |
98 | |
99 TEST_CASE(TimelineEventArgumentsPrintJSON) { | |
100 // Create a test stream. | |
101 TimelineStream stream; | |
102 stream.Init("testStream", true); | |
103 | |
104 // Create a test event. | |
105 TimelineEvent event; | |
106 | |
107 event.DurationBegin(&stream, "apple"); | |
108 event.SetNumArguments(2); | |
109 event.CopyArgument(0, "arg1", "value1"); | |
110 event.CopyArgument(1, "arg2", "value2"); | |
111 event.DurationEnd(); | |
112 | |
113 { | |
114 // Test printing to JSON. | |
115 JSONStream js; | |
116 event.PrintJSON(&js); | |
117 | |
118 // Check both arguments. | |
119 EXPECT_SUBSTRING("\"arg1\":\"value1\"", js.ToCString()); | |
120 EXPECT_SUBSTRING("\"arg2\":\"value2\"", js.ToCString()); | |
121 } | |
122 } | |
123 | |
124 | |
125 TEST_CASE(TimelineEventBufferPrintJSON) { | |
126 Isolate* isolate = Isolate::Current(); | |
127 TimelineEventBuffer* buffer = isolate->timeline_event_buffer(); | |
128 JSONStream js; | |
129 buffer->PrintJSON(&js); | |
130 // Check the type. This test will fail if we ever make Timeline public. | |
131 EXPECT_SUBSTRING("\"type\":\"_Timeline\"", js.ToCString()); | |
132 // Check that there is a traceEvents array. | |
133 EXPECT_SUBSTRING("\"traceEvents\":[", js.ToCString()); | |
134 } | |
135 | |
136 } // namespace dart | |
OLD | NEW |