1 /* Copyright (c) 2016, MariaDB
2 
3    This program is free software; you can redistribute it and/or
4    modify it under the terms of the GNU General Public License as
5    published by the Free Software Foundation; version 2 of the License.
6 
7    This program is distributed in the hope that it will be useful, but
8    WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10    General Public License for more details.
11 
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335  USA */
15 
16 #include <my_global.h>
17 #include <m_string.h>
18 #include <my_sys.h>
19 #include <tap.h>
20 
21 DYNAMIC_STRING str1;
22 
check(const char * res)23 static void check(const char *res)
24 {
25   ok(strcmp(str1.str, res) == 0, "strcmp: %s", str1.str);
26   str1.length= 0;
27 }
28 
main(void)29 int main(void)
30 {
31   plan(23);
32 
33   IF_WIN(skip_all("Test of POSIX shell escaping rules, not for CMD.EXE\n"), );
34 
35   ok(init_dynamic_string(&str1, NULL, 0, 32) == 0, "init");
36 
37   ok(dynstr_append_os_quoted(&str1, "test1", NULL) == 0, "append");
38   check("'test1'");
39 
40   ok(dynstr_append_os_quoted(&str1, "con", "cat", NULL) == 0, "append");
41   check("'concat'");
42 
43   ok(dynstr_append_os_quoted(&str1, "", NULL) == 0, "append");
44   check("''");
45 
46   ok(dynstr_append_os_quoted(&str1, "space inside", NULL) == 0, "append");
47   check("'space inside'");
48 
49   ok(dynstr_append_os_quoted(&str1, "single'quote", NULL) == 0, "append");
50   check("'single'\"'\"'quote'");
51 
52   ok(dynstr_append_os_quoted(&str1, "many'single'quotes", NULL) == 0, "append");
53   check("'many'\"'\"'single'\"'\"'quotes'");
54 
55   ok(dynstr_append_os_quoted(&str1, "'single quoted'", NULL) == 0, "append");
56   check("''\"'\"'single quoted'\"'\"''");
57 
58   ok(dynstr_append_os_quoted(&str1, "double\"quote", NULL) == 0, "append");
59   check("'double\"quote'");
60 
61   ok(dynstr_append_os_quoted(&str1, "mixed\"single'and\"double'quotes", NULL) == 0, "append");
62   check("'mixed\"single'\"'\"'and\"double'\"'\"'quotes'");
63 
64   ok(dynstr_append_os_quoted(&str1, "back\\space", NULL) == 0, "append");
65   check("'back\\space'");
66 
67   ok(dynstr_append_os_quoted(&str1, "backspace\\'and\\\"quote", NULL) == 0, "append");
68   check("'backspace\\'\"'\"'and\\\"quote'");
69 
70   dynstr_free(&str1);
71 
72   return exit_status();
73 }
74 
75