webrtc_m130/webrtc/video_engine/overuse_frame_detector_unittest.cc

69 lines
2.3 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/system_wrappers/interface/clock.h"
#include "webrtc/system_wrappers/interface/scoped_ptr.h"
#include "webrtc/video_engine/include/vie_base.h"
#include "webrtc/video_engine/overuse_frame_detector.h"
using ::testing::_;
using ::testing::AnyNumber;
using ::testing::Return;
namespace webrtc {
const int kProcessIntervalMs = 2000;
class MockCpuOveruseObserver : public CpuOveruseObserver {
public:
MockCpuOveruseObserver() {}
virtual ~MockCpuOveruseObserver() {}
MOCK_METHOD0(OveruseDetected, void());
MOCK_METHOD0(NormalUsage, void());
};
class OveruseFrameDetectorTest : public ::testing::Test {
protected:
virtual void SetUp() {
clock_.reset(new SimulatedClock(1234));
observer_.reset(new MockCpuOveruseObserver());
overuse_detector_.reset(new OveruseFrameDetector(clock_.get()));
overuse_detector_->SetObserver(observer_.get());
}
scoped_ptr<SimulatedClock> clock_;
scoped_ptr<MockCpuOveruseObserver> observer_;
scoped_ptr<OveruseFrameDetector> overuse_detector_;
};
TEST_F(OveruseFrameDetectorTest, TriggerOveruse) {
EXPECT_EQ(overuse_detector_->TimeUntilNextProcess(), kProcessIntervalMs);
overuse_detector_->CapturedFrame();
overuse_detector_->EncodedFrame();
clock_->AdvanceTimeMilliseconds(kProcessIntervalMs);
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
overuse_detector_->Process();
overuse_detector_->CapturedFrame();
clock_->AdvanceTimeMilliseconds(kProcessIntervalMs);
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
overuse_detector_->Process();
clock_->AdvanceTimeMilliseconds(5000);
overuse_detector_->CapturedFrame();
overuse_detector_->EncodedFrame();
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
overuse_detector_->Process();
}
} // namespace webrtc