Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / liblouis / src / tests / resolve_table.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include "liblouis.h"
6 #include "resolve_table.h"
7
8 #define ASSERT(test)  \
9   do {                \
10     if (!(test))      \
11       result = 1;     \
12   } while(0)          \
13     
14 int
15 main(int argc, char **argv)
16 {
17     
18   /* ====================================================================== *
19    * `-- resolve_table                                                      *
20    *     |-- dir_1                                                          *
21    *     |   |-- dir_1.1                                                    *
22    *     |   |   `-- table_1.1.1                                            *
23    *     |   |-- table_1.1                                                  *
24    *     |   |-- table_1.2      ------------------------------              *
25    *     |   `-- table_1.3 --> | include dir_1.1/table_1.1.1 |              *
26    *     |-- dir_2             `-----------------------------               *
27    *     |   |-- table_2.1      ------------------                          *
28    *     |   `-- table_2.2 --> | include table_1 |                          *
29    *     |-- table_1           `-----------------                           *
30    *     |-- table_2      ------------------                                *
31    *     |-- table_3 --> | include table_2 |                                *
32    *     |               `-----------------                                 *
33    *     |                --------------------------                        *
34    *     |-- table_4 --> | include dir_1/table_1.3 |                        *
35    *     |               `-------------------------                         *
36    *     |                --------------------------                        *
37    *     |-- table_5 --> | include dir_2/table_2.2 |                        *
38    *     |               `-------------------------                         *
39    *     |                ----------------------                            *
40    *     `-- table_6 --> | dir_1.1/table_1.1.1 |                            *
41    *                     `---------------------                             *
42    * ====================================================================== */
43   
44   int result = 0;
45
46   // this test relies on being in the test dir, so that it can test
47   // finding tables by relative path
48   if (chdir(TEST_SRC_DIR)) return 1;
49
50   // Full path
51   setenv ("LOUIS_TABLEPATH", "", 1);
52   ASSERT (lou_getTable ("tables/resolve_table/table_1"));
53   
54   // File name not on LOUIS_TABLEPATH
55   ASSERT (!lou_getTable ("table_1"));
56   
57   // File name on LOUIS_TABLEPATH
58   setenv ("LOUIS_TABLEPATH", "tables/resolve_table", 1);
59   ASSERT (lou_getTable ("table_1"));
60   
61   // First is full path, second is in same directory
62   setenv ("LOUIS_TABLEPATH", "", 1);
63   ASSERT (lou_getTable ("tables/resolve_table/table_1,"
64                         "table_2"));
65   
66   // First is full path, second is not in same directory
67   ASSERT (!lou_getTable ("tables/resolve_table/table_1,"
68                          "table_1.1.1"));
69   
70   // Two full paths
71   ASSERT (lou_getTable ("tables/resolve_table/dir_1/table_1.1,"
72                         "tables/resolve_table/dir_2/table_2.1"));
73   
74   // First is full path, second is on LOUIS_TABLEPATH, third is in same
75   // directory as first
76   setenv ("LOUIS_TABLEPATH", "tables/resolve_table/dir_2", 1);
77   ASSERT (lou_getTable ("tables/resolve_table/dir_1/table_1.1,"
78                         "table_2.1,"
79                         "table_1.2"));
80   
81   // First is full path, second is in subdirectory
82   setenv ("LOUIS_TABLEPATH", "", 1);
83   ASSERT (lou_getTable ("tables/resolve_table/table_1,"
84                         "dir_1/table_1.1"));
85   
86   // Two file names in different directories, but both on LOUIS_TABLEPATH
87   setenv ("LOUIS_TABLEPATH", "tables/resolve_table/dir_1,"
88                              "tables/resolve_table/dir_2", 1);
89   ASSERT (lou_getTable ("table_1.2,"
90                         "table_2.1"));
91   
92   // First is file name on LOUIS_TABLEPATH, second is full path, third is in
93   // same directory as second
94   setenv ("LOUIS_TABLEPATH", "tables/resolve_table", 1);
95   ASSERT (!lou_getTable ("table_1,"
96                          "tables/resolve_table/dir_1/table_1.1,"
97                          "table_1.2"));
98   
99   // Full path, include table in same directory
100   setenv ("LOUIS_TABLEPATH", "", 1);
101   ASSERT (lou_getTable ("tables/resolve_table/table_3"));
102   
103   // Full path, include table in subdirectory
104   ASSERT (lou_getTable ("tables/resolve_table/dir_1/table_1.3"));
105   
106   // Full path, include table in subdirectory, from there include table in
107   // sub-subdirectory
108   ASSERT (lou_getTable ("tables/resolve_table/table_4"));
109   
110   // Full path, include table in subdirectory, from there include table in
111   // first directory
112   ASSERT (!lou_getTable ("tables/resolve_table/table_5"));
113   
114   // Full path, include table in subdirectory, from there include table on
115   // LOUIS_TABLEPATH
116   setenv ("LOUIS_TABLEPATH", "tables/resolve_table", 1);
117   ASSERT (lou_getTable ("tables/resolve_table/table_5"));
118   
119   // Full path, include table in subdirectory of LOUIS_TABLEPATH
120   setenv ("LOUIS_TABLEPATH", "tables/resolve_table/dir_1", 1);
121   ASSERT (lou_getTable ("tables/resolve_table/table_6"));
122   
123   return result;
124   
125 }