blob: 58117cbc6b0cadfe4726f2c72966b002a23acfe3 [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
Christian Egli26fabec2015-09-11 16:28:40 +020010#include <config.h>
Bert Freesdc97ef72014-02-10 14:26:09 +000011#include <stdio.h>
12#include <string.h>
13#include <stdlib.h>
Christian Eglibb8a27b2014-03-03 09:43:05 +000014#include <unistd.h>
Bert Freesdc97ef72014-02-10 14:26:09 +000015#include "liblouis.h"
Christian Eglibb8a27b2014-03-03 09:43:05 +000016#include "resolve_table.h"
Bert Freesdc97ef72014-02-10 14:26:09 +000017
18#define ASSERT(test) \
19 do { \
20 if (!(test)) \
21 result = 1; \
22 } while(0) \
23
24int
25main(int argc, char **argv)
26{
27
28 /* ====================================================================== *
29 * `-- resolve_table *
30 * |-- dir_1 *
31 * | |-- dir_1.1 *
32 * | | `-- table_1.1.1 *
33 * | |-- table_1.1 *
34 * | |-- table_1.2 ------------------------------ *
35 * | `-- table_1.3 --> | include dir_1.1/table_1.1.1 | *
36 * |-- dir_2 `----------------------------- *
37 * | |-- table_2.1 ------------------ *
38 * | `-- table_2.2 --> | include table_1 | *
39 * |-- table_1 `----------------- *
40 * |-- table_2 ------------------ *
41 * |-- table_3 --> | include table_2 | *
42 * | `----------------- *
43 * | -------------------------- *
44 * |-- table_4 --> | include dir_1/table_1.3 | *
45 * | `------------------------- *
46 * | -------------------------- *
47 * |-- table_5 --> | include dir_2/table_2.2 | *
48 * | `------------------------- *
49 * | ---------------------- *
50 * `-- table_6 --> | dir_1.1/table_1.1.1 | *
51 * `--------------------- *
52 * ====================================================================== */
53
54 int result = 0;
Christian Eglibb8a27b2014-03-03 09:43:05 +000055
56 // this test relies on being in the test dir, so that it can test
57 // finding tables by relative path
Christian Egli717c96d2014-03-07 10:59:51 +000058 if (chdir(TEST_SRC_DIR)) return 1;
Christian Eglibb8a27b2014-03-03 09:43:05 +000059
Bert Freesdc97ef72014-02-10 14:26:09 +000060 // Full path
61 setenv ("LOUIS_TABLEPATH", "", 1);
62 ASSERT (lou_getTable ("tables/resolve_table/table_1"));
63
64 // File name not on LOUIS_TABLEPATH
65 ASSERT (!lou_getTable ("table_1"));
66
67 // File name on LOUIS_TABLEPATH
68 setenv ("LOUIS_TABLEPATH", "tables/resolve_table", 1);
69 ASSERT (lou_getTable ("table_1"));
70
71 // First is full path, second is in same directory
72 setenv ("LOUIS_TABLEPATH", "", 1);
73 ASSERT (lou_getTable ("tables/resolve_table/table_1,"
74 "table_2"));
75
76 // First is full path, second is not in same directory
77 ASSERT (!lou_getTable ("tables/resolve_table/table_1,"
78 "table_1.1.1"));
79
80 // Two full paths
81 ASSERT (lou_getTable ("tables/resolve_table/dir_1/table_1.1,"
82 "tables/resolve_table/dir_2/table_2.1"));
83
84 // First is full path, second is on LOUIS_TABLEPATH, third is in same
85 // directory as first
86 setenv ("LOUIS_TABLEPATH", "tables/resolve_table/dir_2", 1);
87 ASSERT (lou_getTable ("tables/resolve_table/dir_1/table_1.1,"
88 "table_2.1,"
89 "table_1.2"));
90
91 // First is full path, second is in subdirectory
92 setenv ("LOUIS_TABLEPATH", "", 1);
93 ASSERT (lou_getTable ("tables/resolve_table/table_1,"
94 "dir_1/table_1.1"));
95
96 // Two file names in different directories, but both on LOUIS_TABLEPATH
97 setenv ("LOUIS_TABLEPATH", "tables/resolve_table/dir_1,"
98 "tables/resolve_table/dir_2", 1);
99 ASSERT (lou_getTable ("table_1.2,"
100 "table_2.1"));
101
102 // First is file name on LOUIS_TABLEPATH, second is full path, third is in
103 // same directory as second
104 setenv ("LOUIS_TABLEPATH", "tables/resolve_table", 1);
105 ASSERT (!lou_getTable ("table_1,"
106 "tables/resolve_table/dir_1/table_1.1,"
107 "table_1.2"));
108
109 // Full path, include table in same directory
110 setenv ("LOUIS_TABLEPATH", "", 1);
111 ASSERT (lou_getTable ("tables/resolve_table/table_3"));
112
113 // Full path, include table in subdirectory
114 ASSERT (lou_getTable ("tables/resolve_table/dir_1/table_1.3"));
115
116 // Full path, include table in subdirectory, from there include table in
117 // sub-subdirectory
118 ASSERT (lou_getTable ("tables/resolve_table/table_4"));
119
120 // Full path, include table in subdirectory, from there include table in
121 // first directory
122 ASSERT (!lou_getTable ("tables/resolve_table/table_5"));
123
124 // Full path, include table in subdirectory, from there include table on
125 // LOUIS_TABLEPATH
126 setenv ("LOUIS_TABLEPATH", "tables/resolve_table", 1);
127 ASSERT (lou_getTable ("tables/resolve_table/table_5"));
128
129 // Full path, include table in subdirectory of LOUIS_TABLEPATH
130 setenv ("LOUIS_TABLEPATH", "tables/resolve_table/dir_1", 1);
131 ASSERT (lou_getTable ("tables/resolve_table/table_6"));
Christian Eglib5bcac12015-08-19 11:16:09 +0200132
133 lou_free();
134
Bert Freesdc97ef72014-02-10 14:26:09 +0000135 return result;
136
137}