Changeset 8bce750


Ignore:
Timestamp:
Aug 17, 2009, 9:52:16 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
e30ed92
Parents:
a2b3289
git-author:
Nelson Elhage <nelhage@mit.edu> (08/17/09 21:51:29)
git-committer:
Nelson Elhage <nelhage@mit.edu> (08/17/09 21:52:16)
Message:
Move all regression tests into tester.c.
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r2fa9a1a0 r8bce750  
    1111
    1212tester_SOURCES = $(BASE_SRCS) \
    13      owl.h owl_perl.h config.h test.h \
     13     owl.h owl_perl.h config.h \
    1414     libzcrypt.a \
    1515     $(GEN_C) $(GEN_H) \
  • dict.c

    r636b137 r8bce750  
    143143}
    144144
    145 
    146 
    147 /************* REGRESSION TESTS **************/
    148 #ifdef OWL_INCLUDE_REG_TESTS
    149 
    150 #include "test.h"
    151 
    152 int owl_dict_regtest(void) {
    153   owl_dict d;
    154   owl_list l;
    155   int numfailed=0;
    156   char *av="aval", *bv="bval", *cv="cval", *dv="dval";
    157 
    158   printf("# BEGIN testing owl_dict\n");
    159   FAIL_UNLESS("create", 0==owl_dict_create(&d));
    160   FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_free));
    161   FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_free));
    162   FAIL_UNLESS("insert a", 0==owl_dict_insert_element(&d, "a", av, owl_dict_noop_free));
    163   FAIL_UNLESS("insert c", 0==owl_dict_insert_element(&d, "c", cv, owl_dict_noop_free));
    164   FAIL_UNLESS("reinsert d (no replace)", -2==owl_dict_insert_element(&d, "d", dv, 0));
    165   FAIL_UNLESS("find a", av==owl_dict_find_element(&d, "a"));
    166   FAIL_UNLESS("find b", bv==owl_dict_find_element(&d, "b"));
    167   FAIL_UNLESS("find c", cv==owl_dict_find_element(&d, "c"));
    168   FAIL_UNLESS("find d", dv==owl_dict_find_element(&d, "d"));
    169   FAIL_UNLESS("find e (non-existent)", NULL==owl_dict_find_element(&d, "e"));
    170   FAIL_UNLESS("remove d", dv==owl_dict_remove_element(&d, "d"));
    171   FAIL_UNLESS("find d (post-removal)", NULL==owl_dict_find_element(&d, "d"));
    172 
    173   FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d));
    174   FAIL_UNLESS("get_keys", 0==owl_dict_get_keys(&d, &l));
    175   FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l));
    176  
    177   /* these assume the returned keys are sorted */
    178   FAIL_UNLESS("get_keys result val",0==strcmp("a",owl_list_get_element(&l,0)));
    179   FAIL_UNLESS("get_keys result val",0==strcmp("b",owl_list_get_element(&l,1)));
    180   FAIL_UNLESS("get_keys result val",0==strcmp("c",owl_list_get_element(&l,2)));
    181 
    182   owl_list_free_all(&l, owl_free);
    183   owl_dict_free_all(&d, NULL);
    184 
    185   /*  if (numfailed) printf("*** WARNING: failures encountered with owl_dict\n"); */
    186   printf("# END testing owl_dict (%d failures)\n", numfailed);
    187   return(numfailed);
    188 }
    189 
    190 #endif /* OWL_INCLUDE_REG_TESTS */
  • filter.c

    ra2b3289 r8bce750  
    263263  if (f->name) owl_free(f->name);
    264264}
    265 
    266 /**************************************************************************/
    267 /************************* REGRESSION TESTS *******************************/
    268 /**************************************************************************/
    269 
    270 #ifdef OWL_INCLUDE_REG_TESTS
    271 
    272 int owl_filter_test_string(const char * filt, const owl_message *m, int shouldmatch) /* noproto */ {
    273   owl_filter f;
    274   int ok;
    275   int failed = 0;
    276   if(owl_filter_init_fromstring(&f, "test-filter", filt)) {
    277     printf("not ok can't parse %s\n", filt);
    278     failed = 1;
    279     goto out;
    280   }
    281   ok = owl_filter_message_match(&f, m);
    282   if((shouldmatch && !ok) || (!shouldmatch && ok)) {
    283     printf("not ok match %s (got %d, expected %d)\n", filt, ok, shouldmatch);
    284     failed = 1;
    285   }
    286  out:
    287   owl_filter_free(&f);
    288   if(!failed) {
    289     printf("ok %s %s\n", shouldmatch ? "matches" : "doesn't match", filt);
    290   }
    291   return failed;
    292 }
    293 
    294 
    295 #include "test.h"
    296 
    297 
    298 int owl_filter_regtest(void) {
    299   int numfailed=0;
    300   owl_message m;
    301   owl_filter f1, f2, f3, f4, f5;
    302 
    303   owl_list_create(&(g.filterlist));
    304   owl_message_init(&m);
    305   owl_message_set_type_zephyr(&m);
    306   owl_message_set_direction_in(&m);
    307   owl_message_set_class(&m, "owl");
    308   owl_message_set_instance(&m, "tester");
    309   owl_message_set_sender(&m, "owl-user");
    310   owl_message_set_recipient(&m, "joe");
    311   owl_message_set_attribute(&m, "foo", "bar");
    312 
    313 #define TEST_FILTER(f, e) do {                          \
    314     numtests++;                                         \
    315     numfailed += owl_filter_test_string(f, &m, e);      \
    316       } while(0)
    317 
    318   TEST_FILTER("true", 1);
    319   TEST_FILTER("false", 0);
    320   TEST_FILTER("( true )", 1);
    321   TEST_FILTER("not false", 1);
    322   TEST_FILTER("( true ) or ( false )", 1);
    323   TEST_FILTER("true and false", 0);
    324   TEST_FILTER("( true or true ) or ( ( false ) )", 1);
    325 
    326   TEST_FILTER("class owl", 1);
    327   TEST_FILTER("class ^owl$", 1);
    328   TEST_FILTER("instance test", 1);
    329   TEST_FILTER("instance ^test$", 0);
    330   TEST_FILTER("instance ^tester$", 1);
    331 
    332   TEST_FILTER("foo bar", 1);
    333   TEST_FILTER("class owl and instance tester", 1);
    334   TEST_FILTER("type ^zephyr$ and direction ^in$ and ( class ^owl$ or instance ^owl$ )", 1);
    335 
    336   /* Order of operations and precedence */
    337   TEST_FILTER("not true or false", 0);
    338   TEST_FILTER("true or true and false", 0);
    339   TEST_FILTER("true and true and false or true", 1);
    340   TEST_FILTER("false and false or true", 1);
    341   TEST_FILTER("true and false or false", 0);
    342 
    343   owl_filter_init_fromstring(&f1, "f1", "class owl");
    344   owl_global_add_filter(&g, &f1);
    345   TEST_FILTER("filter f1", 1);
    346 
    347   /* Test recursion prevention */
    348   FAIL_UNLESS("self reference", owl_filter_init_fromstring(&f2, "test", "filter test"));
    349 
    350   /* mutual recursion */
    351   owl_filter_init_fromstring(&f3, "f3", "filter f4");
    352   owl_global_add_filter(&g, &f3);
    353   FAIL_UNLESS("mutual recursion",   owl_filter_init_fromstring(&f4, "f4", "filter f3"));
    354 
    355   /* support referencing a filter several times */
    356   FAIL_UNLESS("DAG", !owl_filter_init_fromstring(&f5, "dag", "filter f1 or filter f1"));
    357 
    358   return 0;
    359 }
    360 
    361 
    362 #endif /* OWL_INCLUDE_REG_TESTS */
  • obarray.c

    rb1d5517 r8bce750  
    6666  owl_list_create(&(oa->strings));
    6767}
    68 
    69 /**************************************************************************/
    70 /************************* REGRESSION TESTS *******************************/
    71 /**************************************************************************/
    72 
    73 #ifdef OWL_INCLUDE_REG_TESTS
    74 
    75 #include "test.h"
    76 
    77 int owl_obarray_regtest(void) {
    78   int numfailed = 0;
    79   const char *p,*p2;
    80 
    81   owl_obarray oa;
    82   owl_obarray_init(&oa);
    83 
    84   printf("# BEGIN testing owl_obarray\n");
    85 
    86   p = owl_obarray_insert(&oa, "test");
    87   FAIL_UNLESS("returned string is equal", p && !strcmp(p, "test"));
    88   p2 = owl_obarray_insert(&oa, "test");
    89   FAIL_UNLESS("returned string is equal", p2 && !strcmp(p2, "test"));
    90   FAIL_UNLESS("returned the same string", p2 && p == p2);
    91 
    92   p = owl_obarray_insert(&oa, "test2");
    93   FAIL_UNLESS("returned string is equal", p && !strcmp(p, "test2"));
    94   p2 = owl_obarray_find(&oa, "test2");
    95   FAIL_UNLESS("returned the same string", p2 && !strcmp(p2, "test2"));
    96 
    97   p = owl_obarray_find(&oa, "nothere");
    98   FAIL_UNLESS("Didn't find a string that isn't there", p == NULL);
    99 
    100   printf("# END testing owl_obarray (%d failures)\n", numfailed);
    101 
    102   return numfailed;
    103 }
    104 
    105 #endif /* OWL_INCLUDE_REG_TESTS */
  • owl.h

    rafa200a r8bce750  
    173173#define OWL_DEFAULT_ZAWAYMSG    "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n"
    174174#define OWL_DEFAULT_AAWAYMSG    "I'm sorry, but I am currently away from the terminal and am\nnot able to receive your message.\n"
    175 
    176 #define OWL_INCLUDE_REG_TESTS   1  /* whether to build in regression tests */
    177175
    178176#define OWL_CMD_ALIAS_SUMMARY_PREFIX "command alias to: "
  • tester.c

    ra2b3289 r8bce750  
    66
    77int numtests;
     8
     9int owl_util_regtest(void);
     10int owl_dict_regtest(void);
     11int owl_variable_regtest(void);
     12int owl_filter_regtest(void);
     13int owl_obarray_regtest(void);
    814
    915int main(int argc, char **argv, char **env)
     
    2935  return(numfailures);
    3036}
     37
     38#define FAIL_UNLESS(desc,pred) do { int __pred = (pred);                \
     39    numtests++;                                                         \
     40    printf("%s %s", (__pred)?"ok":(numfailed++,"not ok"), desc);        \
     41    if(!(__pred)) printf("\t(%s:%d)", __FILE__, __LINE__); printf("%c", '\n'); } while(0)
     42
     43
     44int owl_util_regtest(void)
     45{
     46  int numfailed=0;
     47
     48  printf("# BEGIN testing owl_util\n");
     49
     50  FAIL_UNLESS("owl_util_substitute 1",
     51              !strcmp("foo", owl_text_substitute("foo", "", "Y")));
     52  FAIL_UNLESS("owl_text_substitute 2",
     53              !strcmp("fYZYZ", owl_text_substitute("foo", "o", "YZ")));
     54  FAIL_UNLESS("owl_text_substitute 3",
     55              !strcmp("foo", owl_text_substitute("fYZYZ", "YZ", "o")));
     56  FAIL_UNLESS("owl_text_substitute 4",
     57              !strcmp("/u/foo/meep", owl_text_substitute("~/meep", "~", "/u/foo")));
     58
     59  FAIL_UNLESS("skiptokens 1",
     60              !strcmp("bar quux", skiptokens("foo bar quux", 1)));
     61  FAIL_UNLESS("skiptokens 2",
     62              !strcmp("meep", skiptokens("foo 'bar quux' meep", 2)));
     63
     64  FAIL_UNLESS("expand_tabs 1",
     65              !strcmp("        hi", owl_text_expand_tabs("\thi")));
     66
     67  FAIL_UNLESS("expand_tabs 2",
     68              !strcmp("        hi\nword    tab", owl_text_expand_tabs("\thi\nword\ttab")));
     69
     70  FAIL_UNLESS("expand_tabs 3",
     71              !strcmp("                2 tabs", owl_text_expand_tabs("\t\t2 tabs")));
     72
     73  /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
     74  printf("# END testing owl_util (%d failures)\n", numfailed);
     75  return(numfailed);
     76}
     77
     78int owl_dict_regtest(void) {
     79  owl_dict d;
     80  owl_list l;
     81  int numfailed=0;
     82  char *av="aval", *bv="bval", *cv="cval", *dv="dval";
     83
     84  printf("# BEGIN testing owl_dict\n");
     85  FAIL_UNLESS("create", 0==owl_dict_create(&d));
     86  FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_free));
     87  FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_free));
     88  FAIL_UNLESS("insert a", 0==owl_dict_insert_element(&d, "a", av, owl_dict_noop_free));
     89  FAIL_UNLESS("insert c", 0==owl_dict_insert_element(&d, "c", cv, owl_dict_noop_free));
     90  FAIL_UNLESS("reinsert d (no replace)", -2==owl_dict_insert_element(&d, "d", dv, 0));
     91  FAIL_UNLESS("find a", av==owl_dict_find_element(&d, "a"));
     92  FAIL_UNLESS("find b", bv==owl_dict_find_element(&d, "b"));
     93  FAIL_UNLESS("find c", cv==owl_dict_find_element(&d, "c"));
     94  FAIL_UNLESS("find d", dv==owl_dict_find_element(&d, "d"));
     95  FAIL_UNLESS("find e (non-existent)", NULL==owl_dict_find_element(&d, "e"));
     96  FAIL_UNLESS("remove d", dv==owl_dict_remove_element(&d, "d"));
     97  FAIL_UNLESS("find d (post-removal)", NULL==owl_dict_find_element(&d, "d"));
     98
     99  FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d));
     100  FAIL_UNLESS("get_keys", 0==owl_dict_get_keys(&d, &l));
     101  FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l));
     102 
     103  /* these assume the returned keys are sorted */
     104  FAIL_UNLESS("get_keys result val",0==strcmp("a",owl_list_get_element(&l,0)));
     105  FAIL_UNLESS("get_keys result val",0==strcmp("b",owl_list_get_element(&l,1)));
     106  FAIL_UNLESS("get_keys result val",0==strcmp("c",owl_list_get_element(&l,2)));
     107
     108  owl_list_free_all(&l, owl_free);
     109  owl_dict_free_all(&d, NULL);
     110
     111  /*  if (numfailed) printf("*** WARNING: failures encountered with owl_dict\n"); */
     112  printf("# END testing owl_dict (%d failures)\n", numfailed);
     113  return(numfailed);
     114}
     115
     116int owl_variable_regtest(void) {
     117  owl_vardict vd;
     118  int numfailed=0;
     119  char buf[1024];
     120  const void *v;
     121
     122  printf("# BEGIN testing owl_variable\n");
     123  FAIL_UNLESS("setup", 0==owl_variable_dict_setup(&vd));
     124
     125  FAIL_UNLESS("get bool", 0==owl_variable_get_bool(&vd,"rxping"));
     126  FAIL_UNLESS("get bool (no such)", -1==owl_variable_get_bool(&vd,"mumble"));
     127  FAIL_UNLESS("get bool as string 1", 0==owl_variable_get_tostring(&vd,"rxping", buf, 1024));
     128  FAIL_UNLESS("get bool as string 2", 0==strcmp(buf,"off"));
     129  FAIL_UNLESS("set bool 1", 0==owl_variable_set_bool_on(&vd,"rxping"));
     130  FAIL_UNLESS("get bool 2", 1==owl_variable_get_bool(&vd,"rxping"));
     131  FAIL_UNLESS("set bool 3", 0==owl_variable_set_fromstring(&vd,"rxping","off",0,0));
     132  FAIL_UNLESS("get bool 4", 0==owl_variable_get_bool(&vd,"rxping"));
     133  FAIL_UNLESS("set bool 5", -1==owl_variable_set_fromstring(&vd,"rxping","xxx",0,0));
     134  FAIL_UNLESS("get bool 6", 0==owl_variable_get_bool(&vd,"rxping"));
     135
     136
     137  FAIL_UNLESS("get string", 0==strcmp("~/zlog/people", owl_variable_get_string(&vd,"logpath")));
     138  FAIL_UNLESS("set string 7", 0==owl_variable_set_string(&vd,"logpath","whee"));
     139  FAIL_UNLESS("get string", 0==strcmp("whee", owl_variable_get_string(&vd,"logpath")));
     140
     141  FAIL_UNLESS("get int", 8==owl_variable_get_int(&vd,"typewinsize"));
     142  FAIL_UNLESS("get int (no such)", -1==owl_variable_get_int(&vd,"mmble"));
     143  FAIL_UNLESS("get int as string 1", 0==owl_variable_get_tostring(&vd,"typewinsize", buf, 1024));
     144  FAIL_UNLESS("get int as string 2", 0==strcmp(buf,"8"));
     145  FAIL_UNLESS("set int 1", 0==owl_variable_set_int(&vd,"typewinsize",12));
     146  FAIL_UNLESS("get int 2", 12==owl_variable_get_int(&vd,"typewinsize"));
     147  FAIL_UNLESS("set int 1b", -1==owl_variable_set_int(&vd,"typewinsize",-3));
     148  FAIL_UNLESS("get int 2b", 12==owl_variable_get_int(&vd,"typewinsize"));
     149  FAIL_UNLESS("set int 3", 0==owl_variable_set_fromstring(&vd,"typewinsize","9",0,0));
     150  FAIL_UNLESS("get int 4", 9==owl_variable_get_int(&vd,"typewinsize"));
     151  FAIL_UNLESS("set int 5", -1==owl_variable_set_fromstring(&vd,"typewinsize","xxx",0,0));
     152  FAIL_UNLESS("set int 6", -1==owl_variable_set_fromstring(&vd,"typewinsize","",0,0));
     153  FAIL_UNLESS("get int 7", 9==owl_variable_get_int(&vd,"typewinsize"));
     154
     155  owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval");
     156  FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar", OWL_VARIABLE_STRING)));
     157  FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(&vd, "stringvar")));
     158  owl_variable_set_string(&vd, "stringvar", "new val");
     159  FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(&vd, "stringvar")));
     160
     161  owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47);
     162  FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(&vd, "intvar", OWL_VARIABLE_INT)));
     163  FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(&vd, "intvar"));
     164  owl_variable_set_int(&vd, "intvar", 17);
     165  FAIL_UNLESS("update bool val", 17 == owl_variable_get_int(&vd, "intvar"));
     166
     167  owl_variable_dict_newvar_bool(&vd, "boolvar", "", "", 1);
     168  FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(&vd, "boolvar", OWL_VARIABLE_BOOL)));
     169  FAIL_UNLESS("get new bool val", owl_variable_get_bool(&vd, "boolvar"));
     170  owl_variable_set_bool_off(&vd, "boolvar");
     171  FAIL_UNLESS("update string val", !owl_variable_get_bool(&vd, "boolvar"));
     172
     173  owl_variable_dict_free(&vd);
     174
     175  /* if (numfailed) printf("*** WARNING: failures encountered with owl_variable\n"); */
     176  printf("# END testing owl_variable (%d failures)\n", numfailed);
     177  return(numfailed);
     178}
     179
     180int owl_filter_test_string(const char * filt, const owl_message *m, int shouldmatch) /* noproto */ {
     181  owl_filter f;
     182  int ok;
     183  int failed = 0;
     184  if(owl_filter_init_fromstring(&f, "test-filter", filt)) {
     185    printf("not ok can't parse %s\n", filt);
     186    failed = 1;
     187    goto out;
     188  }
     189  ok = owl_filter_message_match(&f, m);
     190  if((shouldmatch && !ok) || (!shouldmatch && ok)) {
     191    printf("not ok match %s (got %d, expected %d)\n", filt, ok, shouldmatch);
     192    failed = 1;
     193  }
     194 out:
     195  owl_filter_free(&f);
     196  if(!failed) {
     197    printf("ok %s %s\n", shouldmatch ? "matches" : "doesn't match", filt);
     198  }
     199  return failed;
     200}
     201
     202int owl_filter_regtest(void) {
     203  int numfailed=0;
     204  owl_message m;
     205  owl_filter f1, f2, f3, f4, f5;
     206
     207  owl_list_create(&(g.filterlist));
     208  owl_message_init(&m);
     209  owl_message_set_type_zephyr(&m);
     210  owl_message_set_direction_in(&m);
     211  owl_message_set_class(&m, "owl");
     212  owl_message_set_instance(&m, "tester");
     213  owl_message_set_sender(&m, "owl-user");
     214  owl_message_set_recipient(&m, "joe");
     215  owl_message_set_attribute(&m, "foo", "bar");
     216
     217#define TEST_FILTER(f, e) do {                          \
     218    numtests++;                                         \
     219    numfailed += owl_filter_test_string(f, &m, e);      \
     220      } while(0)
     221
     222  TEST_FILTER("true", 1);
     223  TEST_FILTER("false", 0);
     224  TEST_FILTER("( true )", 1);
     225  TEST_FILTER("not false", 1);
     226  TEST_FILTER("( true ) or ( false )", 1);
     227  TEST_FILTER("true and false", 0);
     228  TEST_FILTER("( true or true ) or ( ( false ) )", 1);
     229
     230  TEST_FILTER("class owl", 1);
     231  TEST_FILTER("class ^owl$", 1);
     232  TEST_FILTER("instance test", 1);
     233  TEST_FILTER("instance ^test$", 0);
     234  TEST_FILTER("instance ^tester$", 1);
     235
     236  TEST_FILTER("foo bar", 1);
     237  TEST_FILTER("class owl and instance tester", 1);
     238  TEST_FILTER("type ^zephyr$ and direction ^in$ and ( class ^owl$ or instance ^owl$ )", 1);
     239
     240  /* Order of operations and precedence */
     241  TEST_FILTER("not true or false", 0);
     242  TEST_FILTER("true or true and false", 0);
     243  TEST_FILTER("true and true and false or true", 1);
     244  TEST_FILTER("false and false or true", 1);
     245  TEST_FILTER("true and false or false", 0);
     246
     247  owl_filter_init_fromstring(&f1, "f1", "class owl");
     248  owl_global_add_filter(&g, &f1);
     249  TEST_FILTER("filter f1", 1);
     250
     251  /* Test recursion prevention */
     252  FAIL_UNLESS("self reference", owl_filter_init_fromstring(&f2, "test", "filter test"));
     253
     254  /* mutual recursion */
     255  owl_filter_init_fromstring(&f3, "f3", "filter f4");
     256  owl_global_add_filter(&g, &f3);
     257  FAIL_UNLESS("mutual recursion",   owl_filter_init_fromstring(&f4, "f4", "filter f3"));
     258
     259  /* support referencing a filter several times */
     260  FAIL_UNLESS("DAG", !owl_filter_init_fromstring(&f5, "dag", "filter f1 or filter f1"));
     261
     262  return 0;
     263}
     264
     265
     266int owl_obarray_regtest(void) {
     267  int numfailed = 0;
     268  const char *p,*p2;
     269
     270  owl_obarray oa;
     271  owl_obarray_init(&oa);
     272
     273  printf("# BEGIN testing owl_obarray\n");
     274
     275  p = owl_obarray_insert(&oa, "test");
     276  FAIL_UNLESS("returned string is equal", p && !strcmp(p, "test"));
     277  p2 = owl_obarray_insert(&oa, "test");
     278  FAIL_UNLESS("returned string is equal", p2 && !strcmp(p2, "test"));
     279  FAIL_UNLESS("returned the same string", p2 && p == p2);
     280
     281  p = owl_obarray_insert(&oa, "test2");
     282  FAIL_UNLESS("returned string is equal", p && !strcmp(p, "test2"));
     283  p2 = owl_obarray_find(&oa, "test2");
     284  FAIL_UNLESS("returned the same string", p2 && !strcmp(p2, "test2"));
     285
     286  p = owl_obarray_find(&oa, "nothere");
     287  FAIL_UNLESS("Didn't find a string that isn't there", p == NULL);
     288
     289  printf("# END testing owl_obarray (%d failures)\n", numfailed);
     290
     291  return numfailed;
     292}
  • util.c

    r9e5c9f3 r8bce750  
    758758  return 0;
    759759}
    760 
    761 /**************************************************************************/
    762 /************************* REGRESSION TESTS *******************************/
    763 /**************************************************************************/
    764 
    765 #ifdef OWL_INCLUDE_REG_TESTS
    766 
    767 #include "test.h"
    768 
    769 int owl_util_regtest(void)
    770 {
    771   int numfailed=0;
    772 
    773   printf("# BEGIN testing owl_util\n");
    774 
    775   FAIL_UNLESS("owl_util_substitute 1",
    776               !strcmp("foo", owl_text_substitute("foo", "", "Y")));
    777   FAIL_UNLESS("owl_text_substitute 2",
    778               !strcmp("fYZYZ", owl_text_substitute("foo", "o", "YZ")));
    779   FAIL_UNLESS("owl_text_substitute 3",
    780               !strcmp("foo", owl_text_substitute("fYZYZ", "YZ", "o")));
    781   FAIL_UNLESS("owl_text_substitute 4",
    782               !strcmp("/u/foo/meep", owl_text_substitute("~/meep", "~", "/u/foo")));
    783 
    784   FAIL_UNLESS("skiptokens 1",
    785               !strcmp("bar quux", skiptokens("foo bar quux", 1)));
    786   FAIL_UNLESS("skiptokens 2",
    787               !strcmp("meep", skiptokens("foo 'bar quux' meep", 2)));
    788 
    789   FAIL_UNLESS("expand_tabs 1",
    790               !strcmp("        hi", owl_text_expand_tabs("\thi")));
    791 
    792   FAIL_UNLESS("expand_tabs 2",
    793               !strcmp("        hi\nword    tab", owl_text_expand_tabs("\thi\nword\ttab")));
    794 
    795   FAIL_UNLESS("expand_tabs 3",
    796               !strcmp("                2 tabs", owl_text_expand_tabs("\t\t2 tabs")));
    797 
    798   /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
    799   printf("# END testing owl_util (%d failures)\n", numfailed);
    800   return(numfailed);
    801 }
    802 
    803 #endif /* OWL_INCLUDE_REG_TESTS */
  • variable.c

    r01ff87d r8bce750  
    55#include <ctype.h>
    66#include "owl.h"
    7 
    8 static int in_regtest = 0;
    97
    108#define OWLVAR_BOOL(name,default,summary,description) \
     
    434432int owl_variable_disable_ctrl_d_set(owl_variable *v, const void *newval)
    435433{
    436 
    437   if (in_regtest) return owl_variable_int_set_default(v, newval);
    438 
    439434  if (newval && !owl_context_is_startup(owl_global_get_context(&g))) {
    440435    if (*(const int*)newval == 2) {
     
    1001996}
    1002997
    1003 
    1004 
    1005 /**************************************************************************/
    1006 /************************* REGRESSION TESTS *******************************/
    1007 /**************************************************************************/
    1008 
    1009 #ifdef OWL_INCLUDE_REG_TESTS
    1010 
    1011 #include "test.h"
    1012 
    1013 int owl_variable_regtest(void) {
    1014   owl_vardict vd;
    1015   int numfailed=0;
    1016   char buf[1024];
    1017   const void *v;
    1018 
    1019   in_regtest = 1;
    1020 
    1021   printf("# BEGIN testing owl_variable\n");
    1022   FAIL_UNLESS("setup", 0==owl_variable_dict_setup(&vd));
    1023 
    1024   FAIL_UNLESS("get bool", 0==owl_variable_get_bool(&vd,"rxping"));
    1025   FAIL_UNLESS("get bool (no such)", -1==owl_variable_get_bool(&vd,"mumble"));
    1026   FAIL_UNLESS("get bool as string 1", 0==owl_variable_get_tostring(&vd,"rxping", buf, 1024));
    1027   FAIL_UNLESS("get bool as string 2", 0==strcmp(buf,"off"));
    1028   FAIL_UNLESS("set bool 1", 0==owl_variable_set_bool_on(&vd,"rxping"));
    1029   FAIL_UNLESS("get bool 2", 1==owl_variable_get_bool(&vd,"rxping"));
    1030   FAIL_UNLESS("set bool 3", 0==owl_variable_set_fromstring(&vd,"rxping","off",0,0));
    1031   FAIL_UNLESS("get bool 4", 0==owl_variable_get_bool(&vd,"rxping"));
    1032   FAIL_UNLESS("set bool 5", -1==owl_variable_set_fromstring(&vd,"rxping","xxx",0,0));
    1033   FAIL_UNLESS("get bool 6", 0==owl_variable_get_bool(&vd,"rxping"));
    1034 
    1035 
    1036   FAIL_UNLESS("get string", 0==strcmp("~/zlog/people", owl_variable_get_string(&vd,"logpath")));
    1037   FAIL_UNLESS("set string 7", 0==owl_variable_set_string(&vd,"logpath","whee"));
    1038   FAIL_UNLESS("get string", 0==strcmp("whee", owl_variable_get_string(&vd,"logpath")));
    1039 
    1040   FAIL_UNLESS("get int", 8==owl_variable_get_int(&vd,"typewinsize"));
    1041   FAIL_UNLESS("get int (no such)", -1==owl_variable_get_int(&vd,"mmble"));
    1042   FAIL_UNLESS("get int as string 1", 0==owl_variable_get_tostring(&vd,"typewinsize", buf, 1024));
    1043   FAIL_UNLESS("get int as string 2", 0==strcmp(buf,"8"));
    1044   FAIL_UNLESS("set int 1", 0==owl_variable_set_int(&vd,"typewinsize",12));
    1045   FAIL_UNLESS("get int 2", 12==owl_variable_get_int(&vd,"typewinsize"));
    1046   FAIL_UNLESS("set int 1b", -1==owl_variable_set_int(&vd,"typewinsize",-3));
    1047   FAIL_UNLESS("get int 2b", 12==owl_variable_get_int(&vd,"typewinsize"));
    1048   FAIL_UNLESS("set int 3", 0==owl_variable_set_fromstring(&vd,"typewinsize","9",0,0));
    1049   FAIL_UNLESS("get int 4", 9==owl_variable_get_int(&vd,"typewinsize"));
    1050   FAIL_UNLESS("set int 5", -1==owl_variable_set_fromstring(&vd,"typewinsize","xxx",0,0));
    1051   FAIL_UNLESS("set int 6", -1==owl_variable_set_fromstring(&vd,"typewinsize","",0,0));
    1052   FAIL_UNLESS("get int 7", 9==owl_variable_get_int(&vd,"typewinsize"));
    1053 
    1054   owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval");
    1055   FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar", OWL_VARIABLE_STRING)));
    1056   FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(&vd, "stringvar")));
    1057   owl_variable_set_string(&vd, "stringvar", "new val");
    1058   FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(&vd, "stringvar")));
    1059 
    1060   owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47);
    1061   FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(&vd, "intvar", OWL_VARIABLE_INT)));
    1062   FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(&vd, "intvar"));
    1063   owl_variable_set_int(&vd, "intvar", 17);
    1064   FAIL_UNLESS("update bool val", 17 == owl_variable_get_int(&vd, "intvar"));
    1065 
    1066   owl_variable_dict_newvar_bool(&vd, "boolvar", "", "", 1);
    1067   FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(&vd, "boolvar", OWL_VARIABLE_BOOL)));
    1068   FAIL_UNLESS("get new bool val", owl_variable_get_bool(&vd, "boolvar"));
    1069   owl_variable_set_bool_off(&vd, "boolvar");
    1070   FAIL_UNLESS("update string val", !owl_variable_get_bool(&vd, "boolvar"));
    1071 
    1072   owl_variable_dict_free(&vd);
    1073 
    1074   /* if (numfailed) printf("*** WARNING: failures encountered with owl_variable\n"); */
    1075   printf("# END testing owl_variable (%d failures)\n", numfailed);
    1076   return(numfailed);
    1077 }
    1078 
    1079 
    1080 #endif /* OWL_INCLUDE_REG_TESTS */
Note: See TracChangeset for help on using the changeset viewer.