test_sl.c revision 178825
1178825Sdfr/* 2178825Sdfr * Copyright (c) 2006 Kungliga Tekniska H�gskolan 3178825Sdfr * (Royal Institute of Technology, Stockholm, Sweden). 4178825Sdfr * All rights reserved. 5178825Sdfr * 6178825Sdfr * Redistribution and use in source and binary forms, with or without 7178825Sdfr * modification, are permitted provided that the following conditions 8178825Sdfr * are met: 9178825Sdfr * 10178825Sdfr * 1. Redistributions of source code must retain the above copyright 11178825Sdfr * notice, this list of conditions and the following disclaimer. 12178825Sdfr * 13178825Sdfr * 2. Redistributions in binary form must reproduce the above copyright 14178825Sdfr * notice, this list of conditions and the following disclaimer in the 15178825Sdfr * 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 35178825SdfrRCSID("$Id: test_sl.c 19555 2006-12-28 23:40:17Z lha $"); 36178825Sdfr 37178825Sdfrstruct { 38178825Sdfr int ok; 39178825Sdfr const char *line; 40178825Sdfr int argc; 41178825Sdfr const char *argv[4]; 42178825Sdfr} lines[] = { 43178825Sdfr { 1, "", 1, { "" } }, 44178825Sdfr { 1, "foo", 1, { "foo" } }, 45178825Sdfr { 1, "foo bar", 2, { "foo", "bar" }}, 46178825Sdfr { 1, "foo bar baz", 3, { "foo", "bar", "baz" }}, 47178825Sdfr { 1, "foobar baz", 2, { "foobar", "baz" }}, 48178825Sdfr { 1, " foo", 1, { "foo" } }, 49178825Sdfr { 1, "foo ", 1, { "foo" } }, 50178825Sdfr { 1, " foo ", 1, { "foo" } }, 51178825Sdfr { 1, " foo bar", 2, { "foo", "bar" } }, 52178825Sdfr { 1, "foo\\ bar", 1, { "foo bar" } }, 53178825Sdfr { 1, "\"foo bar\"", 1, { "foo bar" } }, 54178825Sdfr { 1, "\"foo\\ bar\"", 1, { "foo bar" } }, 55178825Sdfr { 1, "\"foo\\\" bar\"", 1, { "foo\" bar" } }, 56178825Sdfr { 1, "\"\"f\"\"oo\"\"", 1, { "foo" } }, 57178825Sdfr { 1, "\"foobar\"baz", 1, { "foobarbaz" }}, 58178825Sdfr { 1, "foo\tbar baz", 3, { "foo", "bar", "baz" }}, 59178825Sdfr { 1, "\"foo bar\" baz", 2, { "foo bar", "baz" }}, 60178825Sdfr { 1, "\"foo bar baz\"", 1, { "foo bar baz" }}, 61178825Sdfr { 1, "\\\"foo bar baz", 3, { "\"foo", "bar", "baz" }}, 62178825Sdfr { 1, "\\ foo bar baz", 3, { " foo", "bar", "baz" }}, 63178825Sdfr { 0, "\\", 0, { "" }}, 64178825Sdfr { 0, "\"", 0, { "" }} 65178825Sdfr}; 66178825Sdfr 67178825Sdfrint 68178825Sdfrmain(int argc, char **argv) 69178825Sdfr{ 70178825Sdfr int ret, i; 71178825Sdfr 72178825Sdfr for (i = 0; i < sizeof(lines)/sizeof(lines[0]); i++) { 73178825Sdfr int j, rargc = 0; 74178825Sdfr char **rargv = NULL; 75178825Sdfr char *buf = strdup(lines[i].line); 76178825Sdfr 77178825Sdfr ret = sl_make_argv(buf, &rargc, &rargv); 78178825Sdfr if (ret) { 79178825Sdfr if (!lines[i].ok) 80178825Sdfr goto next; 81178825Sdfr errx(1, "sl_make_argv test %d failed", i); 82178825Sdfr } else if (!lines[i].ok) 83178825Sdfr errx(1, "sl_make_argv passed test %d when it shouldn't", i); 84178825Sdfr if (rargc != lines[i].argc) 85178825Sdfr errx(1, "result argc (%d) != should be argc (%d) for test %d", 86178825Sdfr rargc, lines[i].argc, i); 87178825Sdfr for (j = 0; j < rargc; j++) 88178825Sdfr if (strcmp(rargv[j], lines[i].argv[j]) != 0) 89178825Sdfr errx(1, "result argv (%s) != should be argv (%s) for test %d", 90178825Sdfr rargv[j], lines[i].argv[j], i); 91178825Sdfr next: 92178825Sdfr free(buf); 93178825Sdfr free(rargv); 94178825Sdfr } 95178825Sdfr 96178825Sdfr return 0; 97178825Sdfr} 98