OLD | NEW |
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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 public: | 40 public: |
41 // Just used for testing. | 41 // Just used for testing. |
42 int64_t LeakyValue() const { return Value(); } | 42 int64_t LeakyValue() const { return Value(); } |
43 }; | 43 }; |
44 | 44 |
45 UNIT_TEST_CASE(Metric_OnDemand) { | 45 UNIT_TEST_CASE(Metric_OnDemand) { |
46 Dart_CreateIsolate( | 46 Dart_CreateIsolate( |
47 NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL, NULL); | 47 NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL, NULL); |
48 { | 48 { |
49 Isolate* isolate = Isolate::Current(); | 49 Thread* thread = Thread::Current(); |
50 StackZone zone(isolate); | 50 StackZone zone(thread); |
51 HANDLESCOPE(isolate); | 51 HANDLESCOPE(thread); |
52 MyMetric metric; | 52 MyMetric metric; |
53 | 53 |
54 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kByte); | 54 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kByte); |
55 // value is still the default value. | 55 // value is still the default value. |
56 EXPECT_EQ(0, metric.value()); | 56 EXPECT_EQ(0, metric.value()); |
57 // Call LeakyValue to confirm that Value returns constant 99. | 57 // Call LeakyValue to confirm that Value returns constant 99. |
58 EXPECT_EQ(99, metric.LeakyValue()); | 58 EXPECT_EQ(99, metric.LeakyValue()); |
59 | 59 |
60 // Serialize to JSON. | 60 // Serialize to JSON. |
61 JSONStream js; | 61 JSONStream js; |
62 metric.PrintJSON(&js); | 62 metric.PrintJSON(&js); |
63 const char* json = js.ToCString(); | 63 const char* json = js.ToCString(); |
64 EXPECT_STREQ("{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":" | 64 EXPECT_STREQ("{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":" |
65 "\"foobar\",\"unit\":\"byte\"," | 65 "\"foobar\",\"unit\":\"byte\"," |
66 "\"fixedId\":true,\"id\":\"metrics\\/native\\/a.b.c\"" | 66 "\"fixedId\":true,\"id\":\"metrics\\/native\\/a.b.c\"" |
67 ",\"value\":99.000000}", json); | 67 ",\"value\":99.000000}", json); |
68 } | 68 } |
69 Dart_ShutdownIsolate(); | 69 Dart_ShutdownIsolate(); |
70 } | 70 } |
71 | 71 |
72 } // namespace dart | 72 } // namespace dart |
OLD | NEW |