1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /**
18  * Test for testing the creation of OpenMAX AL objects.
19  * The tests verify the creation and completion of the call to Realize() for the following objects:
20  *   - Engine
21  *   - OutputMix
22  */
23 
24 #define LOG_NDEBUG 0
25 #define LOG_TAG "XAObjectCreationTest"
26 
27 #include <gtest/gtest.h>
28 #include <utils/Log.h>
29 
30 #if !defined(BUILD_ONLY)
31 #include "OMXAL/OpenMAXAL.h"
32 #include "OMXAL/OpenMAXAL_Android.h"
33 #endif
34 
35 #if !defined(BUILD_ONLY)
36 //-----------------------------------------------------------------
37 /* Checks for error and displays the error code if any */
IsOk(XAresult res)38 bool IsOk(XAresult res) {
39     if (XA_RESULT_SUCCESS != res) {
40         fprintf(stderr, "IsOk failure: 0x%x, exiting\n", res);
41         return false;
42     }
43     return true;
44 }
45 
46 //-----------------------------------------------------------------
47 class XAObjectCreationTest : public ::testing::Test {
48 
49 protected:
50     XAresult res;
51     XAObjectItf engineObj, outputMixObj, mediaPlayerObj;
52     XAEngineItf engineItf;
53 
54     XADataSource mediaSource;
55     XADataSink   audioSink;
56     XADataLocator_URI locatorUriSrc;
57     XADataLocator_AndroidBufferQueue locatorAbqSrc;
58     XADataLocator_AndroidFD locatorFdSrc;
59     XADataFormat_MIME formatMimeSrc;
60 
61     XADataLocator_OutputMix locatorOutputmixSink;
62     XADataFormat_PCM formatPcmSink;
63 
64     XADataLocator_NativeDisplay locatorVideoSink;
65     XADataSink imageSink;
66 
67     //ANativeWindow* pNativeWindow;
68 
XAObjectCreationTest()69     XAObjectCreationTest() { }
70 
~XAObjectCreationTest()71     virtual ~XAObjectCreationTest() { }
72 
73     /* Test setup*/
SetUp()74     virtual void SetUp() {
75         ALOGV("Test Setup()");
76         res = XA_RESULT_UNKNOWN_ERROR;
77         engineItf = NULL;
78         engineObj = NULL;
79         outputMixObj = NULL;
80         mediaPlayerObj = NULL;
81         // Engine creation
82         res = xaCreateEngine(&engineObj, 0, NULL, 0, NULL, NULL);
83         ASSERT_TRUE(IsOk(res));
84         res = (*engineObj)->Realize(engineObj, XA_BOOLEAN_FALSE);
85         ASSERT_TRUE(IsOk(res));
86         res = (*engineObj)->GetInterface(engineObj, XA_IID_ENGINE, &engineItf);
87         ASSERT_TRUE(IsOk(res));
88         ASSERT_TRUE(NULL != engineItf);
89     }
90 
TearDown()91     virtual void TearDown() {
92         ALOGV("Test TearDown()");
93         if (mediaPlayerObj) {
94             (*mediaPlayerObj)->Destroy(mediaPlayerObj);
95             mediaPlayerObj = NULL;
96         }
97         if (outputMixObj) {
98             (*outputMixObj)->Destroy(outputMixObj);
99             outputMixObj = NULL;
100         }
101         if (engineObj){
102             (*engineObj)->Destroy(engineObj);
103             engineObj = NULL;
104         }
105     }
106 
107     //---------------------------------------------------------------------------------------------
108     // Tests
109 
110     /* Test case for creating an MediaPlayer object */
OutputMixCreation()111     void OutputMixCreation() {
112         res = (*engineItf)->CreateOutputMix(engineItf, &outputMixObj,
113                 0, NULL/*iidArray*/, NULL/*required*/);
114         ASSERT_TRUE(IsOk(res));
115         ASSERT_TRUE(NULL != outputMixObj);
116         res = (*outputMixObj)->Realize(outputMixObj, XA_BOOLEAN_FALSE);
117         ASSERT_TRUE(IsOk(res));
118     }
119 
120 };
121 #else
122 class XAObjectCreationTest : public ::testing::Test {
123 protected:
OutputMixCreation()124     void OutputMixCreation() { }
125 };
126 #endif
127 
128 //-------------------------------------------------------------------------------------------------
TEST_F(XAObjectCreationTest,testEngineCreation)129 TEST_F(XAObjectCreationTest, testEngineCreation) {
130     ALOGV("Test Fixture: EngineCreation");
131     // nothing to do here that isn't done in SetUp()
132 }
133 
TEST_F(XAObjectCreationTest,testOutputMixCreation)134 TEST_F(XAObjectCreationTest, testOutputMixCreation) {
135     ALOGV("Test Fixture: OutputMixCreation");
136     OutputMixCreation();
137 }
138 
main(int argc,char ** argv)139 int main(int argc, char **argv) {
140     testing::InitGoogleTest(&argc, argv);
141 
142     return RUN_ALL_TESTS();
143 }
144 
145