blob: 0a745016e7575664edcecfeaadd5f441976516a0 [file] [log] [blame]
Bert Freesdc97ef72014-02-10 14:26:09 +00001#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
Christian Eglibb8a27b2014-03-03 09:43:05 +00004#include <unistd.h>
Bert Freesdc97ef72014-02-10 14:26:09 +00005#include "liblouis.h"
Christian Eglibb8a27b2014-03-03 09:43:05 +00006#include "resolve_table.h"
Bert Freesdc97ef72014-02-10 14:26:09 +00007
8#define ASSERT(test) \
9 do { \
10 if (!(test)) \
11 result = 1; \
12 } while(0) \
13
14int
15main(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;
Christian Eglibb8a27b2014-03-03 09:43:05 +000045
46 // this test relies on being in the test dir, so that it can test
47 // finding tables by relative path
Christian Egli717c96d2014-03-07 10:59:51 +000048 if (chdir(TEST_SRC_DIR)) return 1;
Christian Eglibb8a27b2014-03-03 09:43:05 +000049
Bert Freesdc97ef72014-02-10 14:26:09 +000050 // 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}