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
|
/*
* Drizzle Client & Protocol Library
*
* Copyright (C) 2008 Eric Day (eday@oddments.org)
* All rights reserved.
*
* Use and distribution licensed under the BSD license. See
* the COPYING file in this directory for full text.
*/
/**
* @file
* @brief drizzle_con_st tests
*/
#include <libdrizzle-1.0/t/common.h>
#include <assert.h>
#include <unistd.h>
#define DRIZZLE_TEST_PORT 12399
int main(void)
{
close(STDOUT_FILENO);
drizzle_st *drizzle;
drizzle_con_st *con;
drizzle_con_st con_buffer;
drizzle_con_st *clone;
drizzle_return_t ret;
printf("sizeof(drizzle_con_st) = %zu\n", sizeof(drizzle_con_st));
printf("sizeof(drizzle_con_tcp_st) = %zu\n", sizeof(drizzle_con_tcp_st));
printf("sizeof(drizzle_con_uds_st) = %zu\n", sizeof(drizzle_con_uds_st));
printf("sizeof(drizzle_con_options_t) = %zu\n",
sizeof(drizzle_con_options_t));
printf("sizeof(drizzle_con_socket_t) = %zu\n", sizeof(drizzle_con_socket_t));
printf("sizeof(drizzle_con_status_t) = %zu\n", sizeof(drizzle_con_status_t));
printf("sizeof(drizzle_capabilities_t) = %zu\n",
sizeof(drizzle_capabilities_t));
drizzle_test("drizzle_create");
if ((drizzle= drizzle_create(NULL)) == NULL)
drizzle_test_error("returned NULL");
drizzle_test("drizzle_con_create buffer");
if ((con= drizzle_con_create(drizzle, &con_buffer)) == NULL)
drizzle_test_error("returned NULL");
drizzle_con_free(con);
drizzle_test("drizzle_con_create");
if ((con= drizzle_con_create(drizzle, NULL)) == NULL)
drizzle_test_error("returned NULL");
drizzle_test("drizzle_con_clone");
if ((clone= drizzle_con_clone(drizzle, NULL, con)) == NULL)
drizzle_test_error("returned NULL");
drizzle_con_free(clone);
drizzle_test("drizzle_con_options");
if (drizzle_con_options(con) != (DRIZZLE_CON_ALLOCATED | DRIZZLE_CON_MYSQL))
drizzle_test_error("drizzle_con_options");
drizzle_test("drizzle_con_add_options");
drizzle_con_add_options(con, DRIZZLE_CON_EXPERIMENTAL);
if (drizzle_con_options(con) != (DRIZZLE_CON_ALLOCATED | DRIZZLE_CON_EXPERIMENTAL))
drizzle_test_error("drizzle_con_options");
drizzle_test("drizzle_con_set_tcp");
drizzle_con_set_tcp(con, "localhost", 1);
drizzle_test("drizzle_con_host");
if (strcmp(drizzle_con_host(con), "localhost"))
drizzle_test_error("expected host not set");
drizzle_test("drizzle_con_port");
if (drizzle_con_port(con) != 1)
drizzle_test_error("expected port not set");
drizzle_test("drizzle_con_fd");
if (drizzle_con_fd(con) != -1)
drizzle_test_error("drizzle_con_fd != -1 for a new connection");
drizzle_test("drizzle_con_connect");
ret= drizzle_con_connect(con);
if (ret != DRIZZLE_RETURN_COULD_NOT_CONNECT)
drizzle_test_error("expected COULD_NOT_CONNECT, got: %s\n", drizzle_error(drizzle));
if (drizzle_con_fd(con) != -1)
drizzle_test_error("drizzle_con_fd != -1 for unconnected connection");
drizzle_test("drizzle_con_listen");
drizzle_con_set_tcp(con, "localhost", DRIZZLE_TEST_PORT);
ret = drizzle_con_listen(con);
if (ret != DRIZZLE_RETURN_OK)
drizzle_test_error("drizzle_con_listen: %s", drizzle_error(drizzle));
if (drizzle_con_fd(con) <= 0)
drizzle_test_error("drizzle_con_fd <= 0 for a listening connection");
drizzle_test("drizzle_con_free");
drizzle_con_free(con);
drizzle_test("drizzle_con_clone with uds");
con= drizzle_con_create(drizzle, NULL);
assert(con != NULL);
drizzle_con_set_uds(con, "/dev/null");
clone= drizzle_con_clone(drizzle, NULL, con);
if (clone == NULL)
drizzle_test_error("drizzle_con_clone uds: %s", drizzle_error(drizzle));
drizzle_con_free(clone);
drizzle_con_free(con);
drizzle_test("drizzle_free");
drizzle_free(drizzle);
return 0;
}
|