int main(int argc, char **argv){ FAIL_UNLESS(testConstructor); FAIL_UNLESS(testInAvail); FAIL_UNLESS(testNulChar); FAIL_UNLESS(testPut); FAIL_UNLESS(testStringStream); return kPassed; }
static int test_cuted_rows(MYSQL *mysql) { int rc, count; MYSQL_RES *result; mysql_query(mysql, "DROP TABLE if exists t1"); mysql_query(mysql, "DROP TABLE if exists t2"); rc= mysql_query(mysql, "CREATE TABLE t1(c1 tinyint)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE TABLE t2(c1 int not null)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "INSERT INTO t1 values(10), (NULL), (NULL)"); check_mysql_rc(rc, mysql); count= mysql_warning_count(mysql); FAIL_UNLESS(count == 0, "warnings != 0"); rc= mysql_query(mysql, "INSERT INTO t2 SELECT * FROM t1"); check_mysql_rc(rc, mysql); count= mysql_warning_count(mysql); FAIL_UNLESS(count == 2, "warnings != 2"); rc= mysql_query(mysql, "SHOW WARNINGS"); check_mysql_rc(rc, mysql); result= mysql_store_result(mysql); FAIL_IF(!result, "Invalid result set"); rc= 0; while (mysql_fetch_row(result)) rc++; FAIL_UNLESS(rc == 2, "rowcount != 2"); mysql_free_result(result); rc= mysql_query(mysql, "INSERT INTO t1 VALUES('junk'), (876789)"); check_mysql_rc(rc, mysql); count= mysql_warning_count(mysql); FAIL_UNLESS(count == 2, "warnings != 2"); rc= mysql_query(mysql, "SHOW WARNINGS"); check_mysql_rc(rc, mysql); result= mysql_store_result(mysql); FAIL_IF(!result, "Invalid result set"); rc= 0; while (mysql_fetch_row(result)) rc++; FAIL_UNLESS(rc == 2, "rowcount != 2"); mysql_free_result(result); return OK; }
static int test_opt_reconnect(MYSQL *mysql) { my_bool my_true= TRUE; int rc; my_bool reconnect; printf("true: %d\n", TRUE); mysql= mysql_init(NULL); FAIL_IF(!mysql, "not enough memory"); mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect); FAIL_UNLESS(reconnect == 0, "reconnect != 0"); rc= mysql_options(mysql, MYSQL_OPT_RECONNECT, &my_true); check_mysql_rc(rc, mysql); mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect); FAIL_UNLESS(reconnect == 1, "reconnect != 1"); if (!(mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0))) { diag("connection failed"); mysql_close(mysql); return FAIL; } mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect); FAIL_UNLESS(reconnect == 1, "reconnect != 1"); mysql_close(mysql); mysql= mysql_init(NULL); FAIL_IF(!mysql, "not enough memory"); mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect); FAIL_UNLESS(reconnect == 0, "reconnect != 0"); if (!(mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0))) { diag("connection failed"); mysql_close(mysql); return FAIL; } mysql_get_option(mysql, MYSQL_OPT_RECONNECT, &reconnect); FAIL_UNLESS(reconnect == 0, "reconnect != 0"); mysql_close(mysql); return OK; }
static int test_compress(MYSQL *mysql) { MYSQL_RES *res; MYSQL_ROW row; int rc; mysql= mysql_init(NULL); FAIL_IF(!mysql, "not enough memory"); /* use compressed protocol */ rc= mysql_options(mysql, MYSQL_OPT_COMPRESS, NULL); if (!(mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, 0))) { diag("connection failed"); return FAIL; } rc= mysql_query(mysql, "SHOW STATUS LIKE 'compression'"); check_mysql_rc(rc, mysql); res= mysql_store_result(mysql); row= mysql_fetch_row(res); FAIL_UNLESS(strcmp(row[1], "ON") == 0, "Compression off"); mysql_free_result(res); mysql_close(mysql); return OK; }
static int test_bug29306(MYSQL *mysql) { MYSQL_FIELD *field; int rc; MYSQL_RES *res; rc= mysql_query(mysql, "DROP TABLE IF EXISTS tab17557"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP VIEW IF EXISTS view17557"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE TABLE tab17557 (dd decimal (3,1))"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE VIEW view17557 as SELECT dd FROM tab17557"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "INSERT INTO tab17557 VALUES (7.6)"); check_mysql_rc(rc, mysql); /* Checking the view */ res= mysql_list_fields(mysql, "view17557", NULL); while ((field= mysql_fetch_field(res))) { FAIL_UNLESS(field->decimals == 1, "field->decimals != 1"); } mysql_free_result(res); rc= mysql_query(mysql, "DROP TABLE tab17557"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP VIEW view17557"); check_mysql_rc(rc, mysql); return OK; }
static int test_bug12001(MYSQL *mysql) { MYSQL_RES *result; const char *query= "DROP TABLE IF EXISTS test_table;" "CREATE TABLE test_table(id INT);" "INSERT INTO test_table VALUES(10);" "UPDATE test_table SET id=20 WHERE id=10;" "SELECT * FROM test_table;" "INSERT INTO non_existent_table VALUES(11);"; int rc, res; rc= mysql_query(mysql, query); check_mysql_rc(rc, mysql); do { if (mysql_field_count(mysql) && (result= mysql_use_result(mysql))) { mysql_free_result(result); } } while (!(res= mysql_next_result(mysql))); rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_table"); check_mysql_rc(rc, mysql); FAIL_UNLESS(res==1, "res != 1"); return OK; }
static int test_reconnect(MYSQL *mysql) { my_bool my_true= TRUE; MYSQL *mysql1; int rc; my_bool reconnect; mysql1= mysql_init(NULL); FAIL_IF(!mysql1, "not enough memory"); mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect); FAIL_UNLESS(reconnect == 0, "reconnect != 0"); rc= mysql_options(mysql1, MYSQL_OPT_RECONNECT, &my_true); check_mysql_rc(rc, mysql1); mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect); FAIL_UNLESS(reconnect == 1, "reconnect != 1"); if (!(mysql_real_connect(mysql1, hostname, username, password, schema, port, socketname, 0))) { diag("connection failed"); mysql_close(mysql); return FAIL; } mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect); FAIL_UNLESS(reconnect == 1, "reconnect != 1"); diag("Thread_id before kill: %lu", mysql_thread_id(mysql1)); mysql_kill(mysql, mysql_thread_id(mysql1)); sleep(4); mysql_ping(mysql1); rc= mysql_query(mysql1, "SELECT 1 FROM DUAL LIMIT 0"); check_mysql_rc(rc, mysql1); diag("Thread_id after kill: %lu", mysql_thread_id(mysql1)); mysql_get_option(mysql1, MYSQL_OPT_RECONNECT, &reconnect); FAIL_UNLESS(reconnect == 1, "reconnect != 1"); mysql_close(mysql1); return OK; }
static int test_bug11111(MYSQL *mysql) { MYSQL_STMT *stmt; MYSQL_BIND my_bind[2]; char buf[2][20]; ulong len[2]; int i; int rc; const char *query= "SELECT DISTINCT f1,ff2 FROM v1"; rc= mysql_query(mysql, "drop table if exists t1, t2, v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "drop view if exists t1, t2, v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create table t1 (f1 int, f2 int)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create table t2 (ff1 int, ff2 int)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create view v1 as select * from t1, t2 where f1=ff1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "insert into t1 values (1,1), (2,2), (3,3)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "insert into t2 values (1,1), (2,2), (3,3)"); check_mysql_rc(rc, mysql); stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_stmt_rc(rc, stmt); rc= mysql_stmt_execute(stmt); check_stmt_rc(rc, stmt); memset(my_bind, '\0', sizeof(my_bind)); for (i=0; i < 2; i++) { my_bind[i].buffer_type= MYSQL_TYPE_STRING; my_bind[i].buffer= (uchar* *)&buf[i]; my_bind[i].buffer_length= 20; my_bind[i].length= &len[i]; } rc= mysql_stmt_bind_result(stmt, my_bind); check_stmt_rc(rc, stmt); rc= mysql_stmt_fetch(stmt); check_stmt_rc(rc, stmt); FAIL_UNLESS(!strcmp(buf[1],"1"), "buf[1] != '1'"); mysql_stmt_close(stmt); rc= mysql_query(mysql, "drop view v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "drop table t1, t2"); check_mysql_rc(rc, mysql); return OK; }
int owl_editwin_regtest(void) { int numfailed = 0; const char *p; printf("# BEGIN testing owl_editwin\n"); owl_editwin *oe; oe = owl_editwin_new(NULL, 80, 80, OWL_EDITWIN_STYLE_MULTILINE, NULL); /* TODO: make the strings a little more lenient w.r.t trailing whitespace */ /* check paragraph fill */ owl_editwin_insert_string(oe, "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah.\n\nblah"); owl_editwin_move_to_top(oe); owl_editwin_fill_paragraph(oe); p = owl_editwin_get_text(oe); FAIL_UNLESS("text was correctly wrapped", p && !strcmp(p, "blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n" "blah blah blah.\n" "\n" "blah")); owl_editwin_delete(oe); oe = NULL; oe = owl_editwin_new(NULL, 80, 80, OWL_EDITWIN_STYLE_MULTILINE, NULL); /* check that lines ending with ". " correctly fill */ owl_editwin_insert_string(oe, "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah. \n\nblah"); owl_editwin_move_to_top(oe); owl_editwin_fill_paragraph(oe); p = owl_editwin_get_text(oe); FAIL_UNLESS("text was correctly wrapped", p && !strcmp(p, "blah blah blah blah blah blah blah blah blah blah blah blah blah blah\n" "blah blah blah. \n" "\n" "blah")); owl_editwin_delete(oe); oe = NULL; printf("# END testing owl_editwin (%d failures)\n", numfailed); return numfailed; }
static int test_view_star(MYSQL *mysql) { MYSQL_STMT *stmt; int rc, i; MYSQL_BIND my_bind[8]; char parms[8][100]; ulong length[8]; const char *query= "SELECT * FROM vt1 WHERE a IN (?,?)"; rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, vt1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP VIEW IF EXISTS t1, vt1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE TABLE t1 (a int)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE VIEW vt1 AS SELECT a FROM t1"); check_mysql_rc(rc, mysql); memset(my_bind, '\0', sizeof(MYSQL_BIND)); for (i= 0; i < 2; i++) { sprintf((char *)&parms[i], "%d", i); my_bind[i].buffer_type = MYSQL_TYPE_VAR_STRING; my_bind[i].buffer = (char *)&parms[i]; my_bind[i].buffer_length = 100; my_bind[i].is_null = 0; my_bind[i].length = &length[i]; length[i] = 1; } stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_stmt_rc(rc, stmt); rc= mysql_stmt_bind_param(stmt, my_bind); check_stmt_rc(rc, stmt); for (i= 0; i < 3; i++) { rc= mysql_stmt_execute(stmt); check_stmt_rc(rc, stmt); rc= mysql_stmt_fetch(stmt); FAIL_UNLESS(MYSQL_NO_DATA == rc, "Expected 0 rows"); } mysql_stmt_close(stmt); rc= mysql_query(mysql, "DROP TABLE t1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP VIEW vt1"); check_mysql_rc(rc, mysql); return OK; }
int main(int argc, char **argv) { FAIL_UNLESS(testSwapInt); FAIL_UNLESS(testMin); FAIL_UNLESS(testMax); FAIL_UNLESS(testFill); FAIL_UNLESS(testFill_N); FAIL_UNLESS(testEqual); FAIL_UNLESS(testCopy); return kPassed; }
static int test_bug28505(MYSQL *mysql) { my_ulonglong res; int rc; rc= mysql_query(mysql, "drop table if exists t1"); rc= mysql_query(mysql, "create table t1(f1 int primary key)"); rc= mysql_query(mysql, "insert into t1 values(1)"); rc= mysql_query(mysql, "insert into t1 values(1) on duplicate key update f1=1"); res= mysql_affected_rows(mysql); FAIL_UNLESS(!res, "res != 0"); rc= mysql_query(mysql, "drop table t1"); return OK; }
static int test_bug16143(MYSQL *mysql) { MYSQL_STMT *stmt; stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); /* Check mysql_stmt_sqlstate return "no error" */ FAIL_UNLESS(strcmp(mysql_stmt_sqlstate(stmt), "00000") == 0, "Expected SQLstate 000000"); mysql_stmt_close(stmt); return OK; }
static int test_bad_union(MYSQL *mysql) { MYSQL_STMT *stmt; int rc; const char *query= "SELECT 1, 2 union SELECT 1"; stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); rc= mysql_stmt_prepare(stmt, query, strlen(query)); FAIL_UNLESS(rc && mysql_errno(mysql) == 1222, "Error expected"); mysql_stmt_close(stmt); return OK; }
static int test_bug29692(MYSQL *mysql) { int rc; rc= mysql_query(mysql, "drop table if exists t1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create table t1(f1 int)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "insert into t1 values(1)"); check_mysql_rc(rc, mysql); FAIL_UNLESS(1 == mysql_affected_rows(mysql), "affected_rows != 1"); rc= mysql_query(mysql, "drop table t1"); check_mysql_rc(rc, mysql); return OK; }
static int test_view_sp_list_fields(MYSQL *mysql) { int rc; MYSQL_RES *res; MYSQL_ROW row; int skip; /* skip this test if bin_log is on */ rc= mysql_query(mysql, "SHOW VARIABLES LIKE 'log_bin'"); check_mysql_rc(rc, mysql); res= mysql_store_result(mysql); FAIL_IF(!res, "empty/invalid resultset"); row = mysql_fetch_row(res); skip= (strcmp((char *)row[1], "ON") == 0); mysql_free_result(res); if (skip) { diag("bin_log is ON -> skip"); return SKIP; } rc= mysql_query(mysql, "DROP FUNCTION IF EXISTS f1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP TABLE IF EXISTS v1, t1, t2"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP VIEW IF EXISTS v1, t1, t2"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create function f1 () returns int return 5"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create table t1 (s1 char,s2 char)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create table t2 (s1 int);"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create view v1 as select s2,sum(s1) - \ count(s2) as vx from t1 group by s2 having sum(s1) - count(s2) < (select f1() \ from t2);"); check_mysql_rc(rc, mysql); res= mysql_list_fields(mysql, "v1", NullS); FAIL_UNLESS(res != 0 && mysql_num_fields(res) != 0, "0 Fields"); rc= mysql_query(mysql, "DROP FUNCTION f1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP VIEW v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP TABLE t1, t2"); mysql_free_result(res); check_mysql_rc(rc, mysql); return OK; }
static int test_parse_error_and_bad_length(MYSQL *mysql) { MYSQL_STMT *stmt; int rc; /* check that we get 4 syntax errors over the 4 calls */ rc= mysql_query(mysql, "SHOW DATABAAAA"); FAIL_UNLESS(rc, "Error expected"); rc= mysql_real_query(mysql, "SHOW DATABASES", 100); FAIL_UNLESS(rc, "Error expected"); stmt= mysql_stmt_init(mysql); FAIL_IF(!stmt, mysql_error(mysql)); rc= mysql_stmt_prepare(stmt, "SHOW DATABAAAA", strlen("SHOW DATABAAAA")); FAIL_IF(!rc, "Error expected"); mysql_stmt_close(stmt); stmt= mysql_stmt_init(mysql); FAIL_UNLESS(stmt, ""); rc= mysql_stmt_prepare(stmt, "SHOW DATABASES", 100); FAIL_IF(!rc, "Error expected"); mysql_stmt_close(stmt); return OK; }
int main(int argc, char **argv) { FAIL_UNLESS(testSpecialized); FAIL_UNLESS(testMin); FAIL_UNLESS(testMax); FAIL_UNLESS(testSigned); FAIL_UNLESS(testIsInteger); FAIL_UNLESS(testDigits); return kPassed; }
int EstEID_loadCertInfo(EstEID_Certs *certs, int index) { CK_SLOT_ID slotID = certs->slotIDs[index]; CK_SLOT_INFO slotInfo; FAIL_IF(EstEID_CK_failure("C_GetSlotInfo", fl->C_GetSlotInfo(slotID, &slotInfo))); if (!(slotInfo.flags & CKF_TOKEN_PRESENT)) return SUCCESS; CK_TOKEN_INFO tokenInfo; FAIL_IF(EstEID_CK_failure("C_GetTokenInfo", fl->C_GetTokenInfo(slotID, &tokenInfo))); certs->certs[index] = EstEID_createCertMap(tokenInfo); FAIL_UNLESS(EstEID_loadCertInfoEntries(certs, index)); return SUCCESS; }
static int test_bug15752(MYSQL *mysql) { int rc, i; const int ITERATION_COUNT= 100; const char *query= "CALL p1()"; rc= mysql_query(mysql, "drop procedure if exists p1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create procedure p1() select 1"); check_mysql_rc(rc, mysql); rc= mysql_real_query(mysql, query, strlen(query)); check_mysql_rc(rc, mysql); mysql_free_result(mysql_store_result(mysql)); rc= mysql_real_query(mysql, query, strlen(query)); FAIL_UNLESS(rc && mysql_errno(mysql) == CR_COMMANDS_OUT_OF_SYNC, "Error expected"); rc= mysql_next_result(mysql); check_mysql_rc(rc, mysql); mysql_free_result(mysql_store_result(mysql)); rc= mysql_next_result(mysql); FAIL_IF(rc != -1, "rc != -1"); for (i = 0; i < ITERATION_COUNT; i++) { rc= mysql_real_query(mysql, query, strlen(query)); check_mysql_rc(rc, mysql); mysql_free_result(mysql_store_result(mysql)); rc= mysql_next_result(mysql); check_mysql_rc(rc, mysql); mysql_free_result(mysql_store_result(mysql)); rc= mysql_next_result(mysql); FAIL_IF(rc != -1, "rc != -1"); } rc= mysql_query(mysql, "drop procedure p1"); check_mysql_rc(rc, mysql); return OK; }
static int test_view_where(MYSQL *mysql) { MYSQL_STMT *stmt; int rc, i; const char *query= "select v1.c,v2.c from v1, v2"; rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,v1,v2"); check_mysql_rc(rc, mysql); rc = mysql_query(mysql, "DROP VIEW IF EXISTS v1,v2,t1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql,"CREATE TABLE t1 (a int, b int)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql,"insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql,"create view v1 (c) as select b from t1 where a<3"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql,"create view v2 (c) as select b from t1 where a>=3"); check_mysql_rc(rc, mysql); stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_stmt_rc(rc, stmt); for (i= 0; i < 3; i++) { int rowcount= 0; rc= mysql_stmt_execute(stmt); check_stmt_rc(rc, stmt); while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) rowcount++; FAIL_UNLESS(4 == rowcount, "Expected 4 rows"); } mysql_stmt_close(stmt); rc= mysql_query(mysql, "DROP TABLE t1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP VIEW v1, v2"); check_mysql_rc(rc, mysql); return OK; }
static int test_left_join_view(MYSQL *mysql) { MYSQL_STMT *stmt; int rc, i; const char *query= "select t1.a, v1.x from t1 left join v1 on (t1.a= v1.x);"; rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,v1"); check_mysql_rc(rc, mysql); rc = mysql_query(mysql, "DROP VIEW IF EXISTS v1,t1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql,"CREATE TABLE t1 (a int)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql,"insert into t1 values (1), (2), (3)"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql,"create view v1 (x) as select a from t1 where a > 1"); check_mysql_rc(rc, mysql); stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_stmt_rc(rc, stmt); for (i= 0; i < 3; i++) { int rowcount= 0; rc= mysql_stmt_execute(stmt); check_stmt_rc(rc, stmt); while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) rowcount++; FAIL_UNLESS(3 == rowcount, "Expected 3 rows"); } mysql_stmt_close(stmt); rc= mysql_query(mysql, "DROP VIEW v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP TABLE t1"); check_mysql_rc(rc, mysql); return OK; }
int owl_dict_regtest(void) { owl_dict d; owl_list l; int numfailed=0; char *av="aval", *bv="bval", *cv="cval", *dv="dval"; printf("# BEGIN testing owl_dict\n"); FAIL_UNLESS("create", 0==owl_dict_create(&d)); FAIL_UNLESS("insert b", 0==owl_dict_insert_element(&d, "b", bv, owl_dict_noop_delete)); FAIL_UNLESS("insert d", 0==owl_dict_insert_element(&d, "d", dv, owl_dict_noop_delete)); FAIL_UNLESS("insert a", 0==owl_dict_insert_element(&d, "a", av, owl_dict_noop_delete)); FAIL_UNLESS("insert c", 0==owl_dict_insert_element(&d, "c", cv, owl_dict_noop_delete)); FAIL_UNLESS("reinsert d (no replace)", -2==owl_dict_insert_element(&d, "d", dv, 0)); FAIL_UNLESS("find a", av==owl_dict_find_element(&d, "a")); FAIL_UNLESS("find b", bv==owl_dict_find_element(&d, "b")); FAIL_UNLESS("find c", cv==owl_dict_find_element(&d, "c")); FAIL_UNLESS("find d", dv==owl_dict_find_element(&d, "d")); FAIL_UNLESS("find e (non-existent)", NULL==owl_dict_find_element(&d, "e")); FAIL_UNLESS("remove d", dv==owl_dict_remove_element(&d, "d")); FAIL_UNLESS("find d (post-removal)", NULL==owl_dict_find_element(&d, "d")); FAIL_UNLESS("get_size", 3==owl_dict_get_size(&d)); FAIL_UNLESS("get_keys", 0==owl_dict_get_keys(&d, &l)); FAIL_UNLESS("get_keys result size", 3==owl_list_get_size(&l)); /* these assume the returned keys are sorted */ FAIL_UNLESS("get_keys result val",0==strcmp("a",owl_list_get_element(&l,0))); FAIL_UNLESS("get_keys result val",0==strcmp("b",owl_list_get_element(&l,1))); FAIL_UNLESS("get_keys result val",0==strcmp("c",owl_list_get_element(&l,2))); owl_list_cleanup(&l, owl_free); owl_dict_cleanup(&d, NULL); /* if (numfailed) printf("*** WARNING: failures encountered with owl_dict\n"); */ printf("# END testing owl_dict (%d failures)\n", numfailed); return(numfailed); }
int owl_util_regtest(void) { int numfailed=0; printf("# BEGIN testing owl_util\n"); FAIL_UNLESS("owl_util_substitute 1", !strcmp("foo", owl_text_substitute("foo", "", "Y"))); FAIL_UNLESS("owl_text_substitute 2", !strcmp("fYZYZ", owl_text_substitute("foo", "o", "YZ"))); FAIL_UNLESS("owl_text_substitute 3", !strcmp("foo", owl_text_substitute("fYZYZ", "YZ", "o"))); FAIL_UNLESS("owl_text_substitute 4", !strcmp("/u/foo/meep", owl_text_substitute("~/meep", "~", "/u/foo"))); FAIL_UNLESS("skiptokens 1", !strcmp("bar quux", skiptokens("foo bar quux", 1))); FAIL_UNLESS("skiptokens 2", !strcmp("meep", skiptokens("foo 'bar quux' meep", 2))); FAIL_UNLESS("expand_tabs 1", !strcmp(" hi", owl_text_expand_tabs("\thi"))); FAIL_UNLESS("expand_tabs 2", !strcmp(" hi\nword tab", owl_text_expand_tabs("\thi\nword\ttab"))); FAIL_UNLESS("expand_tabs 3", !strcmp(" 2 tabs", owl_text_expand_tabs("\t\t2 tabs"))); FAIL_UNLESS("expand_tabs 4", !strcmp("α ααααααα! ", owl_text_expand_tabs("α\tααααααα!\t"))); FAIL_UNLESS("expand_tabs 5", !strcmp("A AAA!! ", owl_text_expand_tabs("A\tAAA!!\t"))); FAIL_UNLESS("skiptokens 1", !strcmp("world", skiptokens("hello world", 1))); FAIL_UNLESS("skiptokens 2", !strcmp("c d e", skiptokens("a b c d e", 2))); FAIL_UNLESS("skiptokens 3", !strcmp("\"b\" c d e", skiptokens("a \"b\" c d e", 1))); FAIL_UNLESS("skiptokens 4", !strcmp("c d e", skiptokens("a \"b\" c d e", 2))); FAIL_UNLESS("skiptokens 5", !strcmp("c d e", skiptokens("a \"'\" c d e", 2))); /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */ printf("# END testing owl_util (%d failures)\n", numfailed); return(numfailed); }
static int test_view_insert_fields(MYSQL *mysql) { MYSQL_STMT *stmt; char parm[11][1000]; ulong l[11]; int rc, i; int rowcount= 0; MYSQL_BIND my_bind[11]; const char *query= "INSERT INTO `v1` ( `K1C4` ,`K2C4` ,`K3C4` ,`K4N4` ,`F1C4` ,`F2I4` ,`F3N5` ,`F7F8` ,`F6N4` ,`F5C8` ,`F9D8` ) VALUES( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )"; rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1, v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP VIEW IF EXISTS t1, v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE TABLE t1 (K1C4 varchar(4) NOT NULL," "K2C4 varchar(4) NOT NULL, K3C4 varchar(4) NOT NULL," "K4N4 varchar(4) NOT NULL default '0000'," "F1C4 varchar(4) NOT NULL, F2I4 int(11) NOT NULL," "F3N5 varchar(5) NOT NULL default '00000'," "F4I4 int(11) NOT NULL default '0', F5C8 varchar(8) NOT NULL," "F6N4 varchar(4) NOT NULL default '0000'," "F7F8 double NOT NULL default '0'," "F8F8 double NOT NULL default '0'," "F9D8 decimal(8,2) NOT NULL default '0.00'," "PRIMARY KEY (K1C4,K2C4,K3C4,K4N4)) " "CHARSET=latin1 COLLATE latin1_bin"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE VIEW v1 AS select sql_no_cache " " K1C4 AS K1C4, K2C4 AS K2C4, K3C4 AS K3C4, K4N4 AS K4N4, " " F1C4 AS F1C4, F2I4 AS F2I4, F3N5 AS F3N5," " F7F8 AS F7F8, F6N4 AS F6N4, F5C8 AS F5C8, F9D8 AS F9D8" " from t1 T0001"); memset(my_bind, '\0', sizeof(my_bind)); for (i= 0; i < 11; i++) { l[i]= 20; my_bind[i].buffer_type= MYSQL_TYPE_STRING; my_bind[i].is_null= 0; my_bind[i].buffer= (char *)&parm[i]; strcpy(parm[i], "1"); my_bind[i].buffer_length= 2; my_bind[i].length= &l[i]; } stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_stmt_rc(rc, stmt); rc= mysql_stmt_bind_param(stmt, my_bind); check_stmt_rc(rc, stmt); rc= mysql_stmt_execute(stmt); check_stmt_rc(rc, stmt); mysql_stmt_close(stmt); query= "select * from t1"; stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_stmt_rc(rc, stmt); rc= mysql_stmt_execute(stmt); check_stmt_rc(rc, stmt); while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA) rowcount++; FAIL_UNLESS(1 == rowcount, "Expected 1 row"); mysql_stmt_close(stmt); rc= mysql_query(mysql, "DROP VIEW v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP TABLE t1"); check_mysql_rc(rc, mysql); return OK; }
static int test_view_insert(MYSQL *mysql) { MYSQL_STMT *insert_stmt, *select_stmt; int rc, i; MYSQL_BIND my_bind[1]; int my_val = 0; ulong my_length = 0L; long my_null = 0L; const char *query= "insert into v1 values (?)"; rc = mysql_query(mysql, "DROP TABLE IF EXISTS t1,v1"); check_mysql_rc(rc, mysql); rc = mysql_query(mysql, "DROP VIEW IF EXISTS t1,v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql,"create table t1 (a int, primary key (a))"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "create view v1 as select a from t1 where a>=1"); check_mysql_rc(rc, mysql); insert_stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(insert_stmt, query, strlen(query)); check_stmt_rc(rc, insert_stmt); query= "select * from t1"; select_stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(select_stmt, query, strlen(query)); check_stmt_rc(rc, select_stmt); memset(my_bind, '\0', sizeof(MYSQL_BIND)); my_bind[0].buffer_type = MYSQL_TYPE_LONG; my_bind[0].buffer = (char *)&my_val; my_bind[0].length = &my_length; my_bind[0].is_null = (char*)&my_null; rc= mysql_stmt_bind_param(insert_stmt, my_bind); check_stmt_rc(rc, select_stmt); for (i= 0; i < 3; i++) { int rowcount= 0; my_val= i; rc= mysql_stmt_execute(insert_stmt); check_stmt_rc(rc, insert_stmt);; rc= mysql_stmt_execute(select_stmt); check_stmt_rc(rc, select_stmt);; while (mysql_stmt_fetch(select_stmt) != MYSQL_NO_DATA) rowcount++; FAIL_UNLESS((i+1) == rowcount, "rowcount != i+1"); } mysql_stmt_close(insert_stmt); mysql_stmt_close(select_stmt); rc= mysql_query(mysql, "DROP VIEW v1"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP TABLE t1"); check_mysql_rc(rc, mysql); return OK; }
int owl_variable_regtest(void) { owl_vardict vd; int numfailed=0; char buf[1024]; const void *v; printf("# BEGIN testing owl_variable\n"); FAIL_UNLESS("setup", 0==owl_variable_dict_setup(&vd)); FAIL_UNLESS("get bool", 0==owl_variable_get_bool(&vd,"rxping")); FAIL_UNLESS("get bool (no such)", -1==owl_variable_get_bool(&vd,"mumble")); FAIL_UNLESS("get bool as string 1", 0==owl_variable_get_tostring(&vd,"rxping", buf, 1024)); FAIL_UNLESS("get bool as string 2", 0==strcmp(buf,"off")); FAIL_UNLESS("set bool 1", 0==owl_variable_set_bool_on(&vd,"rxping")); FAIL_UNLESS("get bool 2", 1==owl_variable_get_bool(&vd,"rxping")); FAIL_UNLESS("set bool 3", 0==owl_variable_set_fromstring(&vd,"rxping","off",0,0)); FAIL_UNLESS("get bool 4", 0==owl_variable_get_bool(&vd,"rxping")); FAIL_UNLESS("set bool 5", -1==owl_variable_set_fromstring(&vd,"rxping","xxx",0,0)); FAIL_UNLESS("get bool 6", 0==owl_variable_get_bool(&vd,"rxping")); FAIL_UNLESS("get string", 0==strcmp("~/zlog/people", owl_variable_get_string(&vd,"logpath"))); FAIL_UNLESS("set string 7", 0==owl_variable_set_string(&vd,"logpath","whee")); FAIL_UNLESS("get string", 0==strcmp("whee", owl_variable_get_string(&vd,"logpath"))); FAIL_UNLESS("get int", 8==owl_variable_get_int(&vd,"typewinsize")); FAIL_UNLESS("get int (no such)", -1==owl_variable_get_int(&vd,"mmble")); FAIL_UNLESS("get int as string 1", 0==owl_variable_get_tostring(&vd,"typewinsize", buf, 1024)); FAIL_UNLESS("get int as string 2", 0==strcmp(buf,"8")); FAIL_UNLESS("set int 1", 0==owl_variable_set_int(&vd,"typewinsize",12)); FAIL_UNLESS("get int 2", 12==owl_variable_get_int(&vd,"typewinsize")); FAIL_UNLESS("set int 1b", -1==owl_variable_set_int(&vd,"typewinsize",-3)); FAIL_UNLESS("get int 2b", 12==owl_variable_get_int(&vd,"typewinsize")); FAIL_UNLESS("set int 3", 0==owl_variable_set_fromstring(&vd,"typewinsize","9",0,0)); FAIL_UNLESS("get int 4", 9==owl_variable_get_int(&vd,"typewinsize")); FAIL_UNLESS("set int 5", -1==owl_variable_set_fromstring(&vd,"typewinsize","xxx",0,0)); FAIL_UNLESS("set int 6", -1==owl_variable_set_fromstring(&vd,"typewinsize","",0,0)); FAIL_UNLESS("get int 7", 9==owl_variable_get_int(&vd,"typewinsize")); owl_variable_dict_newvar_string(&vd, "stringvar", "", "", "testval"); FAIL_UNLESS("get new string var", NULL != (v = owl_variable_get(&vd, "stringvar", OWL_VARIABLE_STRING))); FAIL_UNLESS("get new string val", !strcmp("testval", owl_variable_get_string(&vd, "stringvar"))); owl_variable_set_string(&vd, "stringvar", "new val"); FAIL_UNLESS("update string val", !strcmp("new val", owl_variable_get_string(&vd, "stringvar"))); owl_variable_dict_newvar_int(&vd, "intvar", "", "", 47); FAIL_UNLESS("get new int var", NULL != (v = owl_variable_get(&vd, "intvar", OWL_VARIABLE_INT))); FAIL_UNLESS("get new int val", 47 == owl_variable_get_int(&vd, "intvar")); owl_variable_set_int(&vd, "intvar", 17); FAIL_UNLESS("update bool val", 17 == owl_variable_get_int(&vd, "intvar")); owl_variable_dict_newvar_bool(&vd, "boolvar", "", "", 1); FAIL_UNLESS("get new bool var", NULL != (v = owl_variable_get(&vd, "boolvar", OWL_VARIABLE_BOOL))); FAIL_UNLESS("get new bool val", owl_variable_get_bool(&vd, "boolvar")); owl_variable_set_bool_off(&vd, "boolvar"); FAIL_UNLESS("update string val", !owl_variable_get_bool(&vd, "boolvar")); owl_variable_dict_cleanup(&vd); /* if (numfailed) printf("*** WARNING: failures encountered with owl_variable\n"); */ printf("# END testing owl_variable (%d failures)\n", numfailed); return(numfailed); }
static int test_view_2where(MYSQL *mysql) { MYSQL_STMT *stmt; int rc, i; MYSQL_BIND my_bind[8]; char parms[8][100]; ulong length[8]; const char *query= "select relid, report, handle, log_group, username, variant, type, " "version, erfdat, erftime, erfname, aedat, aetime, aename, dependvars, " "inactive from V_LTDX where mandt = ? and relid = ? and report = ? and " "handle = ? and log_group = ? and username in ( ? , ? ) and type = ?"; rc= mysql_query(mysql, "DROP TABLE IF EXISTS LTDX"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP VIEW IF EXISTS V_LTDX"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE TABLE LTDX (MANDT char(3) NOT NULL default '000', " " RELID char(2) NOT NULL, REPORT varchar(40) NOT NULL," " HANDLE varchar(4) NOT NULL, LOG_GROUP varchar(4) NOT NULL," " USERNAME varchar(12) NOT NULL," " VARIANT varchar(12) NOT NULL," " TYPE char(1) NOT NULL, SRTF2 int(11) NOT NULL," " VERSION varchar(6) NOT NULL default '000000'," " ERFDAT varchar(8) NOT NULL default '00000000'," " ERFTIME varchar(6) NOT NULL default '000000'," " ERFNAME varchar(12) NOT NULL," " AEDAT varchar(8) NOT NULL default '00000000'," " AETIME varchar(6) NOT NULL default '000000'," " AENAME varchar(12) NOT NULL," " DEPENDVARS varchar(10) NOT NULL," " INACTIVE char(1) NOT NULL, CLUSTR smallint(6) NOT NULL," " CLUSTD blob," " PRIMARY KEY (MANDT, RELID, REPORT, HANDLE, LOG_GROUP, " "USERNAME, VARIANT, TYPE, SRTF2))" " CHARSET=latin1 COLLATE latin1_bin"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "CREATE VIEW V_LTDX AS select T0001.MANDT AS " " MANDT,T0001.RELID AS RELID,T0001.REPORT AS " " REPORT,T0001.HANDLE AS HANDLE,T0001.LOG_GROUP AS " " LOG_GROUP,T0001.USERNAME AS USERNAME,T0001.VARIANT AS " " VARIANT,T0001.TYPE AS TYPE,T0001.VERSION AS " " VERSION,T0001.ERFDAT AS ERFDAT,T0001.ERFTIME AS " " ERFTIME,T0001.ERFNAME AS ERFNAME,T0001.AEDAT AS " " AEDAT,T0001.AETIME AS AETIME,T0001.AENAME AS " " AENAME,T0001.DEPENDVARS AS DEPENDVARS,T0001.INACTIVE AS " " INACTIVE from LTDX T0001 where (T0001.SRTF2 = 0)"); check_mysql_rc(rc, mysql); memset(my_bind, '\0', sizeof(MYSQL_BIND)); for (i=0; i < 8; i++) { strcpy(parms[i], "1"); my_bind[i].buffer_type = MYSQL_TYPE_VAR_STRING; my_bind[i].buffer = (char *)&parms[i]; my_bind[i].buffer_length = 100; my_bind[i].is_null = 0; my_bind[i].length = &length[i]; length[i] = 1; } stmt= mysql_stmt_init(mysql); rc= mysql_stmt_prepare(stmt, query, strlen(query)); check_stmt_rc(rc, stmt); rc= mysql_stmt_bind_param(stmt, my_bind); check_stmt_rc(rc, stmt); rc= mysql_stmt_execute(stmt); check_stmt_rc(rc, stmt); rc= mysql_stmt_fetch(stmt); FAIL_UNLESS(MYSQL_NO_DATA == rc, "Expected 0 rows"); mysql_stmt_close(stmt); rc= mysql_query(mysql, "DROP VIEW V_LTDX"); check_mysql_rc(rc, mysql); rc= mysql_query(mysql, "DROP TABLE LTDX"); check_mysql_rc(rc, mysql); return OK; }
/* try creating with acls */ static bool test_create_acl_ext(struct torture_context *tctx, struct smb2_tree *tree, bool test_dir) { bool ret = true; struct smb2_create io; NTSTATUS status; struct security_ace ace; struct security_descriptor *sd; struct dom_sid *test_sid; union smb_fileinfo q = {}; uint32_t attrib = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | (test_dir ? FILE_ATTRIBUTE_DIRECTORY : 0); NTSTATUS (*delete_func)(struct smb2_tree *, const char *) = test_dir ? smb2_util_rmdir : smb2_util_unlink; smb2_deltree(tree, FNAME); ZERO_STRUCT(io); io.in.desired_access = SEC_FLAG_MAXIMUM_ALLOWED; io.in.file_attributes = FILE_ATTRIBUTE_NORMAL; io.in.create_disposition = NTCREATEX_DISP_CREATE; io.in.share_access = NTCREATEX_SHARE_ACCESS_DELETE | NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE; io.in.create_options = NTCREATEX_OPTIONS_ASYNC_ALERT | 0x00200000 | (test_dir ? NTCREATEX_OPTIONS_DIRECTORY : (NTCREATEX_OPTIONS_NON_DIRECTORY_FILE)); io.in.fname = FNAME; torture_comment(tctx, "basic create\n"); status = smb2_create(tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); q.query_secdesc.level = RAW_FILEINFO_SEC_DESC; q.query_secdesc.in.file.handle = io.out.file.handle; q.query_secdesc.in.secinfo_flags = SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL; status = smb2_getinfo_file(tree, tctx, &q); CHECK_STATUS(status, NT_STATUS_OK); sd = q.query_secdesc.out.sd; status = smb2_util_close(tree, io.out.file.handle); CHECK_STATUS(status, NT_STATUS_OK); status = delete_func(tree, FNAME); CHECK_STATUS(status, NT_STATUS_OK); torture_comment(tctx, "adding a new ACE\n"); test_sid = dom_sid_parse_talloc(tctx, SID_NT_AUTHENTICATED_USERS); ace.type = SEC_ACE_TYPE_ACCESS_ALLOWED; ace.flags = 0; ace.access_mask = SEC_STD_ALL; ace.trustee = *test_sid; status = security_descriptor_dacl_add(sd, &ace); CHECK_STATUS(status, NT_STATUS_OK); torture_comment(tctx, "creating a file with an initial ACL\n"); io.in.sec_desc = sd; status = smb2_create(tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); FAIL_UNLESS(smb2_util_verify_sd(tctx, tree, io.out.file.handle, sd)); status = smb2_util_close(tree, io.out.file.handle); CHECK_STATUS(status, NT_STATUS_OK); status = delete_func(tree, FNAME); CHECK_STATUS(status, NT_STATUS_OK); torture_comment(tctx, "creating with attributes\n"); io.in.sec_desc = NULL; io.in.file_attributes = attrib; status = smb2_create(tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); FAIL_UNLESS(smb2_util_verify_attrib(tctx, tree, io.out.file.handle, attrib)); status = smb2_util_close(tree, io.out.file.handle); CHECK_STATUS(status, NT_STATUS_OK); status = delete_func(tree, FNAME); CHECK_STATUS(status, NT_STATUS_OK); torture_comment(tctx, "creating with attributes and ACL\n"); io.in.sec_desc = sd; io.in.file_attributes = attrib; status = smb2_create(tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); FAIL_UNLESS(smb2_util_verify_sd(tctx, tree, io.out.file.handle, sd)); FAIL_UNLESS(smb2_util_verify_attrib(tctx, tree, io.out.file.handle, attrib)); status = smb2_util_close(tree, io.out.file.handle); CHECK_STATUS(status, NT_STATUS_OK); status = delete_func(tree, FNAME); CHECK_STATUS(status, NT_STATUS_OK); torture_comment(tctx, "creating with attributes, ACL and owner\n"); sd = security_descriptor_dacl_create(tctx, 0, SID_WORLD, SID_BUILTIN_USERS, SID_WORLD, SEC_ACE_TYPE_ACCESS_ALLOWED, SEC_RIGHTS_FILE_READ | SEC_STD_ALL, 0, NULL); io.in.sec_desc = sd; io.in.file_attributes = attrib; status = smb2_create(tree, tctx, &io); CHECK_STATUS(status, NT_STATUS_OK); FAIL_UNLESS(smb2_util_verify_sd(tctx, tree, io.out.file.handle, sd)); FAIL_UNLESS(smb2_util_verify_attrib(tctx, tree, io.out.file.handle, attrib)); done: status = smb2_util_close(tree, io.out.file.handle); CHECK_STATUS(status, NT_STATUS_OK); status = delete_func(tree, FNAME); CHECK_STATUS(status, NT_STATUS_OK); return ret; }
int owl_filter_regtest(void) { int numfailed=0; owl_message m; owl_filter *f1, *f2, *f3, *f4, *f5; owl_dict_create(&g.filters); g.filterlist = NULL; owl_message_init(&m); owl_message_set_type_zephyr(&m); owl_message_set_direction_in(&m); owl_message_set_class(&m, "owl"); owl_message_set_instance(&m, "tester"); owl_message_set_sender(&m, "owl-user"); owl_message_set_recipient(&m, "joe"); owl_message_set_attribute(&m, "foo", "bar"); #define TEST_FILTER(f, e) do { \ numtests++; \ numfailed += owl_filter_test_string(f, &m, e); \ } while(0) TEST_FILTER("true", 1); TEST_FILTER("false", 0); TEST_FILTER("( true )", 1); TEST_FILTER("not false", 1); TEST_FILTER("( true ) or ( false )", 1); TEST_FILTER("true and false", 0); TEST_FILTER("( true or true ) or ( ( false ) )", 1); TEST_FILTER("class owl", 1); TEST_FILTER("class ^owl$", 1); TEST_FILTER("instance test", 1); TEST_FILTER("instance ^test$", 0); TEST_FILTER("instance ^tester$", 1); TEST_FILTER("foo bar", 1); TEST_FILTER("class owl and instance tester", 1); TEST_FILTER("type ^zephyr$ and direction ^in$ and ( class ^owl$ or instance ^owl$ )", 1); /* Order of operations and precedence */ TEST_FILTER("not true or false", 0); TEST_FILTER("true or true and false", 0); TEST_FILTER("true and true and false or true", 1); TEST_FILTER("false and false or true", 1); TEST_FILTER("true and false or false", 0); f1 = owl_filter_new_fromstring("f1", "class owl"); owl_global_add_filter(&g, f1); TEST_FILTER("filter f1", 1); owl_global_remove_filter(&g, "f1"); /* Test recursion prevention */ FAIL_UNLESS("self reference", (f2 = owl_filter_new_fromstring("test", "filter test")) == NULL); owl_filter_delete(f2); /* mutual recursion */ f3 = owl_filter_new_fromstring("f3", "filter f4"); owl_global_add_filter(&g, f3); FAIL_UNLESS("mutual recursion", (f4 = owl_filter_new_fromstring("f4", "filter f3")) == NULL); owl_global_remove_filter(&g, "f3"); owl_filter_delete(f4); /* support referencing a filter several times */ FAIL_UNLESS("DAG", (f5 = owl_filter_new_fromstring("dag", "filter f1 or filter f1")) != NULL); owl_filter_delete(f5); return 0; }