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

Side by Side Diff: metrics_library_test.cc

Issue 2832008: add C wrapper for libmetrics (Closed) Base URL: ssh://git@chromiumos-git//metrics.git
Patch Set: remove include Created 10 years, 6 months 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
« c_metrics_library.h ('K') | « metrics_library.h ('k') | no next file » | 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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 "metrics_library.h"
6
7 #include <cstring> 5 #include <cstring>
8 6
9 #include <base/file_util.h> 7 #include <base/file_util.h>
10 #include <gtest/gtest.h> 8 #include <gtest/gtest.h>
11 9
10 #include "c_metrics_library.h"
11 #include "metrics_library.h"
12
12 static const FilePath kTestUMAEventsFile("test-uma-events"); 13 static const FilePath kTestUMAEventsFile("test-uma-events");
13 14
14 class MetricsLibraryTest : public testing::Test { 15 class MetricsLibraryTest : public testing::Test {
15 protected: 16 protected:
16 virtual void SetUp() { 17 virtual void SetUp() {
17 EXPECT_EQ(NULL, lib_.uma_events_file_); 18 EXPECT_EQ(NULL, lib_.uma_events_file_);
18 lib_.Init(); 19 lib_.Init();
19 EXPECT_TRUE(NULL != lib_.uma_events_file_); 20 EXPECT_TRUE(NULL != lib_.uma_events_file_);
20 lib_.uma_events_file_ = kTestUMAEventsFile.value().c_str(); 21 lib_.uma_events_file_ = kTestUMAEventsFile.value().c_str();
21 } 22 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 char buf[100]; 77 char buf[100];
77 const int kLen = 37; 78 const int kLen = 37;
78 EXPECT_TRUE(lib_.SendToUMA("Test.Metric", 2, 1, 100, 50)); 79 EXPECT_TRUE(lib_.SendToUMA("Test.Metric", 2, 1, 100, 50));
79 EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100)); 80 EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
80 81
81 char exp[kLen]; 82 char exp[kLen];
82 sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0); 83 sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0);
83 EXPECT_EQ(0, memcmp(exp, buf, kLen)); 84 EXPECT_EQ(0, memcmp(exp, buf, kLen));
84 } 85 }
85 86
87 class CMetricsLibraryTest : public testing::Test {
88 protected:
89 virtual void SetUp() {
90 lib_ = CMetricsLibraryNew();
91 MetricsLibrary& ml = *reinterpret_cast<MetricsLibrary*>(lib_);
92 EXPECT_EQ(NULL, ml.uma_events_file_);
93 CMetricsLibraryInit(lib_);
94 EXPECT_TRUE(NULL != ml.uma_events_file_);
95 ml.uma_events_file_ = kTestUMAEventsFile.value().c_str();
96 }
97
98 virtual void TearDown() {
99 CMetricsLibraryDelete(lib_);
100 file_util::Delete(kTestUMAEventsFile, false);
101 }
102
103 CMetricsLibrary lib_;
104 };
105
106 TEST_F(CMetricsLibraryTest, SendEnumToUMA) {
107 char buf[100];
108 const int kLen = 40;
109 EXPECT_TRUE(CMetricsLibrarySendEnumToUMA(lib_, "Test.EnumMetric", 1, 3));
110 EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
111
112 char exp[kLen];
113 sprintf(exp, "%c%c%c%clinearhistogram%cTest.EnumMetric 1 3",
114 kLen, 0, 0, 0, 0);
115 EXPECT_EQ(0, memcmp(exp, buf, kLen));
116 }
117
118 TEST_F(CMetricsLibraryTest, SendToUMA) {
119 char buf[100];
120 const int kLen = 37;
121 EXPECT_TRUE(CMetricsLibrarySendToUMA(lib_, "Test.Metric", 2, 1, 100, 50));
122 EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
123
124 char exp[kLen];
125 sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0);
126 EXPECT_EQ(0, memcmp(exp, buf, kLen));
127 }
128
86 int main(int argc, char** argv) { 129 int main(int argc, char** argv) {
87 testing::InitGoogleTest(&argc, argv); 130 testing::InitGoogleTest(&argc, argv);
88 return RUN_ALL_TESTS(); 131 return RUN_ALL_TESTS();
89 } 132 }
OLDNEW
« c_metrics_library.h ('K') | « metrics_library.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698