Debian Codegraph @

src/test_str_util.cxx

raw
1 /**
2 * FreeDink test suite
3
4 * Copyright (C) 2014, 2015 Sylvain Beucler
5
6 * This file is part of GNU FreeDink
7
8 * GNU FreeDink is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 3 of the
11 * License, or (at your option) any later version.
12
13 * GNU FreeDink is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdlib.h>
28 #include "str_util.h"
29
30 /* Pleases gnulib's error module */
31 char* program_name = __FILE__;
32
33 #include <cxxtest/TestSuite.h>
34 class Test_str_util : public CxxTest::TestSuite {
35 public:
36 void test_strtoupper() {
37 char str[] = "toto";
38 char* str2 = strdup(str);
39 TS_ASSERT_EQUALS(str, str2);
40 strtoupper(str2);
41 TS_ASSERT_EQUALS(str2, "TOTO");
42 TS_ASSERT_DIFFERS(str, str2);
43 }
44
45 void test_reverse() {
46 char str[] = "toto";
47 reverse(str);
48 TS_ASSERT_EQUALS(str, "otot");
49 }
50
51 void test_separate_string() {
52 char str[] = "a!:b!c";
53 char* ret;
54 ret = separate_string(str, 1, '-');
55 TS_ASSERT_EQUALS(ret, str);
56 free(ret);
57 ret = separate_string(str, 2, '-');
58 TS_ASSERT_EQUALS(ret, "");
59 free(ret);
60 ret = separate_string(str, 3, '-');
61 TS_ASSERT_EQUALS(ret, "");
62 free(ret);
63
64 ret = separate_string(str, 1, ':');
65 TS_ASSERT_EQUALS(ret, "a!");
66 free(ret);
67
68 ret = separate_string(str, 1, '!');
69 TS_ASSERT_EQUALS(ret, "a");
70 free(ret);
71 ret = separate_string(str, 2, '!');
72 TS_ASSERT_EQUALS(ret, ":b");
73 free(ret);
74 ret = separate_string(str, 3, '!');
75 TS_ASSERT_EQUALS(ret, "c");
76 free(ret);
77 ret = separate_string(str, 4, '!');
78 TS_ASSERT_EQUALS(ret, "");
79 free(ret);
80 }
81 };