blob: 52b18bfa23ecb07fbdc85a3072880d56216974e4 [file] [log] [blame]
Roger Meier213a6642010-10-27 12:30:11 +00001#include <assert.h>
2#include <netdb.h>
3
4#include "transport/thrift_transport.h"
5#include "transport/thrift_socket.h"
6#include "transport/thrift_server_transport.h"
7#include "transport/thrift_server_socket.h"
8
9#define TEST_DATA { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' }
10
11#include "../src/transport/thrift_memory_buffer.c"
12
13/* test object creation and destruction */
14static void
15test_create_and_destroy(void)
16{
17 GObject *object = NULL;
18 object = g_object_new (THRIFT_TYPE_MEMORY_BUFFER, NULL);
19 assert (object != NULL);
20 g_object_unref (object);
21}
22
23static void
24test_open_and_close(void)
25{
26 ThriftMemoryBuffer *tbuffer = NULL;
27
28 /* create a ThriftMemoryBuffer */
29 tbuffer = g_object_new (THRIFT_TYPE_MEMORY_BUFFER, NULL);
30
31 /* this shouldn't work */
32 assert (thrift_memory_buffer_open (THRIFT_TRANSPORT (tbuffer), NULL) == TRUE);
33 assert (thrift_memory_buffer_is_open (THRIFT_TRANSPORT (tbuffer)) == TRUE);
34 assert (thrift_memory_buffer_close (THRIFT_TRANSPORT (tbuffer), NULL) == TRUE);
35 g_object_unref (tbuffer);
36}
37
38static void
39test_read_and_write(void)
40{
41 ThriftMemoryBuffer *tbuffer = NULL;
42 guchar buf[10] = TEST_DATA;
43 guchar read[10];
44 GError *error = NULL;
45
46 tbuffer = g_object_new (THRIFT_TYPE_MEMORY_BUFFER, "buf_size", 5, NULL);
47 assert (thrift_memory_buffer_write (THRIFT_TRANSPORT (tbuffer),
48 (gpointer) buf,
49 10, &error) == FALSE);
50 assert (error != NULL);
51 g_error_free (error);
52 error = NULL;
53 g_object_unref (tbuffer);
54
55 tbuffer = g_object_new (THRIFT_TYPE_MEMORY_BUFFER, "buf_size", 15, NULL);
56 assert (thrift_memory_buffer_write (THRIFT_TRANSPORT (tbuffer),
57 (gpointer) buf, 10, &error) == TRUE);
58 assert (error == NULL);
59
60 assert (thrift_memory_buffer_read (THRIFT_TRANSPORT (tbuffer),
61 &read, 10, &error) > 0);
62 assert (error == NULL);
63}
64
65int
66main(void)
67{
68 g_type_init();
69 test_create_and_destroy();
70 test_open_and_close();
71 test_read_and_write();
72
73 return 0;
74}
75