1 /*
2 * Copyright (C) 2016 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 // Test the minimal perfect hash generator function
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <SLES/OpenSLES.h>
22 #include "MPH.h"
23
24 extern int IID_to_MPH(const SLInterfaceID iid);
25 extern const struct SLInterfaceID_ SL_IID_array[MPH_MAX];
26
main(int argc,char ** argv)27 int main(int argc, char **argv)
28 {
29 int i;
30 for (i = 0; i < MPH_MAX; i++) {
31 const struct SLInterfaceID_ *original = &SL_IID_array[i];
32 // test the address-based lookup
33 int MPH = IID_to_MPH(original);
34 if (MPH != i) {
35 fprintf(stderr, "error: IID_to_MPH(SL_IID_array) = %d != %d\n", MPH, i);
36 return EXIT_FAILURE;
37 }
38 // test the content-based lookup
39 const struct SLInterfaceID_ copy = *original;
40 MPH = IID_to_MPH(©);
41 if (MPH != i) {
42 fprintf(stderr, "error: IID_to_MPH(copy) = %d != %d\n", MPH, i);
43 return EXIT_FAILURE;
44 }
45 }
46 printf("OK\n");
47 return EXIT_SUCCESS;
48 }
49