1 /*
2 * Copyright (C) 2010 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 #include <assert.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <SLES/OpenSLES.h>
22 #include "OpenSLESUT.h"
23
main(int arg __unused,char ** argv __unused)24 int main(int arg __unused, char **argv __unused)
25 {
26 SLresult result;
27
28 printf("Create engine\n");
29 SLObjectItf engineObject;
30 // create engine
31 result = slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);
32 assert(SL_RESULT_SUCCESS == result);
33 result = (*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
34 assert(SL_RESULT_SUCCESS == result);
35 SLEngineItf engineEngine;
36 result = (*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine);
37 assert(SL_RESULT_SUCCESS == result);
38 SLuint32 i;
39 // loop through both valid and invalid object IDs
40 SLuint32 objectID;
41 // Test object IDs from one less than the first valid object
42 // ID, up to one more than the last valid object ID. This way
43 // we can test for both valid and invalid object IDs at both
44 // ends. If more objects are added, be sure to update the macros.
45 #define FIRST_VALID SL_OBJECTID_ENGINE
46 #define LAST_VALID SL_OBJECTID_METADATAEXTRACTOR
47 for (objectID = FIRST_VALID - 1; objectID <= LAST_VALID + 1; ++objectID) {
48 printf("object ID %x", objectID);
49 const char *string = slesutObjectIDToString(objectID);
50 if (NULL != string)
51 printf(" (%s)", string);
52 printf(":\n");
53 result = (*engineEngine)->QueryNumSupportedInterfaces(engineEngine, objectID, NULL);
54 assert(SL_RESULT_PARAMETER_INVALID == result);
55 SLuint32 numSupportedInterfaces = 12345;
56 result = (*engineEngine)->QueryNumSupportedInterfaces(engineEngine, objectID,
57 &numSupportedInterfaces);
58 SLInterfaceID interfaceID;
59 if (SL_RESULT_FEATURE_UNSUPPORTED == result) {
60 printf(" unsupported\n");
61 result = (*engineEngine)->QuerySupportedInterfaces(engineEngine, objectID, 0,
62 &interfaceID);
63 assert(SL_RESULT_FEATURE_UNSUPPORTED == result);
64 assert(NULL == interfaceID);
65 continue;
66 }
67 assert(SL_RESULT_SUCCESS == result);
68 printf("numSupportedInterfaces %u\n", numSupportedInterfaces);
69 for (i = 0; i < numSupportedInterfaces + 1; ++i) {
70 result = (*engineEngine)->QuerySupportedInterfaces(engineEngine, objectID, i, NULL);
71 assert(SL_RESULT_PARAMETER_INVALID == result);
72 result = (*engineEngine)->QuerySupportedInterfaces(engineEngine, objectID, i,
73 &interfaceID);
74 if (i < numSupportedInterfaces) {
75 assert(SL_RESULT_SUCCESS == result);
76 printf(" interface %u ", i);
77 slesutPrintIID(interfaceID);
78 } else {
79 assert(SL_RESULT_PARAMETER_INVALID == result);
80 }
81 }
82 }
83 // query number of extensions
84 result = (*engineEngine)->QueryNumSupportedExtensions(engineEngine, NULL);
85 assert(SL_RESULT_PARAMETER_INVALID == result);
86 SLuint32 numExtensions = 0x12345;
87 result = (*engineEngine)->QueryNumSupportedExtensions(engineEngine, &numExtensions);
88 assert(SL_RESULT_SUCCESS == result);
89 printf("numExtensions = %u\n", numExtensions);
90 // query names of the extensions
91 for (i = 0; i < numExtensions + 1; ++i) {
92 SLchar extensionName[32];
93 result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, extensionName, NULL);
94 assert(SL_RESULT_PARAMETER_INVALID == result);
95 SLint16 nameLength = -1;
96 result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, NULL, &nameLength);
97 if (i < numExtensions) {
98 assert(SL_RESULT_SUCCESS == result);
99 printf(" extension[%u] length = %u\n", i, nameLength);
100 } else {
101 assert(SL_RESULT_PARAMETER_INVALID == result);
102 assert(0 == nameLength);
103 }
104 memset(extensionName, 'X', sizeof(extensionName));
105 nameLength = -1;
106 result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, extensionName,
107 &nameLength);
108 if (i < numExtensions) {
109 assert(SL_RESULT_BUFFER_INSUFFICIENT == result);
110 } else {
111 assert(SL_RESULT_PARAMETER_INVALID == result);
112 }
113 assert('X' == extensionName[0]);
114 nameLength = 0;
115 result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, extensionName,
116 &nameLength);
117 if (i < numExtensions) {
118 assert(SL_RESULT_BUFFER_INSUFFICIENT == result);
119 } else {
120 assert(SL_RESULT_PARAMETER_INVALID == result);
121 }
122 assert('X' == extensionName[0]);
123 nameLength = 1;
124 result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, extensionName,
125 &nameLength);
126 if (i < numExtensions) {
127 assert(SL_RESULT_BUFFER_INSUFFICIENT == result);
128 assert('\0' == extensionName[0]);
129 } else {
130 assert(SL_RESULT_PARAMETER_INVALID == result);
131 }
132 assert('X' == extensionName[1]);
133 nameLength = sizeof(extensionName);
134 result = (*engineEngine)->QuerySupportedExtension(engineEngine, i, extensionName,
135 &nameLength);
136 if (i < numExtensions) {
137 assert(SL_RESULT_SUCCESS == result);
138 assert((1 <= nameLength) && (nameLength <= (SLint16) sizeof(extensionName)));
139 printf(" extension[%u] = \"%.*s\"\n", i, nameLength, extensionName);
140 } else {
141 assert(SL_RESULT_PARAMETER_INVALID == result);
142 assert(0 == nameLength);
143 }
144 }
145 // check if extension is supported
146 SLboolean isSupported = SL_BOOLEAN_TRUE;
147 result = (*engineEngine)->IsExtensionSupported(engineEngine, NULL, &isSupported);
148 assert(SL_RESULT_PARAMETER_INVALID == result);
149 assert(SL_BOOLEAN_FALSE == isSupported);
150 SLchar *unsupportedExt = (SLchar *) "fish";
151 result = (*engineEngine)->IsExtensionSupported(engineEngine, unsupportedExt, NULL);
152 assert(SL_RESULT_PARAMETER_INVALID == result);
153 isSupported = SL_BOOLEAN_TRUE;
154 result = (*engineEngine)->IsExtensionSupported(engineEngine, unsupportedExt, &isSupported);
155 assert(SL_RESULT_SUCCESS == result);
156 assert(SL_BOOLEAN_FALSE == isSupported);
157 SLchar *supportedExt;
158 #ifdef ANDROID
159 // whereas the implementation uses PLATFORM_SDK_VERSION, use a hard-coded value here
160 // so that we're actually testing for a particular expected value
161 supportedExt = (SLchar *) "ANDROID_SDK_LEVEL_19";
162 #else
163 supportedExt = (SLchar *) "WILHELM_DESKTOP";
164 #endif
165 isSupported = SL_BOOLEAN_FALSE;
166 result = (*engineEngine)->IsExtensionSupported(engineEngine, supportedExt, &isSupported);
167 assert(SL_RESULT_SUCCESS == result);
168 assert(SL_BOOLEAN_TRUE == isSupported);
169 // create an extension object with no place to put the new object
170 result = (*engineEngine)->CreateExtensionObject(engineEngine, NULL, NULL, 0x123, 0, NULL, NULL);
171 assert(SL_RESULT_PARAMETER_INVALID == result);
172 // create an extension object, which is unsupported
173 SLObjectItf extensionObject;
174 result = (*engineEngine)->CreateExtensionObject(engineEngine, &extensionObject, NULL, 0x123, 0,
175 NULL, NULL);
176 assert(SL_RESULT_FEATURE_UNSUPPORTED == result);
177 assert(NULL == extensionObject);
178 // destroy engine
179 (*engineObject)->Destroy(engineObject);
180 return EXIT_SUCCESS;
181 }
182