Changeset 8bce750 for filter.c


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

Legend:

Unmodified
Added
Removed
  • filter.c

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