| OLD | NEW |
| 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 <cstring> | 5 #include <cstring> |
| 6 | 6 |
| 7 #include <base/file_util.h> | 7 #include <base/file_util.h> |
| 8 #include <gtest/gtest.h> | 8 #include <gtest/gtest.h> |
| 9 | 9 |
| 10 #include "c_metrics_library.h" | 10 #include "c_metrics_library.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0); | 207 sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0); |
| 208 EXPECT_EQ(0, memcmp(exp, buf, kLen)); | 208 EXPECT_EQ(0, memcmp(exp, buf, kLen)); |
| 209 } | 209 } |
| 210 | 210 |
| 211 TEST_F(MetricsLibraryTest, SendToUMANotEnabled) { | 211 TEST_F(MetricsLibraryTest, SendToUMANotEnabled) { |
| 212 SetMetricsEnabled(false); | 212 SetMetricsEnabled(false); |
| 213 EXPECT_TRUE(lib_.SendToUMA("Test.Metric", 2, 1, 100, 50)); | 213 EXPECT_TRUE(lib_.SendToUMA("Test.Metric", 2, 1, 100, 50)); |
| 214 EXPECT_FALSE(file_util::PathExists(kTestUMAEventsFile)); | 214 EXPECT_FALSE(file_util::PathExists(kTestUMAEventsFile)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 TEST_F(MetricsLibraryTest, SendUserActionToUMA) { |
| 218 char buf[100]; |
| 219 const int kLen = 30; |
| 220 EXPECT_TRUE(lib_.SendUserActionToUMA("SomeKeyPressed")); |
| 221 EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100)); |
| 222 |
| 223 char exp[kLen]; |
| 224 sprintf(exp, "%c%c%c%cuseraction%cSomeKeyPressed", kLen, 0, 0, 0, 0); |
| 225 EXPECT_EQ(0, memcmp(exp, buf, kLen)); |
| 226 } |
| 227 |
| 228 TEST_F(MetricsLibraryTest, SendUserActionToUMANotEnabled) { |
| 229 SetMetricsEnabled(false); |
| 230 EXPECT_TRUE(lib_.SendUserActionToUMA("SomeOtherKeyPressed")); |
| 231 EXPECT_FALSE(file_util::PathExists(kTestUMAEventsFile)); |
| 232 } |
| 233 |
| 217 class CMetricsLibraryTest : public testing::Test { | 234 class CMetricsLibraryTest : public testing::Test { |
| 218 protected: | 235 protected: |
| 219 virtual void SetUp() { | 236 virtual void SetUp() { |
| 220 lib_ = CMetricsLibraryNew(); | 237 lib_ = CMetricsLibraryNew(); |
| 221 MetricsLibrary& ml = *reinterpret_cast<MetricsLibrary*>(lib_); | 238 MetricsLibrary& ml = *reinterpret_cast<MetricsLibrary*>(lib_); |
| 222 EXPECT_EQ(NULL, ml.uma_events_file_); | 239 EXPECT_EQ(NULL, ml.uma_events_file_); |
| 223 CMetricsLibraryInit(lib_); | 240 CMetricsLibraryInit(lib_); |
| 224 EXPECT_TRUE(NULL != ml.uma_events_file_); | 241 EXPECT_TRUE(NULL != ml.uma_events_file_); |
| 225 ml.uma_events_file_ = kTestUMAEventsFile.value().c_str(); | 242 ml.uma_events_file_ = kTestUMAEventsFile.value().c_str(); |
| 226 SetMetricsEnabled(true); | 243 SetMetricsEnabled(true); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 char buf[100]; | 278 char buf[100]; |
| 262 const int kLen = 37; | 279 const int kLen = 37; |
| 263 EXPECT_TRUE(CMetricsLibrarySendToUMA(lib_, "Test.Metric", 2, 1, 100, 50)); | 280 EXPECT_TRUE(CMetricsLibrarySendToUMA(lib_, "Test.Metric", 2, 1, 100, 50)); |
| 264 EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100)); | 281 EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100)); |
| 265 | 282 |
| 266 char exp[kLen]; | 283 char exp[kLen]; |
| 267 sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0); | 284 sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0); |
| 268 EXPECT_EQ(0, memcmp(exp, buf, kLen)); | 285 EXPECT_EQ(0, memcmp(exp, buf, kLen)); |
| 269 } | 286 } |
| 270 | 287 |
| 288 TEST_F(CMetricsLibraryTest, SendUserActionToUMA) { |
| 289 char buf[100]; |
| 290 const int kLen = 30; |
| 291 EXPECT_TRUE(CMetricsLibrarySendUserActionToUMA(lib_, "SomeKeyPressed")); |
| 292 EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100)); |
| 293 |
| 294 char exp[kLen]; |
| 295 sprintf(exp, "%c%c%c%cuseraction%cSomeKeyPressed", kLen, 0, 0, 0, 0); |
| 296 EXPECT_EQ(0, memcmp(exp, buf, kLen)); |
| 297 } |
| 298 |
| 271 int main(int argc, char** argv) { | 299 int main(int argc, char** argv) { |
| 272 testing::InitGoogleTest(&argc, argv); | 300 testing::InitGoogleTest(&argc, argv); |
| 273 return RUN_ALL_TESTS(); | 301 return RUN_ALL_TESTS(); |
| 274 } | 302 } |
| OLD | NEW |