Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 20 | #include <netdb.h> |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 21 | #include <sys/wait.h> |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 22 | |
Roger Meier | e3da768 | 2013-01-11 11:41:53 +0100 | [diff] [blame] | 23 | #include <thrift/c_glib/transport/thrift_transport.h> |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 24 | #include <thrift/c_glib/transport/thrift_buffered_transport.h> |
Roger Meier | e3da768 | 2013-01-11 11:41:53 +0100 | [diff] [blame] | 25 | #include <thrift/c_glib/transport/thrift_server_transport.h> |
| 26 | #include <thrift/c_glib/transport/thrift_server_socket.h> |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 27 | |
| 28 | #define TEST_DATA { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' } |
| 29 | |
| 30 | /* substituted functions to test failures of system and library calls */ |
| 31 | static int socket_error = 0; |
| 32 | int |
| 33 | my_socket(int domain, int type, int protocol) |
| 34 | { |
| 35 | if (socket_error == 0) |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 36 | { |
| 37 | return socket (domain, type, protocol); |
| 38 | } |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 39 | return -1; |
| 40 | } |
| 41 | |
| 42 | static int recv_error = 0; |
| 43 | ssize_t |
| 44 | my_recv(int socket, void *buffer, size_t length, int flags) |
| 45 | { |
| 46 | if (recv_error == 0) |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 47 | { |
| 48 | return recv (socket, buffer, length, flags); |
| 49 | } |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 50 | return -1; |
| 51 | } |
| 52 | |
| 53 | static int send_error = 0; |
| 54 | ssize_t |
| 55 | my_send(int socket, const void *buffer, size_t length, int flags) |
| 56 | { |
| 57 | if (send_error == 0) |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 58 | { |
| 59 | return send (socket, buffer, length, flags); |
| 60 | } |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 61 | return -1; |
| 62 | } |
| 63 | |
| 64 | #define socket my_socket |
| 65 | #define recv my_recv |
| 66 | #define send my_send |
Roger Meier | e3da768 | 2013-01-11 11:41:53 +0100 | [diff] [blame] | 67 | #include "../src/thrift/c_glib/transport/thrift_socket.c" |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 68 | #undef socket |
| 69 | #undef recv |
| 70 | #undef send |
| 71 | |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 72 | static void thrift_socket_server (const int port); |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 73 | static void thrift_socket_server_open (const int port, int times); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 74 | /* test object creation and destruction */ |
| 75 | static void |
| 76 | test_create_and_destroy(void) |
| 77 | { |
| 78 | gchar *hostname = NULL; |
| 79 | guint port = 0; |
| 80 | |
| 81 | GObject *object = NULL; |
| 82 | object = g_object_new (THRIFT_TYPE_SOCKET, NULL); |
James E. King, III | 43f4bf2 | 2017-10-28 12:54:02 -0400 | [diff] [blame] | 83 | g_assert (object != NULL); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 84 | g_object_get (G_OBJECT(object), "hostname", &hostname, "port", &port, NULL); |
| 85 | g_free (hostname); |
| 86 | |
| 87 | g_object_unref (object); |
| 88 | } |
| 89 | |
| 90 | static void |
| 91 | test_open_and_close(void) |
| 92 | { |
| 93 | ThriftSocket *tsocket = NULL; |
| 94 | ThriftTransport *transport = NULL; |
| 95 | GError *err = NULL; |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 96 | int port = 51199; |
| 97 | pid_t pid; |
| 98 | int status; |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 99 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 100 | pid = fork (); |
| 101 | g_assert ( pid >= 0 ); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 102 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 103 | if ( pid == 0 ) |
| 104 | { |
| 105 | /* child listens */ |
| 106 | thrift_socket_server_open (port, 1); |
| 107 | exit (0); |
| 108 | } else { |
| 109 | /* parent connects, wait a bit for the socket to be created */ |
| 110 | sleep (1); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 111 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 112 | /* open a connection and close it */ |
| 113 | tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost", |
| 114 | "port", port, NULL); |
| 115 | transport = THRIFT_TRANSPORT (tsocket); |
| 116 | thrift_socket_open (transport, NULL); |
| 117 | g_assert (thrift_socket_is_open (transport) == TRUE); |
| 118 | thrift_socket_close (transport, NULL); |
| 119 | g_assert (thrift_socket_is_open (transport) == FALSE); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 120 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 121 | /* test close failure */ |
| 122 | tsocket->sd = -1; |
| 123 | thrift_socket_close (transport, NULL); |
| 124 | g_object_unref (tsocket); |
| 125 | |
| 126 | /* try a hostname lookup failure */ |
| 127 | tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost.broken", |
| 128 | NULL); |
| 129 | transport = THRIFT_TRANSPORT (tsocket); |
| 130 | g_assert (thrift_socket_open (transport, &err) == FALSE); |
| 131 | g_object_unref (tsocket); |
| 132 | g_error_free (err); |
| 133 | err = NULL; |
| 134 | |
| 135 | /* try an error call to socket() */ |
| 136 | tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost", NULL); |
| 137 | transport = THRIFT_TRANSPORT (tsocket); |
| 138 | socket_error = 1; |
| 139 | g_assert (thrift_socket_open (transport, &err) == FALSE); |
| 140 | socket_error = 0; |
| 141 | g_object_unref (tsocket); |
| 142 | g_error_free (err); |
| 143 | g_assert ( wait (&status) == pid ); |
| 144 | g_assert ( status == 0 ); |
| 145 | } |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | static void |
| 149 | test_read_and_write(void) |
| 150 | { |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 151 | ThriftSocket *tsocket = NULL; |
| 152 | ThriftTransport *transport = NULL; |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 153 | pid_t pid; |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 154 | int port = 51199; |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 155 | int status; |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 156 | guchar buf[10] = TEST_DATA; /* a buffer */ |
| 157 | |
| 158 | pid = fork (); |
James E. King, III | 43f4bf2 | 2017-10-28 12:54:02 -0400 | [diff] [blame] | 159 | g_assert ( pid >= 0 ); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 160 | |
| 161 | if ( pid == 0 ) |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 162 | { |
| 163 | /* child listens */ |
| 164 | thrift_socket_server (port); |
| 165 | exit (0); |
| 166 | } else { |
| 167 | /* parent connects, wait a bit for the socket to be created */ |
| 168 | sleep (1); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 169 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 170 | tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost", |
| 171 | "port", port, NULL); |
| 172 | transport = THRIFT_TRANSPORT (tsocket); |
| 173 | g_assert (thrift_socket_open (transport, NULL) == TRUE); |
| 174 | g_assert (thrift_socket_is_open (transport)); |
| 175 | thrift_socket_write (transport, buf, 10, NULL); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 176 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 177 | /* write fail */ |
| 178 | send_error = 1; |
| 179 | thrift_socket_write (transport, buf, 1, NULL); |
| 180 | send_error = 0; |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 181 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 182 | thrift_socket_write_end (transport, NULL); |
| 183 | thrift_socket_flush (transport, NULL); |
| 184 | thrift_socket_close (transport, NULL); |
| 185 | g_object_unref (tsocket); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 186 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 187 | g_assert ( wait (&status) == pid ); |
| 188 | g_assert ( status == 0 ); |
| 189 | } |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 192 | /* test ThriftSocket's peek() implementation */ |
| 193 | static void |
| 194 | test_peek(void) |
| 195 | { |
| 196 | gint status; |
| 197 | pid_t pid; |
| 198 | guint port = 51199; |
| 199 | gchar data = 'A'; |
| 200 | ThriftTransport *client_transport; |
| 201 | GError *error = NULL; |
| 202 | |
| 203 | client_transport = g_object_new (THRIFT_TYPE_SOCKET, |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 204 | "hostname", "localhost", |
| 205 | "port", port, |
| 206 | NULL); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 207 | |
| 208 | /* thrift_transport_peek returns FALSE when the socket is closed */ |
| 209 | g_assert (thrift_transport_is_open (client_transport) == FALSE); |
| 210 | g_assert (thrift_transport_peek (client_transport, &error) == FALSE); |
| 211 | g_assert (error == NULL); |
| 212 | |
| 213 | pid = fork (); |
| 214 | g_assert (pid >= 0); |
| 215 | |
| 216 | if (pid == 0) |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 217 | { |
| 218 | ThriftServerTransport *server_transport = NULL; |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 219 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 220 | g_object_unref (client_transport); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 221 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 222 | /* child listens */ |
| 223 | server_transport = g_object_new (THRIFT_TYPE_SERVER_SOCKET, |
| 224 | "port", port, |
| 225 | NULL); |
| 226 | g_assert (server_transport != NULL); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 227 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 228 | thrift_server_transport_listen (server_transport, &error); |
| 229 | g_assert (error == NULL); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 230 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 231 | client_transport = g_object_new |
| 232 | (THRIFT_TYPE_BUFFERED_TRANSPORT, |
| 233 | "transport", thrift_server_transport_accept (server_transport, &error), |
| 234 | "r_buf_size", 0, |
| 235 | "w_buf_size", sizeof data, |
| 236 | NULL); |
| 237 | g_assert (error == NULL); |
| 238 | g_assert (client_transport != NULL); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 239 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 240 | /* write exactly one character to the client */ |
| 241 | g_assert (thrift_transport_write (client_transport, |
| 242 | &data, |
| 243 | sizeof data, |
| 244 | &error) == TRUE); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 245 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 246 | thrift_transport_flush (client_transport, &error); |
| 247 | thrift_transport_write_end (client_transport, &error); |
| 248 | thrift_transport_close (client_transport, &error); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 249 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 250 | g_object_unref (client_transport); |
| 251 | g_object_unref (server_transport); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 252 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 253 | exit (0); |
| 254 | } |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 255 | else { |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 256 | /* parent connects, wait a bit for the socket to be created */ |
| 257 | sleep (1); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 258 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 259 | /* connect to the child */ |
| 260 | thrift_transport_open (client_transport, &error); |
| 261 | g_assert (error == NULL); |
| 262 | g_assert (thrift_transport_is_open (client_transport) == TRUE); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 263 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 264 | /* thrift_transport_peek returns TRUE when the socket is open and there is |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 265 | data available to be read */ |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 266 | g_assert (thrift_transport_peek (client_transport, &error) == TRUE); |
| 267 | g_assert (error == NULL); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 268 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 269 | /* read exactly one character from the server */ |
| 270 | g_assert_cmpint (thrift_transport_read (client_transport, |
| 271 | &data, |
| 272 | sizeof data, |
| 273 | &error), ==, sizeof data); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 274 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 275 | /* thrift_transport_peek returns FALSE when the socket is open but there is |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 276 | no (more) data available to be read */ |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 277 | g_assert (thrift_transport_is_open (client_transport) == TRUE); |
| 278 | g_assert (thrift_transport_peek (client_transport, &error) == FALSE); |
| 279 | g_assert (error == NULL); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 280 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 281 | thrift_transport_read_end (client_transport, &error); |
| 282 | thrift_transport_close (client_transport, &error); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 283 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 284 | g_object_unref (client_transport); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 285 | |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 286 | g_assert (wait (&status) == pid); |
| 287 | g_assert (status == 0); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 291 | static void |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 292 | thrift_socket_server_open (const int port, int times) |
| 293 | { |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 294 | ThriftServerTransport *transport = NULL; |
| 295 | ThriftTransport *client = NULL; |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 296 | int i; |
| 297 | ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET, |
| 298 | "port", port, NULL); |
| 299 | |
| 300 | transport = THRIFT_SERVER_TRANSPORT (tsocket); |
| 301 | thrift_server_transport_listen (transport, NULL); |
| 302 | for(i=0;i<times;i++){ |
| 303 | client = thrift_server_transport_accept (transport, NULL); |
| 304 | g_assert (client != NULL); |
| 305 | thrift_socket_close (client, NULL); |
| 306 | g_object_unref (client); |
| 307 | } |
| 308 | g_object_unref (tsocket); |
| 309 | } |
| 310 | |
| 311 | |
| 312 | static void |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 313 | thrift_socket_server (const int port) |
| 314 | { |
| 315 | int bytes = 0; |
| 316 | ThriftServerTransport *transport = NULL; |
| 317 | ThriftTransport *client = NULL; |
| 318 | guchar buf[10]; /* a buffer */ |
| 319 | guchar match[10] = TEST_DATA; |
| 320 | |
| 321 | ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET, |
Gonzalo Aguilar Delgado | 87ad2bc | 2017-09-15 12:26:02 +0200 | [diff] [blame] | 322 | "port", port, NULL); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 323 | |
| 324 | transport = THRIFT_SERVER_TRANSPORT (tsocket); |
| 325 | thrift_server_transport_listen (transport, NULL); |
| 326 | client = thrift_server_transport_accept (transport, NULL); |
James E. King, III | 43f4bf2 | 2017-10-28 12:54:02 -0400 | [diff] [blame] | 327 | g_assert (client != NULL); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 328 | |
| 329 | /* read 10 bytes */ |
| 330 | bytes = thrift_socket_read (client, buf, 10, NULL); |
James E. King, III | 43f4bf2 | 2017-10-28 12:54:02 -0400 | [diff] [blame] | 331 | g_assert (bytes == 10); /* make sure we've read 10 bytes */ |
| 332 | g_assert ( memcmp(buf, match, 10) == 0 ); /* make sure what we got matches */ |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 333 | |
| 334 | /* failed read */ |
| 335 | recv_error = 1; |
| 336 | thrift_socket_read (client, buf, 1, NULL); |
| 337 | recv_error = 0; |
| 338 | |
| 339 | thrift_socket_read_end (client, NULL); |
| 340 | thrift_socket_close (client, NULL); |
| 341 | g_object_unref (tsocket); |
| 342 | g_object_unref (client); |
| 343 | } |
| 344 | |
| 345 | int |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 346 | main(int argc, char *argv[]) |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 347 | { |
Jens Geyer | 1c19027 | 2015-07-28 23:15:18 +0200 | [diff] [blame] | 348 | #if (!GLIB_CHECK_VERSION (2, 36, 0)) |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 349 | g_type_init(); |
Jens Geyer | 1c19027 | 2015-07-28 23:15:18 +0200 | [diff] [blame] | 350 | #endif |
| 351 | |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 352 | g_test_init (&argc, &argv, NULL); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 353 | |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 354 | g_test_add_func ("/testtransportsocket/CreateAndDestroy", test_create_and_destroy); |
| 355 | g_test_add_func ("/testtransportsocket/OpenAndClose", test_open_and_close); |
| 356 | g_test_add_func ("/testtransportsocket/ReadAndWrite", test_read_and_write); |
Roger Meier | 63243c6 | 2014-09-29 20:29:58 +0200 | [diff] [blame] | 357 | g_test_add_func ("/testtransportsocket/Peek", test_peek); |
Roger Meier | c101092 | 2010-11-26 10:17:48 +0000 | [diff] [blame] | 358 | |
| 359 | return g_test_run (); |
Roger Meier | 213a664 | 2010-10-27 12:30:11 +0000 | [diff] [blame] | 360 | } |
| 361 | |