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

Unified Diff: counter_test.cc

Issue 3181015: Add # daily crashes metrics and separate kernel crashes out. (Closed) Base URL: ssh://git@chromiumos-git//metrics.git
Patch Set: Respond to review Created 10 years, 4 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
« no previous file with comments | « counter_mock.h ('k') | metrics_daemon.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: counter_test.cc
diff --git a/counter_test.cc b/counter_test.cc
index fd5a38939e718dbb66f03dc5f639f13951555ad9..eb68b2acb79114666ef108ab80d46195ec8d0075 100644
--- a/counter_test.cc
+++ b/counter_test.cc
@@ -12,6 +12,7 @@
#include <gtest/gtest.h>
#include "counter.h"
+#include "counter_mock.h" // For TaggedCounterMock.
using ::testing::_;
using ::testing::MockFunction;
@@ -255,6 +256,64 @@ TEST_F(TaggedCounterTest, Update) {
EXPECT_EQ(TaggedCounter::kRecordValid, counter_.record_state_);
}
+class FrequencyCounterTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ tagged_counter_ = new StrictMock<TaggedCounterMock>;
+ frequency_counter_.tagged_counter_.reset(tagged_counter_);
+ }
+
+ static void FakeReporter(void *, int32, int32) {
+ }
+
+ void CheckInit(int32 cycle_duration);
+ void CheckCycleNumber(int32 cycle_duration);
+
+ FrequencyCounter frequency_counter_;
+ StrictMock<TaggedCounterMock>* tagged_counter_;
+
+ TaggedCounter::Reporter reporter_;
+};
+
+void FrequencyCounterTest::CheckInit(int32 cycle_duration) {
+ EXPECT_CALL(*tagged_counter_, Init(kTestRecordFile, FakeReporter, this))
+ .Times(1)
+ .RetiresOnSaturation();
+ frequency_counter_.Init(kTestRecordFile,
+ FakeReporter,
+ this,
+ cycle_duration);
+ EXPECT_EQ(cycle_duration, frequency_counter_.cycle_duration_);
+}
+
+TEST_F(FrequencyCounterTest, Init) {
+ CheckInit(100);
+}
+
+void FrequencyCounterTest::CheckCycleNumber(int32 cycle_duration) {
+ CheckInit(cycle_duration);
+ EXPECT_EQ(150, frequency_counter_.GetCycleNumber(cycle_duration * 150));
+ EXPECT_EQ(150, frequency_counter_.GetCycleNumber(cycle_duration * 150 +
+ cycle_duration - 1));
+ EXPECT_EQ(151, frequency_counter_.GetCycleNumber(cycle_duration * 151 + 1));
+ EXPECT_EQ(0, frequency_counter_.GetCycleNumber(0));
+}
+
+
+TEST_F(FrequencyCounterTest, GetCycleNumberForWeek) {
+ CheckCycleNumber(kSecondsPerWeek);
+}
+
+TEST_F(FrequencyCounterTest, GetCycleNumberForDay) {
+ CheckCycleNumber(kSecondsPerDay);
+}
+
+TEST_F(FrequencyCounterTest, UpdateInternal) {
+ CheckInit(kSecondsPerWeek);
+ EXPECT_CALL(*tagged_counter_, Update(150, 2));
+ frequency_counter_.UpdateInternal(2, kSecondsPerWeek * 150);
+}
+
} // namespace chromeos_metrics
int main(int argc, char** argv) {
« no previous file with comments | « counter_mock.h ('k') | metrics_daemon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698