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

Unified 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 side-by-side diff with in-line comments
Download patch
« c_metrics_library.h ('K') | « metrics_library.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: metrics_library_test.cc
diff --git a/metrics_library_test.cc b/metrics_library_test.cc
index f585d350734b10c13e49dd2818059d9d54bf6051..596abd3e651116e0c0169c1ad418d3e2f011ea33 100644
--- a/metrics_library_test.cc
+++ b/metrics_library_test.cc
@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "metrics_library.h"
-
#include <cstring>
#include <base/file_util.h>
#include <gtest/gtest.h>
+#include "c_metrics_library.h"
+#include "metrics_library.h"
+
static const FilePath kTestUMAEventsFile("test-uma-events");
class MetricsLibraryTest : public testing::Test {
@@ -83,6 +84,48 @@ TEST_F(MetricsLibraryTest, SendToUMA) {
EXPECT_EQ(0, memcmp(exp, buf, kLen));
}
+class CMetricsLibraryTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ lib_ = CMetricsLibraryNew();
+ MetricsLibrary& ml = *reinterpret_cast<MetricsLibrary*>(lib_);
+ EXPECT_EQ(NULL, ml.uma_events_file_);
+ CMetricsLibraryInit(lib_);
+ EXPECT_TRUE(NULL != ml.uma_events_file_);
+ ml.uma_events_file_ = kTestUMAEventsFile.value().c_str();
+ }
+
+ virtual void TearDown() {
+ CMetricsLibraryDelete(lib_);
+ file_util::Delete(kTestUMAEventsFile, false);
+ }
+
+ CMetricsLibrary lib_;
+};
+
+TEST_F(CMetricsLibraryTest, SendEnumToUMA) {
+ char buf[100];
+ const int kLen = 40;
+ EXPECT_TRUE(CMetricsLibrarySendEnumToUMA(lib_, "Test.EnumMetric", 1, 3));
+ EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
+
+ char exp[kLen];
+ sprintf(exp, "%c%c%c%clinearhistogram%cTest.EnumMetric 1 3",
+ kLen, 0, 0, 0, 0);
+ EXPECT_EQ(0, memcmp(exp, buf, kLen));
+}
+
+TEST_F(CMetricsLibraryTest, SendToUMA) {
+ char buf[100];
+ const int kLen = 37;
+ EXPECT_TRUE(CMetricsLibrarySendToUMA(lib_, "Test.Metric", 2, 1, 100, 50));
+ EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
+
+ char exp[kLen];
+ sprintf(exp, "%c%c%c%chistogram%cTest.Metric 2 1 100 50", kLen, 0, 0, 0, 0);
+ EXPECT_EQ(0, memcmp(exp, buf, kLen));
+}
+
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
« 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