2
* Drizzle Client & Protocol Library
4
* Copyright (C) 2008 Eric Day (eday@oddments.org)
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions are
12
* * Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
15
* * Redistributions in binary form must reproduce the above
16
* copyright notice, this list of conditions and the following disclaimer
17
* in the documentation and/or other materials provided with the
20
* * The names of its contributors may not be used to endorse or
21
* promote products derived from this software without specific prior
24
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
* @brief drizzle_con_st tests
42
#include <libdrizzle-1.0/t/common.h>
47
#define DRIZZLE_TEST_PORT 12399
55
drizzle_con_st con_buffer;
56
drizzle_con_st *clone;
59
printf("sizeof(drizzle_con_st) = %zu\n", sizeof(drizzle_con_st));
60
printf("sizeof(drizzle_con_tcp_st) = %zu\n", sizeof(drizzle_con_tcp_st));
61
printf("sizeof(drizzle_con_uds_st) = %zu\n", sizeof(drizzle_con_uds_st));
62
printf("sizeof(drizzle_con_options_t) = %zu\n",
63
sizeof(drizzle_con_options_t));
64
printf("sizeof(drizzle_con_socket_t) = %zu\n", sizeof(drizzle_con_socket_t));
65
printf("sizeof(drizzle_con_status_t) = %zu\n", sizeof(drizzle_con_status_t));
66
printf("sizeof(drizzle_capabilities_t) = %zu\n",
67
sizeof(drizzle_capabilities_t));
69
drizzle_test("drizzle_create");
70
if ((drizzle= drizzle_create(NULL)) == NULL)
71
drizzle_test_error("returned NULL");
73
drizzle_test("drizzle_con_create buffer");
74
if ((con= drizzle_con_create(drizzle, &con_buffer)) == NULL)
75
drizzle_test_error("returned NULL");
76
drizzle_con_free(con);
78
drizzle_test("drizzle_con_create");
79
if ((con= drizzle_con_create(drizzle, NULL)) == NULL)
80
drizzle_test_error("returned NULL");
82
drizzle_test("drizzle_con_clone");
83
if ((clone= drizzle_con_clone(drizzle, NULL, con)) == NULL)
84
drizzle_test_error("returned NULL");
85
drizzle_con_free(clone);
87
drizzle_test("drizzle_con_options");
88
if (drizzle_con_options(con) != (DRIZZLE_CON_ALLOCATED | DRIZZLE_CON_MYSQL))
89
drizzle_test_error("drizzle_con_options");
91
drizzle_test("drizzle_con_add_options");
92
drizzle_con_add_options(con, DRIZZLE_CON_EXPERIMENTAL);
93
if (drizzle_con_options(con) != (DRIZZLE_CON_ALLOCATED | DRIZZLE_CON_EXPERIMENTAL))
94
drizzle_test_error("drizzle_con_options");
96
drizzle_test("drizzle_con_set_tcp");
97
drizzle_con_set_tcp(con, "localhost", 1);
99
drizzle_test("drizzle_con_host");
100
if (strcmp(drizzle_con_host(con), "localhost"))
101
drizzle_test_error("expected host not set");
103
drizzle_test("drizzle_con_port");
104
if (drizzle_con_port(con) != 1)
105
drizzle_test_error("expected port not set");
107
drizzle_test("drizzle_con_fd");
108
if (drizzle_con_fd(con) != -1)
109
drizzle_test_error("drizzle_con_fd != -1 for a new connection");
111
drizzle_test("drizzle_con_connect");
112
ret= drizzle_con_connect(con);
113
if (ret != DRIZZLE_RETURN_COULD_NOT_CONNECT)
114
drizzle_test_error("expected COULD_NOT_CONNECT, got: %s\n", drizzle_error(drizzle));
116
if (drizzle_con_fd(con) != -1)
117
drizzle_test_error("drizzle_con_fd != -1 for unconnected connection");
119
drizzle_test("drizzle_con_listen");
120
drizzle_con_set_tcp(con, "localhost", DRIZZLE_TEST_PORT);
121
ret = drizzle_con_listen(con);
122
if (ret != DRIZZLE_RETURN_OK)
123
drizzle_test_error("drizzle_con_listen: %s", drizzle_error(drizzle));
125
if (drizzle_con_fd(con) <= 0)
126
drizzle_test_error("drizzle_con_fd <= 0 for a listening connection");
128
drizzle_test("drizzle_con_free");
129
drizzle_con_free(con);
131
drizzle_test("drizzle_con_clone with uds");
132
con= drizzle_con_create(drizzle, NULL);
134
drizzle_con_set_uds(con, "/dev/null");
135
clone= drizzle_con_clone(drizzle, NULL, con);
137
drizzle_test_error("drizzle_con_clone uds: %s", drizzle_error(drizzle));
138
drizzle_con_free(clone);
139
drizzle_con_free(con);
141
drizzle_test("drizzle_free");
142
drizzle_free(drizzle);