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

Side by Side Diff: runtime/vm/metrics_test.cc

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/metrics.cc ('k') | runtime/vm/mirrors_api_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 6
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/dart_api_state.h" 8 #include "vm/dart_api_state.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/json_stream.h" 10 #include "vm/json_stream.h"
11 #include "vm/metrics.h" 11 #include "vm/metrics.h"
12 #include "vm/unit_test.h" 12 #include "vm/unit_test.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 #ifndef PRODUCT 16 #ifndef PRODUCT
17 17
18 UNIT_TEST_CASE(Metric_Simple) { 18 UNIT_TEST_CASE(Metric_Simple) {
19 Dart_CreateIsolate( 19 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL,
20 NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL, NULL); 20 NULL);
21 { 21 {
22 Metric metric; 22 Metric metric;
23 23
24 // Initialize metric. 24 // Initialize metric.
25 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kCounter); 25 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kCounter);
26 EXPECT_EQ(0, metric.value()); 26 EXPECT_EQ(0, metric.value());
27 metric.increment(); 27 metric.increment();
28 EXPECT_EQ(1, metric.value()); 28 EXPECT_EQ(1, metric.value());
29 metric.set_value(44); 29 metric.set_value(44);
30 EXPECT_EQ(44, metric.value()); 30 EXPECT_EQ(44, metric.value());
31 } 31 }
32 Dart_ShutdownIsolate(); 32 Dart_ShutdownIsolate();
33 } 33 }
34 34
35 class MyMetric : public Metric { 35 class MyMetric : public Metric {
36 protected: 36 protected:
37 int64_t Value() const { 37 int64_t Value() const {
38 // 99 bytes. 38 // 99 bytes.
39 return 99; 39 return 99;
40 } 40 }
41 41
42 public: 42 public:
43 // Just used for testing. 43 // Just used for testing.
44 int64_t LeakyValue() const { return Value(); } 44 int64_t LeakyValue() const { return Value(); }
45 }; 45 };
46 46
47 UNIT_TEST_CASE(Metric_OnDemand) { 47 UNIT_TEST_CASE(Metric_OnDemand) {
48 Dart_CreateIsolate( 48 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL,
49 NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL, NULL); 49 NULL);
50 { 50 {
51 Thread* thread = Thread::Current(); 51 Thread* thread = Thread::Current();
52 StackZone zone(thread); 52 StackZone zone(thread);
53 HANDLESCOPE(thread); 53 HANDLESCOPE(thread);
54 MyMetric metric; 54 MyMetric metric;
55 55
56 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kByte); 56 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kByte);
57 // value is still the default value. 57 // value is still the default value.
58 EXPECT_EQ(0, metric.value()); 58 EXPECT_EQ(0, metric.value());
59 // Call LeakyValue to confirm that Value returns constant 99. 59 // Call LeakyValue to confirm that Value returns constant 99.
60 EXPECT_EQ(99, metric.LeakyValue()); 60 EXPECT_EQ(99, metric.LeakyValue());
61 61
62 // Serialize to JSON. 62 // Serialize to JSON.
63 JSONStream js; 63 JSONStream js;
64 metric.PrintJSON(&js); 64 metric.PrintJSON(&js);
65 const char* json = js.ToCString(); 65 const char* json = js.ToCString();
66 EXPECT_STREQ("{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":" 66 EXPECT_STREQ(
67 "\"foobar\",\"unit\":\"byte\"," 67 "{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":"
68 "\"fixedId\":true,\"id\":\"metrics\\/native\\/a.b.c\"" 68 "\"foobar\",\"unit\":\"byte\","
69 ",\"value\":99.000000}", json); 69 "\"fixedId\":true,\"id\":\"metrics\\/native\\/a.b.c\""
70 ",\"value\":99.000000}",
71 json);
70 } 72 }
71 Dart_ShutdownIsolate(); 73 Dart_ShutdownIsolate();
72 } 74 }
73 75
74 #endif // !PRODUCT 76 #endif // !PRODUCT
75 77
76 } // namespace dart 78 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/metrics.cc ('k') | runtime/vm/mirrors_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698