xref: /aosp_15_r20/frameworks/wilhelm/tools/hashgen/test.c (revision bebae9c0e76121f8312ccb50385c080b3a0b023c)
1*bebae9c0SAndroid Build Coastguard Worker /*
2*bebae9c0SAndroid Build Coastguard Worker  * Copyright (C) 2016 The Android Open Source Project
3*bebae9c0SAndroid Build Coastguard Worker  *
4*bebae9c0SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*bebae9c0SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*bebae9c0SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*bebae9c0SAndroid Build Coastguard Worker  *
8*bebae9c0SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*bebae9c0SAndroid Build Coastguard Worker  *
10*bebae9c0SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*bebae9c0SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*bebae9c0SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*bebae9c0SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*bebae9c0SAndroid Build Coastguard Worker  * limitations under the License.
15*bebae9c0SAndroid Build Coastguard Worker  */
16*bebae9c0SAndroid Build Coastguard Worker 
17*bebae9c0SAndroid Build Coastguard Worker // Test the minimal perfect hash generator function
18*bebae9c0SAndroid Build Coastguard Worker 
19*bebae9c0SAndroid Build Coastguard Worker #include <stdio.h>
20*bebae9c0SAndroid Build Coastguard Worker #include <stdlib.h>
21*bebae9c0SAndroid Build Coastguard Worker #include <SLES/OpenSLES.h>
22*bebae9c0SAndroid Build Coastguard Worker #include "MPH.h"
23*bebae9c0SAndroid Build Coastguard Worker 
24*bebae9c0SAndroid Build Coastguard Worker extern int IID_to_MPH(const SLInterfaceID iid);
25*bebae9c0SAndroid Build Coastguard Worker extern const struct SLInterfaceID_ SL_IID_array[MPH_MAX];
26*bebae9c0SAndroid Build Coastguard Worker 
main(int argc,char ** argv)27*bebae9c0SAndroid Build Coastguard Worker int main(int argc, char **argv)
28*bebae9c0SAndroid Build Coastguard Worker {
29*bebae9c0SAndroid Build Coastguard Worker     int i;
30*bebae9c0SAndroid Build Coastguard Worker     for (i = 0; i < MPH_MAX; i++) {
31*bebae9c0SAndroid Build Coastguard Worker         const struct SLInterfaceID_ *original = &SL_IID_array[i];
32*bebae9c0SAndroid Build Coastguard Worker         // test the address-based lookup
33*bebae9c0SAndroid Build Coastguard Worker         int MPH = IID_to_MPH(original);
34*bebae9c0SAndroid Build Coastguard Worker         if (MPH != i) {
35*bebae9c0SAndroid Build Coastguard Worker             fprintf(stderr, "error: IID_to_MPH(SL_IID_array) = %d != %d\n", MPH, i);
36*bebae9c0SAndroid Build Coastguard Worker             return EXIT_FAILURE;
37*bebae9c0SAndroid Build Coastguard Worker         }
38*bebae9c0SAndroid Build Coastguard Worker         // test the content-based lookup
39*bebae9c0SAndroid Build Coastguard Worker         const struct SLInterfaceID_ copy = *original;
40*bebae9c0SAndroid Build Coastguard Worker         MPH = IID_to_MPH(&copy);
41*bebae9c0SAndroid Build Coastguard Worker         if (MPH != i) {
42*bebae9c0SAndroid Build Coastguard Worker             fprintf(stderr, "error: IID_to_MPH(copy) = %d != %d\n", MPH, i);
43*bebae9c0SAndroid Build Coastguard Worker             return EXIT_FAILURE;
44*bebae9c0SAndroid Build Coastguard Worker         }
45*bebae9c0SAndroid Build Coastguard Worker     }
46*bebae9c0SAndroid Build Coastguard Worker     printf("OK\n");
47*bebae9c0SAndroid Build Coastguard Worker     return EXIT_SUCCESS;
48*bebae9c0SAndroid Build Coastguard Worker }
49