~clint-fewbar/drizzle/regex-policy-cache-limiter

« back to all changes in this revision

Viewing changes to libdrizzle-1.0/t/drizzle_con_st.c

  • Committer: Clint Byrum
  • Date: 2012-03-15 18:05:43 UTC
  • mfrom: (2224.1.302 workspace)
  • Revision ID: clint@ubuntu.com-20120315180543-9jxxm4q10k3np2ws
merging with latest trunk

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
  drizzle_st *drizzle;
 
54
  drizzle_con_st *con;
 
55
  drizzle_con_st con_buffer;
 
56
  drizzle_con_st *clone;
 
57
  drizzle_return_t ret;
 
58
 
 
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));
 
68
 
 
69
  drizzle_test("drizzle_create");
 
70
  if ((drizzle= drizzle_create(NULL)) == NULL)
 
71
    drizzle_test_error("returned NULL");
 
72
 
 
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);
 
77
 
 
78
  drizzle_test("drizzle_con_create");
 
79
  if ((con= drizzle_con_create(drizzle, NULL)) == NULL)
 
80
    drizzle_test_error("returned NULL");
 
81
 
 
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);
 
86
 
 
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");
 
90
 
 
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");
 
95
 
 
96
  drizzle_test("drizzle_con_set_tcp");
 
97
  drizzle_con_set_tcp(con, "localhost", 1);
 
98
 
 
99
  drizzle_test("drizzle_con_host");
 
100
  if (strcmp(drizzle_con_host(con), "localhost"))
 
101
    drizzle_test_error("expected host not set");
 
102
 
 
103
  drizzle_test("drizzle_con_port");
 
104
  if (drizzle_con_port(con) != 1)
 
105
    drizzle_test_error("expected port not set");
 
106
 
 
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");
 
110
 
 
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));
 
115
 
 
116
  if (drizzle_con_fd(con) != -1)
 
117
    drizzle_test_error("drizzle_con_fd != -1 for unconnected connection");
 
118
 
 
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));
 
124
 
 
125
  if (drizzle_con_fd(con) <= 0)
 
126
    drizzle_test_error("drizzle_con_fd <= 0 for a listening connection");
 
127
 
 
128
  drizzle_test("drizzle_con_free");
 
129
  drizzle_con_free(con);
 
130
 
 
131
  drizzle_test("drizzle_con_clone with uds");
 
132
  con= drizzle_con_create(drizzle, NULL);
 
133
  assert(con != NULL);
 
134
  drizzle_con_set_uds(con, "/dev/null");
 
135
  clone= drizzle_con_clone(drizzle, NULL, con);
 
136
  if (clone == NULL) 
 
137
    drizzle_test_error("drizzle_con_clone uds: %s", drizzle_error(drizzle));
 
138
  drizzle_con_free(clone);
 
139
  drizzle_con_free(con);
 
140
  
 
141
  drizzle_test("drizzle_free");
 
142
  drizzle_free(drizzle);
 
143
 
 
144
  return 0;
 
145
}