Files
android/libwvdrmengine/cdm/test/timer_unittest.cpp
Alex Dale 4e2c4d14fe Replaced NULL with nullptr in Android CDM.
[ Merge of http://go/wvgerrit/85503 ]

Replacing a few instances of C's NULL with C++'s nullptr in some of the
smaller sub-directories in the CDM.

Note that clang-format has performed additional changes to some of the
test files that have not yet been formatted.

Bug: 120602075
Test: Android unittest
Change-Id: I926135ed4b85e9d2d58a014b4a62098b0cb7a373
2019-09-05 20:40:01 +00:00

53 lines
1.2 KiB
C++

// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
// source code may only be used and distributed under the Widevine Master
// License Agreement.
#include <gtest/gtest.h>
#include "timer.h"
namespace wvcdm {
class TestTimerHandler : public TimerHandler {
public:
TestTimerHandler() : timer_events_(0) {};
virtual ~TestTimerHandler() {};
virtual void OnTimerEvent() { timer_events_++; }
uint32_t timer_events() { return timer_events_; }
private:
uint32_t timer_events_;
};
TEST(TimerTest, ParametersCheck) {
Timer timer;
EXPECT_FALSE(timer.Start(nullptr, 10));
TestTimerHandler handler;
EXPECT_FALSE(timer.Start(&handler, 0));
}
TEST(TimerTest, TimerCheck) {
TestTimerHandler handler;
Timer timer;
uint32_t duration = 10;
EXPECT_EQ(0u, handler.timer_events());
EXPECT_FALSE(timer.IsRunning());
EXPECT_TRUE(timer.Start(&handler, 1));
EXPECT_TRUE(timer.IsRunning());
sleep(duration);
EXPECT_LE(duration - 1, handler.timer_events());
EXPECT_LE(handler.timer_events(), duration + 1);
timer.Stop();
EXPECT_FALSE(timer.IsRunning());
sleep(duration);
EXPECT_LE(duration - 1, handler.timer_events());
EXPECT_LE(handler.timer_events(), duration + 1);
}
}