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
18
#include "tests/common.h"
20
#define DRIZZLE_TEST_PORT 12399
26
drizzle_con_st con_buffer;
27
drizzle_con_st *clone;
30
printf("sizeof(drizzle_con_st) = %zu\n", sizeof(drizzle_con_st));
31
printf("sizeof(drizzle_con_tcp_st) = %zu\n", sizeof(drizzle_con_tcp_st));
32
printf("sizeof(drizzle_con_uds_st) = %zu\n", sizeof(drizzle_con_uds_st));
33
printf("sizeof(drizzle_con_options_t) = %zu\n",
34
sizeof(drizzle_con_options_t));
35
printf("sizeof(drizzle_con_socket_t) = %zu\n", sizeof(drizzle_con_socket_t));
36
printf("sizeof(drizzle_con_status_t) = %zu\n", sizeof(drizzle_con_status_t));
37
printf("sizeof(drizzle_capabilities_t) = %zu\n",
38
sizeof(drizzle_capabilities_t));
40
drizzle_test("drizzle_create");
41
if ((drizzle= drizzle_create(NULL)) == NULL)
42
drizzle_test_error("returned NULL");
44
drizzle_test("drizzle_con_create buffer");
45
if ((con= drizzle_con_create(drizzle, &con_buffer)) == NULL)
46
drizzle_test_error("returned NULL");
47
drizzle_con_free(con);
49
drizzle_test("drizzle_con_create");
50
if ((con= drizzle_con_create(drizzle, NULL)) == NULL)
51
drizzle_test_error("returned NULL");
53
drizzle_test("drizzle_con_clone");
54
if ((clone= drizzle_con_clone(drizzle, NULL, con)) == NULL)
55
drizzle_test_error("returned NULL");
56
drizzle_con_free(clone);
58
drizzle_test("drizzle_con_options");
59
if (drizzle_con_options(con) != (DRIZZLE_CON_ALLOCATED | DRIZZLE_CON_MYSQL))
60
drizzle_test_error("drizzle_con_options");
62
drizzle_test("drizzle_con_add_options");
63
drizzle_con_add_options(con, DRIZZLE_CON_EXPERIMENTAL);
64
if (drizzle_con_options(con) != (DRIZZLE_CON_ALLOCATED | DRIZZLE_CON_EXPERIMENTAL))
65
drizzle_test_error("drizzle_con_options");
67
drizzle_test("drizzle_con_set_tcp");
68
drizzle_con_set_tcp(con, "127.0.0.1", 1);
70
drizzle_test("drizzle_con_host");
71
if (strcmp(drizzle_con_host(con), "127.0.0.1"))
72
drizzle_test_error("expected host not set");
74
drizzle_test("drizzle_con_port");
75
if (drizzle_con_port(con) != 1)
76
drizzle_test_error("expected port not set");
78
drizzle_test("drizzle_con_fd");
79
if (drizzle_con_fd(con) != -1)
80
drizzle_test_error("drizzle_con_fd != -1 for a new connection");
82
drizzle_test("drizzle_con_connect");
83
ret= drizzle_con_connect(con);
84
if (ret != DRIZZLE_RETURN_COULD_NOT_CONNECT)
85
drizzle_test_error("expected COULD_NOT_CONNECT, got: %s\n", drizzle_error(drizzle));
87
if (drizzle_con_fd(con) != -1)
88
drizzle_test_error("drizzle_con_fd != -1 for unconnected connection");
90
drizzle_test("drizzle_con_listen");
91
drizzle_con_set_tcp(con, "127.0.0.1", DRIZZLE_TEST_PORT);
92
ret = drizzle_con_listen(con);
93
if (ret != DRIZZLE_RETURN_OK)
94
drizzle_test_error("drizzle_con_listen: %s", drizzle_error(drizzle));
96
if (drizzle_con_fd(con) <= 0)
97
drizzle_test_error("drizzle_con_fd <= 0 for a listening connection");
99
drizzle_test("drizzle_con_free");
100
drizzle_con_free(con);
102
drizzle_test("drizzle_con_clone with uds");
103
con= drizzle_con_create(drizzle, NULL);
105
drizzle_con_set_uds(con, "/dev/null");
106
clone= drizzle_con_clone(drizzle, NULL, con);
108
drizzle_test_error("drizzle_con_clone uds: %s", drizzle_error(drizzle));
109
drizzle_con_free(clone);
110
drizzle_con_free(con);
112
drizzle_test("drizzle_free");
113
drizzle_free(drizzle);