1*50d315dbSchristos /* $NetBSD: t_stresep.c,v 1.4 2017/08/23 10:29:51 christos Exp $ */
23ca5a7dbSpgoyette
33ca5a7dbSpgoyette /*-
43ca5a7dbSpgoyette * Copyright (c) 2005 The NetBSD Foundation, Inc.
53ca5a7dbSpgoyette * All rights reserved.
63ca5a7dbSpgoyette *
73ca5a7dbSpgoyette * This code is derived from software contributed to The NetBSD Foundation
83ca5a7dbSpgoyette * by Christos Zoulas.
93ca5a7dbSpgoyette *
103ca5a7dbSpgoyette * Redistribution and use in source and binary forms, with or without
113ca5a7dbSpgoyette * modification, are permitted provided that the following conditions
123ca5a7dbSpgoyette * are met:
133ca5a7dbSpgoyette * 1. Redistributions of source code must retain the above copyright
143ca5a7dbSpgoyette * notice, this list of conditions and the following disclaimer.
153ca5a7dbSpgoyette * 2. Redistributions in binary form must reproduce the above copyright
163ca5a7dbSpgoyette * notice, this list of conditions and the following disclaimer in the
173ca5a7dbSpgoyette * documentation and/or other materials provided with the distribution.
183ca5a7dbSpgoyette *
193ca5a7dbSpgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
203ca5a7dbSpgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
213ca5a7dbSpgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223ca5a7dbSpgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
233ca5a7dbSpgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
243ca5a7dbSpgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
253ca5a7dbSpgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
263ca5a7dbSpgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
273ca5a7dbSpgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
283ca5a7dbSpgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
293ca5a7dbSpgoyette * POSSIBILITY OF SUCH DAMAGE.
303ca5a7dbSpgoyette */
313ca5a7dbSpgoyette
323ca5a7dbSpgoyette #include <atf-c.h>
333ca5a7dbSpgoyette
343ca5a7dbSpgoyette #include <stdio.h>
353ca5a7dbSpgoyette #include <stdlib.h>
363ca5a7dbSpgoyette #include <string.h>
373ca5a7dbSpgoyette
383ca5a7dbSpgoyette #define expect(a) \
393ca5a7dbSpgoyette if ((p = stresep(&q, " ", '\\')) == NULL || strcmp(p, a)) { \
403ca5a7dbSpgoyette fprintf(stderr, "failed on line %d: %s != %s\n", \
413ca5a7dbSpgoyette __LINE__, p, a); \
423ca5a7dbSpgoyette atf_tc_fail("Check stderr for test id/line"); \
433ca5a7dbSpgoyette }
443ca5a7dbSpgoyette
451c3ef2c7Sjruoho ATF_TC(stresep_basic);
ATF_TC_HEAD(stresep_basic,tc)461c3ef2c7Sjruoho ATF_TC_HEAD(stresep_basic, tc)
473ca5a7dbSpgoyette {
483ca5a7dbSpgoyette
493ca5a7dbSpgoyette atf_tc_set_md_var(tc, "descr", "Test stresep results");
503ca5a7dbSpgoyette }
513ca5a7dbSpgoyette
ATF_TC_BODY(stresep_basic,tc)521c3ef2c7Sjruoho ATF_TC_BODY(stresep_basic, tc)
533ca5a7dbSpgoyette {
54d2ff7839Schristos char brkstr[] = "foo\\ \\ bar baz bar\\ foo\\ bar\\ \\ foo \\ \\ \\ "
553ca5a7dbSpgoyette "baz bar\\ \\ ";
56d2ff7839Schristos char *p, *q = brkstr;
573ca5a7dbSpgoyette
583ca5a7dbSpgoyette expect("foo bar");
593ca5a7dbSpgoyette expect("baz");
603ca5a7dbSpgoyette expect("bar foo ");
613ca5a7dbSpgoyette expect("bar foo");
623ca5a7dbSpgoyette expect(" baz");
633ca5a7dbSpgoyette expect("bar ");
64*50d315dbSchristos
65*50d315dbSchristos char brkstr2[] = "aa bb cc\\ \\ \\ \\ dd-";
66*50d315dbSchristos q = brkstr2;
67*50d315dbSchristos expect("aa");
68*50d315dbSchristos expect("bb");
69*50d315dbSchristos expect("cc dd-");
703ca5a7dbSpgoyette }
713ca5a7dbSpgoyette
ATF_TP_ADD_TCS(tp)723ca5a7dbSpgoyette ATF_TP_ADD_TCS(tp)
733ca5a7dbSpgoyette {
743ca5a7dbSpgoyette
751c3ef2c7Sjruoho ATF_TP_ADD_TC(tp, stresep_basic);
763ca5a7dbSpgoyette
773ca5a7dbSpgoyette return atf_no_error();
783ca5a7dbSpgoyette }
79