Chromium Code Reviews| Index: components/feature_engagement_tracker/internal/test/event_util.cc |
| diff --git a/components/feature_engagement_tracker/internal/test/event_util.cc b/components/feature_engagement_tracker/internal/test/event_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..836d530193b3991ad74697e8dde03fc80c52aee6 |
| --- /dev/null |
| +++ b/components/feature_engagement_tracker/internal/test/event_util.cc |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/feature_engagement_tracker/internal/test/event_util.h" |
| + |
| +#include <map> |
|
nyquist
2017/05/11 17:08:03
Nit: Did you end up using this include? Maybe I'm
David Trainor- moved to gerrit
2017/05/11 19:30:28
Done.
|
| + |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace feature_engagement_tracker { |
| +namespace test { |
| + |
| +void SetEventCountForDay(Event* event, uint32_t day, uint32_t count) { |
| + Event_Count* event_count = event->add_events(); |
| + event_count->set_day(day); |
| + event_count->set_count(count); |
| +} |
| + |
| +void VerifyEventCount(const Event* event, uint32_t day, uint32_t count) { |
| + bool found_day = false; |
| + for (int i = 0; i < event->events_size(); ++i) { |
|
nyquist
2017/05/11 17:08:03
Nit: I know you just moved this around, but should
David Trainor- moved to gerrit
2017/05/11 19:30:28
Done.
|
| + Event_Count event_count = event->events(i); |
| + if (event_count.day() == day) { |
| + EXPECT_FALSE(found_day); |
| + found_day = true; |
| + EXPECT_EQ(count, event_count.count()); |
| + } |
| + } |
| + EXPECT_TRUE(found_day); |
| +} |
| + |
| +void VerifyEventsEqual(const Event* a, const Event* b) { |
| + if (!a || !b) { |
| + // If one of the events are nullptr, both should be nullptr. |
| + ASSERT_EQ(a, b); |
| + return; |
| + } |
| + |
| + EXPECT_EQ(a->name(), b->name()); |
| + EXPECT_EQ(a->events_size(), b->events_size()); |
| + for (int i = 0; i < a->events_size(); ++i) { |
| + VerifyEventCount(b, a->events(i).day(), a->events(i).count()); |
| + } |
| +} |
| + |
| +} // namespace test |
| +} // namespace feature_engagement_tracker |