Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester.c

    r14c9e05 r25891a8  
    44#undef WINDOW
    55
    6 #include <errno.h>
    76#include <unistd.h>
    8 #include <pwd.h>
    9 #include <stdio.h>
    107#include <stdlib.h>
    11 #include <string.h>
    12 #include <sys/types.h>
    138
    149#undef instr
     
    129124#define FAIL_UNLESS(desc,pred) do { int __pred = (pred);                \
    130125    numtests++;                                                         \
    131     printf("%s %d %s", (__pred) ? "ok" : (numfailed++, "not ok"), numtests, desc); \
     126    printf("%s %s", (__pred)?"ok":(numfailed++,"not ok"), desc);        \
    132127    if(!(__pred)) printf("\t(%s:%d)", __FILE__, __LINE__); printf("%c", '\n'); } while(0)
    133128
     
    136131{
    137132  int numfailed=0;
    138   const char *home;
    139   char *s, *path;
    140   struct passwd *pw;
    141133
    142134  printf("# BEGIN testing owl_util\n");
     
    233225  g_string_free(g, true);
    234226
    235 
    236   s = owl_util_baseclass("barnowl");
    237   FAIL_UNLESS("baseclass barnowl", !strcmp("barnowl", s));
    238   g_free(s);
    239   s = owl_util_baseclass("unbarnowl");
    240   FAIL_UNLESS("baseclass unbarnowl", !strcmp("barnowl", s));
    241   g_free(s);
    242   s = owl_util_baseclass("unununbarnowl.d.d");
    243   FAIL_UNLESS("baseclass unununbarnowl.d.d", !strcmp("barnowl", s));
    244   g_free(s);
    245   s = owl_util_baseclass("ununun.d.d");
    246   FAIL_UNLESS("baseclass ununun.d.d", !strcmp("", s));
    247   g_free(s);
    248   s = owl_util_baseclass("d.d.d.d");
    249   FAIL_UNLESS("baseclass d.d.d.d", !strcmp("d", s));
    250   g_free(s);
    251   s = owl_util_baseclass("n.d.d.d");
    252   FAIL_UNLESS("baseclass n.d.d.d", !strcmp("n", s));
    253   g_free(s);
    254   s = owl_util_baseclass("ununun.");
    255   FAIL_UNLESS("baseclass ununun.", !strcmp(".", s));
    256   g_free(s);
    257   s = owl_util_baseclass("unununu");
    258   FAIL_UNLESS("baseclass unununu", !strcmp("u", s));
    259   g_free(s);
    260 
    261 
    262   s = owl_util_makepath("foo/bar");
    263   FAIL_UNLESS("makepath foo/bar", !strcmp("foo/bar", s));
    264   g_free(s);
    265   s = owl_util_makepath("//foo///bar");
    266   FAIL_UNLESS("makepath //foo///bar", !strcmp("/foo/bar", s));
    267   g_free(s);
    268   s = owl_util_makepath("foo/~//bar/");
    269   FAIL_UNLESS("makepath foo/~//bar/", !strcmp("foo/~/bar/", s));
    270   g_free(s);
    271   s = owl_util_makepath("~thisuserhadreallybetternotexist/foobar/");
    272   FAIL_UNLESS("makepath ~thisuserhadreallybetternotexist/foobar/",
    273               !strcmp("~thisuserhadreallybetternotexist/foobar/", s));
    274   g_free(s);
    275 
    276   errno = 0;
    277   pw = getpwuid(getuid());
    278   if (pw) {
    279     home = pw->pw_dir;
    280   } else {
    281     /* Just make some noise so we notice. */
    282     home = "<WHAT>";
    283     fprintf(stderr, "getpwuid: %s", errno ? strerror(errno) : "No such user");
    284   }
    285   s = owl_util_makepath("~");
    286   FAIL_UNLESS("makepath ~", !strcmp(home, s));
    287   g_free(s);
    288 
    289   path = g_strconcat(home, "/foo/bar/baz", NULL);
    290   s = owl_util_makepath("~///foo/bar//baz");
    291   FAIL_UNLESS("makepath ~///foo/bar//baz", !strcmp(path, s));
    292   g_free(s);
    293   g_free(path);
    294 
    295   errno = 0;
    296   pw = getpwnam("root");
    297   if (pw) {
    298     home = pw->pw_dir;
    299   } else {
    300     /* Just make some noise so we notice. */
    301     home = "<WHAT>";
    302     fprintf(stderr, "getpwnam: %s", errno ? strerror(errno) : "No such user");
    303   }
    304 
    305   s = owl_util_makepath("~root");
    306   FAIL_UNLESS("makepath ~root", !strcmp(home, s));
    307   g_free(s);
    308 
    309   path = g_strconcat(home, "/foo/bar/baz", NULL);
    310   s = owl_util_makepath("~root///foo/bar//baz");
    311   FAIL_UNLESS("makepath ~root///foo/bar//baz", !strcmp(path, s));
    312   g_free(s);
    313   g_free(path);
    314 
    315227  /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
    316228  printf("# END testing owl_util (%d failures)\n", numfailed);
     
    364276int owl_variable_regtest(void) {
    365277  owl_vardict vd;
    366   owl_variable *var;
    367278  int numfailed=0;
    368279  char *value;
     
    372283  FAIL_UNLESS("setup", 0==owl_variable_dict_setup(&vd));
    373284
    374   FAIL_UNLESS("get bool var", NULL != (var = owl_variable_get_var(&vd, "rxping")));
    375   FAIL_UNLESS("get bool", 0 == owl_variable_get_bool(var));
    376   FAIL_UNLESS("get bool (no such)", NULL == owl_variable_get_var(&vd, "mumble"));
     285  FAIL_UNLESS("get bool", 0==owl_variable_get_bool(&vd,"rxping"));
     286  FAIL_UNLESS("get bool (no such)", -1==owl_variable_get_bool(&vd,"mumble"));
    377287  FAIL_UNLESS("get bool as string",
    378               !strcmp((value = owl_variable_get_tostring(var)), "off"));
     288              !strcmp((value = owl_variable_get_tostring(&vd,"rxping")), "off"));
    379289  g_free(value);
    380   FAIL_UNLESS("set bool 1", 0 == owl_variable_set_bool_on(var));
    381   FAIL_UNLESS("get bool 2", 1 == owl_variable_get_bool(var));
    382   FAIL_UNLESS("set bool 3", 0 == owl_variable_set_fromstring(var, "off", 0));
    383   FAIL_UNLESS("get bool 4", 0 == owl_variable_get_bool(var));
    384   FAIL_UNLESS("set bool 5", -1 == owl_variable_set_fromstring(var, "xxx", 0));
    385   FAIL_UNLESS("get bool 6", 0 == owl_variable_get_bool(var));
    386 
    387 
    388   FAIL_UNLESS("get string var", NULL != (var = owl_variable_get_var(&vd, "logpath")));
    389   FAIL_UNLESS("get string", 0 == strcmp("~/zlog/people", owl_variable_get_string(var)));
    390   FAIL_UNLESS("set string 7", 0 == owl_variable_set_string(var, "whee"));
    391   FAIL_UNLESS("get string", !strcmp("whee", owl_variable_get_string(var)));
    392 
    393   FAIL_UNLESS("get int var", NULL != (var = owl_variable_get_var(&vd, "typewinsize")));
    394   FAIL_UNLESS("get int", 8 == owl_variable_get_int(var));
    395   FAIL_UNLESS("get int (no such)", NULL == owl_variable_get_var(&vd, "mumble"));
     290  FAIL_UNLESS("set bool 1", 0==owl_variable_set_bool_on(&vd,"rxping"));
     291  FAIL_UNLESS("get bool 2", 1==owl_variable_get_bool(&vd,"rxping"));
     292  FAIL_UNLESS("set bool 3", 0==owl_variable_set_fromstring(&vd,"rxping","off",0,0));
     293  FAIL_UNLESS("get bool 4", 0==owl_variable_get_bool(&vd,"rxping"));
     294  FAIL_UNLESS("set bool 5", -1==owl_variable_set_fromstring(&vd,"rxping","xxx",0,0));
     295  FAIL_UNLESS("get bool 6", 0==owl_variable_get_bool(&vd,"rxping"));
     296
     297
     298  FAIL_UNLESS("get string", 0==strcmp("~/zlog/people", owl_variable_get_string(&vd,"logpath")));
     299  FAIL_UNLESS("set string 7", 0==owl_variable_set_string(&vd,"logpath","whee"));
     300  FAIL_UNLESS("get string", 0==strcmp("whee", owl_variable_get_string(&vd,"logpath")));
     301
     302  FAIL_UNLESS("get int", 8==owl_variable_get_int(&vd,"typewinsize"));
     303  FAIL_UNLESS("get int (no such)", -1==owl_variable_get_int(&vd,"mmble"));
    396304  FAIL_UNLESS("get int as string",
    397               !strcmp((value = owl_variable_get_tostring(var)), "8"));
     305              !strcmp((value = owl_variable_get_tostring(&vd,"typewinsize")), "8"));
    398306  g_free(value);
    399   FAIL_UNLESS("set int 1", 0 == owl_variable_set_int(var, 12));
    400   FAIL_UNLESS("get int 2", 12 == owl_variable_get_int(var));
    401   FAIL_UNLESS("set int 1b", -1 == owl_variable_set_int(var, -3));
    402   FAIL_UNLESS("get int 2b", 12 == owl_variable_get_int(var));
    403   FAIL_UNLESS("set int 3", 0 == owl_variable_set_fromstring(var, "9", 0));
    404   FAIL_UNLESS("get int 4", 9 == owl_variable_get_int(var));
    405   FAIL_UNLESS("set int 5", -1 == owl_variable_set_fromstring(var, "xxx", 0));
    406   FAIL_UNLESS("set int 6", -1 == owl_variable_set_fromstring(var, "", 0));
    407   FAIL_UNLESS("get int 7", 9 == owl_variable_get_int(var));
     307  FAIL_UNLESS("set int 1", 0==owl_variable_set_int(&vd,"typewinsize",12));
     308  FAIL_UNLESS("get int 2", 12==owl_variable_get_int(&vd,"typewinsize"));
     309  FAIL_UNLESS("set int 1b", -1==owl_variable_set_int(&vd,"typewinsize",-3));
     310  FAIL_UNLESS("get int 2b", 12==owl_variable_get_int(&vd,"typewinsize"));
     311  FAIL_UNLESS("set int 3", 0==owl_variable_set_fromstring(&vd,"typewinsize","9",0,0));
     312  FAIL_UNLESS("get int 4", 9==owl_variable_get_int(&vd,"typewinsize"));
     313  FAIL_UNLESS("set int 5", -1==owl_variable_set_fromstring(&vd,"typewinsize","xxx",0,0));
     314  FAIL_UNLESS("set int 6", -1==owl_variable_set_fromstring(&vd,"typewinsize","",0,0));
     315  FAIL_UNLESS("get int 7", 9==owl_variable_get_int(&vd,"typewinsize"));
    408316
    409317  owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval");
    410   FAIL_UNLESS("get new string var", NULL != (var = owl_variable_get_var(&vd, "stringvar")));
    411   FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(var)));
    412   FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(var)));
    413   owl_variable_set_string(var, "new val");
    414   FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(var)));
     318  FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar", OWL_VARIABLE_STRING)));
     319  FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(&vd, "stringvar")));
     320  owl_variable_set_string(&vd, "stringvar", "new val");
     321  FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(&vd, "stringvar")));
    415322
    416323  owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47);
    417   FAIL_UNLESS("get new int var", NULL != (var = owl_variable_get_var(&vd, "intvar")));
    418   FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(var)));
    419   FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(var));
    420   owl_variable_set_int(var, 17);
    421   FAIL_UNLESS("update int val", 17 == owl_variable_get_int(var));
     324  FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(&vd, "intvar", OWL_VARIABLE_INT)));
     325  FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(&vd, "intvar"));
     326  owl_variable_set_int(&vd, "intvar", 17);
     327  FAIL_UNLESS("update bool val", 17 == owl_variable_get_int(&vd, "intvar"));
    422328
    423329  owl_variable_dict_newvar_bool(&vd, "boolvar", "", "", 1);
    424   FAIL_UNLESS("get new bool var", NULL != (var = owl_variable_get_var(&vd, "boolvar")));
    425   FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(var)));
    426   FAIL_UNLESS("get new bool val", owl_variable_get_bool(var));
    427   owl_variable_set_bool_off(var);
    428   FAIL_UNLESS("update bool val", !owl_variable_get_bool(var));
    429 
    430   owl_variable_dict_newvar_string(&vd, "nullstringvar", "", "", NULL);
    431   FAIL_UNLESS("get new string (NULL) var", NULL != (var = owl_variable_get_var(&vd, "nullstringvar")));
    432   FAIL_UNLESS("get string (NULL)", NULL == (value = owl_variable_get_tostring(var)));
    433   g_free(value);
    434   var = owl_variable_get_var(&vd, "zsigproc");
    435   FAIL_UNLESS("get string (NULL) 2", NULL == (value = owl_variable_get_tostring(var)));
    436   g_free(value);
     330  FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(&vd, "boolvar", OWL_VARIABLE_BOOL)));
     331  FAIL_UNLESS("get new bool val", owl_variable_get_bool(&vd, "boolvar"));
     332  owl_variable_set_bool_off(&vd, "boolvar");
     333  FAIL_UNLESS("update string val", !owl_variable_get_bool(&vd, "boolvar"));
    437334
    438335  owl_variable_dict_cleanup(&vd);
Note: See TracChangeset for help on using the changeset viewer.