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

Unified Diff: webrtc/system_wrappers/source/metrics_unittest.cc

Issue 1528403003: Add implementation in metrics.h that uses atomic pointer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: address comments Created 5 years 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
« no previous file with comments | « webrtc/system_wrappers/include/metrics.h ('k') | webrtc/system_wrappers/system_wrappers_tests.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/system_wrappers/source/metrics_unittest.cc
diff --git a/webrtc/system_wrappers/source/metrics_unittest.cc b/webrtc/system_wrappers/source/metrics_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8319b78ee0d0daf35535a5327d8d320253f79b1a
--- /dev/null
+++ b/webrtc/system_wrappers/source/metrics_unittest.cc
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "webrtc/system_wrappers/include/metrics.h"
+#include "webrtc/test/histogram.h"
+
+namespace webrtc {
+namespace {
+const int kSample = 22;
+const std::string kName = "Name";
+
+void AddSparseSample(const std::string& name, int sample) {
+ RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample);
+}
+#if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
+void AddSample(const std::string& name, int sample) {
+ RTC_HISTOGRAM_COUNTS_100(name, sample);
+}
+#endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
+} // namespace
+
+TEST(MetricsTest, InitiallyNoSamples) {
+ test::ClearHistograms();
+ EXPECT_EQ(0, test::NumHistogramSamples(kName));
+ EXPECT_EQ(-1, test::LastHistogramSample(kName));
+}
+
+TEST(MetricsTest, RtcHistogramPercent_AddSample) {
+ test::ClearHistograms();
+ RTC_HISTOGRAM_PERCENTAGE(kName, kSample);
+ EXPECT_EQ(1, test::NumHistogramSamples(kName));
+ EXPECT_EQ(kSample, test::LastHistogramSample(kName));
+}
+
+TEST(MetricsTest, RtcHistogramEnumeration_AddSample) {
+ test::ClearHistograms();
+ RTC_HISTOGRAM_ENUMERATION(kName, kSample, kSample + 1);
+ EXPECT_EQ(1, test::NumHistogramSamples(kName));
+ EXPECT_EQ(kSample, test::LastHistogramSample(kName));
+}
+
+TEST(MetricsTest, RtcHistogramCountsSparse_AddSample) {
+ test::ClearHistograms();
+ RTC_HISTOGRAM_COUNTS_SPARSE_100(kName, kSample);
+ EXPECT_EQ(1, test::NumHistogramSamples(kName));
+ EXPECT_EQ(kSample, test::LastHistogramSample(kName));
+}
+
+TEST(MetricsTest, RtcHistogramCounts_AddSample) {
+ test::ClearHistograms();
+ RTC_HISTOGRAM_COUNTS_100(kName, kSample);
+ EXPECT_EQ(1, test::NumHistogramSamples(kName));
+ EXPECT_EQ(kSample, test::LastHistogramSample(kName));
+}
+
+TEST(MetricsTest, RtcHistogramCounts_AddMultipleSamples) {
+ test::ClearHistograms();
+ const int kNumSamples = 10;
+ for (int i = 0; i < kNumSamples; ++i) {
+ RTC_HISTOGRAM_COUNTS_100(kName, i);
+ }
+ EXPECT_EQ(kNumSamples, test::NumHistogramSamples(kName));
+ EXPECT_EQ(kNumSamples - 1, test::LastHistogramSample(kName));
+}
+
+TEST(MetricsTest, RtcHistogramSparse_NonConstantNameWorks) {
+ test::ClearHistograms();
+ AddSparseSample("Name1", kSample);
+ AddSparseSample("Name2", kSample);
+ EXPECT_EQ(1, test::NumHistogramSamples("Name1"));
+ EXPECT_EQ(1, test::NumHistogramSamples("Name2"));
+}
+
+#if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
+TEST(MetricsTest, RtcHistogram_FailsForNonConstantName) {
+ test::ClearHistograms();
+ AddSample("Name1", kSample);
+ EXPECT_DEATH(AddSample("Name2", kSample), "");
+}
+#endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
+
+} // namespace webrtc
« no previous file with comments | « webrtc/system_wrappers/include/metrics.h ('k') | webrtc/system_wrappers/system_wrappers_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698