[5aa33fd] | 1 | #define OWL_PERL |
---|
| 2 | #define WINDOW FAKE_WINDOW |
---|
[7d4fbcd] | 3 | #include "owl.h" |
---|
[5aa33fd] | 4 | #undef WINDOW |
---|
| 5 | |
---|
[7d4fbcd] | 6 | #include <unistd.h> |
---|
| 7 | #include <stdlib.h> |
---|
| 8 | |
---|
[5aa33fd] | 9 | #undef instr |
---|
| 10 | #include <curses.h> |
---|
| 11 | |
---|
[b2b0773] | 12 | owl_global g; |
---|
| 13 | |
---|
[a2b3289] | 14 | int numtests; |
---|
[1cf3f8d3] | 15 | |
---|
[c2673ab] | 16 | int owl_regtest(void); |
---|
[8bce750] | 17 | int owl_util_regtest(void); |
---|
| 18 | int owl_dict_regtest(void); |
---|
| 19 | int owl_variable_regtest(void); |
---|
| 20 | int owl_filter_regtest(void); |
---|
| 21 | int owl_obarray_regtest(void); |
---|
[4cc02605] | 22 | int owl_editwin_regtest(void); |
---|
[6772d19] | 23 | int owl_fmtext_regtest(void); |
---|
[8bce750] | 24 | |
---|
[5aa33fd] | 25 | extern void owl_perl_xs_init(pTHX); |
---|
| 26 | |
---|
[094009a] | 27 | int main(int argc, char **argv, char **env) |
---|
| 28 | { |
---|
[95414bf] | 29 | FILE *rnull; |
---|
| 30 | FILE *wnull; |
---|
[c2673ab] | 31 | char *perlerr; |
---|
| 32 | int status = 0; |
---|
[95414bf] | 33 | |
---|
| 34 | if (argc <= 1) { |
---|
| 35 | fprintf(stderr, "Usage: %s --builtin|TEST.t|-le CODE\n", argv[0]); |
---|
| 36 | return 1; |
---|
| 37 | } |
---|
| 38 | |
---|
[f034ac0] | 39 | /* initialize a fake ncurses, detached from std{in,out} */ |
---|
[95414bf] | 40 | wnull = fopen("/dev/null", "w"); |
---|
| 41 | rnull = fopen("/dev/null", "r"); |
---|
[f034ac0] | 42 | newterm("xterm", wnull, rnull); |
---|
| 43 | /* initialize global structures */ |
---|
| 44 | owl_global_init(&g); |
---|
[124aebc] | 45 | |
---|
[c2673ab] | 46 | perlerr = owl_perlconfig_initperl(NULL, &argc, &argv, &env); |
---|
| 47 | if (perlerr) { |
---|
| 48 | endwin(); |
---|
| 49 | fprintf(stderr, "Internal perl error: %s\n", perlerr); |
---|
| 50 | status = 1; |
---|
| 51 | goto out; |
---|
| 52 | } |
---|
[98d7757] | 53 | |
---|
[c2673ab] | 54 | owl_global_complete_setup(&g); |
---|
[04b16f8] | 55 | owl_global_setup_default_filters(&g); |
---|
| 56 | |
---|
| 57 | owl_view_create(owl_global_get_current_view(&g), "main", |
---|
| 58 | owl_global_get_filter(&g, "all"), |
---|
| 59 | owl_global_get_style_by_name(&g, "default")); |
---|
[22e02cd] | 60 | |
---|
[98d7757] | 61 | owl_function_firstmsg(); |
---|
[c2673ab] | 62 | |
---|
[95414bf] | 63 | ENTER; |
---|
| 64 | SAVETMPS; |
---|
[5aa33fd] | 65 | |
---|
[95414bf] | 66 | if (strcmp(argv[1], "--builtin") == 0) { |
---|
| 67 | status = owl_regtest(); |
---|
| 68 | } else if (strcmp(argv[1], "-le") == 0 && argc > 2) { |
---|
| 69 | /* |
---|
| 70 | * 'prove' runs its harness perl with '-le CODE' to get some |
---|
| 71 | * information out. |
---|
| 72 | */ |
---|
| 73 | moreswitches("l"); |
---|
| 74 | eval_pv(argv[2], true); |
---|
| 75 | } else { |
---|
| 76 | sv_setpv(get_sv("0", false), argv[1]); |
---|
| 77 | sv_setpv(get_sv("main::test_prog", TRUE), argv[1]); |
---|
[5aa33fd] | 78 | |
---|
[95414bf] | 79 | eval_pv("do $main::test_prog; die($@) if($@)", true); |
---|
| 80 | } |
---|
[5aa33fd] | 81 | |
---|
[95414bf] | 82 | status = 0; |
---|
[5aa33fd] | 83 | |
---|
[95414bf] | 84 | FREETMPS; |
---|
| 85 | LEAVE; |
---|
[c2673ab] | 86 | |
---|
| 87 | out: |
---|
[5aa33fd] | 88 | perl_destruct(owl_global_get_perlinterp(&g)); |
---|
| 89 | perl_free(owl_global_get_perlinterp(&g)); |
---|
[c2673ab] | 90 | /* probably not necessary, but tear down the screen */ |
---|
| 91 | endwin(); |
---|
| 92 | fclose(rnull); |
---|
| 93 | fclose(wnull); |
---|
| 94 | return status; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | int owl_regtest(void) { |
---|
[a2b3289] | 98 | numtests = 0; |
---|
[7d4fbcd] | 99 | int numfailures=0; |
---|
[a2b3289] | 100 | /* |
---|
| 101 | printf("1..%d\n", OWL_UTIL_NTESTS+OWL_DICT_NTESTS+OWL_VARIABLE_NTESTS |
---|
| 102 | +OWL_FILTER_NTESTS+OWL_OBARRAY_NTESTS); |
---|
| 103 | */ |
---|
[3381399] | 104 | numfailures += owl_util_regtest(); |
---|
| 105 | numfailures += owl_dict_regtest(); |
---|
| 106 | numfailures += owl_variable_regtest(); |
---|
| 107 | numfailures += owl_filter_regtest(); |
---|
[4cc02605] | 108 | numfailures += owl_editwin_regtest(); |
---|
[6772d19] | 109 | numfailures += owl_fmtext_regtest(); |
---|
[3381399] | 110 | if (numfailures) { |
---|
[1cf3f8d3] | 111 | fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures); |
---|
[7d4fbcd] | 112 | } |
---|
[a2b3289] | 113 | printf("1..%d\n", numtests); |
---|
[f034ac0] | 114 | |
---|
[3381399] | 115 | return(numfailures); |
---|
[7d4fbcd] | 116 | } |
---|
[8bce750] | 117 | |
---|
| 118 | #define FAIL_UNLESS(desc,pred) do { int __pred = (pred); \ |
---|
| 119 | numtests++; \ |
---|
| 120 | printf("%s %s", (__pred)?"ok":(numfailed++,"not ok"), desc); \ |
---|
| 121 | if(!(__pred)) printf("\t(%s:%d)", __FILE__, __LINE__); printf("%c", '\n'); } while(0) |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | int owl_util_regtest(void) |
---|
| 125 | { |
---|
| 126 | int numfailed=0; |
---|
| 127 | |
---|
| 128 | printf("# BEGIN testing owl_util\n"); |
---|
| 129 | |
---|
| 130 | FAIL_UNLESS("owl_util_substitute 1", |
---|
| 131 | !strcmp("foo", owl_text_substitute("foo", "", "Y"))); |
---|
| 132 | FAIL_UNLESS("owl_text_substitute 2", |
---|
| 133 | !strcmp("fYZYZ", owl_text_substitute("foo", "o", "YZ"))); |
---|
| 134 | FAIL_UNLESS("owl_text_substitute 3", |
---|
| 135 | !strcmp("foo", owl_text_substitute("fYZYZ", "YZ", "o"))); |
---|
| 136 | FAIL_UNLESS("owl_text_substitute 4", |
---|
| 137 | !strcmp("/u/foo/meep", owl_text_substitute("~/meep", "~", "/u/foo"))); |
---|
| 138 | |
---|
| 139 | FAIL_UNLESS("skiptokens 1", |
---|
| 140 | !strcmp("bar quux", skiptokens("foo bar quux", 1))); |
---|
| 141 | FAIL_UNLESS("skiptokens 2", |
---|
| 142 | !strcmp("meep", skiptokens("foo 'bar quux' meep", 2))); |
---|
| 143 | |
---|
| 144 | FAIL_UNLESS("expand_tabs 1", |
---|
| 145 | !strcmp(" hi", owl_text_expand_tabs("\thi"))); |
---|
| 146 | |
---|
| 147 | FAIL_UNLESS("expand_tabs 2", |
---|
| 148 | !strcmp(" hi\nword tab", owl_text_expand_tabs("\thi\nword\ttab"))); |
---|
| 149 | |
---|
| 150 | FAIL_UNLESS("expand_tabs 3", |
---|
| 151 | !strcmp(" 2 tabs", owl_text_expand_tabs("\t\t2 tabs"))); |
---|
[f7cd7c9] | 152 | FAIL_UNLESS("expand_tabs 4", |
---|
| 153 | !strcmp("α ααααααα! ", owl_text_expand_tabs("α\tααααααα!\t"))); |
---|
| 154 | FAIL_UNLESS("expand_tabs 5", |
---|
| 155 | !strcmp("A AAA!! ", owl_text_expand_tabs("A\tAAA!!\t"))); |
---|
[8bce750] | 156 | |
---|
[e30ed92] | 157 | FAIL_UNLESS("skiptokens 1", |
---|
| 158 | !strcmp("world", skiptokens("hello world", 1))); |
---|
| 159 | |
---|
| 160 | FAIL_UNLESS("skiptokens 2", |
---|
| 161 | !strcmp("c d e", skiptokens("a b c d e", 2))); |
---|
| 162 | |
---|
| 163 | FAIL_UNLESS("skiptokens 3", |
---|
| 164 | !strcmp("\"b\" c d e", skiptokens("a \"b\" c d e", 1))); |
---|
| 165 | |
---|
| 166 | FAIL_UNLESS("skiptokens 4", |
---|
| 167 | !strcmp("c d e", skiptokens("a \"b\" c d e", 2))); |
---|
| 168 | |
---|
| 169 | FAIL_UNLESS("skiptokens 5", |
---|
| 170 | !strcmp("c d e", skiptokens("a \"'\" c d e", 2))); |
---|
| 171 | |
---|
[8bce750] | 172 | /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */ |
---|
| 173 | printf("# END testing owl_util (%d failures)\n", numfailed); |
---|
| 174 | return(numfailed); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | int owl_dict_regtest(void) { |
---|
| 178 | owl_dict d; |
---|
| 179 | owl_list l; |
---|
| 180 | int numfailed=0; |
---|
| 181 | char *av="aval", *bv="bval", *cv="cval", *dv="dval"; |
---|
| 182 | |
---|
| 183 | printf("# BEGIN testing owl_dict\n"); |
---|
| 184 | FAIL_UNLESS("create", 0==owl_dict_create(&d)); |
---|
[a1074de] | 185 | FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_delete)); |
---|
| 186 | FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_delete)); |
---|
| 187 | FAIL_UNLESS("insert a", 0==owl_dict_insert_element(&d, "a", av, owl_dict_noop_delete)); |
---|
| 188 | FAIL_UNLESS("insert c", 0==owl_dict_insert_element(&d, "c", cv, owl_dict_noop_delete)); |
---|
[8bce750] | 189 | FAIL_UNLESS("reinsert d (no replace)", -2==owl_dict_insert_element(&d, "d", dv, 0)); |
---|
| 190 | FAIL_UNLESS("find a", av==owl_dict_find_element(&d, "a")); |
---|
| 191 | FAIL_UNLESS("find b", bv==owl_dict_find_element(&d, "b")); |
---|
| 192 | FAIL_UNLESS("find c", cv==owl_dict_find_element(&d, "c")); |
---|
| 193 | FAIL_UNLESS("find d", dv==owl_dict_find_element(&d, "d")); |
---|
| 194 | FAIL_UNLESS("find e (non-existent)", NULL==owl_dict_find_element(&d, "e")); |
---|
| 195 | FAIL_UNLESS("remove d", dv==owl_dict_remove_element(&d, "d")); |
---|
| 196 | FAIL_UNLESS("find d (post-removal)", NULL==owl_dict_find_element(&d, "d")); |
---|
| 197 | |
---|
| 198 | FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d)); |
---|
| 199 | FAIL_UNLESS("get_keys", 0==owl_dict_get_keys(&d, &l)); |
---|
| 200 | FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l)); |
---|
| 201 | |
---|
| 202 | /* these assume the returned keys are sorted */ |
---|
| 203 | FAIL_UNLESS("get_keys result val",0==strcmp("a",owl_list_get_element(&l,0))); |
---|
| 204 | FAIL_UNLESS("get_keys result val",0==strcmp("b",owl_list_get_element(&l,1))); |
---|
| 205 | FAIL_UNLESS("get_keys result val",0==strcmp("c",owl_list_get_element(&l,2))); |
---|
| 206 | |
---|
[8c59178] | 207 | owl_list_cleanup(&l, owl_free); |
---|
[bf7aa1d] | 208 | owl_dict_cleanup(&d, NULL); |
---|
[8bce750] | 209 | |
---|
| 210 | /* if (numfailed) printf("*** WARNING: failures encountered with owl_dict\n"); */ |
---|
| 211 | printf("# END testing owl_dict (%d failures)\n", numfailed); |
---|
| 212 | return(numfailed); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | int owl_variable_regtest(void) { |
---|
| 216 | owl_vardict vd; |
---|
| 217 | int numfailed=0; |
---|
| 218 | char buf[1024]; |
---|
| 219 | const void *v; |
---|
| 220 | |
---|
| 221 | printf("# BEGIN testing owl_variable\n"); |
---|
| 222 | FAIL_UNLESS("setup", 0==owl_variable_dict_setup(&vd)); |
---|
| 223 | |
---|
| 224 | FAIL_UNLESS("get bool", 0==owl_variable_get_bool(&vd,"rxping")); |
---|
| 225 | FAIL_UNLESS("get bool (no such)", -1==owl_variable_get_bool(&vd,"mumble")); |
---|
| 226 | FAIL_UNLESS("get bool as string 1", 0==owl_variable_get_tostring(&vd,"rxping", buf, 1024)); |
---|
| 227 | FAIL_UNLESS("get bool as string 2", 0==strcmp(buf,"off")); |
---|
| 228 | FAIL_UNLESS("set bool 1", 0==owl_variable_set_bool_on(&vd,"rxping")); |
---|
| 229 | FAIL_UNLESS("get bool 2", 1==owl_variable_get_bool(&vd,"rxping")); |
---|
| 230 | FAIL_UNLESS("set bool 3", 0==owl_variable_set_fromstring(&vd,"rxping","off",0,0)); |
---|
| 231 | FAIL_UNLESS("get bool 4", 0==owl_variable_get_bool(&vd,"rxping")); |
---|
| 232 | FAIL_UNLESS("set bool 5", -1==owl_variable_set_fromstring(&vd,"rxping","xxx",0,0)); |
---|
| 233 | FAIL_UNLESS("get bool 6", 0==owl_variable_get_bool(&vd,"rxping")); |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | FAIL_UNLESS("get string", 0==strcmp("~/zlog/people", owl_variable_get_string(&vd,"logpath"))); |
---|
| 237 | FAIL_UNLESS("set string 7", 0==owl_variable_set_string(&vd,"logpath","whee")); |
---|
| 238 | FAIL_UNLESS("get string", 0==strcmp("whee", owl_variable_get_string(&vd,"logpath"))); |
---|
| 239 | |
---|
| 240 | FAIL_UNLESS("get int", 8==owl_variable_get_int(&vd,"typewinsize")); |
---|
| 241 | FAIL_UNLESS("get int (no such)", -1==owl_variable_get_int(&vd,"mmble")); |
---|
| 242 | FAIL_UNLESS("get int as string 1", 0==owl_variable_get_tostring(&vd,"typewinsize", buf, 1024)); |
---|
| 243 | FAIL_UNLESS("get int as string 2", 0==strcmp(buf,"8")); |
---|
| 244 | FAIL_UNLESS("set int 1", 0==owl_variable_set_int(&vd,"typewinsize",12)); |
---|
| 245 | FAIL_UNLESS("get int 2", 12==owl_variable_get_int(&vd,"typewinsize")); |
---|
| 246 | FAIL_UNLESS("set int 1b", -1==owl_variable_set_int(&vd,"typewinsize",-3)); |
---|
| 247 | FAIL_UNLESS("get int 2b", 12==owl_variable_get_int(&vd,"typewinsize")); |
---|
| 248 | FAIL_UNLESS("set int 3", 0==owl_variable_set_fromstring(&vd,"typewinsize","9",0,0)); |
---|
| 249 | FAIL_UNLESS("get int 4", 9==owl_variable_get_int(&vd,"typewinsize")); |
---|
| 250 | FAIL_UNLESS("set int 5", -1==owl_variable_set_fromstring(&vd,"typewinsize","xxx",0,0)); |
---|
| 251 | FAIL_UNLESS("set int 6", -1==owl_variable_set_fromstring(&vd,"typewinsize","",0,0)); |
---|
| 252 | FAIL_UNLESS("get int 7", 9==owl_variable_get_int(&vd,"typewinsize")); |
---|
| 253 | |
---|
| 254 | owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval"); |
---|
| 255 | FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar", OWL_VARIABLE_STRING))); |
---|
| 256 | FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(&vd, "stringvar"))); |
---|
| 257 | owl_variable_set_string(&vd, "stringvar", "new val"); |
---|
| 258 | FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(&vd, "stringvar"))); |
---|
| 259 | |
---|
| 260 | owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47); |
---|
| 261 | FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(&vd, "intvar", OWL_VARIABLE_INT))); |
---|
| 262 | FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(&vd, "intvar")); |
---|
| 263 | owl_variable_set_int(&vd, "intvar", 17); |
---|
| 264 | FAIL_UNLESS("update bool val", 17 == owl_variable_get_int(&vd, "intvar")); |
---|
| 265 | |
---|
| 266 | owl_variable_dict_newvar_bool(&vd, "boolvar", "", "", 1); |
---|
| 267 | FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(&vd, "boolvar", OWL_VARIABLE_BOOL))); |
---|
| 268 | FAIL_UNLESS("get new bool val", owl_variable_get_bool(&vd, "boolvar")); |
---|
| 269 | owl_variable_set_bool_off(&vd, "boolvar"); |
---|
| 270 | FAIL_UNLESS("update string val", !owl_variable_get_bool(&vd, "boolvar")); |
---|
| 271 | |
---|
[0fef6eb] | 272 | owl_variable_dict_cleanup(&vd); |
---|
[8bce750] | 273 | |
---|
| 274 | /* if (numfailed) printf("*** WARNING: failures encountered with owl_variable\n"); */ |
---|
| 275 | printf("# END testing owl_variable (%d failures)\n", numfailed); |
---|
| 276 | return(numfailed); |
---|
| 277 | } |
---|
| 278 | |
---|
[e9c6fc8] | 279 | static int owl_filter_test_string(const char *filt, const owl_message *m, int shouldmatch) |
---|
| 280 | { |
---|
[23fddad] | 281 | owl_filter *f; |
---|
[8bce750] | 282 | int ok; |
---|
| 283 | int failed = 0; |
---|
[23fddad] | 284 | if ((f = owl_filter_new_fromstring("test-filter", filt)) == NULL) { |
---|
[8bce750] | 285 | printf("not ok can't parse %s\n", filt); |
---|
| 286 | failed = 1; |
---|
| 287 | goto out; |
---|
| 288 | } |
---|
[23fddad] | 289 | ok = owl_filter_message_match(f, m); |
---|
[8bce750] | 290 | if((shouldmatch && !ok) || (!shouldmatch && ok)) { |
---|
| 291 | printf("not ok match %s (got %d, expected %d)\n", filt, ok, shouldmatch); |
---|
| 292 | failed = 1; |
---|
| 293 | } |
---|
| 294 | out: |
---|
[23fddad] | 295 | owl_filter_delete(f); |
---|
[8bce750] | 296 | if(!failed) { |
---|
| 297 | printf("ok %s %s\n", shouldmatch ? "matches" : "doesn't match", filt); |
---|
| 298 | } |
---|
| 299 | return failed; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | int owl_filter_regtest(void) { |
---|
| 303 | int numfailed=0; |
---|
| 304 | owl_message m; |
---|
[23fddad] | 305 | owl_filter *f1, *f2, *f3, *f4, *f5; |
---|
[8bce750] | 306 | |
---|
[f0f2eec] | 307 | owl_dict_create(&g.filters); |
---|
| 308 | g.filterlist = NULL; |
---|
[8bce750] | 309 | owl_message_init(&m); |
---|
| 310 | owl_message_set_type_zephyr(&m); |
---|
| 311 | owl_message_set_direction_in(&m); |
---|
| 312 | owl_message_set_class(&m, "owl"); |
---|
| 313 | owl_message_set_instance(&m, "tester"); |
---|
| 314 | owl_message_set_sender(&m, "owl-user"); |
---|
| 315 | owl_message_set_recipient(&m, "joe"); |
---|
| 316 | owl_message_set_attribute(&m, "foo", "bar"); |
---|
| 317 | |
---|
| 318 | #define TEST_FILTER(f, e) do { \ |
---|
| 319 | numtests++; \ |
---|
| 320 | numfailed += owl_filter_test_string(f, &m, e); \ |
---|
| 321 | } while(0) |
---|
| 322 | |
---|
| 323 | TEST_FILTER("true", 1); |
---|
| 324 | TEST_FILTER("false", 0); |
---|
| 325 | TEST_FILTER("( true )", 1); |
---|
| 326 | TEST_FILTER("not false", 1); |
---|
| 327 | TEST_FILTER("( true ) or ( false )", 1); |
---|
| 328 | TEST_FILTER("true and false", 0); |
---|
| 329 | TEST_FILTER("( true or true ) or ( ( false ) )", 1); |
---|
| 330 | |
---|
| 331 | TEST_FILTER("class owl", 1); |
---|
| 332 | TEST_FILTER("class ^owl$", 1); |
---|
| 333 | TEST_FILTER("instance test", 1); |
---|
| 334 | TEST_FILTER("instance ^test$", 0); |
---|
| 335 | TEST_FILTER("instance ^tester$", 1); |
---|
| 336 | |
---|
| 337 | TEST_FILTER("foo bar", 1); |
---|
| 338 | TEST_FILTER("class owl and instance tester", 1); |
---|
| 339 | TEST_FILTER("type ^zephyr$ and direction ^in$ and ( class ^owl$ or instance ^owl$ )", 1); |
---|
| 340 | |
---|
| 341 | /* Order of operations and precedence */ |
---|
| 342 | TEST_FILTER("not true or false", 0); |
---|
| 343 | TEST_FILTER("true or true and false", 0); |
---|
| 344 | TEST_FILTER("true and true and false or true", 1); |
---|
| 345 | TEST_FILTER("false and false or true", 1); |
---|
| 346 | TEST_FILTER("true and false or false", 0); |
---|
| 347 | |
---|
[23fddad] | 348 | f1 = owl_filter_new_fromstring("f1", "class owl"); |
---|
| 349 | owl_global_add_filter(&g, f1); |
---|
[8bce750] | 350 | TEST_FILTER("filter f1", 1); |
---|
[23fddad] | 351 | owl_global_remove_filter(&g, "f1"); |
---|
[8bce750] | 352 | |
---|
| 353 | /* Test recursion prevention */ |
---|
[23fddad] | 354 | FAIL_UNLESS("self reference", (f2 = owl_filter_new_fromstring("test", "filter test")) == NULL); |
---|
| 355 | owl_filter_delete(f2); |
---|
[8bce750] | 356 | |
---|
| 357 | /* mutual recursion */ |
---|
[23fddad] | 358 | f3 = owl_filter_new_fromstring("f3", "filter f4"); |
---|
| 359 | owl_global_add_filter(&g, f3); |
---|
| 360 | FAIL_UNLESS("mutual recursion", (f4 = owl_filter_new_fromstring("f4", "filter f3")) == NULL); |
---|
| 361 | owl_global_remove_filter(&g, "f3"); |
---|
| 362 | owl_filter_delete(f4); |
---|
[8bce750] | 363 | |
---|
| 364 | /* support referencing a filter several times */ |
---|
[23fddad] | 365 | FAIL_UNLESS("DAG", (f5 = owl_filter_new_fromstring("dag", "filter f1 or filter f1")) != NULL); |
---|
| 366 | owl_filter_delete(f5); |
---|
[8bce750] | 367 | |
---|
| 368 | return 0; |
---|
| 369 | } |
---|
| 370 | |
---|
[4cc02605] | 371 | int owl_editwin_regtest(void) { |
---|
| 372 | int numfailed = 0; |
---|
| 373 | const char *p; |
---|
[35a30f9] | 374 | owl_editwin *oe; |
---|
[4cc02605] | 375 | |
---|
| 376 | printf("# BEGIN testing owl_editwin\n"); |
---|
| 377 | |
---|
[4123da1] | 378 | oe = owl_editwin_new(NULL, 80, 80, OWL_EDITWIN_STYLE_MULTILINE, NULL); |
---|
[4cc02605] | 379 | |
---|
| 380 | /* TODO: make the strings a little more lenient w.r.t trailing whitespace */ |
---|
| 381 | |
---|
| 382 | /* check paragraph fill */ |
---|
| 383 | owl_editwin_insert_string(oe, "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah.\n\nblah"); |
---|
| 384 | owl_editwin_move_to_top(oe); |
---|
| 385 | owl_editwin_fill_paragraph(oe); |
---|
| 386 | p = owl_editwin_get_text(oe); |
---|
| 387 | FAIL_UNLESS("text was correctly wrapped", p && !strcmp(p, "blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n" |
---|
| 388 | "blah blah blah.\n" |
---|
| 389 | "\n" |
---|
| 390 | "blah")); |
---|
| 391 | |
---|
[4123da1] | 392 | owl_editwin_delete(oe); oe = NULL; |
---|
| 393 | oe = owl_editwin_new(NULL, 80, 80, OWL_EDITWIN_STYLE_MULTILINE, NULL); |
---|
| 394 | |
---|
[4cc02605] | 395 | /* check that lines ending with ". " correctly fill */ |
---|
| 396 | owl_editwin_insert_string(oe, "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah. \n\nblah"); |
---|
| 397 | owl_editwin_move_to_top(oe); |
---|
| 398 | owl_editwin_fill_paragraph(oe); |
---|
| 399 | p = owl_editwin_get_text(oe); |
---|
| 400 | FAIL_UNLESS("text was correctly wrapped", p && !strcmp(p, "blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n" |
---|
| 401 | "blah blah blah. \n" |
---|
| 402 | "\n" |
---|
| 403 | "blah")); |
---|
| 404 | |
---|
[4123da1] | 405 | owl_editwin_delete(oe); oe = NULL; |
---|
[4cc02605] | 406 | |
---|
| 407 | printf("# END testing owl_editwin (%d failures)\n", numfailed); |
---|
| 408 | |
---|
| 409 | return numfailed; |
---|
| 410 | } |
---|
[6772d19] | 411 | |
---|
| 412 | int owl_fmtext_regtest(void) { |
---|
| 413 | int numfailed = 0; |
---|
| 414 | owl_fmtext fm1; |
---|
| 415 | owl_fmtext fm2; |
---|
| 416 | char *str; |
---|
| 417 | |
---|
| 418 | printf("# BEGIN testing owl_fmtext\n"); |
---|
| 419 | |
---|
| 420 | owl_fmtext_init_null(&fm1); |
---|
| 421 | owl_fmtext_init_null(&fm2); |
---|
| 422 | |
---|
| 423 | /* Verify text gets correctly appended. */ |
---|
| 424 | owl_fmtext_append_normal(&fm1, "1234567898"); |
---|
| 425 | owl_fmtext_append_fmtext(&fm2, &fm1); |
---|
| 426 | FAIL_UNLESS("string lengths correct", |
---|
| 427 | owl_fmtext_num_bytes(&fm2) == strlen(owl_fmtext_get_text(&fm2))); |
---|
| 428 | |
---|
| 429 | /* Test owl_fmtext_num_lines. */ |
---|
| 430 | owl_fmtext_clear(&fm1); |
---|
| 431 | FAIL_UNLESS("empty line correct", owl_fmtext_num_lines(&fm1) == 0); |
---|
| 432 | owl_fmtext_append_normal(&fm1, "12345\n67898"); |
---|
| 433 | FAIL_UNLESS("trailing chars correct", owl_fmtext_num_lines(&fm1) == 2); |
---|
| 434 | owl_fmtext_append_normal(&fm1, "\n"); |
---|
| 435 | FAIL_UNLESS("trailing newline correct", owl_fmtext_num_lines(&fm1) == 2); |
---|
| 436 | owl_fmtext_append_bold(&fm1, ""); |
---|
| 437 | FAIL_UNLESS("trailing attributes correct", owl_fmtext_num_lines(&fm1) == 2); |
---|
| 438 | |
---|
| 439 | /* Test owl_fmtext_truncate_lines */ |
---|
| 440 | owl_fmtext_clear(&fm1); |
---|
| 441 | owl_fmtext_append_normal(&fm1, "0\n1\n2\n3\n4\n"); |
---|
| 442 | |
---|
| 443 | owl_fmtext_clear(&fm2); |
---|
| 444 | owl_fmtext_truncate_lines(&fm1, 1, 3, &fm2); |
---|
| 445 | str = owl_fmtext_print_plain(&fm2); |
---|
| 446 | FAIL_UNLESS("lines corrected truncated", |
---|
| 447 | str && !strcmp(str, "1\n2\n3\n")); |
---|
| 448 | owl_free(str); |
---|
| 449 | |
---|
| 450 | owl_fmtext_clear(&fm2); |
---|
| 451 | owl_fmtext_truncate_lines(&fm1, 1, 5, &fm2); |
---|
| 452 | str = owl_fmtext_print_plain(&fm2); |
---|
| 453 | FAIL_UNLESS("lines corrected truncated", |
---|
| 454 | str && !strcmp(str, "1\n2\n3\n4\n")); |
---|
| 455 | owl_free(str); |
---|
| 456 | |
---|
| 457 | /* Test owl_fmtext_truncate_cols. */ |
---|
| 458 | owl_fmtext_clear(&fm1); |
---|
| 459 | owl_fmtext_append_normal(&fm1, "123456789012345\n"); |
---|
| 460 | owl_fmtext_append_normal(&fm1, "123456789\n"); |
---|
| 461 | owl_fmtext_append_normal(&fm1, "1234567890\n"); |
---|
| 462 | |
---|
| 463 | owl_fmtext_clear(&fm2); |
---|
| 464 | owl_fmtext_truncate_cols(&fm1, 4, 9, &fm2); |
---|
| 465 | str = owl_fmtext_print_plain(&fm2); |
---|
| 466 | FAIL_UNLESS("columns correctly truncated", |
---|
| 467 | str && !strcmp(str, "567890" |
---|
| 468 | "56789\n" |
---|
| 469 | "567890")); |
---|
| 470 | owl_free(str); |
---|
| 471 | |
---|
| 472 | owl_fmtext_cleanup(&fm1); |
---|
| 473 | owl_fmtext_cleanup(&fm2); |
---|
| 474 | |
---|
| 475 | printf("# END testing owl_fmtext (%d failures)\n", numfailed); |
---|
| 476 | |
---|
| 477 | return numfailed; |
---|
| 478 | } |
---|