blob: 04e09a67d8f058ba67a6db8a2199a70c8d6ba83b [file] [log] [blame]
wu@webrtc.orgea7b33e2013-08-05 20:36:57 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "testing/gtest/include/gtest/gtest.h"
12#include "webrtc/common_video/interface/native_handle.h"
13#include "webrtc/common_video/interface/texture_video_frame.h"
14
15namespace webrtc {
16
17class NativeHandleImpl : public NativeHandle {
18 public:
19 NativeHandleImpl() : ref_count_(0) {}
20 virtual ~NativeHandleImpl() {}
21 virtual int32_t AddRef() { return ++ref_count_; }
22 virtual int32_t Release() { return --ref_count_; }
23 virtual void* GetHandle() { return NULL; }
24
25 int32_t ref_count() { return ref_count_; }
26 private:
27 int32_t ref_count_;
28};
29
30TEST(TestTextureVideoFrame, InitialValues) {
31 NativeHandleImpl handle;
32 TextureVideoFrame frame(&handle, 640, 480, 100, 10);
33 EXPECT_EQ(640, frame.width());
34 EXPECT_EQ(480, frame.height());
35 EXPECT_EQ(100u, frame.timestamp());
36 EXPECT_EQ(10, frame.render_time_ms());
37 EXPECT_EQ(&handle, frame.native_handle());
38
39 EXPECT_EQ(0, frame.set_width(320));
40 EXPECT_EQ(320, frame.width());
41 EXPECT_EQ(0, frame.set_height(240));
42 EXPECT_EQ(240, frame.height());
43 frame.set_timestamp(200);
44 EXPECT_EQ(200u, frame.timestamp());
45 frame.set_render_time_ms(20);
46 EXPECT_EQ(20, frame.render_time_ms());
47}
48
49TEST(TestTextureVideoFrame, RefCount) {
50 NativeHandleImpl handle;
51 EXPECT_EQ(0, handle.ref_count());
52 TextureVideoFrame *frame = new TextureVideoFrame(&handle, 640, 480, 100, 200);
53 EXPECT_EQ(1, handle.ref_count());
54 delete frame;
55 EXPECT_EQ(0, handle.ref_count());
56}
57
58} // namespace webrtc