(This is a merge of http://go/wvgerrit/139989.) Googletest added a new, more powerful MOCK_METHOD() macro in 1.10. This patch updates all our usage of the old MOCK_METHOD family to the new macro. Full details can be found at https://github.com/google/googletest/blob/release-1.10.0/googlemock/docs/cook_book.md#creating-mock-classes but in brief, the new MOCK_METHOD() replaces the entire old MOCK_METHOD family and has the following advantages: 1) No need to count parameters or update the macro name when changing parameters. 2) No need for a different macro for const methods. 3) The ability to specify override, noexcept, and other function qualifiers. 4) The macro order is now the same as C++ method definition order: Return Type -> Name -> Arguments -> Qualifiers In addition to upgrading all our usage sites to the new macro, the addition of the override qualifier to our MOCK_METHODs helped uncover several cases where we were using MOCK_METHOD to override methods that didn't exist. This is a great example of why the override qualifier is so useful. These places have been updated, by removing the invalid and unused mock method. Bug: 207693687 Test: build_and_run_all_unit_tests Change-Id: Iaad4a22c7f72bb48b1356fe01a41eb0a2f555244
33 lines
872 B
C++
33 lines
872 B
C++
// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
|
|
// source code may only be used and distributed under the Widevine License
|
|
// Agreement.
|
|
|
|
#ifndef CDM_TEST_MOCK_CLOCK_H_
|
|
#define CDM_TEST_MOCK_CLOCK_H_
|
|
|
|
#include "clock.h"
|
|
#include <gmock/gmock.h>
|
|
|
|
namespace wvcdm {
|
|
|
|
class MockClock : public Clock {
|
|
public:
|
|
MOCK_METHOD(int64_t, GetCurrentTime, (), (override));
|
|
};
|
|
|
|
// Frozen clock will always return the same value for the current time.
|
|
// Intended to be used for testing where using the actual time would
|
|
// cause flaky tests.
|
|
class FrozenClock : public Clock {
|
|
int64_t always_time_;
|
|
|
|
public:
|
|
FrozenClock(int64_t always_time = 0) : always_time_(always_time) {}
|
|
int64_t GetCurrentTime() override { return always_time_; }
|
|
void SetTime(int64_t new_time) { always_time_ = new_time; }
|
|
};
|
|
|
|
} // wvcdm
|
|
|
|
#endif // CDM_TEST_MOCK_CLOCK_H_
|