1 /* $OpenBSD: regress.c,v 1.7 2010/07/19 19:46:44 espie Exp $ */ 2 3 /* 4 * Copyright (c) 1999 Marc Espie. 5 * 6 * Code written for the OpenBSD project. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD 21 * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 /* regression tests */ 31 #include <stdio.h> 32 #include <string.h> 33 #include "defines.h" 34 #include "str.h" 35 36 int main(void); 37 #define CHECK(s) \ 38 do { \ 39 printf("%-65s", #s); \ 40 if (s) \ 41 printf("ok\n"); \ 42 else { \ 43 printf("failed\n"); \ 44 errors++; \ 45 } \ 46 } while (0); 47 48 int 49 main(void) 50 { 51 unsigned int errors = 0; 52 53 CHECK(Str_Match("string", "string") == true); 54 CHECK(Str_Match("string", "string2") == false); 55 CHECK(Str_Match("string", "string*") == true); 56 CHECK(Str_Match("Long string", "Lo*ng") == true); 57 CHECK(Str_Match("Long string", "Lo*ng ") == false); 58 CHECK(Str_Match("Long string", "Lo*ng *") == true); 59 CHECK(Str_Match("string", "stri?g") == true); 60 CHECK(Str_Match("str?ng", "str\\?ng") == true); 61 CHECK(Str_Match("striiiing", "str?*ng") == true); 62 CHECK(Str_Match("Very long string just to see", "******a****") == false); 63 CHECK(Str_Match("d[abc?", "d\\[abc\\?") == true); 64 CHECK(Str_Match("d[abc!", "d\\[abc\\?") == false); 65 CHECK(Str_Match("dwabc?", "d\\[abc\\?") == false); 66 CHECK(Str_Match("da0", "d[bcda]0") == true); 67 CHECK(Str_Match("da0", "d[z-a]0") == true); 68 CHECK(Str_Match("d-0", "d[-a-z]0") == true); 69 CHECK(Str_Match("dy0", "d[a\\-z]0") == false); 70 CHECK(Str_Match("d-0", "d[a\\-z]0") == true); 71 CHECK(Str_Match("dz0", "d[a\\]z]0") == true); 72 73 if (errors != 0) 74 printf("Errors: %d\n", errors); 75 exit(0); 76 } 77 78 79