"Fossies" - the Fresh Open Source Software Archive

Member "vnstat-2.9/tests/dbsql_tests.c" (31 Dec 2021, 76468 Bytes) of package /linux/misc/vnstat-2.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "dbsql_tests.c": 2.8_vs_2.9.

    1 #include "common.h"
    2 #include "vnstat_tests.h"
    3 #include "dbsql_tests.h"
    4 #include "dbsql.h"
    5 #include "misc.h"
    6 #include "cfg.h"
    7 
    8 START_TEST(db_close_does_no_harm_when_db_is_already_closed)
    9 {
   10     int ret;
   11 
   12 
   13     ret = db_close();
   14     ck_assert_int_eq(ret, 1);
   15 }
   16 END_TEST
   17 
   18 START_TEST(db_open_rw_can_create_database_if_file_does_not_exist)
   19 {
   20     int ret;
   21 
   22 
   23     ret = db_open_rw(1);
   24     ck_assert_int_eq(ret, 1);
   25     ret = db_close();
   26     ck_assert_int_eq(ret, 1);
   27 }
   28 END_TEST
   29 
   30 START_TEST(db_open_ro_cannot_create_a_database)
   31 {
   32     int ret;
   33 
   34     suppress_output();
   35 
   36     ret = db_open_ro();
   37     ck_assert_int_eq(ret, 0);
   38 }
   39 END_TEST
   40 
   41 START_TEST(db_getinfo_fails_with_no_open_db)
   42 {
   43     suppress_output();
   44 
   45     ck_assert_int_eq(strlen(db_getinfo("foofoo")), 0);
   46 }
   47 END_TEST
   48 
   49 START_TEST(db_getinfo_fails_with_nonexisting_name)
   50 {
   51     int ret;
   52 
   53     ret = db_open_rw(1);
   54     ck_assert_int_eq(ret, 1);
   55 
   56     ck_assert_str_eq(db_getinfo("broken_name"), "");
   57 
   58     ret = db_close();
   59     ck_assert_int_eq(ret, 1);
   60 }
   61 END_TEST
   62 
   63 START_TEST(db_getinfo_can_get_dbversion)
   64 {
   65     int ret;
   66 
   67     ret = db_open_rw(1);
   68     ck_assert_int_eq(ret, 1);
   69 
   70     ck_assert_str_eq(db_getinfo("dbversion"), SQLDBVERSION);
   71 
   72     ret = db_close();
   73     ck_assert_int_eq(ret, 1);
   74 }
   75 END_TEST
   76 
   77 START_TEST(db_setinfo_fails_with_no_open_db)
   78 {
   79     suppress_output();
   80 
   81     ck_assert_int_eq(db_setinfo("foo", "bar", 0), 0);
   82     ck_assert_int_eq(db_setinfo("foo", "bar", 1), 0);
   83 }
   84 END_TEST
   85 
   86 START_TEST(db_setinfo_can_set_infos)
   87 {
   88     int ret;
   89 
   90     ret = db_open_rw(1);
   91     ck_assert_int_eq(ret, 1);
   92 
   93     ck_assert_int_eq(db_setinfo("foo", "bar", 1), 1);
   94     ck_assert_str_eq(db_getinfo("foo"), "bar");
   95 
   96     ret = db_close();
   97     ck_assert_int_eq(ret, 1);
   98 }
   99 END_TEST
  100 
  101 START_TEST(db_setinfo_can_update_infos)
  102 {
  103     int ret;
  104 
  105     ret = db_open_rw(1);
  106     ck_assert_int_eq(ret, 1);
  107 
  108     ck_assert_int_eq(db_setinfo("foo", "bar", 1), 1);
  109     ck_assert_str_eq(db_getinfo("foo"), "bar");
  110 
  111     ck_assert_int_eq(db_setinfo("foo", "qux", 0), 1);
  112     ck_assert_str_eq(db_getinfo("foo"), "qux");
  113 
  114     ck_assert_int_eq(db_setinfo("foo", "quux", 1), 1);
  115     ck_assert_str_eq(db_getinfo("foo"), "quux");
  116 
  117     ret = db_close();
  118     ck_assert_int_eq(ret, 1);
  119 }
  120 END_TEST
  121 
  122 START_TEST(db_setinfo_can_not_update_nonexisting_name)
  123 {
  124     int ret;
  125 
  126     ret = db_open_rw(1);
  127     ck_assert_int_eq(ret, 1);
  128 
  129     ck_assert_int_eq(db_setinfo("foo", "bar", 1), 1);
  130     ck_assert_str_eq(db_getinfo("foo"), "bar");
  131 
  132     ck_assert_int_eq(db_setinfo("bar", "qux", 0), 0);
  133 
  134     ret = db_close();
  135     ck_assert_int_eq(ret, 1);
  136 }
  137 END_TEST
  138 
  139 START_TEST(db_addtraffic_with_no_traffic_does_nothing)
  140 {
  141     suppress_output();
  142 
  143     ck_assert_int_eq(db_addtraffic("eth0", 0, 0), 0);
  144 }
  145 END_TEST
  146 
  147 START_TEST(db_addtraffic_can_add_traffic_and_interfaces)
  148 {
  149     int ret;
  150 
  151     ret = db_open_rw(1);
  152     ck_assert_int_eq(ret, 1);
  153 
  154     ck_assert_int_eq(db_addtraffic("eth0", 0, 0), 1);
  155     ck_assert_int_eq(db_addtraffic("eth0", 12, 34), 1);
  156     ck_assert_int_eq(db_addtraffic("eth1", 56, 78), 1);
  157 
  158     ret = db_close();
  159     ck_assert_int_eq(ret, 1);
  160 }
  161 END_TEST
  162 
  163 START_TEST(db_addtraffic_can_add_traffic_and_interfaces_utc)
  164 {
  165     int ret;
  166 
  167     cfg.useutc = 1;
  168     validatecfg(CT_Daemon);
  169 
  170     ret = db_open_rw(1);
  171     ck_assert_int_eq(ret, 1);
  172 
  173     ck_assert_int_eq(db_addtraffic("eth0", 0, 0), 1);
  174     ck_assert_int_eq(db_addtraffic("eth0", 12, 34), 1);
  175     ck_assert_int_eq(db_addtraffic("eth1", 56, 78), 1);
  176 
  177     ret = db_close();
  178     ck_assert_int_eq(ret, 1);
  179 }
  180 END_TEST
  181 
  182 START_TEST(db_addtraffic_dated_does_not_touch_updated_time)
  183 {
  184     int ret;
  185     interfaceinfo info;
  186 
  187     ret = db_open_rw(1);
  188     ck_assert_int_eq(ret, 1);
  189 
  190     ret = db_addtraffic("eth0", 1, 1);
  191     ck_assert_int_eq(ret, 1);
  192     ret = db_getinterfaceinfo("eth0", &info);
  193     ck_assert_int_eq(ret, 1);
  194     ck_assert_int_eq(info.rxtotal, 1);
  195     ck_assert_int_eq(info.txtotal, 1);
  196     ck_assert_int_gt(info.updated, 1000);
  197     ck_assert_int_lt(info.updated, 2100000000);
  198 
  199     ret = db_addtraffic_dated("eth0", 1, 1, 1000);
  200     ck_assert_int_eq(ret, 1);
  201     ret = db_getinterfaceinfo("eth0", &info);
  202     ck_assert_int_eq(ret, 1);
  203     ck_assert_int_eq(info.rxtotal, 2);
  204     ck_assert_int_eq(info.txtotal, 2);
  205     ck_assert_int_gt(info.updated, 1000);
  206     ck_assert_int_lt(info.updated, 2100000000);
  207 
  208     ret = db_addtraffic_dated("eth0", 1, 1, 2100000000);
  209     ck_assert_int_eq(ret, 1);
  210     ret = db_getinterfaceinfo("eth0", &info);
  211     ck_assert_int_eq(ret, 1);
  212     ck_assert_int_eq(info.rxtotal, 3);
  213     ck_assert_int_eq(info.txtotal, 3);
  214     ck_assert_int_lt(info.updated, 2100000000);
  215 
  216     ret = db_addtraffic_dated("eth0", 1, 1, 1000);
  217     ck_assert_int_eq(ret, 1);
  218     ret = db_getinterfaceinfo("eth0", &info);
  219     ck_assert_int_eq(ret, 1);
  220     ck_assert_int_eq(info.rxtotal, 4);
  221     ck_assert_int_eq(info.txtotal, 4);
  222     ck_assert_int_lt(info.updated, 2100000000);
  223 
  224     ret = db_addtraffic("eth0", 1, 1);
  225     ck_assert_int_eq(ret, 1);
  226     ret = db_getinterfaceinfo("eth0", &info);
  227     ck_assert_int_eq(ret, 1);
  228     ck_assert_int_eq(info.rxtotal, 5);
  229     ck_assert_int_eq(info.txtotal, 5);
  230     ck_assert_int_gt(info.updated, 1000);
  231     ck_assert_int_lt(info.updated, 2100000000);
  232 
  233     ret = db_close();
  234     ck_assert_int_eq(ret, 1);
  235 }
  236 END_TEST
  237 
  238 START_TEST(db_setactive_fails_with_no_open_db)
  239 {
  240     suppress_output();
  241 
  242     ck_assert_int_eq(db_setactive("eth0", 0), 0);
  243     ck_assert_int_eq(db_setactive("eth0", 1), 0);
  244 }
  245 END_TEST
  246 
  247 START_TEST(db_setactive_fails_if_interface_does_not_exist_in_database)
  248 {
  249     int ret;
  250 
  251     ret = db_open_rw(1);
  252     ck_assert_int_eq(ret, 1);
  253 
  254     ck_assert_int_eq(db_setactive("eth0", 0), 0);
  255     ck_assert_int_eq(db_setactive("eth0", 1), 0);
  256 
  257     ret = db_close();
  258     ck_assert_int_eq(ret, 1);
  259 }
  260 END_TEST
  261 
  262 START_TEST(db_setactive_can_change_interface_activity_status)
  263 {
  264     int ret;
  265 
  266     ret = db_open_rw(1);
  267     ck_assert_int_eq(ret, 1);
  268 
  269     ck_assert_int_eq(db_addtraffic("eth0", 0, 0), 1);
  270     ck_assert_int_eq(db_setactive("eth0", 0), 1);
  271     ck_assert_int_eq(db_setactive("eth0", 1), 1);
  272 
  273     ck_assert_int_eq(db_addtraffic("eth0", 12, 34), 1);
  274     ck_assert_int_eq(db_setactive("eth0", 0), 1);
  275     ck_assert_int_eq(db_setactive("eth0", 1), 1);
  276 
  277     ret = db_close();
  278     ck_assert_int_eq(ret, 1);
  279 }
  280 END_TEST
  281 
  282 START_TEST(db_setalias_fails_with_no_open_db)
  283 {
  284     suppress_output();
  285 
  286     ck_assert_int_eq(db_setalias("eth0", "The Internet"), 0);
  287 }
  288 END_TEST
  289 
  290 START_TEST(db_setalias_fails_if_interface_does_not_exist_in_database)
  291 {
  292     int ret;
  293 
  294     ret = db_open_rw(1);
  295     ck_assert_int_eq(ret, 1);
  296 
  297     ck_assert_int_eq(db_setalias("eth0", "The Internet"), 0);
  298 
  299     ret = db_close();
  300     ck_assert_int_eq(ret, 1);
  301 }
  302 END_TEST
  303 
  304 START_TEST(db_setalias_can_change_interface_alias)
  305 {
  306     int ret;
  307 
  308     ret = db_open_rw(1);
  309     ck_assert_int_eq(ret, 1);
  310 
  311     ck_assert_int_eq(db_addtraffic("eth0", 0, 0), 1);
  312     ck_assert_int_eq(db_setalias("eth0", "The Internet"), 1);
  313 
  314     ck_assert_int_eq(db_addtraffic("eth0", 12, 34), 1);
  315     ck_assert_int_eq(db_setalias("eth0", "The Internet"), 1);
  316 
  317     ret = db_close();
  318     ck_assert_int_eq(ret, 1);
  319 }
  320 END_TEST
  321 
  322 START_TEST(db_setupdated_fails_with_no_open_db)
  323 {
  324     suppress_output();
  325 
  326     ck_assert_int_eq(db_setupdated("eth0", 123456), 0);
  327 }
  328 END_TEST
  329 
  330 START_TEST(db_setupdated_fails_if_interface_does_not_exist_in_database)
  331 {
  332     int ret;
  333 
  334     ret = db_open_rw(1);
  335     ck_assert_int_eq(ret, 1);
  336 
  337     ck_assert_int_eq(db_setupdated("eth0", 123456), 0);
  338 
  339     ret = db_close();
  340     ck_assert_int_eq(ret, 1);
  341 }
  342 END_TEST
  343 
  344 START_TEST(db_setupdated_can_change_updated)
  345 {
  346     int ret;
  347 
  348     ret = db_open_rw(1);
  349     ck_assert_int_eq(ret, 1);
  350 
  351     ck_assert_int_eq(db_addtraffic("eth0", 12, 34), 1);
  352     ck_assert_int_eq(db_setupdated("eth0", 123456), 1);
  353 
  354     ret = db_close();
  355     ck_assert_int_eq(ret, 1);
  356 }
  357 END_TEST
  358 
  359 START_TEST(db_addinterface_fails_with_no_open_db)
  360 {
  361     int ret;
  362 
  363     suppress_output();
  364 
  365     ret = db_addinterface("eth0");
  366     ck_assert_int_eq(ret, 0);
  367 }
  368 END_TEST
  369 
  370 START_TEST(db_addinterface_can_add_interfaces)
  371 {
  372     int ret;
  373 
  374     ret = db_open_rw(1);
  375     ck_assert_int_eq(ret, 1);
  376 
  377     ret = db_addinterface("eth0");
  378     ck_assert_int_eq(ret, 1);
  379     ret = db_addinterface("eth1");
  380     ck_assert_int_eq(ret, 1);
  381 
  382     ret = db_close();
  383     ck_assert_int_eq(ret, 1);
  384 }
  385 END_TEST
  386 
  387 START_TEST(db_addinterface_can_not_add_same_interface_twice)
  388 {
  389     int ret;
  390 
  391     suppress_output();
  392 
  393     ret = db_open_rw(1);
  394     ck_assert_int_eq(ret, 1);
  395 
  396     ret = db_addinterface("eth0");
  397     ck_assert_int_eq(ret, 1);
  398     ret = db_addinterface("eth0");
  399     ck_assert_int_eq(ret, 0);
  400     ret = db_addinterface("eth1");
  401     ck_assert_int_eq(ret, 1);
  402     ret = db_addinterface("eth1");
  403     ck_assert_int_eq(ret, 0);
  404 
  405     ret = db_close();
  406     ck_assert_int_eq(ret, 1);
  407 }
  408 END_TEST
  409 
  410 START_TEST(db_removeinterface_knows_if_interface_exists)
  411 {
  412     int ret;
  413 
  414     ret = db_open_rw(1);
  415     ck_assert_int_eq(ret, 1);
  416 
  417     ret = db_removeinterface("eth0");
  418     ck_assert_int_eq(ret, 0);
  419     ret = db_removeinterface("nothing");
  420     ck_assert_int_eq(ret, 0);
  421     ret = db_removeinterface("");
  422     ck_assert_int_eq(ret, 0);
  423 
  424     ret = db_close();
  425     ck_assert_int_eq(ret, 1);
  426 }
  427 END_TEST
  428 
  429 START_TEST(db_removeinterface_can_remove_interfaces)
  430 {
  431     int ret;
  432 
  433     ret = db_open_rw(1);
  434     ck_assert_int_eq(ret, 1);
  435 
  436     ret = db_addinterface("eth0");
  437     ck_assert_int_eq(ret, 1);
  438     ret = db_addinterface("eth1");
  439     ck_assert_int_eq(ret, 1);
  440     ret = db_addinterface("eth2");
  441     ck_assert_int_eq(ret, 1);
  442 
  443     ck_assert_int_eq(db_getinterfacecount(), 3);
  444     ck_assert_int_eq(db_getinterfacecountbyname("eth0"), 1);
  445     ck_assert_int_eq(db_getinterfacecountbyname("eth1"), 1);
  446     ck_assert_int_eq(db_getinterfacecountbyname("eth2"), 1);
  447     ck_assert_int_eq(db_getinterfacecountbyname("eth3"), 0);
  448 
  449     ret = db_removeinterface("eth1");
  450     ck_assert_int_eq(ret, 1);
  451     ret = db_removeinterface("nothing");
  452     ck_assert_int_eq(ret, 0);
  453     ret = db_removeinterface("");
  454     ck_assert_int_eq(ret, 0);
  455 
  456     ck_assert_int_eq(db_getinterfacecount(), 2);
  457     ck_assert_int_eq(db_getinterfacecountbyname("eth0"), 1);
  458     ck_assert_int_eq(db_getinterfacecountbyname("eth1"), 0);
  459     ck_assert_int_eq(db_getinterfacecountbyname("eth2"), 1);
  460     ck_assert_int_eq(db_getinterfacecountbyname("eth3"), 0);
  461 
  462     ret = db_close();
  463     ck_assert_int_eq(ret, 1);
  464 }
  465 END_TEST
  466 
  467 START_TEST(db_renameinterface_knows_if_interface_exists)
  468 {
  469     int ret;
  470 
  471     ret = db_open_rw(1);
  472     ck_assert_int_eq(ret, 1);
  473 
  474     ret = db_renameinterface("eth0", "eth1");
  475     ck_assert_int_eq(ret, 0);
  476     ret = db_renameinterface("nothing", "something");
  477     ck_assert_int_eq(ret, 0);
  478     ret = db_renameinterface("", "");
  479     ck_assert_int_eq(ret, 0);
  480 
  481     ret = db_close();
  482     ck_assert_int_eq(ret, 1);
  483 }
  484 END_TEST
  485 
  486 START_TEST(db_renameinterface_can_rename_interfaces)
  487 {
  488     int ret;
  489 
  490     ret = db_open_rw(1);
  491     ck_assert_int_eq(ret, 1);
  492 
  493     ret = db_addinterface("eth0");
  494     ck_assert_int_eq(ret, 1);
  495     ret = db_addinterface("eth1");
  496     ck_assert_int_eq(ret, 1);
  497     ret = db_addinterface("eth2");
  498     ck_assert_int_eq(ret, 1);
  499 
  500     ck_assert_int_eq(db_getinterfacecount(), 3);
  501     ck_assert_int_eq(db_getinterfacecountbyname("eth0"), 1);
  502     ck_assert_int_eq(db_getinterfacecountbyname("eth1"), 1);
  503     ck_assert_int_eq(db_getinterfacecountbyname("eth2"), 1);
  504     ck_assert_int_eq(db_getinterfacecountbyname("eth3"), 0);
  505 
  506     suppress_output();
  507 
  508     ret = db_renameinterface("eth0", "eth1");
  509     ck_assert_int_eq(ret, 0);
  510     ret = db_renameinterface("eth2", "eth3");
  511     ck_assert_int_eq(ret, 1);
  512     ret = db_renameinterface("eth1", "eth2");
  513     ck_assert_int_eq(ret, 1);
  514     ret = db_renameinterface("eth0", "");
  515     ck_assert_int_eq(ret, 0);
  516     ret = db_renameinterface("eth0", "eth1");
  517     ck_assert_int_eq(ret, 1);
  518 
  519     ck_assert_int_eq(db_getinterfacecount(), 3);
  520     ck_assert_int_eq(db_getinterfacecountbyname("eth0"), 0);
  521     ck_assert_int_eq(db_getinterfacecountbyname("eth1"), 1);
  522     ck_assert_int_eq(db_getinterfacecountbyname("eth2"), 1);
  523     ck_assert_int_eq(db_getinterfacecountbyname("eth3"), 1);
  524 
  525     ret = db_close();
  526     ck_assert_int_eq(ret, 1);
  527 }
  528 END_TEST
  529 
  530 START_TEST(db_getinterfacecount_counts_interfaces)
  531 {
  532     int ret;
  533 
  534     suppress_output();
  535 
  536     ret = db_open_rw(1);
  537     ck_assert_int_eq(ret, 1);
  538 
  539     ret = (int)db_getinterfacecount();
  540     ck_assert_int_eq(ret, 0);
  541 
  542     ret = db_addinterface("eth0");
  543     ck_assert_int_eq(ret, 1);
  544 
  545     ret = (int)db_getinterfacecount();
  546     ck_assert_int_eq(ret, 1);
  547 
  548     ret = db_addinterface("eth0");
  549     ck_assert_int_eq(ret, 0);
  550 
  551     ret = (int)db_getinterfacecount();
  552     ck_assert_int_eq(ret, 1);
  553 
  554     ret = db_addinterface("eth1");
  555     ck_assert_int_eq(ret, 1);
  556 
  557     ret = (int)db_getinterfacecount();
  558     ck_assert_int_eq(ret, 2);
  559 
  560     ret = db_close();
  561     ck_assert_int_eq(ret, 1);
  562 }
  563 END_TEST
  564 
  565 START_TEST(db_getinterfacecountbyname_counts_interfaces)
  566 {
  567     int ret;
  568 
  569     ret = db_open_rw(1);
  570     ck_assert_int_eq(ret, 1);
  571 
  572     ret = db_addinterface("eth0");
  573     ck_assert_int_eq(ret, 1);
  574 
  575     ret = db_addinterface("eth1");
  576     ck_assert_int_eq(ret, 1);
  577 
  578     ret = db_addinterface("eth3");
  579     ck_assert_int_eq(ret, 1);
  580 
  581     ret = (int)db_getinterfacecountbyname("foo");
  582     ck_assert_int_eq(ret, 0);
  583 
  584     ret = (int)db_getinterfacecountbyname("eth0");
  585     ck_assert_int_eq(ret, 1);
  586 
  587     ret = (int)db_getinterfacecountbyname("eth1");
  588     ck_assert_int_eq(ret, 1);
  589 
  590     ret = (int)db_getinterfacecountbyname("eth2");
  591     ck_assert_int_eq(ret, 0);
  592 
  593     ret = (int)db_getinterfacecountbyname("");
  594     ck_assert_int_eq(ret, 3);
  595 
  596     ret = (int)db_getinterfacecountbyname("eth0+eth1");
  597     ck_assert_int_eq(ret, 2);
  598 
  599     ret = (int)db_getinterfacecountbyname("eth0+eth1+eth3");
  600     ck_assert_int_eq(ret, 3);
  601 
  602     ret = (int)db_getinterfacecountbyname("eth0+eth1+eth2");
  603     ck_assert_int_eq(ret, 0);
  604 
  605     ret = db_close();
  606     ck_assert_int_eq(ret, 1);
  607 }
  608 END_TEST
  609 
  610 START_TEST(db_getcounters_with_no_interface)
  611 {
  612     int ret;
  613     uint64_t rx, tx;
  614 
  615     rx = tx = 1;
  616 
  617     ret = db_open_rw(1);
  618     ck_assert_int_eq(ret, 1);
  619 
  620     ret = db_getcounters("eth0", &rx, &tx);
  621     ck_assert_int_eq(ret, 0);
  622     ck_assert_int_eq(rx, 0);
  623     ck_assert_int_eq(tx, 0);
  624 
  625     ret = db_close();
  626     ck_assert_int_eq(ret, 1);
  627 }
  628 END_TEST
  629 
  630 START_TEST(db_setcounters_with_no_interface)
  631 {
  632     int ret;
  633     uint64_t rx, tx;
  634 
  635     rx = tx = 1;
  636 
  637     ret = db_open_rw(1);
  638     ck_assert_int_eq(ret, 1);
  639 
  640     ret = db_setcounters("eth0", 2, 2);
  641     ck_assert_int_eq(ret, 0);
  642 
  643     ret = db_getcounters("eth0", &rx, &tx);
  644     ck_assert_int_eq(ret, 0);
  645     ck_assert_int_eq(rx, 0);
  646     ck_assert_int_eq(tx, 0);
  647 
  648     ret = db_close();
  649     ck_assert_int_eq(ret, 1);
  650 }
  651 END_TEST
  652 
  653 START_TEST(db_interface_info_manipulation)
  654 {
  655     int ret;
  656     uint64_t rx, tx, c;
  657     interfaceinfo info;
  658 
  659     rx = tx = 1;
  660 
  661     ret = db_open_rw(1);
  662     ck_assert_int_eq(ret, 1);
  663     ret = db_addinterface("eth0");
  664     ck_assert_int_eq(ret, 1);
  665     ret = db_addinterface("eth1");
  666     ck_assert_int_eq(ret, 1);
  667 
  668     ret = db_getcounters("eth0", &rx, &tx);
  669     ck_assert_int_eq(ret, 1);
  670     ck_assert_int_eq(rx, 0);
  671     ck_assert_int_eq(tx, 0);
  672 
  673     ret = db_setcounters("eth0", 2, 2);
  674     ck_assert_int_eq(ret, 1);
  675 
  676     ret = db_getcounters("eth0", &rx, &tx);
  677     ck_assert_int_eq(ret, 1);
  678     ck_assert_int_eq(rx, 2);
  679     ck_assert_int_eq(tx, 2);
  680 
  681     ret = db_settotal("eth1", 42, 24);
  682     ck_assert_int_eq(ret, 1);
  683 
  684     c = (uint64_t)time(NULL) - 100;
  685     ret = db_setcreation("eth1", (time_t)c);
  686 
  687     ret = db_getinterfaceinfo("eth0", &info);
  688     ck_assert_int_eq(ret, 1);
  689     ck_assert_int_eq(info.active, 1);
  690     ck_assert_int_eq(info.rxcounter, 2);
  691     ck_assert_int_eq(info.txcounter, 2);
  692     ck_assert_int_eq(info.rxtotal, 0);
  693     ck_assert_int_eq(info.txtotal, 0);
  694     ck_assert_int_ne(info.created, 0);
  695 
  696     ck_assert_int_eq(db_setactive("eth1", 0), 1);
  697     ck_assert_int_eq(db_setupdated("eth1", 0), 1);
  698 
  699     ret = db_getinterfaceinfo("eth1", &info);
  700     ck_assert_int_eq(ret, 1);
  701     ck_assert_int_eq(info.active, 0);
  702     ck_assert_int_eq(info.rxcounter, 0);
  703     ck_assert_int_eq(info.txcounter, 0);
  704     ck_assert_int_eq(info.rxtotal, 42);
  705     ck_assert_int_eq(info.txtotal, 24);
  706     ck_assert_int_eq((uint64_t)info.created, c);
  707     ck_assert_int_eq((uint64_t)info.updated, 0);
  708 
  709     ck_assert_int_eq(db_setupdated("eth1", 123456), 1);
  710 
  711     ret = db_getinterfaceinfo("eth1", &info);
  712     ck_assert_int_eq(ret, 1);
  713     ck_assert_int_eq(info.active, 0);
  714     ck_assert_int_eq(info.rxcounter, 0);
  715     ck_assert_int_eq(info.txcounter, 0);
  716     ck_assert_int_eq(info.rxtotal, 42);
  717     ck_assert_int_eq(info.txtotal, 24);
  718     ck_assert_int_eq((uint64_t)info.created, c);
  719     ck_assert_int_eq((uint64_t)info.updated, 123456);
  720 
  721     ret = db_close();
  722     ck_assert_int_eq(ret, 1);
  723 }
  724 END_TEST
  725 
  726 START_TEST(db_getiflist_lists_interfaces)
  727 {
  728     int ret;
  729     iflist *dbifl = NULL, *dbifl_i = NULL;
  730 
  731     ret = db_open_rw(1);
  732     ck_assert_int_eq(ret, 1);
  733     ret = db_addinterface("a");
  734     ck_assert_int_eq(ret, 1);
  735     ret = db_addinterface("b");
  736     ck_assert_int_eq(ret, 1);
  737     ret = db_addinterface("eth0");
  738     ck_assert_int_eq(ret, 1);
  739     ret = db_addinterface("eth1");
  740     ck_assert_int_eq(ret, 1);
  741 
  742     ret = db_getiflist(&dbifl);
  743     ck_assert_int_eq(ret, 4);
  744 
  745     dbifl_i = dbifl;
  746 
  747     ret = db_close();
  748     ck_assert_int_eq(ret, 1);
  749 
  750     ck_assert_str_eq(dbifl_i->interface, "a");
  751     ck_assert_ptr_ne(dbifl_i->next, NULL);
  752     dbifl_i = dbifl_i->next;
  753 
  754     ck_assert_str_eq(dbifl_i->interface, "b");
  755     ck_assert_ptr_ne(dbifl_i->next, NULL);
  756     dbifl_i = dbifl_i->next;
  757 
  758     ck_assert_str_eq(dbifl_i->interface, "eth0");
  759     ck_assert_ptr_ne(dbifl_i->next, NULL);
  760     dbifl_i = dbifl_i->next;
  761 
  762     ck_assert_str_eq(dbifl_i->interface, "eth1");
  763     ck_assert_ptr_eq(dbifl_i->next, NULL);
  764 
  765     iflistfree(&dbifl);
  766     ck_assert_ptr_eq(dbifl, NULL);
  767 }
  768 END_TEST
  769 
  770 START_TEST(db_maintenance_does_not_fault)
  771 {
  772     int ret;
  773 
  774     ret = db_open_rw(1);
  775     ck_assert_int_eq(ret, 1);
  776     ret = db_addinterface("eth0");
  777     ck_assert_int_eq(ret, 1);
  778     ret = db_addinterface("eth1");
  779     ck_assert_int_eq(ret, 1);
  780 
  781     ret = db_vacuum();
  782     ck_assert_int_eq(ret, 1);
  783 
  784     ret = db_removeoldentries();
  785     ck_assert_int_eq(ret, 1);
  786 
  787     ret = db_close();
  788     ck_assert_int_eq(ret, 1);
  789 }
  790 END_TEST
  791 
  792 START_TEST(db_data_can_be_inserted)
  793 {
  794     int ret;
  795     interfaceinfo info;
  796 
  797     ret = db_open_rw(1);
  798     ck_assert_int_eq(ret, 1);
  799     ret = db_addinterface("eth0");
  800     ck_assert_int_eq(ret, 1);
  801 
  802     ret = db_insertdata("foo", "eth0", 1, 2, 3);
  803     ck_assert_int_eq(ret, 0);
  804 
  805     ret = db_insertdata("hour", "eth1", 1, 2, 3);
  806     ck_assert_int_eq(ret, 0);
  807 
  808     ret = db_insertdata("hour", "eth0", 1, 2, 3);
  809     ck_assert_int_eq(ret, 1);
  810 
  811     ret = db_insertdata("day", "eth0", 1, 2, 3);
  812     ck_assert_int_eq(ret, 1);
  813 
  814     ret = db_insertdata("month", "eth0", 1, 2, 3);
  815     ck_assert_int_eq(ret, 1);
  816 
  817     ret = db_insertdata("year", "eth0", 1, 2, 3);
  818     ck_assert_int_eq(ret, 1);
  819 
  820     ret = db_insertdata("top", "eth0", 1, 2, 3);
  821     ck_assert_int_eq(ret, 1);
  822 
  823     /* verify that totals don't get changed */
  824     ret = db_getinterfaceinfo("eth0", &info);
  825     ck_assert_int_eq(ret, 1);
  826     ck_assert_int_eq(info.active, 1);
  827     ck_assert_int_eq(info.rxcounter, 0);
  828     ck_assert_int_eq(info.txcounter, 0);
  829     ck_assert_int_eq(info.rxtotal, 0);
  830     ck_assert_int_eq(info.txtotal, 0);
  831     ck_assert_int_ne(info.created, 0);
  832 
  833     ret = db_close();
  834     ck_assert_int_eq(ret, 1);
  835 }
  836 END_TEST
  837 
  838 START_TEST(db_data_can_be_retrieved)
  839 {
  840     int ret;
  841     dbdatalist *datalist = NULL, *datalist_iterator = NULL;
  842     dbdatalistinfo datainfo;
  843 
  844     ret = db_open_rw(1);
  845     ck_assert_int_eq(ret, 1);
  846     ret = db_addinterface("eth0");
  847     ck_assert_int_eq(ret, 1);
  848 
  849     ret = db_insertdata("hour", "eth0", 1, 2, 3);
  850     ck_assert_int_eq(ret, 1);
  851 
  852     ret = db_insertdata("hour", "eth0", 10, 20, 10000);
  853     ck_assert_int_eq(ret, 1);
  854 
  855     ret = db_getdata(&datalist, &datainfo, "eth0", "hour", 2);
  856     ck_assert_int_eq(ret, 1);
  857 
  858     ck_assert_int_eq(datainfo.count, 2);
  859     ck_assert_int_eq(datainfo.minrx, 1);
  860     ck_assert_int_eq(datainfo.maxrx, 10);
  861     ck_assert_int_eq(datainfo.sumrx, 11);
  862     ck_assert_int_eq(datainfo.mintx, 2);
  863     ck_assert_int_eq(datainfo.maxtx, 20);
  864     ck_assert_int_eq(datainfo.sumtx, 22);
  865     /* db_insertdata rounds the timestamps to full hours */
  866     ck_assert_int_eq((int)datainfo.maxtime, 7200);
  867     ck_assert_int_eq((int)datainfo.mintime, 0);
  868 
  869     datalist_iterator = datalist;
  870 
  871     ck_assert_int_eq(datalist_iterator->rx, 1);
  872     ck_assert_int_eq(datalist_iterator->tx, 2);
  873     ck_assert_int_eq(datalist_iterator->timestamp, 0);
  874 
  875     datalist_iterator = datalist_iterator->next;
  876 
  877     ck_assert_int_eq(datalist_iterator->rx, 10);
  878     ck_assert_int_eq(datalist_iterator->tx, 20);
  879     ck_assert_int_eq(datalist_iterator->timestamp, 7200);
  880 
  881     dbdatalistfree(&datalist);
  882 
  883     ret = db_close();
  884     ck_assert_int_eq(ret, 1);
  885 }
  886 END_TEST
  887 
  888 START_TEST(db_data_can_be_inserted_utc)
  889 {
  890     int ret;
  891     interfaceinfo info;
  892 
  893     cfg.useutc = 1;
  894     validatecfg(CT_Daemon);
  895 
  896     ret = db_open_rw(1);
  897     ck_assert_int_eq(ret, 1);
  898     ret = db_addinterface("eth0");
  899     ck_assert_int_eq(ret, 1);
  900 
  901     ret = db_insertdata("foo", "eth0", 1, 2, 3);
  902     ck_assert_int_eq(ret, 0);
  903 
  904     ret = db_insertdata("hour", "eth1", 1, 2, 3);
  905     ck_assert_int_eq(ret, 0);
  906 
  907     ret = db_insertdata("hour", "eth0", 1, 2, 3);
  908     ck_assert_int_eq(ret, 1);
  909 
  910     ret = db_insertdata("day", "eth0", 1, 2, 3);
  911     ck_assert_int_eq(ret, 1);
  912 
  913     ret = db_insertdata("month", "eth0", 1, 2, 3);
  914     ck_assert_int_eq(ret, 1);
  915 
  916     ret = db_insertdata("year", "eth0", 1, 2, 3);
  917     ck_assert_int_eq(ret, 1);
  918 
  919     ret = db_insertdata("top", "eth0", 1, 2, 3);
  920     ck_assert_int_eq(ret, 1);
  921 
  922     /* verify that totals don't get changed */
  923     ret = db_getinterfaceinfo("eth0", &info);
  924     ck_assert_int_eq(ret, 1);
  925     ck_assert_int_eq(info.active, 1);
  926     ck_assert_int_eq(info.rxcounter, 0);
  927     ck_assert_int_eq(info.txcounter, 0);
  928     ck_assert_int_eq(info.rxtotal, 0);
  929     ck_assert_int_eq(info.txtotal, 0);
  930     ck_assert_int_ne(info.created, 0);
  931 
  932     ret = db_close();
  933     ck_assert_int_eq(ret, 1);
  934 }
  935 END_TEST
  936 
  937 START_TEST(db_data_can_be_retrieved_utc)
  938 {
  939     int ret;
  940     dbdatalist *datalist = NULL, *datalist_iterator = NULL;
  941     dbdatalistinfo datainfo;
  942 
  943     cfg.useutc = 1;
  944     validatecfg(CT_Daemon);
  945 
  946     ret = db_open_rw(1);
  947     ck_assert_int_eq(ret, 1);
  948     ret = db_addinterface("eth0");
  949     ck_assert_int_eq(ret, 1);
  950 
  951     ret = db_insertdata("hour", "eth0", 1, 2, 3);
  952     ck_assert_int_eq(ret, 1);
  953 
  954     ret = db_insertdata("hour", "eth0", 10, 20, 10000);
  955     ck_assert_int_eq(ret, 1);
  956 
  957     ret = db_getdata(&datalist, &datainfo, "eth0", "hour", 2);
  958     ck_assert_int_eq(ret, 1);
  959 
  960     ck_assert_int_eq(datainfo.count, 2);
  961     ck_assert_int_eq(datainfo.minrx, 1);
  962     ck_assert_int_eq(datainfo.maxrx, 10);
  963     ck_assert_int_eq(datainfo.sumrx, 11);
  964     ck_assert_int_eq(datainfo.mintx, 2);
  965     ck_assert_int_eq(datainfo.maxtx, 20);
  966     ck_assert_int_eq(datainfo.sumtx, 22);
  967     /* db_insertdata rounds the timestamps to full hours */
  968     ck_assert_int_eq((int)datainfo.maxtime, 7200);
  969     ck_assert_int_eq((int)datainfo.mintime, 0);
  970 
  971     datalist_iterator = datalist;
  972 
  973     ck_assert_int_eq(datalist_iterator->rx, 1);
  974     ck_assert_int_eq(datalist_iterator->tx, 2);
  975     ck_assert_int_eq(datalist_iterator->timestamp, 0);
  976 
  977     datalist_iterator = datalist_iterator->next;
  978 
  979     ck_assert_int_eq(datalist_iterator->rx, 10);
  980     ck_assert_int_eq(datalist_iterator->tx, 20);
  981     ck_assert_int_eq(datalist_iterator->timestamp, 7200);
  982 
  983     dbdatalistfree(&datalist);
  984 
  985     ret = db_close();
  986     ck_assert_int_eq(ret, 1);
  987 }
  988 END_TEST
  989 
  990 START_TEST(db_fatal_errors_get_detected)
  991 {
  992     ck_assert_int_eq(db_iserrcodefatal(SQLITE_OK), 0);
  993     ck_assert_int_eq(db_iserrcodefatal(SQLITE_FULL), 0);
  994     ck_assert_int_eq(db_iserrcodefatal(SQLITE_IOERR), 0);
  995     ck_assert_int_eq(db_iserrcodefatal(SQLITE_LOCKED), 0);
  996     ck_assert_int_eq(db_iserrcodefatal(SQLITE_BUSY), 0);
  997 
  998     ck_assert_int_eq(db_iserrcodefatal(SQLITE_ERROR), 1);
  999     ck_assert_int_eq(db_iserrcodefatal(SQLITE_ABORT), 1);
 1000     ck_assert_int_eq(db_iserrcodefatal(SQLITE_EMPTY), 1);
 1001     ck_assert_int_eq(db_iserrcodefatal(SQLITE_READONLY), 1);
 1002 }
 1003 END_TEST
 1004 
 1005 START_TEST(db_validate_with_valid_version)
 1006 {
 1007     int ret;
 1008     suppress_output();
 1009 
 1010     ret = db_open_rw(1);
 1011     ck_assert_int_eq(ret, 1);
 1012 
 1013     ret = db_validate(0);
 1014     ck_assert_int_eq(ret, 1);
 1015     ck_assert_int_eq(db_errcode, 0);
 1016 
 1017     ret = db_validate(1);
 1018     ck_assert_int_eq(ret, 1);
 1019     ck_assert_int_eq(db_errcode, 0);
 1020 
 1021     ret = db_close();
 1022     ck_assert_int_eq(ret, 1);
 1023 }
 1024 END_TEST
 1025 
 1026 START_TEST(db_validate_with_no_version)
 1027 {
 1028     int ret;
 1029     suppress_output();
 1030 
 1031     ret = db_open_rw(1);
 1032     ck_assert_int_eq(ret, 1);
 1033 
 1034     ret = db_exec("delete from info where name='dbversion';");
 1035     ck_assert_int_eq(ret, 1);
 1036 
 1037     ret = db_validate(0);
 1038     ck_assert_int_eq(ret, 0);
 1039     ck_assert_int_eq(db_errcode, 0);
 1040 
 1041     ret = db_validate(1);
 1042     ck_assert_int_eq(ret, 0);
 1043     ck_assert_int_eq(db_errcode, 0);
 1044 
 1045     ret = db_close();
 1046     ck_assert_int_eq(ret, 1);
 1047 }
 1048 END_TEST
 1049 
 1050 START_TEST(db_validate_with_low_version)
 1051 {
 1052     int ret;
 1053     suppress_output();
 1054 
 1055     ret = db_open_rw(1);
 1056     ck_assert_int_eq(ret, 1);
 1057 
 1058     ret = db_exec("update info set value='-1' where name='dbversion';");
 1059     ck_assert_int_eq(ret, 1);
 1060 
 1061     ret = db_validate(0);
 1062     ck_assert_int_eq(ret, 0);
 1063     ck_assert_int_eq(db_errcode, 0);
 1064 
 1065     ret = db_validate(1);
 1066     ck_assert_int_eq(ret, 0);
 1067     ck_assert_int_eq(db_errcode, 0);
 1068 
 1069     ret = db_close();
 1070     ck_assert_int_eq(ret, 1);
 1071 }
 1072 END_TEST
 1073 
 1074 START_TEST(db_validate_with_high_version)
 1075 {
 1076     int ret;
 1077     suppress_output();
 1078 
 1079     ret = db_open_rw(1);
 1080     ck_assert_int_eq(ret, 1);
 1081 
 1082     ret = db_exec("update info set value='100' where name='dbversion';");
 1083     ck_assert_int_eq(ret, 1);
 1084 
 1085     ret = db_validate(0);
 1086     ck_assert_int_eq(ret, 0);
 1087     ck_assert_int_eq(db_errcode, 0);
 1088 
 1089     ret = db_validate(1);
 1090     ck_assert_int_eq(ret, 0);
 1091     ck_assert_int_eq(db_errcode, 0);
 1092 
 1093     ret = db_close();
 1094     ck_assert_int_eq(ret, 1);
 1095 }
 1096 END_TEST
 1097 
 1098 void range_test_month_setup(void)
 1099 {
 1100     int ret, i;
 1101     cfg.monthrotate = 2; /* this should have no effect */
 1102 
 1103     ret = db_open_rw(1);
 1104     ck_assert_int_eq(ret, 1);
 1105     ret = db_addinterface("ethtest");
 1106     ck_assert_int_eq(ret, 1);
 1107 
 1108     for (i = 1; i <= 6; i++) {
 1109         ret = db_insertdata("month", "ethtest", 1, 2, get_timestamp(2000, i, 1, 0, 0));
 1110         ck_assert_int_eq(ret, 1);
 1111     }
 1112 }
 1113 
 1114 START_TEST(db_getdata_range_can_get_months_without_range_defined)
 1115 {
 1116     int ret, i;
 1117     char timestamp[64];
 1118     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1119     dbdatalistinfo datainfo;
 1120 
 1121     range_test_month_setup();
 1122 
 1123     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", "");
 1124     ck_assert_int_eq(ret, 1);
 1125     ck_assert_int_eq(datainfo.count, 6);
 1126     datalist_i = datalist;
 1127     i = 0;
 1128     while (datalist_i != NULL) {
 1129         switch (i) {
 1130             case 0:
 1131                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1132                 ck_assert_str_eq(timestamp, "2000-01-01");
 1133                 break;
 1134             case 5:
 1135                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1136                 ck_assert_str_eq(timestamp, "2000-06-01");
 1137                 break;
 1138         }
 1139         datalist_i = datalist_i->next;
 1140         i++;
 1141     }
 1142     dbdatalistfree(&datalist);
 1143 
 1144     ret = db_close();
 1145     ck_assert_int_eq(ret, 1);
 1146 }
 1147 END_TEST
 1148 
 1149 START_TEST(db_getdata_range_can_get_months_with_range_matching_existing_data)
 1150 {
 1151     int ret, i;
 1152     char timestamp[64];
 1153     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1154     dbdatalistinfo datainfo;
 1155 
 1156     range_test_month_setup();
 1157 
 1158     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "2000-01-01", "2000-06-01");
 1159     ck_assert_int_eq(ret, 1);
 1160     ck_assert_int_eq(datainfo.count, 6);
 1161     datalist_i = datalist;
 1162     i = 0;
 1163     while (datalist_i != NULL) {
 1164         switch (i) {
 1165             case 0:
 1166                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1167                 ck_assert_str_eq(timestamp, "2000-01-01");
 1168                 break;
 1169             case 5:
 1170                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1171                 ck_assert_str_eq(timestamp, "2000-06-01");
 1172                 break;
 1173         }
 1174         datalist_i = datalist_i->next;
 1175         i++;
 1176     }
 1177     dbdatalistfree(&datalist);
 1178 
 1179     ret = db_close();
 1180     ck_assert_int_eq(ret, 1);
 1181 }
 1182 END_TEST
 1183 
 1184 START_TEST(db_getdata_range_can_get_months_with_range_past_existing_data)
 1185 {
 1186     int ret, i;
 1187     char timestamp[64];
 1188     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1189     dbdatalistinfo datainfo;
 1190 
 1191     range_test_month_setup();
 1192 
 1193     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "1999-01-01", "2000-08-01");
 1194     ck_assert_int_eq(ret, 1);
 1195     ck_assert_int_eq(datainfo.count, 6);
 1196     datalist_i = datalist;
 1197     i = 0;
 1198     while (datalist_i != NULL) {
 1199         switch (i) {
 1200             case 0:
 1201                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1202                 ck_assert_str_eq(timestamp, "2000-01-01");
 1203                 break;
 1204             case 5:
 1205                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1206                 ck_assert_str_eq(timestamp, "2000-06-01");
 1207                 break;
 1208         }
 1209         datalist_i = datalist_i->next;
 1210         i++;
 1211     }
 1212     dbdatalistfree(&datalist);
 1213 
 1214     ret = db_close();
 1215     ck_assert_int_eq(ret, 1);
 1216 }
 1217 END_TEST
 1218 
 1219 START_TEST(db_getdata_range_can_get_months_with_range_limiting_begin_and_end)
 1220 {
 1221     int ret, i;
 1222     char timestamp[64];
 1223     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1224     dbdatalistinfo datainfo;
 1225 
 1226     range_test_month_setup();
 1227 
 1228     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "2000-02-01", "2000-04-01");
 1229     ck_assert_int_eq(ret, 1);
 1230     ck_assert_int_eq(datainfo.count, 3);
 1231     datalist_i = datalist;
 1232     i = 0;
 1233     while (datalist_i != NULL) {
 1234         switch (i) {
 1235             case 0:
 1236                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1237                 ck_assert_str_eq(timestamp, "2000-02-01");
 1238                 break;
 1239             case 2:
 1240                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1241                 ck_assert_str_eq(timestamp, "2000-04-01");
 1242                 break;
 1243         }
 1244         datalist_i = datalist_i->next;
 1245         i++;
 1246     }
 1247     dbdatalistfree(&datalist);
 1248 
 1249     ret = db_close();
 1250     ck_assert_int_eq(ret, 1);
 1251 }
 1252 END_TEST
 1253 
 1254 START_TEST(db_getdata_range_can_get_months_with_range_limiting_begin)
 1255 {
 1256     int ret, i;
 1257     char timestamp[64];
 1258     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1259     dbdatalistinfo datainfo;
 1260 
 1261     range_test_month_setup();
 1262 
 1263     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "2000-03-01", "");
 1264     ck_assert_int_eq(ret, 1);
 1265     ck_assert_int_eq(datainfo.count, 4);
 1266     datalist_i = datalist;
 1267     i = 0;
 1268     while (datalist_i != NULL) {
 1269         switch (i) {
 1270             case 0:
 1271                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1272                 ck_assert_str_eq(timestamp, "2000-03-01");
 1273                 break;
 1274             case 3:
 1275                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1276                 ck_assert_str_eq(timestamp, "2000-06-01");
 1277                 break;
 1278         }
 1279         datalist_i = datalist_i->next;
 1280         i++;
 1281     }
 1282     dbdatalistfree(&datalist);
 1283 
 1284     ret = db_close();
 1285     ck_assert_int_eq(ret, 1);
 1286 }
 1287 END_TEST
 1288 
 1289 START_TEST(db_getdata_range_can_get_months_with_range_limiting_begin_with_limit)
 1290 {
 1291     int ret, i;
 1292     char timestamp[64];
 1293     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1294     dbdatalistinfo datainfo;
 1295 
 1296     range_test_month_setup();
 1297 
 1298     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 3, "2000-03-01", "");
 1299     ck_assert_int_eq(ret, 1);
 1300     ck_assert_int_eq(datainfo.count, 3);
 1301     datalist_i = datalist;
 1302     i = 0;
 1303     while (datalist_i != NULL) {
 1304         switch (i) {
 1305             case 0:
 1306                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1307                 ck_assert_str_eq(timestamp, "2000-03-01");
 1308                 break;
 1309             case 2:
 1310                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1311                 ck_assert_str_eq(timestamp, "2000-05-01");
 1312                 break;
 1313         }
 1314         datalist_i = datalist_i->next;
 1315         i++;
 1316     }
 1317     dbdatalistfree(&datalist);
 1318 
 1319     ret = db_close();
 1320     ck_assert_int_eq(ret, 1);
 1321 }
 1322 END_TEST
 1323 
 1324 START_TEST(db_getdata_range_can_get_months_with_range_limiting_end)
 1325 {
 1326     int ret, i;
 1327     char timestamp[64];
 1328     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1329     dbdatalistinfo datainfo;
 1330 
 1331     range_test_month_setup();
 1332 
 1333     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", "2000-04-01");
 1334     ck_assert_int_eq(ret, 1);
 1335     ck_assert_int_eq(datainfo.count, 4);
 1336     datalist_i = datalist;
 1337     i = 0;
 1338     while (datalist_i != NULL) {
 1339         switch (i) {
 1340             case 0:
 1341                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1342                 ck_assert_str_eq(timestamp, "2000-01-01");
 1343                 break;
 1344             case 3:
 1345                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1346                 ck_assert_str_eq(timestamp, "2000-04-01");
 1347                 break;
 1348         }
 1349         datalist_i = datalist_i->next;
 1350         i++;
 1351     }
 1352     dbdatalistfree(&datalist);
 1353 
 1354     ret = db_close();
 1355     ck_assert_int_eq(ret, 1);
 1356 }
 1357 END_TEST
 1358 
 1359 START_TEST(db_getdata_range_can_get_months_with_range_limiting_end_with_limit)
 1360 {
 1361     int ret, i;
 1362     char timestamp[64];
 1363     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1364     dbdatalistinfo datainfo;
 1365 
 1366     range_test_month_setup();
 1367 
 1368     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 3, "", "2000-04-01");
 1369     ck_assert_int_eq(ret, 1);
 1370     ck_assert_int_eq(datainfo.count, 3);
 1371     datalist_i = datalist;
 1372     i = 0;
 1373     while (datalist_i != NULL) {
 1374         switch (i) {
 1375             case 0:
 1376                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1377                 ck_assert_str_eq(timestamp, "2000-02-01");
 1378                 break;
 1379             case 2:
 1380                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1381                 ck_assert_str_eq(timestamp, "2000-04-01");
 1382                 break;
 1383         }
 1384         datalist_i = datalist_i->next;
 1385         i++;
 1386     }
 1387     dbdatalistfree(&datalist);
 1388 
 1389     ret = db_close();
 1390     ck_assert_int_eq(ret, 1);
 1391 }
 1392 END_TEST
 1393 
 1394 START_TEST(db_getdata_range_can_get_months_with_range_on_same_month)
 1395 {
 1396     int ret, i;
 1397     char timestamp[64];
 1398     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1399     dbdatalistinfo datainfo;
 1400 
 1401     range_test_month_setup();
 1402 
 1403     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "2000-04-01", "2000-04-01");
 1404     ck_assert_int_eq(ret, 1);
 1405     ck_assert_int_eq(datainfo.count, 1);
 1406     datalist_i = datalist;
 1407     i = 0;
 1408     while (datalist_i != NULL) {
 1409         switch (i) {
 1410             case 0:
 1411                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1412                 ck_assert_str_eq(timestamp, "2000-04-01");
 1413                 break;
 1414         }
 1415         datalist_i = datalist_i->next;
 1416         i++;
 1417     }
 1418     dbdatalistfree(&datalist);
 1419 
 1420     ret = db_close();
 1421     ck_assert_int_eq(ret, 1);
 1422 }
 1423 END_TEST
 1424 
 1425 START_TEST(db_getdata_range_can_get_months_with_range_past_first_day_of_month)
 1426 {
 1427     int ret, i;
 1428     char timestamp[64];
 1429     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1430     dbdatalistinfo datainfo;
 1431 
 1432     range_test_month_setup();
 1433 
 1434     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 3, "2000-02-02", "2000-05-06");
 1435     ck_assert_int_eq(ret, 1);
 1436     ck_assert_int_eq(datainfo.count, 3);
 1437     datalist_i = datalist;
 1438     i = 0;
 1439     while (datalist_i != NULL) {
 1440         switch (i) {
 1441             case 0:
 1442                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1443                 ck_assert_str_eq(timestamp, "2000-03-01");
 1444                 break;
 1445             case 2:
 1446                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1447                 ck_assert_str_eq(timestamp, "2000-05-01");
 1448                 break;
 1449         }
 1450         datalist_i = datalist_i->next;
 1451         i++;
 1452     }
 1453     dbdatalistfree(&datalist);
 1454 
 1455     ret = db_close();
 1456     ck_assert_int_eq(ret, 1);
 1457 }
 1458 END_TEST
 1459 
 1460 void range_test_hour_setup(void)
 1461 {
 1462     int ret, i, j;
 1463     cfg.monthrotate = 2; /* this should have no effect */
 1464 
 1465     ret = db_open_rw(1);
 1466     ck_assert_int_eq(ret, 1);
 1467     ret = db_addinterface("ethtest");
 1468     ck_assert_int_eq(ret, 1);
 1469 
 1470     for (j = 2; j < 5; j++) {
 1471         for (i = 0; i < 24; i++) {
 1472             ret = db_insertdata("hour", "ethtest", 1, 2, get_timestamp(2002, 2, j, i, 0));
 1473             ck_assert_int_eq(ret, 1);
 1474         }
 1475     }
 1476 }
 1477 
 1478 START_TEST(db_getdata_range_can_get_hours_without_range_defined)
 1479 {
 1480     int ret, i;
 1481     char timestamp[64];
 1482     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1483     dbdatalistinfo datainfo;
 1484 
 1485     range_test_hour_setup();
 1486 
 1487     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "", "");
 1488     ck_assert_int_eq(ret, 1);
 1489     ck_assert_int_eq(datainfo.count, 72);
 1490     datalist_i = datalist;
 1491     i = 0;
 1492     while (datalist_i != NULL) {
 1493         switch (i) {
 1494             case 0:
 1495                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1496                 ck_assert_str_eq(timestamp, "2002-02-02 00:00");
 1497                 break;
 1498             case 71:
 1499                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1500                 ck_assert_str_eq(timestamp, "2002-02-04 23:00");
 1501                 break;
 1502         }
 1503         datalist_i = datalist_i->next;
 1504         i++;
 1505     }
 1506     dbdatalistfree(&datalist);
 1507 
 1508     ret = db_close();
 1509     ck_assert_int_eq(ret, 1);
 1510 }
 1511 END_TEST
 1512 
 1513 START_TEST(db_getdata_range_can_get_hours_with_range_matching_existing_data)
 1514 {
 1515     int ret, i;
 1516     char timestamp[64];
 1517     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1518     dbdatalistinfo datainfo;
 1519 
 1520     range_test_hour_setup();
 1521 
 1522     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-02-02 00:00", "2002-02-04 23:00");
 1523     ck_assert_int_eq(ret, 1);
 1524     ck_assert_int_eq(datainfo.count, 72);
 1525     datalist_i = datalist;
 1526     i = 0;
 1527     while (datalist_i != NULL) {
 1528         switch (i) {
 1529             case 0:
 1530                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1531                 ck_assert_str_eq(timestamp, "2002-02-02 00:00");
 1532                 break;
 1533             case 71:
 1534                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1535                 ck_assert_str_eq(timestamp, "2002-02-04 23:00");
 1536                 break;
 1537         }
 1538         datalist_i = datalist_i->next;
 1539         i++;
 1540     }
 1541     dbdatalistfree(&datalist);
 1542 
 1543     ret = db_close();
 1544     ck_assert_int_eq(ret, 1);
 1545 }
 1546 END_TEST
 1547 
 1548 START_TEST(db_getdata_range_can_get_hours_with_range_past_existing_data)
 1549 {
 1550     int ret, i;
 1551     char timestamp[64];
 1552     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1553     dbdatalistinfo datainfo;
 1554 
 1555     range_test_hour_setup();
 1556 
 1557     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-01-01 15:00", "2002-02-04 23:30");
 1558     ck_assert_int_eq(ret, 1);
 1559     ck_assert_int_eq(datainfo.count, 72);
 1560     datalist_i = datalist;
 1561     i = 0;
 1562     while (datalist_i != NULL) {
 1563         switch (i) {
 1564             case 0:
 1565                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1566                 ck_assert_str_eq(timestamp, "2002-02-02 00:00");
 1567                 break;
 1568             case 71:
 1569                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1570                 ck_assert_str_eq(timestamp, "2002-02-04 23:00");
 1571                 break;
 1572         }
 1573         datalist_i = datalist_i->next;
 1574         i++;
 1575     }
 1576     dbdatalistfree(&datalist);
 1577 
 1578     ret = db_close();
 1579     ck_assert_int_eq(ret, 1);
 1580 }
 1581 END_TEST
 1582 
 1583 START_TEST(db_getdata_range_can_get_hours_with_range_limiting_begin_and_end)
 1584 {
 1585     int ret, i;
 1586     char timestamp[64];
 1587     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1588     dbdatalistinfo datainfo;
 1589 
 1590     range_test_hour_setup();
 1591 
 1592     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-02-02 20:00", "2002-02-03 17:00");
 1593     ck_assert_int_eq(ret, 1);
 1594     ck_assert_int_eq(datainfo.count, 22);
 1595     datalist_i = datalist;
 1596     i = 0;
 1597     while (datalist_i != NULL) {
 1598         switch (i) {
 1599             case 0:
 1600                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1601                 ck_assert_str_eq(timestamp, "2002-02-02 20:00");
 1602                 break;
 1603             case 21:
 1604                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1605                 ck_assert_str_eq(timestamp, "2002-02-03 17:00");
 1606                 break;
 1607         }
 1608         datalist_i = datalist_i->next;
 1609         i++;
 1610     }
 1611     dbdatalistfree(&datalist);
 1612 
 1613     ret = db_close();
 1614     ck_assert_int_eq(ret, 1);
 1615 }
 1616 END_TEST
 1617 
 1618 START_TEST(db_getdata_range_can_get_hours_with_range_limiting_begin)
 1619 {
 1620     int ret, i;
 1621     char timestamp[64];
 1622     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1623     dbdatalistinfo datainfo;
 1624 
 1625     range_test_hour_setup();
 1626 
 1627     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-02-02 20:00", "");
 1628     ck_assert_int_eq(ret, 1);
 1629     ck_assert_int_eq(datainfo.count, 52);
 1630     datalist_i = datalist;
 1631     i = 0;
 1632     while (datalist_i != NULL) {
 1633         switch (i) {
 1634             case 0:
 1635                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1636                 ck_assert_str_eq(timestamp, "2002-02-02 20:00");
 1637                 break;
 1638             case 51:
 1639                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1640                 ck_assert_str_eq(timestamp, "2002-02-04 23:00");
 1641                 break;
 1642         }
 1643         datalist_i = datalist_i->next;
 1644         i++;
 1645     }
 1646     dbdatalistfree(&datalist);
 1647 
 1648     ret = db_close();
 1649     ck_assert_int_eq(ret, 1);
 1650 }
 1651 END_TEST
 1652 
 1653 START_TEST(db_getdata_range_can_get_hours_with_range_limiting_begin_with_limit)
 1654 {
 1655     int ret, i;
 1656     char timestamp[64];
 1657     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1658     dbdatalistinfo datainfo;
 1659 
 1660     range_test_hour_setup();
 1661 
 1662     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 11, "2002-02-02 20:00", "");
 1663     ck_assert_int_eq(ret, 1);
 1664     ck_assert_int_eq(datainfo.count, 11);
 1665     datalist_i = datalist;
 1666     i = 0;
 1667     while (datalist_i != NULL) {
 1668         switch (i) {
 1669             case 0:
 1670                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1671                 ck_assert_str_eq(timestamp, "2002-02-02 20:00");
 1672                 break;
 1673             case 10:
 1674                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1675                 ck_assert_str_eq(timestamp, "2002-02-03 06:00");
 1676                 break;
 1677         }
 1678         datalist_i = datalist_i->next;
 1679         i++;
 1680     }
 1681     dbdatalistfree(&datalist);
 1682 
 1683     ret = db_close();
 1684     ck_assert_int_eq(ret, 1);
 1685 }
 1686 END_TEST
 1687 
 1688 START_TEST(db_getdata_range_can_get_hours_with_range_limiting_end)
 1689 {
 1690     int ret, i;
 1691     char timestamp[64];
 1692     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1693     dbdatalistinfo datainfo;
 1694 
 1695     range_test_hour_setup();
 1696 
 1697     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "", "2002-02-02 20:00");
 1698     ck_assert_int_eq(ret, 1);
 1699     ck_assert_int_eq(datainfo.count, 21);
 1700     datalist_i = datalist;
 1701     i = 0;
 1702     while (datalist_i != NULL) {
 1703         switch (i) {
 1704             case 0:
 1705                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1706                 ck_assert_str_eq(timestamp, "2002-02-02 00:00");
 1707                 break;
 1708             case 20:
 1709                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1710                 ck_assert_str_eq(timestamp, "2002-02-02 20:00");
 1711                 break;
 1712         }
 1713         datalist_i = datalist_i->next;
 1714         i++;
 1715     }
 1716     dbdatalistfree(&datalist);
 1717 
 1718     ret = db_close();
 1719     ck_assert_int_eq(ret, 1);
 1720 }
 1721 END_TEST
 1722 
 1723 START_TEST(db_getdata_range_can_get_hours_with_range_limiting_end_with_limit)
 1724 {
 1725     int ret, i;
 1726     char timestamp[64];
 1727     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1728     dbdatalistinfo datainfo;
 1729 
 1730     range_test_hour_setup();
 1731 
 1732     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 5, "", "2002-02-02 20:00");
 1733     ck_assert_int_eq(ret, 1);
 1734     ck_assert_int_eq(datainfo.count, 5);
 1735     datalist_i = datalist;
 1736     i = 0;
 1737     while (datalist_i != NULL) {
 1738         switch (i) {
 1739             case 0:
 1740                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1741                 ck_assert_str_eq(timestamp, "2002-02-02 16:00");
 1742                 break;
 1743             case 4:
 1744                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1745                 ck_assert_str_eq(timestamp, "2002-02-02 20:00");
 1746                 break;
 1747         }
 1748         datalist_i = datalist_i->next;
 1749         i++;
 1750     }
 1751     dbdatalistfree(&datalist);
 1752 
 1753     ret = db_close();
 1754     ck_assert_int_eq(ret, 1);
 1755 }
 1756 END_TEST
 1757 
 1758 START_TEST(db_getdata_range_can_get_hours_with_range_on_same_hour)
 1759 {
 1760     int ret, i;
 1761     char timestamp[64];
 1762     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1763     dbdatalistinfo datainfo;
 1764 
 1765     range_test_hour_setup();
 1766 
 1767     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-02-02 20:00", "2002-02-02 20:00");
 1768     ck_assert_int_eq(ret, 1);
 1769     ck_assert_int_eq(datainfo.count, 1);
 1770     datalist_i = datalist;
 1771     i = 0;
 1772     while (datalist_i != NULL) {
 1773         switch (i) {
 1774             case 0:
 1775                 strftime(timestamp, 64, "%Y-%m-%d %H:%M", localtime(&datalist_i->timestamp));
 1776                 ck_assert_str_eq(timestamp, "2002-02-02 20:00");
 1777                 break;
 1778         }
 1779         datalist_i = datalist_i->next;
 1780         i++;
 1781     }
 1782     dbdatalistfree(&datalist);
 1783 
 1784     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "hour", 0, "2002-02-02 20:15", "2002-02-02 20:45");
 1785     ck_assert_int_eq(ret, 1);
 1786     ck_assert_int_eq(datainfo.count, 0);
 1787 
 1788     ret = db_close();
 1789     ck_assert_int_eq(ret, 1);
 1790 }
 1791 END_TEST
 1792 
 1793 START_TEST(db_getdata_range_with_merged_interfaces)
 1794 {
 1795     int ret, i;
 1796     char timestamp[64];
 1797     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1798     dbdatalistinfo datainfo;
 1799 
 1800     cfg.monthrotate = 1;
 1801 
 1802     ret = db_open_rw(1);
 1803     ck_assert_int_eq(ret, 1);
 1804     ret = db_addinterface("ethtest");
 1805     ck_assert_int_eq(ret, 1);
 1806     ret = db_addinterface("ethother");
 1807     ck_assert_int_eq(ret, 1);
 1808 
 1809     for (i = 1; i <= 20; i++) {
 1810         ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0));
 1811         ck_assert_int_eq(ret, 1);
 1812         ret = db_addtraffic_dated("ethother", 3, 7, get_timestamp(2000, 2, i, 0, 0));
 1813         ck_assert_int_eq(ret, 1);
 1814     }
 1815 
 1816     ret = db_getdata_range(&datalist, &datainfo, "ethtest+ethother", "month", 0, "", "");
 1817     ck_assert_int_eq(ret, 1);
 1818     ck_assert_int_eq(datainfo.count, 1);
 1819     datalist_i = datalist;
 1820     i = 0;
 1821     while (datalist_i != NULL) {
 1822         switch (i) {
 1823             case 0:
 1824                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1825                 ck_assert_str_eq(timestamp, "2000-02-01");
 1826                 ck_assert_int_eq(datalist_i->rx, 80);
 1827                 ck_assert_int_eq(datalist_i->tx, 180);
 1828                 break;
 1829         }
 1830         datalist_i = datalist_i->next;
 1831         i++;
 1832     }
 1833     dbdatalistfree(&datalist);
 1834 
 1835     ret = db_close();
 1836     ck_assert_int_eq(ret, 1);
 1837 }
 1838 END_TEST
 1839 
 1840 START_TEST(db_addtraffic_without_monthrotate)
 1841 {
 1842     int ret, i;
 1843     char timestamp[64];
 1844     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1845     dbdatalistinfo datainfo;
 1846 
 1847     cfg.monthrotate = 1;
 1848 
 1849     ret = db_open_rw(1);
 1850     ck_assert_int_eq(ret, 1);
 1851     ret = db_addinterface("ethtest");
 1852     ck_assert_int_eq(ret, 1);
 1853 
 1854     for (i = 1; i <= 20; i++) {
 1855         ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0));
 1856         ck_assert_int_eq(ret, 1);
 1857     }
 1858 
 1859     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", "");
 1860     ck_assert_int_eq(ret, 1);
 1861     ck_assert_int_eq(datainfo.count, 1);
 1862     datalist_i = datalist;
 1863     i = 0;
 1864     while (datalist_i != NULL) {
 1865         switch (i) {
 1866             case 0:
 1867                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1868                 ck_assert_str_eq(timestamp, "2000-02-01");
 1869                 ck_assert_int_eq(datalist_i->rx, 20);
 1870                 ck_assert_int_eq(datalist_i->tx, 40);
 1871                 break;
 1872         }
 1873         datalist_i = datalist_i->next;
 1874         i++;
 1875     }
 1876     dbdatalistfree(&datalist);
 1877 
 1878     ret = db_close();
 1879     ck_assert_int_eq(ret, 1);
 1880 }
 1881 END_TEST
 1882 
 1883 START_TEST(db_addtraffic_with_monthrotate)
 1884 {
 1885     int ret, i;
 1886     char timestamp[64];
 1887     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1888     dbdatalistinfo datainfo;
 1889 
 1890     cfg.monthrotate = 7;
 1891 
 1892     ret = db_open_rw(1);
 1893     ck_assert_int_eq(ret, 1);
 1894     ret = db_addinterface("ethtest");
 1895     ck_assert_int_eq(ret, 1);
 1896 
 1897     for (i = 1; i <= 20; i++) {
 1898         ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0));
 1899         ck_assert_int_eq(ret, 1);
 1900     }
 1901 
 1902     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", "");
 1903     ck_assert_int_eq(ret, 1);
 1904     ck_assert_int_eq(datainfo.count, 2);
 1905     datalist_i = datalist;
 1906     i = 0;
 1907     while (datalist_i != NULL) {
 1908         switch (i) {
 1909             case 0:
 1910                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1911                 ck_assert_str_eq(timestamp, "2000-01-01");
 1912                 ck_assert_int_eq(datalist_i->rx, 6);
 1913                 ck_assert_int_eq(datalist_i->tx, 12);
 1914                 break;
 1915             case 1:
 1916                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1917                 ck_assert_str_eq(timestamp, "2000-02-01");
 1918                 ck_assert_int_eq(datalist_i->rx, 14);
 1919                 ck_assert_int_eq(datalist_i->tx, 28);
 1920                 break;
 1921         }
 1922         datalist_i = datalist_i->next;
 1923         i++;
 1924     }
 1925     dbdatalistfree(&datalist);
 1926 
 1927     ret = db_close();
 1928     ck_assert_int_eq(ret, 1);
 1929 }
 1930 END_TEST
 1931 
 1932 START_TEST(db_addtraffic_without_monthrotate_utc)
 1933 {
 1934     int ret, i;
 1935     char timestamp[64];
 1936     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1937     dbdatalistinfo datainfo;
 1938 
 1939     cfg.monthrotate = 1;
 1940     cfg.useutc = 1;
 1941     validatecfg(CT_Daemon);
 1942 
 1943     ret = db_open_rw(1);
 1944     ck_assert_int_eq(ret, 1);
 1945     ret = db_addinterface("ethtest");
 1946     ck_assert_int_eq(ret, 1);
 1947 
 1948     for (i = 1; i <= 20; i++) {
 1949         ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0));
 1950         ck_assert_int_eq(ret, 1);
 1951     }
 1952 
 1953     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", "");
 1954     ck_assert_int_eq(ret, 1);
 1955     ck_assert_int_eq(datainfo.count, 1);
 1956     datalist_i = datalist;
 1957     i = 0;
 1958     while (datalist_i != NULL) {
 1959         switch (i) {
 1960             case 0:
 1961                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 1962                 ck_assert_str_eq(timestamp, "2000-02-01");
 1963                 ck_assert_int_eq(datalist_i->rx, 20);
 1964                 ck_assert_int_eq(datalist_i->tx, 40);
 1965                 break;
 1966         }
 1967         datalist_i = datalist_i->next;
 1968         i++;
 1969     }
 1970     dbdatalistfree(&datalist);
 1971 
 1972     ret = db_close();
 1973     ck_assert_int_eq(ret, 1);
 1974 }
 1975 END_TEST
 1976 
 1977 START_TEST(db_addtraffic_with_monthrotate_utc)
 1978 {
 1979     int ret, i;
 1980     char timestamp[64];
 1981     dbdatalist *datalist = NULL, *datalist_i = NULL;
 1982     dbdatalistinfo datainfo;
 1983 
 1984     cfg.monthrotate = 7;
 1985     cfg.useutc = 1;
 1986     validatecfg(CT_Daemon);
 1987 
 1988     ret = db_open_rw(1);
 1989     ck_assert_int_eq(ret, 1);
 1990     ret = db_addinterface("ethtest");
 1991     ck_assert_int_eq(ret, 1);
 1992 
 1993     for (i = 1; i <= 20; i++) {
 1994         ret = db_addtraffic_dated("ethtest", 1, 2, get_timestamp(2000, 2, i, 0, 0));
 1995         ck_assert_int_eq(ret, 1);
 1996     }
 1997 
 1998     ret = db_getdata_range(&datalist, &datainfo, "ethtest", "month", 0, "", "");
 1999     ck_assert_int_eq(ret, 1);
 2000     ck_assert_int_eq(datainfo.count, 2);
 2001     datalist_i = datalist;
 2002     i = 0;
 2003     while (datalist_i != NULL) {
 2004         switch (i) {
 2005             case 0:
 2006                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 2007                 ck_assert_str_eq(timestamp, "2000-01-01");
 2008                 ck_assert_int_eq(datalist_i->rx, 6);
 2009                 ck_assert_int_eq(datalist_i->tx, 12);
 2010                 break;
 2011             case 1:
 2012                 strftime(timestamp, 64, "%Y-%m-%d", localtime(&datalist_i->timestamp));
 2013                 ck_assert_str_eq(timestamp, "2000-02-01");
 2014                 ck_assert_int_eq(datalist_i->rx, 14);
 2015                 ck_assert_int_eq(datalist_i->tx, 28);
 2016                 break;
 2017         }
 2018         datalist_i = datalist_i->next;
 2019         i++;
 2020     }
 2021     dbdatalistfree(&datalist);
 2022 
 2023     ret = db_close();
 2024     ck_assert_int_eq(ret, 1);
 2025 }
 2026 END_TEST
 2027 
 2028 START_TEST(db_get_date_generator_can_generate_dates)
 2029 {
 2030 
 2031     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL);
 2032     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
 2033     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo, 'localtime')"), NULL);
 2034     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo, 'localtime')"), NULL);
 2035     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL);
 2036     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL);
 2037 
 2038     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL);
 2039     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
 2040     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo, 'localtime')"), NULL);
 2041     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo, 'localtime')"), NULL);
 2042     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL);
 2043     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL);
 2044 }
 2045 END_TEST
 2046 
 2047 START_TEST(db_get_date_generator_can_generate_dates_with_monthrotate)
 2048 {
 2049 
 2050     cfg.monthrotate = 10;
 2051     cfg.monthrotateyears = 0;
 2052 
 2053     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL);
 2054     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
 2055     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo, 'localtime')"), NULL);
 2056     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo, 'localtime')"), NULL);
 2057     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', datetime(foo, '-9 days'), 'localtime')"), NULL);
 2058     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL);
 2059 
 2060     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL);
 2061     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
 2062     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo, 'localtime')"), NULL);
 2063     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo, 'localtime')"), NULL);
 2064     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL);
 2065     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL);
 2066 
 2067     cfg.monthrotate = 8;
 2068     cfg.monthrotateyears = 1;
 2069 
 2070     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL);
 2071     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
 2072     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo, 'localtime')"), NULL);
 2073     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo, 'localtime')"), NULL);
 2074     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', datetime(foo, '-7 days'), 'localtime')"), NULL);
 2075     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', datetime(foo, '-7 days'), 'localtime')"), NULL);
 2076 
 2077     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL);
 2078     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
 2079     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo, 'localtime')"), NULL);
 2080     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo, 'localtime')"), NULL);
 2081     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL);
 2082     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL);
 2083 }
 2084 END_TEST
 2085 
 2086 START_TEST(db_get_date_generator_can_generate_dates_utc)
 2087 {
 2088     cfg.useutc = 1;
 2089     validatecfg(CT_Daemon);
 2090 
 2091     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL);
 2092     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL);
 2093     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo)"), NULL);
 2094     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo)"), NULL);
 2095     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', foo)"), NULL);
 2096     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', foo)"), NULL);
 2097 
 2098     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL);
 2099     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL);
 2100     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo)"), NULL);
 2101     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo)"), NULL);
 2102     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo)"), NULL);
 2103     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo)"), NULL);
 2104 }
 2105 END_TEST
 2106 
 2107 START_TEST(db_get_date_generator_can_generate_dates_with_monthrotate_utc)
 2108 {
 2109     cfg.useutc = 1;
 2110     validatecfg(CT_Daemon);
 2111 
 2112     cfg.monthrotate = 10;
 2113     cfg.monthrotateyears = 0;
 2114 
 2115     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL);
 2116     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL);
 2117     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo)"), NULL);
 2118     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo)"), NULL);
 2119     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', datetime(foo, '-9 days'))"), NULL);
 2120     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', foo)"), NULL);
 2121 
 2122     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL);
 2123     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL);
 2124     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo)"), NULL);
 2125     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo)"), NULL);
 2126     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo)"), NULL);
 2127     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo)"), NULL);
 2128 
 2129     cfg.monthrotate = 8;
 2130     cfg.monthrotateyears = 1;
 2131 
 2132     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL);
 2133     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL);
 2134     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo)"), NULL);
 2135     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo)"), NULL);
 2136     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', datetime(foo, '-7 days'))"), NULL);
 2137     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', datetime(foo, '-7 days'))"), NULL);
 2138 
 2139     ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL);
 2140     ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo)"), NULL);
 2141     ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo)"), NULL);
 2142     ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo)"), NULL);
 2143     ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo)"), NULL);
 2144     ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo)"), NULL);
 2145 }
 2146 END_TEST
 2147 
 2148 START_TEST(getifaceinquery_does_not_mess_regular_interfaces)
 2149 {
 2150     char *result;
 2151 
 2152     result = getifaceinquery("eth0");
 2153     ck_assert_ptr_ne(result, NULL);
 2154     ck_assert_str_eq(result, "\"eth0\"");
 2155     free(result);
 2156 
 2157     /* this isn't a realistic scenario but doesn't hurt to have a test */
 2158     result = getifaceinquery("eth0 with space");
 2159     ck_assert_ptr_ne(result, NULL);
 2160     ck_assert_str_eq(result, "\"eth0 with space\"");
 2161     free(result);
 2162 
 2163     result = getifaceinquery("em1_em2");
 2164     ck_assert_ptr_ne(result, NULL);
 2165     ck_assert_str_eq(result, "\"em1_em2\"");
 2166     free(result);
 2167 
 2168     result = getifaceinquery("em1-em2");
 2169     ck_assert_ptr_ne(result, NULL);
 2170     ck_assert_str_eq(result, "\"em1-em2\"");
 2171     free(result);
 2172 }
 2173 END_TEST
 2174 
 2175 START_TEST(getifaceinquery_can_create_merge_queries)
 2176 {
 2177     char *result;
 2178 
 2179     result = getifaceinquery("eth0+eth1");
 2180     ck_assert_ptr_ne(result, NULL);
 2181     ck_assert_str_eq(result, "\"eth0\",\"eth1\"");
 2182     free(result);
 2183 
 2184     result = getifaceinquery("eth1+eth0");
 2185     ck_assert_ptr_ne(result, NULL);
 2186     ck_assert_str_eq(result, "\"eth1\",\"eth0\"");
 2187     free(result);
 2188 
 2189     result = getifaceinquery("eth0+em1+eth1");
 2190     ck_assert_ptr_ne(result, NULL);
 2191     ck_assert_str_eq(result, "\"eth0\",\"em1\",\"eth1\"");
 2192     free(result);
 2193 }
 2194 END_TEST
 2195 
 2196 START_TEST(getifaceinquery_does_not_tolerate_nonsense)
 2197 {
 2198     char *result;
 2199 
 2200     result = getifaceinquery("");
 2201     ck_assert_ptr_eq(result, NULL);
 2202 
 2203     result = getifaceinquery("+eth0");
 2204     ck_assert_ptr_eq(result, NULL);
 2205 
 2206     result = getifaceinquery("eth0+");
 2207     ck_assert_ptr_eq(result, NULL);
 2208 
 2209     result = getifaceinquery("+eth0+");
 2210     ck_assert_ptr_eq(result, NULL);
 2211 
 2212     result = getifaceinquery("eth0++eth1");
 2213     ck_assert_ptr_eq(result, NULL);
 2214 
 2215     result = getifaceinquery("eth0+++eth1");
 2216     ck_assert_ptr_eq(result, NULL);
 2217 
 2218     result = getifaceinquery("eth0+eth1++eth2");
 2219     ck_assert_ptr_eq(result, NULL);
 2220 
 2221     result = getifaceinquery("+++ATH0");
 2222     ck_assert_ptr_eq(result, NULL);
 2223 }
 2224 END_TEST
 2225 
 2226 START_TEST(db_getinterfaceid_can_get_ids)
 2227 {
 2228     int ret;
 2229 
 2230 
 2231     ret = db_open_rw(1);
 2232     ck_assert_int_eq(ret, 1);
 2233 
 2234     ret = db_addinterface("eth0");
 2235     ck_assert_int_eq(ret, 1);
 2236 
 2237     ret = db_addinterface("eth1");
 2238     ck_assert_int_eq(ret, 1);
 2239 
 2240     ret = db_addinterface("eth3");
 2241     ck_assert_int_eq(ret, 1);
 2242 
 2243     ret = (int)db_getinterfacecount();
 2244     ck_assert_int_eq(ret, 3);
 2245 
 2246     ret = (int)db_getinterfaceid("eth0", 0);
 2247     ck_assert_int_eq(ret, 1);
 2248 
 2249     ret = (int)db_getinterfaceid("eth0", 1);
 2250     ck_assert_int_eq(ret, 1);
 2251 
 2252     ret = (int)db_getinterfaceid("eth1", 0);
 2253     ck_assert_int_eq(ret, 2);
 2254 
 2255     ret = (int)db_getinterfaceid("eth2", 0);
 2256     ck_assert_int_eq(ret, 0);
 2257 
 2258     ret = (int)db_getinterfaceid("eth3", 0);
 2259     ck_assert_int_eq(ret, 3);
 2260 
 2261     ret = (int)db_getinterfaceid("eth2", 1);
 2262     ck_assert_int_eq(ret, 4);
 2263 
 2264     ret = (int)db_getinterfaceid("eth2", 0);
 2265     ck_assert_int_eq(ret, 4);
 2266 
 2267     ret = (int)db_getinterfacecount();
 2268     ck_assert_int_eq(ret, 4);
 2269 
 2270     ret = db_close();
 2271     ck_assert_int_eq(ret, 1);
 2272 }
 2273 END_TEST
 2274 
 2275 START_TEST(db_getinterfaceidin_can_get_in_groups)
 2276 {
 2277     int ret;
 2278     char *result;
 2279 
 2280 
 2281     ret = db_open_rw(1);
 2282     ck_assert_int_eq(ret, 1);
 2283 
 2284     ret = db_addinterface("eth0");
 2285     ck_assert_int_eq(ret, 1);
 2286 
 2287     ret = db_addinterface("eth1");
 2288     ck_assert_int_eq(ret, 1);
 2289 
 2290     ret = db_addinterface("eth3");
 2291     ck_assert_int_eq(ret, 1);
 2292 
 2293     result = db_getinterfaceidin("eth0");
 2294     ck_assert_str_eq(result, "1");
 2295     free(result);
 2296 
 2297     result = db_getinterfaceidin("eth0+eth1");
 2298     ck_assert_str_eq(result, "1,2");
 2299     free(result);
 2300 
 2301     result = db_getinterfaceidin("eth0+eth3");
 2302     ck_assert_str_eq(result, "1,3");
 2303     free(result);
 2304 
 2305     result = db_getinterfaceidin("eth0+eth3+eth1");
 2306     ck_assert_str_eq(result, "1,2,3");
 2307     free(result);
 2308 
 2309     result = db_getinterfaceidin("eth0+eth3+eth1+eth4");
 2310     ck_assert_str_eq(result, "1,2,3");
 2311     free(result);
 2312 
 2313     ret = db_close();
 2314     ck_assert_int_eq(ret, 1);
 2315 }
 2316 END_TEST
 2317 
 2318 START_TEST(db_getinterfaceidin_can_handle_error_situations)
 2319 {
 2320     int ret;
 2321     char *result;
 2322 
 2323 
 2324     ret = db_open_rw(1);
 2325     ck_assert_int_eq(ret, 1);
 2326 
 2327     ret = db_addinterface("eth0");
 2328     ck_assert_int_eq(ret, 1);
 2329 
 2330     result = db_getinterfaceidin("+eth0");
 2331     ck_assert_ptr_eq(result, NULL);
 2332 
 2333     result = db_getinterfaceidin("eth4");
 2334     ck_assert_ptr_eq(result, NULL);
 2335 
 2336     ret = db_close();
 2337     ck_assert_int_eq(ret, 1);
 2338 }
 2339 END_TEST
 2340 
 2341 START_TEST(db_getinterfaceinfo_can_handle_interface_merges)
 2342 {
 2343     int ret;
 2344     interfaceinfo info;
 2345 
 2346 
 2347     ret = db_open_rw(1);
 2348     ck_assert_int_eq(ret, 1);
 2349 
 2350     ret = db_addtraffic("eth0", 1, 1);
 2351     ck_assert_int_eq(ret, 1);
 2352 
 2353     ret = db_addtraffic("eth1", 2, 2);
 2354     ck_assert_int_eq(ret, 1);
 2355 
 2356     ret = db_addtraffic("eth2", 5, 5);
 2357     ck_assert_int_eq(ret, 1);
 2358 
 2359     ret = db_getinterfaceinfo("eth0+ethnone", &info);
 2360     ck_assert_int_eq(ret, 1);
 2361     ck_assert_int_eq(info.rxtotal, 1);
 2362     ck_assert_int_eq(info.txtotal, 1);
 2363     ck_assert_int_gt(info.updated, 1000);
 2364     ck_assert_int_lt(info.updated, 2100000000);
 2365 
 2366     ret = db_getinterfaceinfo("eth0+eth1", &info);
 2367     ck_assert_int_eq(ret, 1);
 2368     ck_assert_int_eq(info.rxtotal, 3);
 2369     ck_assert_int_eq(info.txtotal, 3);
 2370     ck_assert_int_gt(info.updated, 1000);
 2371     ck_assert_int_lt(info.updated, 2100000000);
 2372 
 2373     ret = db_getinterfaceinfo("eth1+eth2", &info);
 2374     ck_assert_int_eq(ret, 1);
 2375     ck_assert_int_eq(info.rxtotal, 7);
 2376     ck_assert_int_eq(info.txtotal, 7);
 2377     ck_assert_int_gt(info.updated, 1000);
 2378     ck_assert_int_lt(info.updated, 2100000000);
 2379 
 2380     ret = db_getinterfaceinfo("eth0+eth1+eth2", &info);
 2381     ck_assert_int_eq(ret, 1);
 2382     ck_assert_int_eq(info.rxtotal, 8);
 2383     ck_assert_int_eq(info.txtotal, 8);
 2384     ck_assert_int_gt(info.updated, 1000);
 2385     ck_assert_int_lt(info.updated, 2100000000);
 2386 
 2387     ret = db_close();
 2388     ck_assert_int_eq(ret, 1);
 2389 }
 2390 END_TEST
 2391 
 2392 START_TEST(db_getinterfaceinfo_can_handle_invalid_input)
 2393 {
 2394     int ret;
 2395     interfaceinfo info;
 2396 
 2397 
 2398     ret = db_open_rw(1);
 2399     ck_assert_int_eq(ret, 1);
 2400 
 2401     ret = db_addtraffic("eth0", 1, 1);
 2402     ck_assert_int_eq(ret, 1);
 2403 
 2404     ret = db_addtraffic("eth1", 2, 2);
 2405     ck_assert_int_eq(ret, 1);
 2406 
 2407     ret = db_addtraffic("eth2", 5, 5);
 2408     ck_assert_int_eq(ret, 1);
 2409 
 2410     ret = db_getinterfaceinfo("eth0+", &info);
 2411     ck_assert_int_eq(ret, 0);
 2412 
 2413     ret = db_getinterfaceinfo("+", &info);
 2414     ck_assert_int_eq(ret, 0);
 2415 
 2416     ret = db_getinterfaceinfo("++", &info);
 2417     ck_assert_int_eq(ret, 0);
 2418 
 2419     ret = db_getinterfaceinfo("", &info);
 2420     ck_assert_int_eq(ret, 0);
 2421 
 2422     ret = db_getinterfaceinfo("ethunknown", &info);
 2423     ck_assert_int_eq(ret, 0);
 2424 
 2425     ret = db_close();
 2426     ck_assert_int_eq(ret, 1);
 2427 }
 2428 END_TEST
 2429 
 2430 START_TEST(getqueryinterfacecount_can_count)
 2431 {
 2432     ck_assert_int_eq(getqueryinterfacecount("eth0"), 1);
 2433     ck_assert_int_eq(getqueryinterfacecount("eth1"), 1);
 2434     ck_assert_int_eq(getqueryinterfacecount("eth1+eth2"), 2);
 2435     ck_assert_int_eq(getqueryinterfacecount("eth1+eth2+eth3"), 3);
 2436     ck_assert_int_eq(getqueryinterfacecount("eth1+eth2+eth3+eth1"), 4);
 2437     ck_assert_int_eq(getqueryinterfacecount("eth0+eth0"), 2);
 2438     ck_assert_int_eq(getqueryinterfacecount("eth0++eth1"), 0);
 2439     ck_assert_int_eq(getqueryinterfacecount(""), 0);
 2440     ck_assert_int_eq(getqueryinterfacecount("1"), 1);
 2441     ck_assert_int_eq(getqueryinterfacecount("+"), 0);
 2442     ck_assert_int_eq(getqueryinterfacecount("++"), 0);
 2443     ck_assert_int_eq(getqueryinterfacecount("+ +"), 0);
 2444     ck_assert_int_eq(getqueryinterfacecount("+ethsomething"), 0);
 2445     ck_assert_int_eq(getqueryinterfacecount("ethnothing+"), 0);
 2446     ck_assert_int_eq(getqueryinterfacecount("eth+nothing"), 2);
 2447     ck_assert_int_eq(getqueryinterfacecount("ethlongcanbelong+ethnotsoshort+ethdoesnotcare"), 3);
 2448 }
 2449 END_TEST
 2450 
 2451 START_TEST(top_list_returns_items_in_correct_order)
 2452 {
 2453     int ret;
 2454     dbdatalist *datalist = NULL, *datalist_iterator = NULL;
 2455     dbdatalistinfo datainfo;
 2456     uint64_t previous_entry;
 2457 
 2458     ret = db_open_rw(1);
 2459     ck_assert_int_eq(ret, 1);
 2460     ret = db_addinterface("ethtest");
 2461     ck_assert_int_eq(ret, 1);
 2462 
 2463     ret = db_addtraffic_dated("ethtest", 0, 0, get_timestamp(2000, 3, 10, 0, 0));
 2464     ck_assert_int_eq(ret, 1);
 2465 
 2466     ret = db_addtraffic_dated("ethtest", 12, 34, get_timestamp(2000, 3, 11, 0, 0));
 2467     ck_assert_int_eq(ret, 1);
 2468 
 2469     ret = db_addtraffic_dated("ethtest", 0, 0, get_timestamp(2000, 3, 12, 0, 0));
 2470     ck_assert_int_eq(ret, 1);
 2471 
 2472     ret = db_addtraffic_dated("ethtest", 0, 0, get_timestamp(2000, 3, 13, 0, 0));
 2473     ck_assert_int_eq(ret, 1);
 2474 
 2475     ret = db_addtraffic_dated("ethtest", 56, 78, get_timestamp(2000, 3, 14, 0, 0));
 2476     ck_assert_int_eq(ret, 1);
 2477 
 2478     ret = db_addtraffic_dated("ethtest", 1, 1, get_timestamp(2000, 3, 15, 0, 0));
 2479     ck_assert_int_eq(ret, 1);
 2480 
 2481     ret = db_addtraffic_dated("ethtest", 1, 1, get_timestamp(2000, 3, 16, 0, 0));
 2482     ck_assert_int_eq(ret, 1);
 2483 
 2484     ret = db_addtraffic_dated("ethtest", 45, 1, get_timestamp(2000, 3, 17, 0, 0));
 2485     ck_assert_int_eq(ret, 1);
 2486 
 2487     ret = db_getdata(&datalist, &datainfo, "ethtest", "top", 10);
 2488     ck_assert_int_eq(ret, 1);
 2489 
 2490     ck_assert_int_eq(datainfo.count, 8);
 2491     ck_assert_int_eq(datainfo.maxrx, 56);
 2492     ck_assert_int_eq(datainfo.maxtx, 78);
 2493     ck_assert_int_eq(datainfo.minrx, 0);
 2494     ck_assert_int_eq(datainfo.mintx, 0);
 2495 
 2496     datalist_iterator = datalist;
 2497 
 2498     ck_assert_int_eq(datalist_iterator->rx, 56);
 2499     ck_assert_int_eq(datalist_iterator->tx, 78);
 2500 
 2501     datalist_iterator = datalist_iterator->next;
 2502 
 2503     ck_assert_int_eq(datalist_iterator->rx, 12);
 2504     ck_assert_int_eq(datalist_iterator->tx, 34);
 2505 
 2506     datalist_iterator = datalist_iterator->next;
 2507 
 2508     ck_assert_int_eq(datalist_iterator->rx, 45);
 2509     ck_assert_int_eq(datalist_iterator->tx, 1);
 2510 
 2511     datalist_iterator = datalist_iterator->next;
 2512 
 2513     ck_assert_int_eq(datalist_iterator->rx, 1);
 2514     ck_assert_int_eq(datalist_iterator->tx, 1);
 2515     previous_entry = (uint64_t)datalist_iterator->timestamp;
 2516 
 2517     datalist_iterator = datalist_iterator->next;
 2518 
 2519     ck_assert_int_eq(datalist_iterator->rx, 1);
 2520     ck_assert_int_eq(datalist_iterator->tx, 1);
 2521     ck_assert_int_lt(previous_entry, (uint64_t)datalist_iterator->timestamp);
 2522 
 2523     datalist_iterator = datalist_iterator->next;
 2524 
 2525     ck_assert_int_eq(datalist_iterator->rx, 0);
 2526     ck_assert_int_eq(datalist_iterator->tx, 0);
 2527     previous_entry = (uint64_t)datalist_iterator->timestamp;
 2528 
 2529     datalist_iterator = datalist_iterator->next;
 2530 
 2531     ck_assert_int_eq(datalist_iterator->rx, 0);
 2532     ck_assert_int_eq(datalist_iterator->tx, 0);
 2533     ck_assert_int_lt(previous_entry, (uint64_t)datalist_iterator->timestamp);
 2534     previous_entry = (uint64_t)datalist_iterator->timestamp;
 2535 
 2536     datalist_iterator = datalist_iterator->next;
 2537 
 2538     ck_assert_int_eq(datalist_iterator->rx, 0);
 2539     ck_assert_int_eq(datalist_iterator->tx, 0);
 2540     ck_assert_int_lt(previous_entry, (uint64_t)datalist_iterator->timestamp);
 2541 
 2542     dbdatalistfree(&datalist);
 2543 
 2544     ret = db_close();
 2545     ck_assert_int_eq(ret, 1);
 2546 }
 2547 END_TEST
 2548 
 2549 START_TEST(db_setinterfacebyalias_sets_nothing_when_there_is_no_match)
 2550 {
 2551     int ret;
 2552     char interface[32];
 2553 
 2554     interface[0] = '\0';
 2555     ck_assert_int_eq(strlen(interface), 0);
 2556 
 2557     ret = db_open_rw(1);
 2558     ck_assert_int_eq(ret, 1);
 2559 
 2560     ret = db_addinterface("eth0");
 2561     ck_assert_int_eq(ret, 1);
 2562 
 2563     ret = db_addinterface("eth1");
 2564     ck_assert_int_eq(ret, 1);
 2565 
 2566     ret = db_setinterfacebyalias(interface, "internet", 1);
 2567     ck_assert_int_eq(ret, 0);
 2568     ck_assert_int_eq(strlen(interface), 0);
 2569 
 2570     ret = db_close();
 2571     ck_assert_int_eq(ret, 1);
 2572 }
 2573 END_TEST
 2574 
 2575 START_TEST(db_setinterfacebyalias_can_set)
 2576 {
 2577     int ret;
 2578     char interface[32];
 2579 
 2580     interface[0] = '\0';
 2581     ck_assert_int_eq(strlen(interface), 0);
 2582 
 2583     ret = db_open_rw(1);
 2584     ck_assert_int_eq(ret, 1);
 2585 
 2586     ret = db_addinterface("eth0");
 2587     ck_assert_int_eq(ret, 1);
 2588 
 2589     ret = db_setalias("eth0", "lan");
 2590     ck_assert_int_eq(ret, 1);
 2591 
 2592     ret = db_addinterface("eth1");
 2593     ck_assert_int_eq(ret, 1);
 2594 
 2595     ret = db_setalias("eth1", "internet");
 2596     ck_assert_int_eq(ret, 1);
 2597 
 2598     ret = db_addinterface("eth2");
 2599     ck_assert_int_eq(ret, 1);
 2600 
 2601     ret = db_setinterfacebyalias(interface, "internet", 1);
 2602     ck_assert_int_eq(ret, 1);
 2603     ck_assert_int_eq(strlen(interface), 4);
 2604     ck_assert_str_eq(interface, "eth1");
 2605 
 2606     ret = db_setinterfacebyalias(interface, "lan", 1);
 2607     ck_assert_int_eq(ret, 1);
 2608     ck_assert_int_eq(strlen(interface), 4);
 2609     ck_assert_str_eq(interface, "eth0");
 2610 
 2611     ret = db_close();
 2612     ck_assert_int_eq(ret, 1);
 2613 }
 2614 END_TEST
 2615 
 2616 START_TEST(db_setinterfacebyalias_sets_highest_traffic_interface_if_alias_is_not_unique)
 2617 {
 2618     int ret;
 2619     char interface[32];
 2620 
 2621     interface[0] = '\0';
 2622     ck_assert_int_eq(strlen(interface), 0);
 2623 
 2624     ret = db_open_rw(1);
 2625     ck_assert_int_eq(ret, 1);
 2626 
 2627     ret = db_addinterface("eth0");
 2628     ck_assert_int_eq(ret, 1);
 2629 
 2630     ret = db_setalias("eth0", "notnet");
 2631     ck_assert_int_eq(ret, 1);
 2632 
 2633     ret = db_settotal("eth0", 2, 2);
 2634     ck_assert_int_eq(ret, 1);
 2635 
 2636     ret = db_addinterface("eth12");
 2637     ck_assert_int_eq(ret, 1);
 2638 
 2639     ret = db_setalias("eth12", "notnet");
 2640     ck_assert_int_eq(ret, 1);
 2641 
 2642     ret = db_settotal("eth12", 2, 3);
 2643     ck_assert_int_eq(ret, 1);
 2644 
 2645     ret = db_setinterfacebyalias(interface, "notnet", 1);
 2646     ck_assert_int_eq(ret, 1);
 2647     ck_assert_int_eq(strlen(interface), 5);
 2648     ck_assert_str_eq(interface, "eth12");
 2649 
 2650     ret = db_close();
 2651     ck_assert_int_eq(ret, 1);
 2652 }
 2653 END_TEST
 2654 
 2655 START_TEST(db_setinterfacebyalias_can_be_case_insensitive)
 2656 {
 2657     int ret;
 2658     char interface[32];
 2659 
 2660     interface[0] = '\0';
 2661     ck_assert_int_eq(strlen(interface), 0);
 2662 
 2663     ret = db_open_rw(1);
 2664     ck_assert_int_eq(ret, 1);
 2665 
 2666     ret = db_addinterface("eth0");
 2667     ck_assert_int_eq(ret, 1);
 2668 
 2669     ret = db_setalias("eth0", "LAN");
 2670     ck_assert_int_eq(ret, 1);
 2671 
 2672     ret = db_addinterface("eth1");
 2673     ck_assert_int_eq(ret, 1);
 2674 
 2675     ret = db_setalias("eth1", "Internet");
 2676     ck_assert_int_eq(ret, 1);
 2677 
 2678     ret = db_addinterface("eth2");
 2679     ck_assert_int_eq(ret, 1);
 2680 
 2681     ret = db_setinterfacebyalias(interface, "internet", 1);
 2682     ck_assert_int_eq(ret, 0);
 2683 
 2684     ret = db_setinterfacebyalias(interface, "lan", 1);
 2685     ck_assert_int_eq(ret, 0);
 2686 
 2687     ret = db_setinterfacebyalias(interface, "internet", 2);
 2688     ck_assert_int_eq(ret, 1);
 2689     ck_assert_int_eq(strlen(interface), 4);
 2690     ck_assert_str_eq(interface, "eth1");
 2691 
 2692     ret = db_setinterfacebyalias(interface, "lan", 2);
 2693     ck_assert_int_eq(ret, 1);
 2694     ck_assert_int_eq(strlen(interface), 4);
 2695     ck_assert_str_eq(interface, "eth0");
 2696 
 2697     ret = db_close();
 2698     ck_assert_int_eq(ret, 1);
 2699 }
 2700 END_TEST
 2701 
 2702 START_TEST(db_setinterfacebyalias_can_match_prefix)
 2703 {
 2704     int ret;
 2705     char interface[32];
 2706 
 2707     interface[0] = '\0';
 2708     ck_assert_int_eq(strlen(interface), 0);
 2709 
 2710     ret = db_open_rw(1);
 2711     ck_assert_int_eq(ret, 1);
 2712 
 2713     ret = db_addinterface("eth0");
 2714     ck_assert_int_eq(ret, 1);
 2715 
 2716     ret = db_setalias("eth0", "LAN");
 2717     ck_assert_int_eq(ret, 1);
 2718 
 2719     ret = db_addinterface("eth1");
 2720     ck_assert_int_eq(ret, 1);
 2721 
 2722     ret = db_setalias("eth1", "Internet");
 2723     ck_assert_int_eq(ret, 1);
 2724 
 2725     ret = db_addinterface("eth2");
 2726     ck_assert_int_eq(ret, 1);
 2727 
 2728     ret = db_setinterfacebyalias(interface, "in", 1);
 2729     ck_assert_int_eq(ret, 0);
 2730 
 2731     ret = db_setinterfacebyalias(interface, "la", 1);
 2732     ck_assert_int_eq(ret, 0);
 2733 
 2734     ret = db_setinterfacebyalias(interface, "in", 2);
 2735     ck_assert_int_eq(ret, 0);
 2736 
 2737     ret = db_setinterfacebyalias(interface, "la", 2);
 2738     ck_assert_int_eq(ret, 0);
 2739 
 2740     ret = db_setinterfacebyalias(interface, "in", 3);
 2741     ck_assert_int_eq(ret, 1);
 2742     ck_assert_int_eq(strlen(interface), 4);
 2743     ck_assert_str_eq(interface, "eth1");
 2744 
 2745     ret = db_setinterfacebyalias(interface, "la", 3);
 2746     ck_assert_int_eq(ret, 1);
 2747     ck_assert_int_eq(strlen(interface), 4);
 2748     ck_assert_str_eq(interface, "eth0");
 2749 
 2750     ret = db_close();
 2751     ck_assert_int_eq(ret, 1);
 2752 }
 2753 END_TEST
 2754 
 2755 void add_dbsql_tests(Suite *s)
 2756 {
 2757     TCase *tc_dbsql = tcase_create("DB SQL");
 2758     tcase_add_checked_fixture(tc_dbsql, setup, teardown);
 2759     tcase_add_unchecked_fixture(tc_dbsql, setup, teardown);
 2760     tcase_add_test(tc_dbsql, db_close_does_no_harm_when_db_is_already_closed);
 2761     tcase_add_test(tc_dbsql, db_open_rw_can_create_database_if_file_does_not_exist);
 2762     tcase_add_test(tc_dbsql, db_open_ro_cannot_create_a_database);
 2763     tcase_add_test(tc_dbsql, db_getinfo_fails_with_no_open_db);
 2764     tcase_add_test(tc_dbsql, db_getinfo_fails_with_nonexisting_name);
 2765     tcase_add_test(tc_dbsql, db_getinfo_can_get_dbversion);
 2766     tcase_add_test(tc_dbsql, db_setinfo_fails_with_no_open_db);
 2767     tcase_add_test(tc_dbsql, db_setinfo_can_set_infos);
 2768     tcase_add_test(tc_dbsql, db_setinfo_can_update_infos);
 2769     tcase_add_test(tc_dbsql, db_setinfo_can_not_update_nonexisting_name);
 2770     tcase_add_test(tc_dbsql, db_addtraffic_with_no_traffic_does_nothing);
 2771     tcase_add_test(tc_dbsql, db_addtraffic_can_add_traffic_and_interfaces);
 2772     tcase_add_test(tc_dbsql, db_addtraffic_can_add_traffic_and_interfaces_utc);
 2773     tcase_add_test(tc_dbsql, db_addtraffic_dated_does_not_touch_updated_time);
 2774     tcase_add_test(tc_dbsql, db_getinterfacecount_counts_interfaces);
 2775     tcase_add_test(tc_dbsql, db_getinterfacecountbyname_counts_interfaces);
 2776     tcase_add_test(tc_dbsql, db_setactive_fails_with_no_open_db);
 2777     tcase_add_test(tc_dbsql, db_setactive_fails_if_interface_does_not_exist_in_database);
 2778     tcase_add_test(tc_dbsql, db_setactive_can_change_interface_activity_status);
 2779     tcase_add_test(tc_dbsql, db_setalias_fails_with_no_open_db);
 2780     tcase_add_test(tc_dbsql, db_setalias_fails_if_interface_does_not_exist_in_database);
 2781     tcase_add_test(tc_dbsql, db_setalias_can_change_interface_alias);
 2782     tcase_add_test(tc_dbsql, db_setupdated_fails_with_no_open_db);
 2783     tcase_add_test(tc_dbsql, db_setupdated_fails_if_interface_does_not_exist_in_database);
 2784     tcase_add_test(tc_dbsql, db_setupdated_can_change_updated);
 2785     tcase_add_test(tc_dbsql, db_addinterface_fails_with_no_open_db);
 2786     tcase_add_test(tc_dbsql, db_addinterface_can_add_interfaces);
 2787     tcase_add_test(tc_dbsql, db_addinterface_can_not_add_same_interface_twice);
 2788     tcase_add_test(tc_dbsql, db_removeinterface_knows_if_interface_exists);
 2789     tcase_add_test(tc_dbsql, db_removeinterface_can_remove_interfaces);
 2790     tcase_add_test(tc_dbsql, db_renameinterface_knows_if_interface_exists);
 2791     tcase_add_test(tc_dbsql, db_renameinterface_can_rename_interfaces);
 2792     tcase_add_test(tc_dbsql, db_getcounters_with_no_interface);
 2793     tcase_add_test(tc_dbsql, db_setcounters_with_no_interface);
 2794     tcase_add_test(tc_dbsql, db_interface_info_manipulation);
 2795     tcase_add_test(tc_dbsql, db_getiflist_lists_interfaces);
 2796     tcase_add_test(tc_dbsql, db_maintenance_does_not_fault);
 2797     tcase_add_test(tc_dbsql, db_data_can_be_inserted);
 2798     tcase_add_test(tc_dbsql, db_data_can_be_retrieved);
 2799     tcase_add_test(tc_dbsql, db_data_can_be_inserted_utc);
 2800     tcase_add_test(tc_dbsql, db_data_can_be_retrieved_utc);
 2801     tcase_add_test(tc_dbsql, db_fatal_errors_get_detected);
 2802     tcase_add_test(tc_dbsql, db_validate_with_valid_version);
 2803     tcase_add_test(tc_dbsql, db_validate_with_no_version);
 2804     tcase_add_test(tc_dbsql, db_validate_with_low_version);
 2805     tcase_add_test(tc_dbsql, db_validate_with_high_version);
 2806     tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_without_range_defined);
 2807     tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_matching_existing_data);
 2808     tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_past_existing_data);
 2809     tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_limiting_begin_and_end);
 2810     tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_limiting_begin);
 2811     tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_limiting_begin_with_limit);
 2812     tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_limiting_end);
 2813     tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_limiting_end_with_limit);
 2814     tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_on_same_month);
 2815     tcase_add_test(tc_dbsql, db_getdata_range_can_get_months_with_range_past_first_day_of_month);
 2816     tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_without_range_defined);
 2817     tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_matching_existing_data);
 2818     tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_past_existing_data);
 2819     tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_limiting_begin_and_end);
 2820     tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_limiting_begin);
 2821     tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_limiting_begin_with_limit);
 2822     tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_limiting_end);
 2823     tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_limiting_end_with_limit);
 2824     tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_on_same_hour);
 2825     tcase_add_test(tc_dbsql, db_getdata_range_with_merged_interfaces);
 2826     tcase_add_test(tc_dbsql, db_addtraffic_without_monthrotate);
 2827     tcase_add_test(tc_dbsql, db_addtraffic_with_monthrotate);
 2828     tcase_add_test(tc_dbsql, db_addtraffic_without_monthrotate_utc);
 2829     tcase_add_test(tc_dbsql, db_addtraffic_with_monthrotate_utc);
 2830     tcase_add_test(tc_dbsql, db_get_date_generator_can_generate_dates);
 2831     tcase_add_test(tc_dbsql, db_get_date_generator_can_generate_dates_with_monthrotate);
 2832     tcase_add_test(tc_dbsql, db_get_date_generator_can_generate_dates_utc);
 2833     tcase_add_test(tc_dbsql, db_get_date_generator_can_generate_dates_with_monthrotate_utc);
 2834     tcase_add_test(tc_dbsql, getifaceinquery_does_not_mess_regular_interfaces);
 2835     tcase_add_test(tc_dbsql, getifaceinquery_can_create_merge_queries);
 2836     tcase_add_test(tc_dbsql, getifaceinquery_does_not_tolerate_nonsense);
 2837     tcase_add_test(tc_dbsql, db_getinterfaceid_can_get_ids);
 2838     tcase_add_test(tc_dbsql, db_getinterfaceidin_can_get_in_groups);
 2839     tcase_add_test(tc_dbsql, db_getinterfaceidin_can_handle_error_situations);
 2840     tcase_add_test(tc_dbsql, db_getinterfaceinfo_can_handle_interface_merges);
 2841     tcase_add_test(tc_dbsql, db_getinterfaceinfo_can_handle_invalid_input);
 2842     tcase_add_test(tc_dbsql, getqueryinterfacecount_can_count);
 2843     tcase_add_test(tc_dbsql, top_list_returns_items_in_correct_order);
 2844     tcase_add_test(tc_dbsql, db_setinterfacebyalias_sets_nothing_when_there_is_no_match);
 2845     tcase_add_test(tc_dbsql, db_setinterfacebyalias_can_set);
 2846     tcase_add_test(tc_dbsql, db_setinterfacebyalias_sets_highest_traffic_interface_if_alias_is_not_unique);
 2847     tcase_add_test(tc_dbsql, db_setinterfacebyalias_can_be_case_insensitive);
 2848     tcase_add_test(tc_dbsql, db_setinterfacebyalias_can_match_prefix);
 2849     suite_add_tcase(s, tc_dbsql);
 2850 }