-
Notifications
You must be signed in to change notification settings - Fork 72
/
blocking_test.c
160 lines (118 loc) · 3.86 KB
/
blocking_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "test.h"
#include "trilogy/blocking.h"
#include "trilogy/error.h"
#define connect_conn(CONN) \
do { \
int err = trilogy_init(CONN); \
ASSERT_OK(err); \
err = trilogy_connect((CONN), get_connopt()); \
ASSERT_OK(err); \
} while (0)
TEST test_blocking_connect()
{
trilogy_conn_t conn;
connect_conn(&conn);
int err = trilogy_close(&conn);
ASSERT_OK(err);
trilogy_free(&conn);
PASS();
}
TEST test_blocking_change_db()
{
trilogy_conn_t conn;
connect_conn(&conn);
const char *db = "test";
int err = trilogy_change_db(&conn, db, strlen(db));
ASSERT_OK(err);
err = trilogy_close(&conn);
ASSERT_OK(err);
trilogy_free(&conn);
PASS();
}
TEST test_blocking_ping()
{
trilogy_conn_t conn;
connect_conn(&conn);
int err = trilogy_ping(&conn);
ASSERT_OK(err);
err = trilogy_close(&conn);
ASSERT_OK(err);
trilogy_free(&conn);
PASS();
}
TEST test_blocking_query()
{
trilogy_conn_t conn;
connect_conn(&conn);
const char *query = "SELECT 1";
uint64_t column_count;
int err = trilogy_query(&conn, query, strlen(query), &column_count);
ASSERT_ERR(TRILOGY_HAVE_RESULTS, err);
ASSERT_EQ(1, column_count);
trilogy_column_t column;
err = trilogy_read_full_column(&conn, &column);
ASSERT_OK(err);
ASSERT_MEM_EQ(column.catalog, "def", column.catalog_len);
ASSERT_EQ(0, column.schema_len);
ASSERT_EQ(0, column.table_len);
ASSERT_EQ(0, column.original_table_len);
ASSERT_MEM_EQ(column.name, "1", column.name_len);
ASSERT_EQ(0, column.original_name_len);
ASSERT_EQ(TRILOGY_CHARSET_BINARY, column.charset);
ASSERT(column.len == 1 || column.len == 2);
ASSERT(column.type == TRILOGY_TYPE_LONGLONG || column.type == TRILOGY_TYPE_LONG);
ASSERT(column.flags & TRILOGY_COLUMN_FLAG_BINARY);
ASSERT(column.flags & TRILOGY_COLUMN_FLAG_NOT_NULL);
ASSERT_EQ(0, column.decimals);
ASSERT_EQ(0, column.default_value_len);
trilogy_value_t row;
err = trilogy_read_full_row(&conn, &row);
ASSERT_OK(err);
ASSERT_MEM_EQ(row.data, "1", row.data_len);
err = trilogy_read_full_row(&conn, &row);
ASSERT_ERR(TRILOGY_EOF, err);
err = trilogy_close(&conn);
ASSERT_OK(err);
trilogy_free(&conn);
PASS();
}
TEST test_blocking_query_error()
{
trilogy_conn_t conn;
connect_conn(&conn);
const char *query = "BAD SYNTAX";
uint64_t column_count;
int err = trilogy_query(&conn, query, strlen(query), &column_count);
ASSERT_ERR(TRILOGY_ERR, err);
ASSERT(conn.error_message_len > 0);
err = trilogy_close(&conn);
ASSERT_OK(err);
trilogy_free(&conn);
PASS();
}
TEST test_blocking_query_no_rows()
{
trilogy_conn_t conn;
connect_conn(&conn);
const char *query = "set @myvar = 1";
uint64_t column_count;
int err = trilogy_query(&conn, query, strlen(query), &column_count);
ASSERT_OK(err);
err = trilogy_close(&conn);
ASSERT_OK(err);
trilogy_free(&conn);
PASS();
}
int blocking_test()
{
RUN_TEST(test_blocking_connect);
RUN_TEST(test_blocking_change_db);
RUN_TEST(test_blocking_ping);
RUN_TEST(test_blocking_query);
RUN_TEST(test_blocking_query_error);
RUN_TEST(test_blocking_query_no_rows);
return 0;
}