blob: e46634bab93a4fae9276cb02fb33342b47669697 [file] [log] [blame]
Christian Egli22ae4a82014-09-18 12:09:31 +02001/* liblouis Braille Translation and Back-Translation Library
2
3Copyright (C) 2014 Swiss Library for the Blind, Visually Impaired and Print Disabled
4
5Copying and distribution of this file, with or without modification,
6are permitted in any medium without royalty provided the copyright
7notice and this notice are preserved. This file is offered as-is,
8without any warranty. */
9
Bert Freesdc97ef72014-02-10 14:26:09 +000010#include <stdio.h>
11#include <string.h>
12#include <stdlib.h>
Christian Eglibb8a27b2014-03-03 09:43:05 +000013#include <unistd.h>
Bert Freesdc97ef72014-02-10 14:26:09 +000014#include "liblouis.h"
Christian Eglibb8a27b2014-03-03 09:43:05 +000015#include "resolve_table.h"
Bert Freesdc97ef72014-02-10 14:26:09 +000016
17#define ASSERT(test) \
18 do { \
19 if (!(test)) \
20 result = 1; \
21 } while(0) \
22
23int
24main(int argc, char **argv)
25{
26
27 /* ====================================================================== *
28 * `-- resolve_table *
29 * |-- dir_1 *
30 * | |-- dir_1.1 *
31 * | | `-- table_1.1.1 *
32 * | |-- table_1.1 *
33 * | |-- table_1.2 ------------------------------ *
34 * | `-- table_1.3 --> | include dir_1.1/table_1.1.1 | *
35 * |-- dir_2 `----------------------------- *
36 * | |-- table_2.1 ------------------ *
37 * | `-- table_2.2 --> | include table_1 | *
38 * |-- table_1 `----------------- *
39 * |-- table_2 ------------------ *
40 * |-- table_3 --> | include table_2 | *
41 * | `----------------- *
42 * | -------------------------- *
43 * |-- table_4 --> | include dir_1/table_1.3 | *
44 * | `------------------------- *
45 * | -------------------------- *
46 * |-- table_5 --> | include dir_2/table_2.2 | *
47 * | `------------------------- *
48 * | ---------------------- *
49 * `-- table_6 --> | dir_1.1/table_1.1.1 | *
50 * `--------------------- *
51 * ====================================================================== */
52
53 int result = 0;
Christian Eglibb8a27b2014-03-03 09:43:05 +000054
55 // this test relies on being in the test dir, so that it can test
56 // finding tables by relative path
Christian Egli717c96d2014-03-07 10:59:51 +000057 if (chdir(TEST_SRC_DIR)) return 1;
Christian Eglibb8a27b2014-03-03 09:43:05 +000058
Bert Freesdc97ef72014-02-10 14:26:09 +000059 // Full path
60 setenv ("LOUIS_TABLEPATH", "", 1);
61 ASSERT (lou_getTable ("tables/resolve_table/table_1"));
62
63 // File name not on LOUIS_TABLEPATH
64 ASSERT (!lou_getTable ("table_1"));
65
66 // File name on LOUIS_TABLEPATH
67 setenv ("LOUIS_TABLEPATH", "tables/resolve_table", 1);
68 ASSERT (lou_getTable ("table_1"));
69
70 // First is full path, second is in same directory
71 setenv ("LOUIS_TABLEPATH", "", 1);
72 ASSERT (lou_getTable ("tables/resolve_table/table_1,"
73 "table_2"));
74
75 // First is full path, second is not in same directory
76 ASSERT (!lou_getTable ("tables/resolve_table/table_1,"
77 "table_1.1.1"));
78
79 // Two full paths
80 ASSERT (lou_getTable ("tables/resolve_table/dir_1/table_1.1,"
81 "tables/resolve_table/dir_2/table_2.1"));
82
83 // First is full path, second is on LOUIS_TABLEPATH, third is in same
84 // directory as first
85 setenv ("LOUIS_TABLEPATH", "tables/resolve_table/dir_2", 1);
86 ASSERT (lou_getTable ("tables/resolve_table/dir_1/table_1.1,"
87 "table_2.1,"
88 "table_1.2"));
89
90 // First is full path, second is in subdirectory
91 setenv ("LOUIS_TABLEPATH", "", 1);
92 ASSERT (lou_getTable ("tables/resolve_table/table_1,"
93 "dir_1/table_1.1"));
94
95 // Two file names in different directories, but both on LOUIS_TABLEPATH
96 setenv ("LOUIS_TABLEPATH", "tables/resolve_table/dir_1,"
97 "tables/resolve_table/dir_2", 1);
98 ASSERT (lou_getTable ("table_1.2,"
99 "table_2.1"));
100
101 // First is file name on LOUIS_TABLEPATH, second is full path, third is in
102 // same directory as second
103 setenv ("LOUIS_TABLEPATH", "tables/resolve_table", 1);
104 ASSERT (!lou_getTable ("table_1,"
105 "tables/resolve_table/dir_1/table_1.1,"
106 "table_1.2"));
107
108 // Full path, include table in same directory
109 setenv ("LOUIS_TABLEPATH", "", 1);
110 ASSERT (lou_getTable ("tables/resolve_table/table_3"));
111
112 // Full path, include table in subdirectory
113 ASSERT (lou_getTable ("tables/resolve_table/dir_1/table_1.3"));
114
115 // Full path, include table in subdirectory, from there include table in
116 // sub-subdirectory
117 ASSERT (lou_getTable ("tables/resolve_table/table_4"));
118
119 // Full path, include table in subdirectory, from there include table in
120 // first directory
121 ASSERT (!lou_getTable ("tables/resolve_table/table_5"));
122
123 // Full path, include table in subdirectory, from there include table on
124 // LOUIS_TABLEPATH
125 setenv ("LOUIS_TABLEPATH", "tables/resolve_table", 1);
126 ASSERT (lou_getTable ("tables/resolve_table/table_5"));
127
128 // Full path, include table in subdirectory of LOUIS_TABLEPATH
129 setenv ("LOUIS_TABLEPATH", "tables/resolve_table/dir_1", 1);
130 ASSERT (lou_getTable ("tables/resolve_table/table_6"));
131
132 return result;
133
134}