int main() { printf("Testing subscriber database code.\n"); osmo_init_logging(&log_info); log_set_print_filename(osmo_stderr_target, 0); dummy_net.subscr_group = &dummy_sgrp; dummy_sgrp.net = &dummy_net; if (db_init("hlr.sqlite3")) { printf("DB: Failed to init database. Please check the option settings.\n"); return 1; } printf("DB: Database initialized.\n"); if (db_prepare()) { printf("DB: Failed to prepare database.\n"); return 1; } printf("DB: Database prepared.\n"); struct gsm_subscriber *alice = NULL; struct gsm_subscriber *alice_db; char *alice_imsi = "3243245432345"; alice = db_create_subscriber(alice_imsi, GSM_MIN_EXTEN, GSM_MAX_EXTEN, true); db_sync_subscriber(alice); alice_db = db_get_subscriber(GSM_SUBSCRIBER_IMSI, alice->imsi); COMPARE(alice, alice_db); SUBSCR_PUT(alice_db); SUBSCR_PUT(alice); test_subs("3693245423445", "1234567890", NULL, true); test_subs("9993245423445", "1234567890", "6543560920", true); test_subs("3123122223445", "1234567890", NULL, false); test_subs("9123121223445", "1234567890", "6543560920", false); /* create it again and see it fails */ alice = db_create_subscriber(alice_imsi, GSM_MIN_EXTEN, GSM_MAX_EXTEN, true); OSMO_ASSERT(!alice); test_sms(); test_sms_migrate(); db_fini(); printf("Done\n"); return 0; }
int main1() { int ret = 0; int single; single = test_adds(); if (single) printf("test_adds: FAILED\n"); ret |= single; single = test_subs(); if (single) printf("test_subs: FAILED\n"); ret |= single; if (!ret) printf("success\n"); return ret; }
void run_tests(void) { int unsolved[HEIGHT][WIDTH] = { { 5, 3, 0, 0, 7, 0, 0, 0, 0 }, { 6, 0, 0, 1, 9, 5, 0, 0, 0 }, { 0, 9, 8, 0, 0, 0, 0, 6, 0 }, { 8, 0, 0, 0, 6, 0, 0, 0, 3 }, { 4, 0, 0, 8, 0, 3, 0, 0, 1 }, { 7, 0, 0, 0, 2, 0, 0, 0, 6 }, { 0, 6, 0, 0, 0, 0, 2, 8, 0 }, { 0, 0, 0, 4, 1, 9, 0, 0, 5 }, { 0, 0, 0, 0, 8, 0, 0, 7, 9 } }; int illegal[HEIGHT][WIDTH] = { { 5, 3, 5, 2, 7, 6, 7, 8, 9 }, { 6, 1, 0, 1, 9, 5, 0, 0, 0 }, { 0, 9, 8, 0, 0, 0, 0, 6, 0 }, { 8, 2, 2, 0, 6, 0, 0, 0, 3 }, { 4, 4, 0, 8, 0, 3, 6, 0, 1 }, { 7, 0, 5, 0, 2, 0, 0, 0, 6 }, { 0, 6, 0, 0, 0, 0, 2, 8, 0 }, { 0, 0, 0, 4, 1, 9, 0, 0, 5 }, { 4, 0, 0, 0, 8, 0, 0, 7, 9 } }; int solved[HEIGHT][WIDTH] = { { 5, 3, 4, 6, 7, 8, 9, 1, 2 }, { 6, 7, 2, 1, 9, 5, 3, 4, 8 }, { 1, 9, 8, 3, 4, 2, 5, 6, 7 }, { 8, 5, 9, 7, 6, 1, 4, 2, 3 }, { 4, 2, 6, 8, 5, 3, 7, 9, 1 }, { 7, 1, 3, 9, 2, 4, 8, 5, 6 }, { 9, 6, 1, 5, 3, 7, 2, 8, 4 }, { 2, 8, 7, 4, 1, 9, 6, 3, 5 }, { 3, 4, 5, 2, 8, 6, 1, 7, 9 } }; int row[WIDTH]; int column[HEIGHT]; int sub[SUB_HEIGHT][SUB_WIDTH]; puts("Unsolved tests"); test_rows(unsolved, 0); test_columns(unsolved, 0); test_subs(unsolved, 0); test_whole(unsolved, 0); copy_row(unsolved, 0, row); test_row_legality(row, 1); copy_column(unsolved, 0, column); test_column_legality(column, 1); copy_sub(unsolved, 0, 0, sub); test_sub_legality(sub, 1); test_legality(unsolved, 1); int illegal_move[3] = {0, 2, 5}; test_legality_after_move(unsolved, illegal_move, 0); int legal_move[3] = {0, 2, 4}; test_legality_after_move(unsolved, legal_move, 1); puts("Illegal tests"); test_rows(illegal, 0); test_columns(illegal, 0); test_subs(illegal, 0); test_whole(illegal, 0); copy_row(illegal, 0, row); test_row_legality(row, 0); copy_column(illegal, 0, column); test_column_legality(column, 0); copy_sub(illegal, 0, 0, sub); test_sub_legality(sub, 0); test_legality(illegal, 0); puts("Presolved tests"); test_rows(solved, 1); test_columns(solved, 1); test_subs(solved, 1); test_whole(solved, 1); solve(unsolved); puts("Solved tests"); test_rows(unsolved, 1); test_columns(unsolved, 1); test_subs(unsolved, 1); test_whole(unsolved, 1); print_test_results(); }