Mercurial > ecos
changeset 2362:a49761badbf1
* tests/fnmatch.c: Test case for fnmatch.
| author | asl |
|---|---|
| date | Mon, 29 Jan 2007 13:41:44 +0000 |
| parents | 667a5457eaa0 |
| children | f0b2da61ab63 |
| files | packages/io/fileio/current/tests/fnmatch.c |
| diffstat | 1 files changed, 152 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/packages/io/fileio/current/tests/fnmatch.c @@ -0,0 +1,152 @@ +//========================================================================== +// +// fnmatch.c +// +// Test fnmatch function +// +//========================================================================== +//####ECOSGPLCOPYRIGHTBEGIN#### +// ------------------------------------------- +// This file is part of eCos, the Embedded Configurable Operating System. +// Copyright (C) 2007 Andrew Lunn <andrew.lunn@ascom.ch> +// +// eCos is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 2 or (at your option) any later version. +// +// eCos is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with eCos; if not, write to the Free Software Foundation, Inc., +// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +// +// As a special exception, if other files instantiate templates or use macros +// or inline functions from this file, or you compile this file and link it +// with other works to produce a work based on this file, this file does not +// by itself cause the resulting work to be covered by the GNU General Public +// License. However the source code for this file must still be made available +// in accordance with section (3) of the GNU General Public License. +// +// This exception does not invalidate any other reasons why a work based on +// this file might be covered by the GNU General Public License. +// ------------------------------------------- +//####ECOSGPLCOPYRIGHTEND#### +//========================================================================== +//#####DESCRIPTIONBEGIN#### +// +// Author(s): asl +// Contributors: asl +// Date: 2007-01-27 +// Purpose: Test fnmatch function. +// Description: // +// +//####DESCRIPTIONEND#### +// +//========================================================================== + +#include <pkgconf/io_fileio.h> + +#ifndef CYGPKG_FILEIO_FNMATCH +# define NA_MSG "FNMATCH function not available" +#endif + +#include <cyg/infra/testcase.h> + +#ifndef NA_MSG +#include <cyg/infra/cyg_type.h> +#include <cyg/infra/diag.h> + +#include <fnmatch.h> + +//========================================================================== +// main + +int main( int argc, char **argv ) +{ + int i; + cyg_bool failed = false; + + struct + { + const int result; + const int flags; + const char * string; + const char * pattern; + } test_case[] = { + { 0, 0, "abc", "abc" }, /* 0 */ + { FNM_NOMATCH, 0, "cba", "abc" }, + { 0, 0, "abc", "a*" }, + { FNM_NOMATCH, 0, "abc", "b*" }, + { 0, 0, "abc", "[abc]*" }, + { FNM_NOMATCH, 0, "abc", "[def]*" }, + { FNM_NOMATCH, 0, "abc", "*[def]*" }, + { 0, 0, "a/b", "a/b" }, + { FNM_NOMATCH, 0, "a/b", "a/a" }, + { FNM_NOMATCH, 0, "a/b", "b/b" }, + + { 0, 0, "a b", "a\\ b"}, /* 10 */ + { FNM_NOMATCH, FNM_NOESCAPE, "a b", "a\\ b"}, + + { 0, 0, "a/b", "a*b" }, + { 0, 0, "a/b", "a?b" }, + { 0, 0, "a/b", "a[/]b" }, + { FNM_NOMATCH, FNM_PATHNAME, "a/b", "a*b"}, + { FNM_NOMATCH, FNM_PATHNAME, "a/b", "a?b"}, + { FNM_NOMATCH, FNM_PATHNAME, "a/b", "a[/]b"}, + { 0, FNM_PATHNAME, "a/b", "a/b"}, + + { 0, 0, ".abc", "?abc" }, + { 0, 0, ".abc", "*abc" }, /* 20 */ + { 0, 0, ".abc", "[.]abc" }, + { 0, 0, ".abc", ".abc" }, + { FNM_NOMATCH, FNM_PERIOD, ".abc", "?abc" }, + { FNM_NOMATCH, FNM_PERIOD, ".abc", "*abc" }, + { 0, FNM_PERIOD, ".abc", "[.]abc" }, + { 0, FNM_PERIOD, ".abc", ".abc" }, + + { 0, 0, "/.abc", "/?abc" }, + { 0, 0, "/.abc", "/*abc" }, + { 0, 0, "/.abc", "/[.]abc" }, + { 0, 0, "/.abc", "/.abc" }, /* 30 */ + { FNM_NOMATCH, FNM_PERIOD|FNM_PATHNAME, "/.abc", "/?abc" }, + { FNM_NOMATCH, FNM_PERIOD|FNM_PATHNAME, "/.abc", "/*abc" }, + { 0, FNM_PERIOD|FNM_PATHNAME, "/.abc", "/[.]abc" }, + { 0, FNM_PERIOD|FNM_PATHNAME, "/.abc", "/.abc" } + }; + + for (i=0; i < CYG_NELEM(test_case); i++) { + if (test_case[i].result != + fnmatch(test_case[i].pattern, + test_case[i].string, + test_case[i].flags)) { + diag_printf("<INFO>: test number %d failed\n", i); + failed = true; + } + } + + if (failed) { + CYG_TEST_FAIL_FINISH("fnmatch failed"); + } else { + CYG_TEST_PASS_FINISH("fnmatch failed"); + } +} + +#else + +//========================================================================== +// main + +int main( int argc, char **argv ) +{ + CYG_TEST_INIT(); + + CYG_TEST_NA(NA_MSG); +} + +#endif + +// ------------------------------------------------------------------------- +// EOF fnmatch.c
