xref: /aosp_15_r20/cts/tests/tests/nativemedia/xa/src/XAObjectCreationTest.cpp (revision b7c941bb3fa97aba169d73cee0bed2de8ac964bf)
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 #include "OMXAL/OpenMAXAL.h"
31 #include "OMXAL/OpenMAXAL_Android.h"
32 
33 //-----------------------------------------------------------------
34 /* Checks for error and displays the error code if any */
IsOk(XAresult res)35 bool IsOk(XAresult res) {
36     if (XA_RESULT_SUCCESS != res) {
37         fprintf(stderr, "IsOk failure: 0x%x, exiting\n", res);
38         return false;
39     }
40     return true;
41 }
42 
43 //-----------------------------------------------------------------
44 class XAObjectCreationTest : public ::testing::Test {
45 
46 protected:
47     XAresult res;
48     XAObjectItf engineObj, outputMixObj, mediaPlayerObj;
49     XAEngineItf engineItf;
50 
51     XADataSource mediaSource;
52     XADataSink   audioSink;
53     XADataLocator_URI locatorUriSrc;
54     XADataLocator_AndroidBufferQueue locatorAbqSrc;
55     XADataLocator_AndroidFD locatorFdSrc;
56     XADataFormat_MIME formatMimeSrc;
57 
58     XADataLocator_OutputMix locatorOutputmixSink;
59     XADataFormat_PCM formatPcmSink;
60 
61     XADataLocator_NativeDisplay locatorVideoSink;
62     XADataSink imageSink;
63 
64     //ANativeWindow* pNativeWindow;
65 
XAObjectCreationTest()66     XAObjectCreationTest() { }
67 
~XAObjectCreationTest()68     virtual ~XAObjectCreationTest() { }
69 
70     /* Test setup*/
SetUp()71     virtual void SetUp() {
72         ALOGV("Test Setup()");
73         res = XA_RESULT_UNKNOWN_ERROR;
74         engineItf = NULL;
75         engineObj = NULL;
76         outputMixObj = NULL;
77         mediaPlayerObj = NULL;
78         // Engine creation
79         res = xaCreateEngine(&engineObj, 0, NULL, 0, NULL, NULL);
80         ASSERT_TRUE(IsOk(res));
81         res = (*engineObj)->Realize(engineObj, XA_BOOLEAN_FALSE);
82         ASSERT_TRUE(IsOk(res));
83         res = (*engineObj)->GetInterface(engineObj, XA_IID_ENGINE, &engineItf);
84         ASSERT_TRUE(IsOk(res));
85         ASSERT_TRUE(NULL != engineItf);
86     }
87 
TearDown()88     virtual void TearDown() {
89         ALOGV("Test TearDown()");
90         if (mediaPlayerObj) {
91             (*mediaPlayerObj)->Destroy(mediaPlayerObj);
92             mediaPlayerObj = NULL;
93         }
94         if (outputMixObj) {
95             (*outputMixObj)->Destroy(outputMixObj);
96             outputMixObj = NULL;
97         }
98         if (engineObj){
99             (*engineObj)->Destroy(engineObj);
100             engineObj = NULL;
101         }
102     }
103 
104     //---------------------------------------------------------------------------------------------
105     // Tests
106 
107     /* Test case for creating an MediaPlayer object */
OutputMixCreation()108     void OutputMixCreation() {
109         res = (*engineItf)->CreateOutputMix(engineItf, &outputMixObj,
110                 0, NULL/*iidArray*/, NULL/*required*/);
111         ASSERT_TRUE(IsOk(res));
112         ASSERT_TRUE(NULL != outputMixObj);
113         res = (*outputMixObj)->Realize(outputMixObj, XA_BOOLEAN_FALSE);
114         ASSERT_TRUE(IsOk(res));
115     }
116 
117 };
118 
119 //-------------------------------------------------------------------------------------------------
TEST_F(XAObjectCreationTest,testEngineCreation)120 TEST_F(XAObjectCreationTest, testEngineCreation) {
121     ALOGV("Test Fixture: EngineCreation");
122     // nothing to do here that isn't done in SetUp()
123 }
124 
TEST_F(XAObjectCreationTest,testOutputMixCreation)125 TEST_F(XAObjectCreationTest, testOutputMixCreation) {
126     ALOGV("Test Fixture: OutputMixCreation");
127     OutputMixCreation();
128 }
129 
main(int argc,char ** argv)130 int main(int argc, char **argv) {
131     testing::InitGoogleTest(&argc, argv);
132 
133     return RUN_ALL_TESTS();
134 }
135 
136