TZIVI-254: IVI needs a newer version of cmake
[profile/ivi/cmake.git] / Tests / BundleTest / BundleLib.cxx
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5
6 #include <CoreFoundation/CoreFoundation.h>
7
8 int fileExists(char* filename)
9 {
10 #ifndef R_OK
11 # define R_OK 04
12 #endif
13   if ( access(filename, R_OK) != 0 )
14     {
15     printf("Cannot find file: %s\n", filename);
16     return 0;
17     }
18   return 1;
19 }
20
21 int findBundleFile(char* exec, const char* file)
22 {
23   int res;
24   char* nexec = strdup(exec);
25   char* fpath = (char*)malloc(strlen(exec) + 100);
26   int cc;
27   int cnt = 0;
28   printf("Process executable name: %s\n", exec);
29
30   // Remove the executable name and directory name
31   for ( cc = strlen(nexec)-1; cc > 0; cc -- )
32     {
33     if ( nexec[cc] == '/' )
34       {
35       nexec[cc] = 0;
36       if ( cnt == 1 )
37         {
38         break;
39         }
40       cnt ++;
41       }
42     }
43   printf("Process executable path: %s\n", nexec);
44   sprintf(fpath, "%s/%s", nexec, file);
45   printf("Check for file: %s\n", fpath);
46   res = fileExists(fpath);
47   free(nexec);
48   free(fpath);
49   return res;
50 }
51
52 int foo(char *exec)
53 {
54   // Call a CoreFoundation function...
55   //
56   CFBundleRef br = CFBundleGetMainBundle();
57   (void) br;
58
59   int res1 = findBundleFile(exec, "Resources/randomResourceFile.plist");
60   int res2 = findBundleFile(exec, "MacOS/SomeRandomFile.txt");
61   int res3 = findBundleFile(exec, "MacOS/ChangeLog.txt");
62   if ( !res1 ||
63     !res2 ||
64     !res3 )
65     {
66     return 1;
67     }
68
69   return 0;
70 }