Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester.c

    r25891a8 r14c9e05  
    44#undef WINDOW
    55
     6#include <errno.h>
    67#include <unistd.h>
     8#include <pwd.h>
     9#include <stdio.h>
    710#include <stdlib.h>
     11#include <string.h>
     12#include <sys/types.h>
    813
    914#undef instr
     
    124129#define FAIL_UNLESS(desc,pred) do { int __pred = (pred);                \
    125130    numtests++;                                                         \
    126     printf("%s %s", (__pred)?"ok":(numfailed++,"not ok"), desc);        \
     131    printf("%s %d %s", (__pred) ? "ok" : (numfailed++, "not ok"), numtests, desc); \
    127132    if(!(__pred)) printf("\t(%s:%d)", __FILE__, __LINE__); printf("%c", '\n'); } while(0)
    128133
     
    131136{
    132137  int numfailed=0;
     138  const char *home;
     139  char *s, *path;
     140  struct passwd *pw;
    133141
    134142  printf("# BEGIN testing owl_util\n");
     
    225233  g_string_free(g, true);
    226234
     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
    227315  /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
    228316  printf("# END testing owl_util (%d failures)\n", numfailed);
     
    276364int owl_variable_regtest(void) {
    277365  owl_vardict vd;
     366  owl_variable *var;
    278367  int numfailed=0;
    279368  char *value;
     
    283372  FAIL_UNLESS("setup", 0==owl_variable_dict_setup(&vd));
    284373
    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"));
     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"));
    287377  FAIL_UNLESS("get bool as string",
    288               !strcmp((value = owl_variable_get_tostring(&vd,"rxping")), "off"));
     378              !strcmp((value = owl_variable_get_tostring(var)), "off"));
    289379  g_free(value);
    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"));
     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"));
    304396  FAIL_UNLESS("get int as string",
    305               !strcmp((value = owl_variable_get_tostring(&vd,"typewinsize")), "8"));
     397              !strcmp((value = owl_variable_get_tostring(var)), "8"));
    306398  g_free(value);
    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"));
     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));
    316408
    317409  owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval");
    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")));
     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)));
    322415
    323416  owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47);
    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"));
     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));
    328422
    329423  owl_variable_dict_newvar_bool(&vd, "boolvar", "", "", 1);
    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"));
     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);
    334437
    335438  owl_variable_dict_cleanup(&vd);
Note: See TracChangeset for help on using the changeset viewer.