~drizzle-trunk/libdrizzle/jenkins-Libdrizzle-78

« back to all changes in this revision

Viewing changes to test/drizzle_con_st.c

  • Committer: Andrew Hutchings
  • Date: 2012-09-03 18:38:34 UTC
  • Revision ID: git-v1:e936672f2f2e4af2b54de08ebf06d53ca1dc6872
The "it compiles!" version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Drizzle Client & Protocol Library
 
3
 *
 
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
 
5
 * All rights reserved.
 
6
 *
 
7
 * 
 
8
 * Redistribution and use in source and binary forms, with or without
 
9
 * modification, are permitted provided that the following conditions are
 
10
 * met:
 
11
 * 
 
12
 *     * Redistributions of source code must retain the above copyright
 
13
 * notice, this list of conditions and the following disclaimer.
 
14
 * 
 
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
 
18
 * distribution.
 
19
 * 
 
20
 *     * The names of its contributors may not be used to endorse or
 
21
 * promote products derived from this software without specific prior
 
22
 * written permission.
 
23
 * 
 
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.
 
35
 */
 
36
 
 
37
/**
 
38
 * @file
 
39
 * @brief drizzle_con_st tests
 
40
 */
 
41
 
 
42
#include <libdrizzle-1.0/t/common.h>
 
43
 
 
44
#include <assert.h>
 
45
#include <unistd.h>
 
46
 
 
47
#define DRIZZLE_TEST_PORT 12399
 
48
 
 
49
int main(void)
 
50
{
 
51
  close(STDOUT_FILENO);
 
52
 
 
53
  printf("sizeof(drizzle_con_st) = %zu\n", sizeof(drizzle_con_st));
 
54
  printf("sizeof(drizzle_con_tcp_st) = %zu\n", sizeof(drizzle_con_tcp_st));
 
55
  printf("sizeof(drizzle_con_uds_st) = %zu\n", sizeof(drizzle_con_uds_st));
 
56
  printf("sizeof(drizzle_con_options_t) = %zu\n",
 
57
         sizeof(drizzle_con_options_t));
 
58
  printf("sizeof(drizzle_con_socket_t) = %zu\n", sizeof(drizzle_con_socket_t));
 
59
  printf("sizeof(drizzle_con_status_t) = %zu\n", sizeof(drizzle_con_status_t));
 
60
  printf("sizeof(drizzle_capabilities_t) = %zu\n",
 
61
         sizeof(drizzle_capabilities_t));
 
62
 
 
63
  drizzle_st *drizzle;
 
64
  drizzle_test("drizzle_create");
 
65
  if ((drizzle= drizzle_create(NULL)) == NULL)
 
66
  {
 
67
    drizzle_test_error("returned NULL");
 
68
  }
 
69
 
 
70
  drizzle_con_st con_buffer;
 
71
  drizzle_con_st *con;
 
72
  drizzle_test("drizzle_con_create buffer");
 
73
  if ((con= drizzle_con_create(drizzle, &con_buffer)) == NULL)
 
74
  {
 
75
    drizzle_test_error("returned NULL");
 
76
  }
 
77
  drizzle_con_free(con);
 
78
 
 
79
  drizzle_test("drizzle_con_create");
 
80
  if ((con= drizzle_con_create(drizzle, NULL)) == NULL)
 
81
  {
 
82
    drizzle_test_error("returned NULL");
 
83
  }
 
84
 
 
85
  drizzle_con_st *clone;
 
86
  drizzle_test("drizzle_con_clone");
 
87
  if ((clone= drizzle_con_clone(drizzle, NULL, con)) == NULL)
 
88
  {
 
89
    drizzle_test_error("returned NULL");
 
90
  }
 
91
  drizzle_con_free(clone);
 
92
 
 
93
  drizzle_test("drizzle_con_options");
 
94
  if (drizzle_con_options(con) != (DRIZZLE_CON_ALLOCATED | DRIZZLE_CON_MYSQL))
 
95
  {
 
96
    drizzle_test_error("drizzle_con_options");
 
97
  }
 
98
 
 
99
  drizzle_test("drizzle_con_add_options");
 
100
  drizzle_con_add_options(con, DRIZZLE_CON_EXPERIMENTAL);
 
101
  if (drizzle_con_options(con) != (DRIZZLE_CON_ALLOCATED | DRIZZLE_CON_EXPERIMENTAL))
 
102
  {
 
103
    drizzle_test_error("drizzle_con_options");
 
104
  }
 
105
 
 
106
  drizzle_test("drizzle_con_set_tcp");
 
107
  drizzle_con_set_tcp(con, "localhost", 1);
 
108
 
 
109
  drizzle_test("drizzle_con_host");
 
110
  if (strcmp(drizzle_con_host(con), "localhost"))
 
111
  {
 
112
    drizzle_test_error("expected host not set");
 
113
  }
 
114
 
 
115
  drizzle_test("drizzle_con_port");
 
116
  if (drizzle_con_port(con) != 1)
 
117
  {
 
118
    drizzle_test_error("expected port not set");
 
119
  }
 
120
 
 
121
  drizzle_test("drizzle_con_fd");
 
122
  if (drizzle_con_fd(con) != -1) 
 
123
  {
 
124
    drizzle_test_error("drizzle_con_fd != -1 for a new connection");
 
125
  }
 
126
 
 
127
  drizzle_test("drizzle_con_connect");
 
128
  drizzle_return_t ret= drizzle_con_connect(con);
 
129
  if (ret != DRIZZLE_RETURN_COULD_NOT_CONNECT) 
 
130
  {
 
131
    drizzle_test_error("expected COULD_NOT_CONNECT, got: %s\n", drizzle_error(drizzle));
 
132
  }
 
133
 
 
134
  if (drizzle_con_fd(con) != -1)
 
135
  {
 
136
    drizzle_test_error("drizzle_con_fd != -1 for unconnected connection");
 
137
  }
 
138
 
 
139
  drizzle_test("drizzle_con_listen");
 
140
  drizzle_con_set_tcp(con, "localhost", DRIZZLE_TEST_PORT);
 
141
  ret = drizzle_con_listen(con);
 
142
  if (ret != DRIZZLE_RETURN_OK) 
 
143
  {
 
144
    drizzle_test_error("drizzle_con_listen: %s", drizzle_error(drizzle));
 
145
  }
 
146
 
 
147
  if (drizzle_con_fd(con) <= 0)
 
148
  {
 
149
    drizzle_test_error("drizzle_con_fd <= 0 for a listening connection");
 
150
  }
 
151
 
 
152
  drizzle_test("drizzle_con_free");
 
153
  drizzle_con_free(con);
 
154
 
 
155
  drizzle_test("drizzle_con_clone with uds");
 
156
  con= drizzle_con_create(drizzle, NULL);
 
157
  assert(con != NULL);
 
158
  drizzle_con_set_uds(con, "/dev/null");
 
159
  clone= drizzle_con_clone(drizzle, NULL, con);
 
160
  if (clone == NULL) 
 
161
  {
 
162
    drizzle_test_error("drizzle_con_clone uds: %s", drizzle_error(drizzle));
 
163
  }
 
164
  drizzle_con_free(clone);
 
165
  drizzle_con_free(con);
 
166
  
 
167
  drizzle_test("drizzle_free");
 
168
  drizzle_free(drizzle);
 
169
 
 
170
  return 0;
 
171
}