2
* Drizzle Client & Protocol Library
4
* Copyright (C) 2008 Eric Day (eday@oddments.org)
7
* Use and distribution licensed under the BSD license. See
8
* the COPYING file in this directory for full text.
13
* @brief drizzle_con_st tests
16
#include <libdrizzle-1.0/t/common.h>
21
#define DRIZZLE_TEST_PORT 12399
29
drizzle_con_st con_buffer;
30
drizzle_con_st *clone;
33
printf("sizeof(drizzle_con_st) = %zu\n", sizeof(drizzle_con_st));
34
printf("sizeof(drizzle_con_tcp_st) = %zu\n", sizeof(drizzle_con_tcp_st));
35
printf("sizeof(drizzle_con_uds_st) = %zu\n", sizeof(drizzle_con_uds_st));
36
printf("sizeof(drizzle_con_options_t) = %zu\n",
37
sizeof(drizzle_con_options_t));
38
printf("sizeof(drizzle_con_socket_t) = %zu\n", sizeof(drizzle_con_socket_t));
39
printf("sizeof(drizzle_con_status_t) = %zu\n", sizeof(drizzle_con_status_t));
40
printf("sizeof(drizzle_capabilities_t) = %zu\n",
41
sizeof(drizzle_capabilities_t));
43
drizzle_test("drizzle_create");
44
if ((drizzle= drizzle_create(NULL)) == NULL)
45
drizzle_test_error("returned NULL");
47
drizzle_test("drizzle_con_create buffer");
48
if ((con= drizzle_con_create(drizzle, &con_buffer)) == NULL)
49
drizzle_test_error("returned NULL");
50
drizzle_con_free(con);
52
drizzle_test("drizzle_con_create");
53
if ((con= drizzle_con_create(drizzle, NULL)) == NULL)
54
drizzle_test_error("returned NULL");
56
drizzle_test("drizzle_con_clone");
57
if ((clone= drizzle_con_clone(drizzle, NULL, con)) == NULL)
58
drizzle_test_error("returned NULL");
59
drizzle_con_free(clone);
61
drizzle_test("drizzle_con_options");
62
if (drizzle_con_options(con) != (DRIZZLE_CON_ALLOCATED | DRIZZLE_CON_MYSQL))
63
drizzle_test_error("drizzle_con_options");
65
drizzle_test("drizzle_con_add_options");
66
drizzle_con_add_options(con, DRIZZLE_CON_EXPERIMENTAL);
67
if (drizzle_con_options(con) != (DRIZZLE_CON_ALLOCATED | DRIZZLE_CON_EXPERIMENTAL))
68
drizzle_test_error("drizzle_con_options");
70
drizzle_test("drizzle_con_set_tcp");
71
drizzle_con_set_tcp(con, "localhost", 1);
73
drizzle_test("drizzle_con_host");
74
if (strcmp(drizzle_con_host(con), "localhost"))
75
drizzle_test_error("expected host not set");
77
drizzle_test("drizzle_con_port");
78
if (drizzle_con_port(con) != 1)
79
drizzle_test_error("expected port not set");
81
drizzle_test("drizzle_con_fd");
82
if (drizzle_con_fd(con) != -1)
83
drizzle_test_error("drizzle_con_fd != -1 for a new connection");
85
drizzle_test("drizzle_con_connect");
86
ret= drizzle_con_connect(con);
87
if (ret != DRIZZLE_RETURN_COULD_NOT_CONNECT)
88
drizzle_test_error("expected COULD_NOT_CONNECT, got: %s\n", drizzle_error(drizzle));
90
if (drizzle_con_fd(con) != -1)
91
drizzle_test_error("drizzle_con_fd != -1 for unconnected connection");
93
drizzle_test("drizzle_con_listen");
94
drizzle_con_set_tcp(con, "localhost", DRIZZLE_TEST_PORT);
95
ret = drizzle_con_listen(con);
96
if (ret != DRIZZLE_RETURN_OK)
97
drizzle_test_error("drizzle_con_listen: %s", drizzle_error(drizzle));
99
if (drizzle_con_fd(con) <= 0)
100
drizzle_test_error("drizzle_con_fd <= 0 for a listening connection");
102
drizzle_test("drizzle_con_free");
103
drizzle_con_free(con);
105
drizzle_test("drizzle_con_clone with uds");
106
con= drizzle_con_create(drizzle, NULL);
108
drizzle_con_set_uds(con, "/dev/null");
109
clone= drizzle_con_clone(drizzle, NULL, con);
111
drizzle_test_error("drizzle_con_clone uds: %s", drizzle_error(drizzle));
112
drizzle_con_free(clone);
113
drizzle_con_free(con);
115
drizzle_test("drizzle_free");
116
drizzle_free(drizzle);