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

Side by Side Diff: statsreport/aggregator_unittest.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « statsreport/aggregator_unittest.h ('k') | statsreport/build.scons » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2006-2009 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15 //
16 // Implementation of helper classes to aggregate the collected in-memory
17 // stats to persistent storage.
18 #include "aggregator.h"
19 #include "aggregator_unittest.h"
20
21 using namespace stats_report;
22
23 class TestMetricsAggregator: public MetricsAggregator {
24 public:
25 TestMetricsAggregator(MetricCollection &coll) : MetricsAggregator(coll)
26 , aggregating_(false), counts_(0), timings_(0), integers_(0), bools_(0) {
27 }
28
29 ~TestMetricsAggregator() {
30 }
31
32 bool aggregating() const { return aggregating_; }
33 int counts() const { return counts_; }
34 int timings() const { return timings_; }
35 int integers() const { return integers_; }
36 int bools() const { return bools_; }
37
38 protected:
39 virtual bool StartAggregation() {
40 aggregating_ = true;
41 counts_ = 0;
42 timings_ = 0;
43 integers_ = 0;
44 bools_ = 0;
45
46 return true;
47 }
48
49 virtual void EndAggregation() {
50 aggregating_ = false;
51 }
52
53 virtual void Aggregate(CountMetric &metric) {
54 EXPECT_TRUE(aggregating());
55 metric.Reset();
56 ++counts_;
57 }
58
59 virtual void Aggregate(TimingMetric &metric) {
60 UNREFERENCED_PARAMETER(metric);
61 EXPECT_TRUE(aggregating());
62 metric.Reset();
63 ++timings_;
64 }
65 virtual void Aggregate(IntegerMetric &metric) {
66 UNREFERENCED_PARAMETER(metric);
67 EXPECT_TRUE(aggregating());
68 // Integer metrics don't get reset on aggregation
69 ++integers_;
70 }
71 virtual void Aggregate(BoolMetric &metric) {
72 EXPECT_TRUE(aggregating());
73 metric.Reset();
74 ++bools_;
75 }
76
77 private:
78 bool aggregating_;
79 int counts_;
80 int timings_;
81 int integers_;
82 int bools_;
83 };
84
85 TEST_F(MetricsAggregatorTest, Aggregate) {
86 TestMetricsAggregator agg(coll_);
87
88 EXPECT_FALSE(agg.aggregating());
89 EXPECT_EQ(0, agg.counts());
90 EXPECT_EQ(0, agg.timings());
91 EXPECT_EQ(0, agg.integers());
92 EXPECT_EQ(0, agg.bools());
93 EXPECT_TRUE(agg.AggregateMetrics());
94 EXPECT_FALSE(agg.aggregating());
95
96 // check that we saw all counters.
97 EXPECT_TRUE(kNumCounts == agg.counts());
98 EXPECT_TRUE(kNumTimings == agg.timings());
99 EXPECT_TRUE(kNumIntegers == agg.integers());
100 EXPECT_TRUE(kNumBools == agg.bools());
101 }
102
103 class FailureTestMetricsAggregator: public TestMetricsAggregator {
104 public:
105 FailureTestMetricsAggregator(MetricCollection &coll) :
106 TestMetricsAggregator(coll) {
107 }
108
109 protected:
110 virtual bool StartAggregation() {
111 return false;
112 }
113 };
114
115 TEST_F(MetricsAggregatorTest, AggregateFailure) {
116 FailureTestMetricsAggregator agg(coll_);
117
118 EXPECT_FALSE(agg.AggregateMetrics());
119 }
OLDNEW
« no previous file with comments | « statsreport/aggregator_unittest.h ('k') | statsreport/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698