Line | Branch | Exec | Source |
---|---|---|---|
1 | #include "gate/tests.h" | ||
2 | #include "test_sqlite.h" | ||
3 | #include "gate/streams.h" | ||
4 | #include "gate/data/sqlite3_adapter.h" | ||
5 | |||
6 | |||
7 | 1 | static gate_bool_t test_sqlite_create_table(gate_data_connection_t* db) | |
8 | { | ||
9 | gate_result_t result; | ||
10 | 1 | gate_int32_t affected_rows = 0; | |
11 | 1 | gate_data_statement_t* ptr_statement = NULL; | |
12 | 1 | gate_data_reader_t* ptr_reader = NULL; | |
13 | 1 | gate_type_id_t field_type_id = 0; | |
14 | 1 | gate_string_t field_value = GATE_STRING_INIT_EMPTY; | |
15 | 1 | gate_value_t const* ptr_value = NULL; | |
16 | 1 | gate_bool_t b = false; | |
17 | |||
18 | static gate_string_t const sql_create_tbl = GATE_STRING_INIT_STATIC( | ||
19 | "CREATE TABLE IF NOT EXISTS unit_test_tbl (id INTEGER PRIMARY KEY, my_data TEXT);" | ||
20 | ); | ||
21 | static gate_string_t const sql_list_tables = GATE_STRING_INIT_STATIC( | ||
22 | "SELECT name FROM sqlite_schema WHERE type='table' AND name='unit_test_tbl';" | ||
23 | ); | ||
24 | |||
25 | { | ||
26 | /* create table */ | ||
27 | 1 | result = gate_data_connection_create_statement(db, &sql_create_tbl, &ptr_statement); | |
28 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE_OK(result); |
29 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_statement != NULL); |
30 | |||
31 | 1 | result = gate_data_statement_execute(ptr_statement, &affected_rows); | |
32 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE_OK(result); |
33 | |||
34 | 1 | gate_object_release(ptr_statement); | |
35 | 1 | ptr_statement = NULL; | |
36 | } | ||
37 | |||
38 | { | ||
39 | /* query if table exists */ | ||
40 | 1 | result = gate_data_connection_create_statement(db, &sql_list_tables, &ptr_statement); | |
41 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE_OK(result); |
42 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_statement != NULL); |
43 | |||
44 | 1 | result = gate_data_statement_query(ptr_statement, &ptr_reader); | |
45 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE_OK(result); |
46 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE_NOT_EQUAL(ptr_reader, NULL); |
47 | |||
48 | 1 | result = gate_data_reader_next(ptr_reader); | |
49 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_OK(result); |
50 | |||
51 | 1 | result = gate_data_reader_get_field_type(ptr_reader, 0, &field_type_id); | |
52 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_OK(result); |
53 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(field_type_id, GATE_TYPE_STRING); |
54 | |||
55 | 1 | result = gate_data_reader_get_field_value(ptr_reader, 0, &ptr_value); | |
56 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_OK(result); |
57 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_NOT_EQUAL(ptr_value, NULL); |
58 | |||
59 | 1 | result = gate_value_get(ptr_value, &field_value, sizeof(field_value)); | |
60 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_OK(result); |
61 | |||
62 | 1 | b = gate_string_equals_str(&field_value, "unit_test_tbl"); | |
63 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(b, true); |
64 | |||
65 | 1 | result = gate_data_reader_next(ptr_reader); | |
66 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_NOT_EQUAL(result, GATE_RESULT_OK); |
67 | |||
68 | 1 | result = gate_data_reader_close(ptr_reader); | |
69 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_OK(result); |
70 | |||
71 | 1 | gate_object_release(ptr_reader); | |
72 | 1 | gate_object_release(ptr_statement); | |
73 | } | ||
74 | |||
75 | 1 | return true; | |
76 | } | ||
77 | |||
78 | 1 | GATE_TEST_FUNCTION(test_sqlite) | |
79 | { | ||
80 | gate_result_t result; | ||
81 | 1 | gate_data_connection_t* ptr_conn = NULL; | |
82 | gate_bool_t succeeded; | ||
83 | |||
84 | 1 | GATE_TEST_UNIT_BEGIN(test_sqlite); | |
85 | |||
86 | 1 | result = gate_data_adapter_sqlite3_create(NULL, GATE_DATA_SQLITE3_FLAG_INMEMORY, &ptr_conn); | |
87 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE_OK(result); |
88 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE_NOT_EQUAL(ptr_conn, NULL); |
89 | |||
90 | 1 | succeeded = test_sqlite_create_table(ptr_conn); | |
91 | |||
92 | 1 | gate_object_release(ptr_conn); | |
93 | |||
94 | 1 | GATE_TEST_UNIT_END; | |
95 | } | ||
96 |