1 /*
2 * Copyright 2015 The Android Open Source Project
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 //#define LOG_NDEBUG 0
17 #define LOG_TAG "MediaResourceManager_test"
18 #include <utils/Log.h>
19
20 #include <gtest/gtest.h>
21 #include "MediaResourceArbitrator.h"
22
23 using namespace android;
24
25
26 class MediaResourceManagerTest : public ::testing::Test {
27 public:
MediaResourceManagerTest()28 MediaResourceManagerTest()
29 : mArbitrator(new MediaResourceArbitrator) {
30 mArbitrator->Config(NULL);
31 }
32
~MediaResourceManagerTest()33 ~MediaResourceManagerTest() {
34 delete mArbitrator;
35 }
36
37 protected:
addDefaultResourceByN(int N)38 void addDefaultResourceByN(int N) {
39 /*
40 CodecInfo codec1;
41 codec1.codecType = CODEC_TYPE_AVC;
42 codec1.isEncoder = false;
43 codec1.isSecured = false;
44 codec1.resolution = Resolution_1080;
45 codec1.frameRate = 30;
46 */
47 int i;
48 ArbitratorErrorType err = ArbitratorErrorNone;
49 for (i=0; i<N; i++) {
50 err = mArbitrator->AddResource(CODEC_TYPE_AVC,
51 false,
52 false,
53 Resolution_1080,
54 30);
55 if (err == ArbitratorErrorInsufficientResources) {
56 ALOGE("%dth codec can not be added anymore.");
57 return;
58 }
59 }
60 }
61
testAddResource(void)62 void testAddResource(void) {
63 addDefaultResourceByN(10);
64 EXPECT_EQ(2u, mArbitrator->GetLivingCodecsNum());
65 }
66
67
testRemoveResource(void)68 void testRemoveResource(void) {
69 addDefaultResourceByN(5);
70 EXPECT_EQ(2u, mArbitrator->GetLivingCodecsNum());
71 EXPECT_TRUE(mArbitrator->CheckIfFullLoad(false));
72 ArbitratorErrorType err = ArbitratorErrorNone;
73 err = mArbitrator->RemoveResource(CODEC_TYPE_AVC,
74 false,
75 false,
76 Resolution_1080,
77 30);
78 EXPECT_EQ(1u, mArbitrator->GetLivingCodecsNum());
79 EXPECT_FALSE(mArbitrator->CheckIfFullLoad(false));
80 }
81
82
testCheckFullLoad(void)83 void testCheckFullLoad(void) {
84 EXPECT_FALSE(mArbitrator->CheckIfFullLoad(false));
85 addDefaultResourceByN(5);
86 EXPECT_TRUE(mArbitrator->CheckIfFullLoad(false));
87 }
88
89
testConfigByXML(void)90 void testConfigByXML(void) {
91 }
92
93
94 MediaResourceArbitrator* mArbitrator;
95 };
96
97
TEST_F(MediaResourceManagerTest,config)98 TEST_F(MediaResourceManagerTest, config) {
99 }
100
101
TEST_F(MediaResourceManagerTest,addResource)102 TEST_F(MediaResourceManagerTest, addResource) {
103 testAddResource();
104 }
105
106
TEST_F(MediaResourceManagerTest,removeResource)107 TEST_F(MediaResourceManagerTest, removeResource) {
108 testRemoveResource();
109 }
110
111
TEST_F(MediaResourceManagerTest,checkFullLoad)112 TEST_F(MediaResourceManagerTest, checkFullLoad) {
113 testCheckFullLoad();
114 }
115
116
TEST_F(MediaResourceManagerTest,configByXML)117 TEST_F(MediaResourceManagerTest, configByXML) {
118 testConfigByXML();
119 }
120
121
122
123