1 /*
2 	(c) 2005 Jelmer Vernooij <jelmer@nl.linux.org>
3 
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 3 of the License, or
7 	(at your option) any later version.
8 
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.
13 
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.
17 */
18 
19 #include <stdio.h>
20 #include <string.h>
21 #include <glib.h>
22 #include <check.h>
23 #include "ctrlproxy.h"
24 
25 START_TEST(test_line_parse_linef)
26 	struct irc_line *l = irc_parse_linef("data");
27 	fail_if (l->argc != 1, "Invalid parse");
28 	fail_if (strcmp(l->args[0], "data") != 0, "Invalid parse");
29 	fail_if (l->origin != NULL, "Invalid origin");
30 
31 	l = irc_parse_linef("data arg1");
32 	fail_if (l->argc != 2, "Invalid parse");
33 	fail_if (strcmp(l->args[0], "data") != 0, "Invalid parse");
34 	fail_if (strcmp(l->args[1], "arg1") != 0, "Invalid parse");
35 	fail_if (l->origin != NULL, "Invalid origin");
36 
37 	l = irc_parse_linef("data :arg1 ");
38 	fail_if (l->argc != 2, "Invalid parse");
39 	fail_if (strcmp(l->args[0], "data") != 0, "Invalid parse");
40 	fail_if (strcmp(l->args[1], "arg1 ") != 0, "Invalid parse");
41 	fail_if (l->origin != NULL, "Invalid origin");
42 END_TEST
43 
44 START_TEST(test_parse_args)
45 	struct irc_line *l = irc_parse_line_args("myorigin", "data", NULL);
46 	fail_if (l->argc != 1, "Invalid parse");
47 	fail_if (l->origin == NULL, "Invalid origin");
48 	fail_if (strcmp(l->origin, "myorigin") != 0, "Invalid origin");
49 	fail_if (strcmp(l->args[0], "data") != 0, "Invalid parse");
50 
51 	l = irc_parse_line_args("myorigin", "data with space", NULL);
52 	fail_if (l->argc != 1, "Invalid parse");
53 	fail_if (l->origin == NULL, "Invalid origin");
54 	fail_if (strcmp(l->origin, "myorigin") != 0, "Invalid origin");
55 	fail_if (strcmp(l->args[0], "data with space") != 0, "Invalid parse");
56 
57 	l = irc_parse_line_args("myorigin", "data", "with", "args", NULL);
58 	fail_if (l->argc != 3, "Invalid parse");
59 	fail_if (l->origin == NULL, "Invalid origin");
60 	fail_if (strcmp(l->origin, "myorigin") != 0, "Invalid origin");
61 	fail_if (strcmp(l->args[0], "data") != 0, "Invalid parse");
62 	fail_if (strcmp(l->args[1], "with") != 0, "Invalid parse");
63 	fail_if (strcmp(l->args[2], "args") != 0, "Invalid parse");
64 
65 	l = irc_parse_line_args("myorigin", NULL);
66 	fail_if (l->argc != 0, "Invalid parse");
67 	fail_if (l->origin == NULL, "Invalid origin");
68 	fail_if (strcmp(l->origin, "myorigin") != 0, "Invalid origin");
69 
70 END_TEST
71 
72 START_TEST(test_prefix_time)
73 	struct irc_line *ol, *nl;
74 
75 	ol = irc_parse_line(":me@host PRIVMSG to :hoi\r\n");
76 
77 	nl = line_prefix_time(ol, 1209309035);
78 
79 	fail_unless (!strcmp(nl->args[2], "[17:10:35] hoi"), "Got: %s", nl->args[2]);
80 
81 	ol = irc_parse_line(":me@host PRIVMSG to :\001ACTION bla\001\r\n");
82 
83 	nl = line_prefix_time(ol, 1209309035);
84 
85 	fail_unless (!strcmp(nl->args[2], "\001ACTION [17:10:35] bla\001"), "Got: %s", nl->args[2]);
86 
87 	ol = irc_parse_line(":me@host PRIVMSG to :\001FINGER bla\001\r\n");
88 
89 	nl = line_prefix_time(ol, 1209309035);
90 
91 	fail_unless (!strcmp(nl->args[2], "\001FINGER bla\001"), "Got: %s", nl->args[2]);
92 
93 END_TEST
94 
95 START_TEST(test_free_null)
96 	free_line(NULL);
97 END_TEST
98 
line_suite(void)99 Suite *line_suite(void)
100 {
101 	Suite *s = suite_create("line");
102 	TCase *tc_core = tcase_create("Core");
103 	suite_add_tcase(s, tc_core);
104 	tcase_add_test(tc_core, test_line_parse_linef);
105 	tcase_add_test(tc_core, test_parse_args);
106 	tcase_add_test(tc_core, test_free_null);
107 	tcase_add_test(tc_core, test_prefix_time);
108 	return s;
109 }
110