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