Changeset 0d935a1 for tester.c


Ignore:
Timestamp:
Jun 27, 2011, 4:28:51 AM (13 years ago)
Author:
Jason Gross <jgross@mit.edu>
Children:
b75a8ac
Parents:
f4e857f
git-author:
Jason Gross <jgross@mit.edu> (06/27/11 01:14:13)
git-committer:
Jason Gross <jgross@mit.edu> (06/27/11 04:28:51)
Message:
Pass owl_variable * around instead of owl_vardict *.

This allows (forces) functions to do their own NULL- and type- checking
on variables.  The functions in varsubs.c get less checking, but if
these auto-generated functions are failing, something more serious is
probably wrong.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester.c

    reeba011 r0d935a1  
    276276int owl_variable_regtest(void) {
    277277  owl_vardict vd;
     278  owl_variable *var;
    278279  int numfailed=0;
    279280  char *value;
     
    283284  FAIL_UNLESS("setup", 0==owl_variable_dict_setup(&vd));
    284285
    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"));
     286  FAIL_UNLESS("get bool var", NULL != (var = owl_variable_get_var(&vd, "rxping")));
     287  FAIL_UNLESS("get bool", 0 == owl_variable_get_bool(var));
     288  FAIL_UNLESS("get bool (no such)", NULL == owl_variable_get_var(&vd, "mumble"));
    287289  FAIL_UNLESS("get bool as string",
    288               !strcmp((value = owl_variable_get_tostring(&vd,"rxping")), "off"));
     290              !strcmp((value = owl_variable_get_tostring(var)), "off"));
    289291  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"));
     292  FAIL_UNLESS("set bool 1", 0 == owl_variable_set_bool_on(var));
     293  FAIL_UNLESS("get bool 2", 1 == owl_variable_get_bool(var));
     294  FAIL_UNLESS("set bool 3", 0 == owl_variable_set_fromstring(var, "off", 0));
     295  FAIL_UNLESS("get bool 4", 0 == owl_variable_get_bool(var));
     296  FAIL_UNLESS("set bool 5", -1 == owl_variable_set_fromstring(var, "xxx", 0));
     297  FAIL_UNLESS("get bool 6", 0 == owl_variable_get_bool(var));
     298
     299
     300  FAIL_UNLESS("get string var", NULL != (var = owl_variable_get_var(&vd, "logpath")));
     301  FAIL_UNLESS("get string", 0 == strcmp("~/zlog/people", owl_variable_get_string(var)));
     302  FAIL_UNLESS("set string 7", 0 == owl_variable_set_string(var, "whee"));
     303  FAIL_UNLESS("get string", !strcmp("whee", owl_variable_get_string(var)));
     304
     305  FAIL_UNLESS("get int var", NULL != (var = owl_variable_get_var(&vd, "typewinsize")));
     306  FAIL_UNLESS("get int", 8 == owl_variable_get_int(var));
     307  FAIL_UNLESS("get int (no such)", NULL == owl_variable_get_var(&vd, "mumble"));
    304308  FAIL_UNLESS("get int as string",
    305               !strcmp((value = owl_variable_get_tostring(&vd,"typewinsize")), "8"));
     309              !strcmp(value = owl_variable_get_tostring(var), "8"));
    306310  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"));
     311  FAIL_UNLESS("set int 1", 0 == owl_variable_set_int(var, 12));
     312  FAIL_UNLESS("get int 2", 12 == owl_variable_get_int(var));
     313  FAIL_UNLESS("set int 1b", -1 == owl_variable_set_int(var, -3));
     314  FAIL_UNLESS("get int 2b", 12 == owl_variable_get_int(var));
     315  FAIL_UNLESS("set int 3", 0 == owl_variable_set_fromstring(var, "9", 0));
     316  FAIL_UNLESS("get int 4", 9 == owl_variable_get_int(var));
     317  FAIL_UNLESS("set int 5", -1 == owl_variable_set_fromstring(var, "xxx", 0));
     318  FAIL_UNLESS("set int 6", -1 == owl_variable_set_fromstring(var, "", 0));
     319  FAIL_UNLESS("get int 7", 9 == owl_variable_get_int(var));
    316320
    317321  owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval");
    318   FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar")));
    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")));
     322  FAIL_UNLESS("get new string var", NULL != (var = owl_variable_get_var(&vd, "stringvar")));
     323  FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(var)));
     324  FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(var)));
     325  owl_variable_set_string(var, "new val");
     326  FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(var)));
    322327
    323328  owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47);
    324   FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(&vd, "intvar")));
    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"));
     329  FAIL_UNLESS("get new int var", NULL != (var = owl_variable_get_var(&vd, "intvar")));
     330  FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(var)));
     331  FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(var));
     332  owl_variable_set_int(var, 17);
     333  FAIL_UNLESS("update int val", 17 == owl_variable_get_int(var));
    328334
    329335  owl_variable_dict_newvar_bool(&vd, "boolvar", "", "", 1);
    330   FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(&vd, "boolvar")));
    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"));
     336  FAIL_UNLESS("get new bool var", NULL != (var = owl_variable_get_var(&vd, "boolvar")));
     337  FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(var)));
     338  FAIL_UNLESS("get new bool val", owl_variable_get_bool(var));
     339  owl_variable_set_bool_off(var);
     340  FAIL_UNLESS("update bool val", !owl_variable_get_bool(var));
    334341
    335342  owl_variable_dict_cleanup(&vd);
Note: See TracChangeset for help on using the changeset viewer.