static bool run_testcase(const config_t *config, const char *basepath, const char *filename) { char buff[BUFSIZ]; char *end; query_t query; const char *eol = read_query(basepath, filename, buff, &end, &query); if (eol == NULL) { return false; } bool ok = true; filter_context_t context; filter_context_prepare(&context, NULL); while (eol < end) { char *neol = memchr(eol, '\n', end - eol); if (neol == NULL) { neol = end; } *neol = '\0'; char *sep = memchr(eol, '=', neol - eol); if (sep == NULL) { eol = neol + 1; err("missing separator"); continue; } *sep = '\0'; int pos = filter_find_with_name(&config->filters, eol); if (pos == -1) { err("Unknown filter %s", eol); eol = neol + 1; continue; } ++sep; filter_result_t result = hook_tokenize(sep, neol - sep); if (result == HTK_UNKNOWN) { err("Unknown filter result %.*s", (int) (neol - sep), sep); eol = neol + 1; continue; } filter_t *filter = array_ptr(config->filters, pos); #define TEST(Name, Run) \ do { \ bool __test = (Run); \ printf(" test %s: %s\n", Name, __test ? "SUCCESS" : "FAILED"); \ ok = ok && __test; \ } while (0) TEST(filter->name, filter_test(filter, &query, &context, result)); eol = neol + 1; } filter_context_wipe(&context); return ok; }
void run_sqlite() { sqlite3 *db; char *zErrMsg = 0; int rc; td_t t1, t2; long evt1, evt2; unsigned int ret1, ret2; int a = 0, b = 0, c = 0; c = treadp(cos_spd_id(), 0, &a, &b); printc("%d %d %d\n", a, b, c); evt1 = evt_split(cos_spd_id(), 0, 0); evt2 = evt_split(cos_spd_id(), 0, 0); assert(evt1 > 0 && evt2 > 0); /* Open database */ rc = sqlite3_open(":memory:", &db); if (rc) { printc("SQLITE: Can't open database: %s\n", sqlite3_errmsg(db)); return; } else { printc("SQLITE: Opened database successfully\n"); } /* Create Table */ sql = "CREATE TABLE PEOPLE(" \ "ID INT PRIMARY KEY NOT NULL," \ "NAME TEXT NOT NULL," \ "AGE INT NOT NULL," \ "ADDRESS CHAR(50));"; rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if( rc != SQLITE_OK ){ printc("SQLITE: SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); }else{ printc("SQLITE: Table created successfully\n"); } /*Insert Table Data*/ printc("SQLITE: Insert 3 rows into the table (Joel, Kevin, Mike)\n"); sql = "INSERT INTO PEOPLE (ID,NAME,AGE,ADDRESS) " \ "VALUES (1, 'Joel', 21, 'Washington DC');" \ "INSERT INTO PEOPLE (ID,NAME,AGE,ADDRESS) " \ "VALUES (2, 'Kevin', 30, 'Rio');" \ "INSERT INTO PEOPLE (ID,NAME,AGE,ADDRESS)" \ "VALUES (3, 'Mike', 23, 'New York');"; rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if( rc != SQLITE_OK ){ printc("SQLITE: SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); }else{ printc("SQLITE: Data inserted successfully\n"); } /*Read Query*/ rc = read_query(); if (rc > 0) { printc("SQLITE: Failed Reading Query Torrent\n"); return; } printc("%s\n", sql); rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg); if( rc != SQLITE_OK ){ printc("SQLITE: SQL error: %s\n", zErrMsg); sqlite3_free(zErrMsg); }else{ printc("SQLITE: Data Queried\n"); } write_response(); if (rc > 0) { printc("SQLITE: Error Writing to Response Torrent\n"); return; } sqlite3_close(db); return; }