1178825Sdfr/*
2233294Sstas * Copyright (c) 2006 Kungliga Tekniska H��gskolan
3233294Sstas * (Royal Institute of Technology, Stockholm, Sweden).
4233294Sstas * All rights reserved.
5178825Sdfr *
6233294Sstas * Redistribution and use in source and binary forms, with or without
7233294Sstas * modification, are permitted provided that the following conditions
8233294Sstas * are met:
9178825Sdfr *
10233294Sstas * 1. Redistributions of source code must retain the above copyright
11233294Sstas *    notice, this list of conditions and the following disclaimer.
12178825Sdfr *
13233294Sstas * 2. Redistributions in binary form must reproduce the above copyright
14233294Sstas *    notice, this list of conditions and the following disclaimer in the
15233294Sstas *    documentation and/or other materials provided with the distribution.
16178825Sdfr *
17178825Sdfr * 3. Neither the name of KTH nor the names of its contributors may be
18178825Sdfr *    used to endorse or promote products derived from this software without
19178825Sdfr *    specific prior written permission.
20178825Sdfr *
21178825Sdfr * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
22178825Sdfr * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23178825Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24178825Sdfr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
25178825Sdfr * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26178825Sdfr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27178825Sdfr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28178825Sdfr * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29178825Sdfr * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30178825Sdfr * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31178825Sdfr * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
32178825Sdfr
33178825Sdfr#include "sl_locl.h"
34178825Sdfr
35178825Sdfrstruct {
36178825Sdfr    int ok;
37178825Sdfr    const char *line;
38178825Sdfr    int argc;
39178825Sdfr    const char *argv[4];
40178825Sdfr} lines[] = {
41178825Sdfr    { 1, "", 1, { "" } },
42178825Sdfr    { 1, "foo", 1, { "foo" } },
43178825Sdfr    { 1, "foo bar", 2, { "foo", "bar" }},
44178825Sdfr    { 1, "foo bar baz", 3, { "foo", "bar", "baz" }},
45178825Sdfr    { 1, "foobar baz", 2, { "foobar", "baz" }},
46178825Sdfr    { 1, " foo", 1, { "foo" } },
47178825Sdfr    { 1, "foo   ", 1, { "foo" } },
48178825Sdfr    { 1, " foo  ", 1, { "foo" } },
49178825Sdfr    { 1, " foo  bar", 2, { "foo", "bar" } },
50178825Sdfr    { 1, "foo\\ bar", 1, { "foo bar" } },
51178825Sdfr    { 1, "\"foo bar\"", 1, { "foo bar" } },
52178825Sdfr    { 1, "\"foo\\ bar\"", 1, { "foo bar" } },
53178825Sdfr    { 1, "\"foo\\\" bar\"", 1, { "foo\" bar" } },
54178825Sdfr    { 1, "\"\"f\"\"oo\"\"", 1, { "foo" } },
55178825Sdfr    { 1, "\"foobar\"baz", 1, { "foobarbaz" }},
56178825Sdfr    { 1, "foo\tbar baz", 3, { "foo", "bar", "baz" }},
57178825Sdfr    { 1, "\"foo bar\" baz", 2, { "foo bar", "baz" }},
58178825Sdfr    { 1, "\"foo bar baz\"", 1, { "foo bar baz" }},
59178825Sdfr    { 1, "\\\"foo bar baz", 3, { "\"foo", "bar", "baz" }},
60178825Sdfr    { 1, "\\ foo bar baz", 3, { " foo", "bar", "baz" }},
61178825Sdfr    { 0, "\\", 0, { "" }},
62178825Sdfr    { 0, "\"", 0, { "" }}
63178825Sdfr};
64178825Sdfr
65178825Sdfrint
66178825Sdfrmain(int argc, char **argv)
67178825Sdfr{
68178825Sdfr    int ret, i;
69178825Sdfr
70178825Sdfr    for (i = 0; i < sizeof(lines)/sizeof(lines[0]); i++) {
71178825Sdfr	int j, rargc = 0;
72178825Sdfr	char **rargv = NULL;
73178825Sdfr	char *buf = strdup(lines[i].line);
74178825Sdfr
75178825Sdfr	ret = sl_make_argv(buf, &rargc, &rargv);
76178825Sdfr	if (ret) {
77178825Sdfr	    if (!lines[i].ok)
78178825Sdfr		goto next;
79178825Sdfr	    errx(1, "sl_make_argv test %d failed", i);
80178825Sdfr	} else if (!lines[i].ok)
81178825Sdfr	    errx(1, "sl_make_argv passed test %d when it shouldn't", i);
82178825Sdfr	if (rargc != lines[i].argc)
83233294Sstas	    errx(1, "result argc (%d) != should be argc (%d) for test %d",
84178825Sdfr		 rargc, lines[i].argc, i);
85178825Sdfr	for (j = 0; j < rargc; j++)
86178825Sdfr	    if (strcmp(rargv[j], lines[i].argv[j]) != 0)
87178825Sdfr		errx(1, "result argv (%s) != should be argv (%s) for test %d",
88178825Sdfr		     rargv[j], lines[i].argv[j], i);
89178825Sdfr    next:
90178825Sdfr	free(buf);
91178825Sdfr	free(rargv);
92178825Sdfr    }
93178825Sdfr
94178825Sdfr    return 0;
95178825Sdfr}
96