Christian Egli | 22ae4a8 | 2014-09-18 12:09:31 +0200 | [diff] [blame] | 1 | /* liblouis Braille Translation and Back-Translation Library |
| 2 | |
| 3 | Copyright (C) 2014 Swiss Library for the Blind, Visually Impaired and Print Disabled |
| 4 | |
| 5 | Copying and distribution of this file, with or without modification, |
| 6 | are permitted in any medium without royalty provided the copyright |
| 7 | notice and this notice are preserved. This file is offered as-is, |
| 8 | without any warranty. */ |
| 9 | |
Christian Egli | 26fabec | 2015-09-11 16:28:40 +0200 | [diff] [blame] | 10 | #include <config.h> |
Bert Frees | dc97ef7 | 2014-02-10 14:26:09 +0000 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | #include <string.h> |
| 13 | #include <stdlib.h> |
Christian Egli | bb8a27b | 2014-03-03 09:43:05 +0000 | [diff] [blame] | 14 | #include <unistd.h> |
Bert Frees | dc97ef7 | 2014-02-10 14:26:09 +0000 | [diff] [blame] | 15 | #include "liblouis.h" |
Christian Egli | bb8a27b | 2014-03-03 09:43:05 +0000 | [diff] [blame] | 16 | #include "resolve_table.h" |
Bert Frees | dc97ef7 | 2014-02-10 14:26:09 +0000 | [diff] [blame] | 17 | |
| 18 | #define ASSERT(test) \ |
| 19 | do { \ |
| 20 | if (!(test)) \ |
| 21 | result = 1; \ |
| 22 | } while(0) \ |
| 23 | |
| 24 | int |
| 25 | main(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 Egli | bb8a27b | 2014-03-03 09:43:05 +0000 | [diff] [blame] | 55 | |
| 56 | // this test relies on being in the test dir, so that it can test |
| 57 | // finding tables by relative path |
Christian Egli | 717c96d | 2014-03-07 10:59:51 +0000 | [diff] [blame] | 58 | if (chdir(TEST_SRC_DIR)) return 1; |
Christian Egli | bb8a27b | 2014-03-03 09:43:05 +0000 | [diff] [blame] | 59 | |
Bert Frees | dc97ef7 | 2014-02-10 14:26:09 +0000 | [diff] [blame] | 60 | // 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 Egli | b5bcac1 | 2015-08-19 11:16:09 +0200 | [diff] [blame] | 132 | |
| 133 | lou_free(); |
| 134 | |
Bert Frees | dc97ef7 | 2014-02-10 14:26:09 +0000 | [diff] [blame] | 135 | return result; |
| 136 | |
| 137 | } |