2 (c) 2005-2006 Jelmer Vernooij <jelmer@nl.linux.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <sys/socket.h>
25 #include <netinet/in.h>
26 #include <glib/gstdio.h>
27 #include "ctrlproxy.h"
30 START_TEST(test_list_make_string)
34 ret = list_make_string(NULL);
35 fail_unless (strcmp(ret, "") == 0);
37 gl = g_list_append(gl, "bla");
38 gl = g_list_append(gl, "bloe");
40 ret = list_make_string(gl);
41 fail_unless (strcmp(ret, "bla bloe") == 0);
45 START_TEST(test_get_description)
49 struct sockaddr_in in;
52 sock[0] = socket(PF_INET, SOCK_STREAM, 0);
53 sock[1] = socket(PF_INET, SOCK_STREAM, 0);
58 fail_if(listen(sock[1], 1) < 0);
60 ch = g_io_channel_unix_new(sock[0]);
61 desc = g_io_channel_ip_get_description(ch);
62 fail_unless(desc == NULL);
64 fail_if(getsockname(sock[1], (struct sockaddr *)&in, &len) < 0);
65 fail_if(connect(sock[0], (struct sockaddr *)&in, len) < 0);
66 desc = g_io_channel_ip_get_description(ch);
67 fail_if(desc == NULL);
72 START_TEST(test_get_set_file_contents)
77 char *f = torture_tempfile("get_set_file_contents");
78 fail_unless(rep_g_file_set_contents(f, "bla\nbloe\n", -1, &error) == TRUE, "g_file_set_contents failed: %s", error == NULL?"(null)":error->message);
79 fail_unless(g_stat(f, &st) == 0);
80 fail_unless((st.st_mode & 0777) == 0644);
81 fail_unless(st.st_size == 9);
82 fail_unless(rep_g_file_get_contents(f, &cont, &len, &error) == TRUE, "g_file_get_contents failed: %s", error == NULL?"(null)":error->message);
83 fail_unless(!strcmp(cont, "bla\nbloe\n"));
84 fail_unless(9 == len);
87 Suite *util_suite(void)
89 Suite *s = suite_create("util");
90 TCase *tc_core = tcase_create("Core");
91 suite_add_tcase(s, tc_core);
92 tcase_add_test(tc_core, test_get_description);
93 tcase_add_test(tc_core, test_list_make_string);
94 tcase_add_test(tc_core, test_get_set_file_contents);