/*-1* Copyright (c) 2017 Spectra Logic Corporation2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526/* Tests functions in sys/cam/cam.c */2728#include <sys/cdefs.h>29#include <errno.h>30#include <fcntl.h>31#include <stdio.h>32#include <camlib.h>3334#include <atf-c.h>3536#define ATF_CHECK_NE(x, y) ATF_CHECK((x) != (y))3738ATF_TC_WITHOUT_HEAD(cam_strmatch);39ATF_TC_BODY(cam_strmatch, tc)40{41/* Basic fixed patterns */42ATF_CHECK_EQ(0, cam_strmatch("foo", "foo", 3));43ATF_CHECK_NE(0, cam_strmatch("foo", "bar", 3));44ATF_CHECK_NE(0, cam_strmatch("foo", "foobar", 3));4546/* The str is not necessarily null-terminated */47ATF_CHECK_EQ(0, cam_strmatch("fooxuehfxeuf", "foo", 3));48ATF_CHECK_NE(0, cam_strmatch("foo\0bar", "foo", 7));4950/* Eat trailing spaces, which get added by SAT */51ATF_CHECK_EQ(0, cam_strmatch("foo ", "foo", 16));5253/* '*' matches everything, like shell globbing */54ATF_CHECK_EQ(0, cam_strmatch("foobar", "foo*", 6));55ATF_CHECK_EQ(0, cam_strmatch("foobar", "*bar", 6));56ATF_CHECK_NE(0, cam_strmatch("foobar", "foo*x", 6));57ATF_CHECK_EQ(0, cam_strmatch("foobarbaz", "*bar*", 9));58/* Even NUL */59ATF_CHECK_EQ(0, cam_strmatch("foo\0bar", "foo*", 7));60/* Or nothing */61ATF_CHECK_EQ(0, cam_strmatch("foo", "foo*", 3));62/* But stuff after the * still must match */63ATF_CHECK_NE(0, cam_strmatch("foo", "foo*x", 3));6465/* '?' matches exactly one single character */66ATF_CHECK_EQ(0, cam_strmatch("foobar", "foo?ar", 6));67ATF_CHECK_NE(0, cam_strmatch("foo", "foo?", 3));68/* Even NUL */69ATF_CHECK_EQ(0, cam_strmatch("foo\0bar", "foo?bar", 7));7071/* '[]' contains a set of characters */72ATF_CHECK_EQ(0, cam_strmatch("foobar", "foo[abc]ar", 6));73ATF_CHECK_EQ(0, cam_strmatch("foobar", "foo[b]ar", 6));74ATF_CHECK_NE(0, cam_strmatch("foobar", "foo[ac]ar", 6));7576/* '[]' can contain a range of characters, too */77ATF_CHECK_EQ(0, cam_strmatch("foobar", "foo[a-c]ar", 6));78ATF_CHECK_EQ(0, cam_strmatch("fooxar", "foo[a-cx]ar", 6));79ATF_CHECK_NE(0, cam_strmatch("foodar", "foo[a-c]ar", 6));8081/* Back-to-back '[]' character sets */82ATF_CHECK_EQ(0, cam_strmatch("foobar", "fo[a-z][abc]ar", 6));83ATF_CHECK_NE(0, cam_strmatch("foAbar", "fo[a-z][abc]ar", 6));84ATF_CHECK_NE(0, cam_strmatch("foodar", "fo[a-z][abc]ar", 6));8586/* A '^' negates a set of characters */87ATF_CHECK_NE(0, cam_strmatch("foobar", "foo[^abc]ar", 6));88ATF_CHECK_NE(0, cam_strmatch("foobar", "foo[^b]ar", 6));89ATF_CHECK_EQ(0, cam_strmatch("foobar", "foo[^ac]ar", 6));90ATF_CHECK_NE(0, cam_strmatch("foobar", "foo[^a-c]ar", 6));91ATF_CHECK_NE(0, cam_strmatch("fooxar", "foo[^a-cx]ar", 6));92ATF_CHECK_EQ(0, cam_strmatch("foodar", "foo[^a-c]ar", 6));9394/* Outside of '[]' a ']' is just an ordinary character */95ATF_CHECK_EQ(0, cam_strmatch("f]o", "f]o", 3));96ATF_CHECK_NE(0, cam_strmatch("foo", "f]o", 3));9798/* Matching a literal '[' requires specifying a range */99ATF_CHECK_EQ(0, cam_strmatch("f[o", "f[[]o", 3));100ATF_CHECK_NE(0, cam_strmatch("foo", "f[[]o", 3));101}102103ATF_TP_ADD_TCS(tp)104{105ATF_TP_ADD_TC(tp, cam_strmatch);106107return (atf_no_error());108}109110111