Update contrib.
1 /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
3 #undef G_DISABLE_ASSERT
15 #include "mrt2_glib2_test.h"
19 #define BUFFER_SIZE 1024
21 gint main (gint argc, gchar * argv[])
23 GIOChannel *gio_r, *gio_w ;
27 char *srcdir = getenv ("srcdir");
31 const gchar encoding[] = "ISO-8859-5";
36 g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
37 g_set_print_handler(mrtPrintHandler);
43 filename = g_strconcat (srcdir, G_DIR_SEPARATOR_S, "iochannel-test-infile", NULL);
45 setbuf (stdout, NULL); /* For debugging */
47 gio_r = g_io_channel_new_file (filename, "r", &gerr);
50 g_warning ("Unable to open file %s: %s", filename, gerr->message);
53 g_assert(FALSE && "iochannel-test failed");
56 testResultXml("iochannel-test");
61 gio_w = g_io_channel_new_file ("c:\\iochannel-test-outfile", "w", &gerr);
64 g_warning ("Unable to open file %s: %s", "iochannel-test-outfile", gerr->message);
67 g_assert(FALSE && "iochannel-test failed");
70 testResultXml("iochannel-test");
76 g_io_channel_set_encoding (gio_r, encoding, &gerr);
79 g_warning (gerr->message);
82 g_assert(FALSE && "iochannel-test failed");
85 testResultXml("iochannel-test");
91 g_io_channel_set_buffer_size (gio_r, BUFFER_SIZE);
93 status = g_io_channel_set_flags (gio_r, G_IO_FLAG_NONBLOCK, &gerr);
94 if (status == G_IO_STATUS_ERROR)
96 g_warning (gerr->message);
97 g_assert(FALSE && "iochannel-test failed");
101 flags = g_io_channel_get_flags (gio_r);
102 buffer = g_string_sized_new (BUFFER_SIZE);
107 status = g_io_channel_read_line_string (gio_r, buffer, NULL, &gerr);
108 while (status == G_IO_STATUS_AGAIN);
109 if (status != G_IO_STATUS_NORMAL)
112 rlength += buffer->len;
115 status = g_io_channel_write_chars (gio_w, buffer->str, buffer->len,
117 while (status == G_IO_STATUS_AGAIN);
118 if (status != G_IO_STATUS_NORMAL)
121 wlength += length_out;
123 if (length_out < buffer->len)
125 g_warning ("Only wrote part of the line.");
126 g_assert(FALSE && "iochannel-test failed");
131 g_print ("%s", buffer->str);
133 g_string_truncate (buffer, 0);
138 case G_IO_STATUS_EOF:
140 case G_IO_STATUS_ERROR:
141 g_warning (gerr->message);
146 g_warning ("Abnormal exit from write loop.");
147 g_assert(FALSE && "iochannel-test failed");
152 status = g_io_channel_flush (gio_w, &gerr);
153 while (status == G_IO_STATUS_AGAIN);
155 if (status == G_IO_STATUS_ERROR)
157 g_warning (gerr->message);
158 g_assert(FALSE && "iochannel-test failed");
164 g_print ("read %d bytes, wrote %ld bytes\n", rlength, wlength);
167 g_io_channel_unref(gio_r);
168 g_io_channel_unref(gio_w);
171 testResultXml("iochannel-test");
172 #endif /* EMULATOR */