Bug 539770 - migrate gstrfunc unit tests to gtest

2008-06-24  Paolo Borelli  <pborelli@katamail.com>

	Bug 539770 - migrate gstrfunc unit tests to gtest

	* tests/strfunc-test.c:
	* tests/testglib.c:
	* tests/strtoll-test.c:
	* tests/strtod-test.c:
	* tests/string-test.c:
	* tests/Makefile.am:
	Removed old tests.

	* glib/tests/fileutils.c:
	* glib/tests/strfuncs.c:
	* glib/tests/Makefile.am:
	Added all the old tests migrated to the new unit test framework
	and add new unit tests for some of the functions.


svn path=/trunk/; revision=7097
This commit is contained in:
Paolo Borelli 2008-06-24 13:55:22 +00:00 committed by Paolo Borelli
parent 1289b6d165
commit 96f99d334d
10 changed files with 1587 additions and 1094 deletions

View File

@ -1,3 +1,21 @@
2008-06-24 Paolo Borelli <pborelli@katamail.com>
Bug 539770 - migrate gstrfunc unit tests to gtest
* tests/strfunc-test.c:
* tests/testglib.c:
* tests/strtoll-test.c:
* tests/strtod-test.c:
* tests/string-test.c:
* tests/Makefile.am:
Removed old tests.
* glib/tests/fileutils.c:
* glib/tests/strfuncs.c:
* glib/tests/Makefile.am:
Added all the old tests migrated to the new unit test framework
and add new unit tests for some of the functions.
2008-06-23 Kristian Rietveld <kris@imendio.com>
* gobject/glib-mkenums.in: introduce an ENUMPREFIX substitution.

View File

@ -14,6 +14,14 @@ TEST_PROGS += option-context
option_context_SOURCES = option-context.c
option_context_LDADD = $(progs_ldadd)
TEST_PROGS += fileutils
fileutils_SOURCES = fileutils.c
fileutils_LDADD = $(progs_ldadd)
TEST_PROGS += strfuncs
strfuncs_SOURCES = strfuncs.c
strfuncs_LDADD = $(progs_ldadd) -lm
# some testing of gtester funcitonality
XMLLINT=xmllint
gtester-xmllint-check: # check testreport xml with xmllint if present

508
glib/tests/fileutils.c Normal file
View File

@ -0,0 +1,508 @@
/* Unit tests for gfileutils
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This work is provided "as is"; redistribution and modification
* in whole or in part, in any medium, physical or electronic is
* permitted without restriction.
*
* This work 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.
*
* In no event shall the authors or contributors be liable for any
* direct, indirect, incidental, special, exemplary, or consequential
* damages (including, but not limited to, procurement of substitute
* goods or services; loss of use, data, or profits; or business
* interruption) however caused and on any theory of liability, whether
* in contract, strict liability, or tort (including negligence or
* otherwise) arising in any way out of the use of this software, even
* if advised of the possibility of such damage.
*/
#include <string.h>
#include <errno.h>
#include <glib.h>
#include <glib/gstdio.h>
#define S G_DIR_SEPARATOR_S
static void
check_string (gchar *str, gchar *expected)
{
g_assert (str != NULL);
g_assert_cmpstr (str, ==, expected);
g_free (str);
}
static void
test_build_path (void)
{
/* check_string (g_build_path ("", NULL), "");*/
check_string (g_build_path ("", "", NULL), "");
check_string (g_build_path ("", "x", NULL), "x");
check_string (g_build_path ("", "x", "y", NULL), "xy");
check_string (g_build_path ("", "x", "y", "z", NULL), "xyz");
/* check_string (g_build_path (":", NULL), "");*/
check_string (g_build_path (":", ":", NULL), ":");
check_string (g_build_path (":", ":x", NULL), ":x");
check_string (g_build_path (":", "x:", NULL), "x:");
check_string (g_build_path (":", "", "x", NULL), "x");
check_string (g_build_path (":", "", ":x", NULL), ":x");
check_string (g_build_path (":", ":", "x", NULL), ":x");
check_string (g_build_path (":", "::", "x", NULL), "::x");
check_string (g_build_path (":", "x", "", NULL), "x");
check_string (g_build_path (":", "x:", "", NULL), "x:");
check_string (g_build_path (":", "x", ":", NULL), "x:");
check_string (g_build_path (":", "x", "::", NULL), "x::");
check_string (g_build_path (":", "x", "y", NULL), "x:y");
check_string (g_build_path (":", ":x", "y", NULL), ":x:y");
check_string (g_build_path (":", "x", "y:", NULL), "x:y:");
check_string (g_build_path (":", ":x:", ":y:", NULL), ":x:y:");
check_string (g_build_path (":", ":x::", "::y:", NULL), ":x:y:");
check_string (g_build_path (":", "x", "","y", NULL), "x:y");
check_string (g_build_path (":", "x", ":", "y", NULL), "x:y");
check_string (g_build_path (":", "x", "::", "y", NULL), "x:y");
check_string (g_build_path (":", "x", "y", "z", NULL), "x:y:z");
check_string (g_build_path (":", ":x:", ":y:", ":z:", NULL), ":x:y:z:");
check_string (g_build_path (":", "::x::", "::y::", "::z::", NULL), "::x:y:z::");
/* check_string (g_build_path ("::", NULL), "");*/
check_string (g_build_path ("::", "::", NULL), "::");
check_string (g_build_path ("::", ":::", NULL), ":::");
check_string (g_build_path ("::", "::x", NULL), "::x");
check_string (g_build_path ("::", "x::", NULL), "x::");
check_string (g_build_path ("::", "", "x", NULL), "x");
check_string (g_build_path ("::", "", "::x", NULL), "::x");
check_string (g_build_path ("::", "::", "x", NULL), "::x");
check_string (g_build_path ("::", "::::", "x", NULL), "::::x");
check_string (g_build_path ("::", "x", "", NULL), "x");
check_string (g_build_path ("::", "x::", "", NULL), "x::");
check_string (g_build_path ("::", "x", "::", NULL), "x::");
/* This following is weird, but keeps the definition simple */
check_string (g_build_path ("::", "x", ":::", NULL), "x:::::");
check_string (g_build_path ("::", "x", "::::", NULL), "x::::");
check_string (g_build_path ("::", "x", "y", NULL), "x::y");
check_string (g_build_path ("::", "::x", "y", NULL), "::x::y");
check_string (g_build_path ("::", "x", "y::", NULL), "x::y::");
check_string (g_build_path ("::", "::x::", "::y::", NULL), "::x::y::");
check_string (g_build_path ("::", "::x:::", ":::y::", NULL), "::x::::y::");
check_string (g_build_path ("::", "::x::::", "::::y::", NULL), "::x::y::");
check_string (g_build_path ("::", "x", "", "y", NULL), "x::y");
check_string (g_build_path ("::", "x", "::", "y", NULL), "x::y");
check_string (g_build_path ("::", "x", "::::", "y", NULL), "x::y");
check_string (g_build_path ("::", "x", "y", "z", NULL), "x::y::z");
check_string (g_build_path ("::", "::x::", "::y::", "::z::", NULL), "::x::y::z::");
check_string (g_build_path ("::", ":::x:::", ":::y:::", ":::z:::", NULL), ":::x::::y::::z:::");
check_string (g_build_path ("::", "::::x::::", "::::y::::", "::::z::::", NULL), "::::x::y::z::::");
}
static void
test_build_pathv (void)
{
gchar *args[10];
args[0] = NULL;
check_string (g_build_pathv ("", args), "");
args[0] = ""; args[1] = NULL;
check_string (g_build_pathv ("", args), "");
args[0] = "x"; args[1] = NULL;
check_string (g_build_pathv ("", args), "x");
args[0] = "x"; args[1] = "y"; args[2] = NULL;
check_string (g_build_pathv ("", args), "xy");
args[0] = "x"; args[1] = "y"; args[2] = "z", args[3] = NULL;
check_string (g_build_pathv ("", args), "xyz");
args[0] = NULL;
check_string (g_build_pathv (":", args), "");
args[0] = ":"; args[1] = NULL;
check_string (g_build_pathv (":", args), ":");
args[0] = ":x"; args[1] = NULL;
check_string (g_build_pathv (":", args), ":x");
args[0] = "x:"; args[1] = NULL;
check_string (g_build_pathv (":", args), "x:");
args[0] = ""; args[1] = "x"; args[2] = NULL;
check_string (g_build_pathv (":", args), "x");
args[0] = ""; args[1] = ":x"; args[2] = NULL;
check_string (g_build_pathv (":", args), ":x");
args[0] = ":"; args[1] = "x"; args[2] = NULL;
check_string (g_build_pathv (":", args), ":x");
args[0] = "::"; args[1] = "x"; args[2] = NULL;
check_string (g_build_pathv (":", args), "::x");
args[0] = "x"; args[1] = ""; args[2] = NULL;
check_string (g_build_pathv (":", args), "x");
args[0] = "x:"; args[1] = ""; args[2] = NULL;
check_string (g_build_pathv (":", args), "x:");
args[0] = "x"; args[1] = ":"; args[2] = NULL;
check_string (g_build_pathv (":", args), "x:");
args[0] = "x"; args[1] = "::"; args[2] = NULL;
check_string (g_build_pathv (":", args), "x::");
args[0] = "x"; args[1] = "y"; args[2] = NULL;
check_string (g_build_pathv (":", args), "x:y");
args[0] = ":x"; args[1] = "y"; args[2] = NULL;
check_string (g_build_pathv (":", args), ":x:y");
args[0] = "x"; args[1] = "y:"; args[2] = NULL;
check_string (g_build_pathv (":", args), "x:y:");
args[0] = ":x:"; args[1] = ":y:"; args[2] = NULL;
check_string (g_build_pathv (":", args), ":x:y:");
args[0] = ":x::"; args[1] = "::y:"; args[2] = NULL;
check_string (g_build_pathv (":", args), ":x:y:");
args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
check_string (g_build_pathv (":", args), "x:y");
args[0] = "x"; args[1] = ":"; args[2] = "y"; args[3] = NULL;
check_string (g_build_pathv (":", args), "x:y");
args[0] = "x"; args[1] = "::"; args[2] = "y"; args[3] = NULL;
check_string (g_build_pathv (":", args), "x:y");
args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
check_string (g_build_pathv (":", args), "x:y:z");
args[0] = ":x:"; args[1] = ":y:"; args[2] = ":z:"; args[3] = NULL;
check_string (g_build_pathv (":", args), ":x:y:z:");
args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
check_string (g_build_pathv (":", args), "::x:y:z::");
args[0] = NULL;
check_string (g_build_pathv ("::", args), "");
args[0] = "::"; args[1] = NULL;
check_string (g_build_pathv ("::", args), "::");
args[0] = ":::"; args[1] = NULL;
check_string (g_build_pathv ("::", args), ":::");
args[0] = "::x"; args[1] = NULL;
check_string (g_build_pathv ("::", args), "::x");
args[0] = "x::"; args[1] = NULL;
check_string (g_build_pathv ("::", args), "x::");
args[0] = ""; args[1] = "x"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "x");
args[0] = ""; args[1] = "::x"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "::x");
args[0] = "::"; args[1] = "x"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "::x");
args[0] = "::::"; args[1] = "x"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "::::x");
args[0] = "x"; args[1] = ""; args[2] = NULL;
check_string (g_build_pathv ("::", args), "x");
args[0] = "x::"; args[1] = ""; args[2] = NULL;
check_string (g_build_pathv ("::", args), "x::");
args[0] = "x"; args[1] = "::"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "x::");
/* This following is weird, but keeps the definition simple */
args[0] = "x"; args[1] = ":::"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "x:::::");
args[0] = "x"; args[1] = "::::"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "x::::");
args[0] = "x"; args[1] = "y"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "x::y");
args[0] = "::x"; args[1] = "y"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "::x::y");
args[0] = "x"; args[1] = "y::"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "x::y::");
args[0] = "::x::"; args[1] = "::y::"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "::x::y::");
args[0] = "::x:::"; args[1] = ":::y::"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "::x::::y::");
args[0] = "::x::::"; args[1] = "::::y::"; args[2] = NULL;
check_string (g_build_pathv ("::", args), "::x::y::");
args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
check_string (g_build_pathv ("::", args), "x::y");
args[0] = "x"; args[1] = "::"; args[2] = "y"; args[3] = NULL;
check_string (g_build_pathv ("::", args), "x::y");
args[0] = "x"; args[1] = "::::"; args[2] = "y"; args[3] = NULL;
check_string (g_build_pathv ("::", args), "x::y");
args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
check_string (g_build_pathv ("::", args), "x::y::z");
args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
check_string (g_build_pathv ("::", args), "::x::y::z::");
args[0] = ":::x:::"; args[1] = ":::y:::"; args[2] = ":::z:::"; args[3] = NULL;
check_string (g_build_pathv ("::", args), ":::x::::y::::z:::");
args[0] = "::::x::::"; args[1] = "::::y::::"; args[2] = "::::z::::"; args[3] = NULL;
check_string (g_build_pathv ("::", args), "::::x::y::z::::");
}
static void
test_build_filename (void)
{
/* check_string (g_build_filename (NULL), "");*/
check_string (g_build_filename (S, NULL), S);
check_string (g_build_filename (S"x", NULL), S"x");
check_string (g_build_filename ("x"S, NULL), "x"S);
check_string (g_build_filename ("", "x", NULL), "x");
check_string (g_build_filename ("", S"x", NULL), S"x");
check_string (g_build_filename (S, "x", NULL), S"x");
check_string (g_build_filename (S S, "x", NULL), S S"x");
check_string (g_build_filename ("x", "", NULL), "x");
check_string (g_build_filename ("x"S, "", NULL), "x"S);
check_string (g_build_filename ("x", S, NULL), "x"S);
check_string (g_build_filename ("x", S S, NULL), "x"S S);
check_string (g_build_filename ("x", "y", NULL), "x"S"y");
check_string (g_build_filename (S"x", "y", NULL), S"x"S"y");
check_string (g_build_filename ("x", "y"S, NULL), "x"S"y"S);
check_string (g_build_filename (S"x"S, S"y"S, NULL), S"x"S"y"S);
check_string (g_build_filename (S"x"S S, S S"y"S, NULL), S"x"S"y"S);
check_string (g_build_filename ("x", "", "y", NULL), "x"S"y");
check_string (g_build_filename ("x", S, "y", NULL), "x"S"y");
check_string (g_build_filename ("x", S S, "y", NULL), "x"S"y");
check_string (g_build_filename ("x", "y", "z", NULL), "x"S"y"S"z");
check_string (g_build_filename (S"x"S, S"y"S, S"z"S, NULL), S"x"S"y"S"z"S);
check_string (g_build_filename (S S"x"S S, S S"y"S S, S S"z"S S, NULL), S S"x"S"y"S"z"S S);
#ifdef G_OS_WIN32
/* Test also using the slash as file name separator */
#define U "/"
check_string (g_build_filename (NULL), "");
check_string (g_build_filename (U, NULL), U);
check_string (g_build_filename (U"x", NULL), U"x");
check_string (g_build_filename ("x"U, NULL), "x"U);
check_string (g_build_filename ("", U"x", NULL), U"x");
check_string (g_build_filename ("", U"x", NULL), U"x");
check_string (g_build_filename (U, "x", NULL), U"x");
check_string (g_build_filename (U U, "x", NULL), U U"x");
check_string (g_build_filename (U S, "x", NULL), U S"x");
check_string (g_build_filename ("x"U, "", NULL), "x"U);
check_string (g_build_filename ("x"S"y", "z"U"a", NULL), "x"S"y"S"z"U"a");
check_string (g_build_filename ("x", U, NULL), "x"U);
check_string (g_build_filename ("x", U U, NULL), "x"U U);
check_string (g_build_filename ("x", S U, NULL), "x"S U);
check_string (g_build_filename (U"x", "y", NULL), U"x"U"y");
check_string (g_build_filename ("x", "y"U, NULL), "x"U"y"U);
check_string (g_build_filename (U"x"U, U"y"U, NULL), U"x"U"y"U);
check_string (g_build_filename (U"x"U U, U U"y"U, NULL), U"x"U"y"U);
check_string (g_build_filename ("x", U, "y", NULL), "x"U"y");
check_string (g_build_filename ("x", U U, "y", NULL), "x"U"y");
check_string (g_build_filename ("x", U S, "y", NULL), "x"S"y");
check_string (g_build_filename ("x", S U, "y", NULL), "x"U"y");
check_string (g_build_filename ("x", U "y", "z", NULL), "x"U"y"U"z");
check_string (g_build_filename ("x", S "y", "z", NULL), "x"S"y"S"z");
check_string (g_build_filename ("x", S "y", "z", U, "a", "b", NULL), "x"S"y"S"z"U"a"U"b");
check_string (g_build_filename (U"x"U, U"y"U, U"z"U, NULL), U"x"U"y"U"z"U);
check_string (g_build_filename (U U"x"U U, U U"y"U U, U U"z"U U, NULL), U U"x"U"y"U"z"U U);
#undef U
#endif /* G_OS_WIN32 */
}
static void
test_build_filenamev (void)
{
gchar *args[10];
args[0] = NULL;
check_string (g_build_filenamev (args), "");
args[0] = S; args[1] = NULL;
check_string (g_build_filenamev (args), S);
args[0] = S"x"; args[1] = NULL;
check_string (g_build_filenamev (args), S"x");
args[0] = "x"S; args[1] = NULL;
check_string (g_build_filenamev (args), "x"S);
args[0] = ""; args[1] = "x"; args[2] = NULL;
check_string (g_build_filenamev (args), "x");
args[0] = ""; args[1] = S"x"; args[2] = NULL;
check_string (g_build_filenamev (args), S"x");
args[0] = S; args[1] = "x"; args[2] = NULL;
check_string (g_build_filenamev (args), S"x");
args[0] = S S; args[1] = "x"; args[2] = NULL;
check_string (g_build_filenamev (args), S S"x");
args[0] = "x"; args[1] = ""; args[2] = NULL;
check_string (g_build_filenamev (args), "x");
args[0] = "x"S; args[1] = ""; args[2] = NULL;
check_string (g_build_filenamev (args), "x"S);
args[0] = "x"; args[1] = S; args[2] = NULL;
check_string (g_build_filenamev (args), "x"S);
args[0] = "x"; args[1] = S S; args[2] = NULL;
check_string (g_build_filenamev (args), "x"S S);
args[0] = "x"; args[1] = "y"; args[2] = NULL;
check_string (g_build_filenamev (args), "x"S"y");
args[0] = S"x"; args[1] = "y"; args[2] = NULL;
check_string (g_build_filenamev (args), S"x"S"y");
args[0] = "x"; args[1] = "y"S; args[2] = NULL;
check_string (g_build_filenamev (args), "x"S"y"S);
args[0] = S"x"S; args[1] = S"y"S; args[2] = NULL;
check_string (g_build_filenamev (args), S"x"S"y"S);
args[0] = S"x"S S; args[1] = S S"y"S; args[2] = NULL;
check_string (g_build_filenamev (args), S"x"S"y"S);
args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
check_string (g_build_filenamev (args), "x"S"y");
args[0] = "x"; args[1] = S; args[2] = "y"; args[3] = NULL;
check_string (g_build_filenamev (args), "x"S"y");
args[0] = "x"; args[1] = S S; args[2] = "y"; args[3] = NULL;
check_string (g_build_filenamev (args), "x"S"y");
args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
check_string (g_build_filenamev (args), "x"S"y"S"z");
args[0] = S"x"S; args[1] = S"y"S; args[2] = S"z"S; args[3] = NULL;
check_string (g_build_filenamev (args), S"x"S"y"S"z"S);
args[0] = S S"x"S S; args[1] = S S"y"S S; args[2] = S S"z"S S; args[3] = NULL;
check_string (g_build_filenamev (args), S S"x"S"y"S"z"S S);
#ifdef G_OS_WIN32
/* Test also using the slash as file name separator */
#define U "/"
args[0] = NULL;
check_string (g_build_filenamev (args), "");
args[0] = U; args[1] = NULL;
check_string (g_build_filenamev (args), U);
args[0] = U"x"; args[1] = NULL;
check_string (g_build_filenamev (args), U"x");
args[0] = "x"U; args[1] = NULL;
check_string (g_build_filenamev (args), "x"U);
args[0] = ""; args[1] = U"x"; args[2] = NULL;
check_string (g_build_filenamev (args), U"x");
args[0] = ""; args[1] = U"x"; args[2] = NULL;
check_string (g_build_filenamev (args), U"x");
args[0] = U; args[1] = "x"; args[2] = NULL;
check_string (g_build_filenamev (args), U"x");
args[0] = U U; args[1] = "x"; args[2] = NULL;
check_string (g_build_filenamev (args), U U"x");
args[0] = U S; args[1] = "x"; args[2] = NULL;
check_string (g_build_filenamev (args), U S"x");
args[0] = "x"U; args[1] = ""; args[2] = NULL;
check_string (g_build_filenamev (args), "x"U);
args[0] = "x"S"y"; args[1] = "z"U"a"; args[2] = NULL;
check_string (g_build_filenamev (args), "x"S"y"S"z"U"a");
args[0] = "x"; args[1] = U; args[2] = NULL;
check_string (g_build_filenamev (args), "x"U);
args[0] = "x"; args[1] = U U; args[2] = NULL;
check_string (g_build_filenamev (args), "x"U U);
args[0] = "x"; args[1] = S U; args[2] = NULL;
check_string (g_build_filenamev (args), "x"S U);
args[0] = U"x"; args[1] = "y"; args[2] = NULL;
check_string (g_build_filenamev (args), U"x"U"y");
args[0] = "x"; args[1] = "y"U; args[2] = NULL;
check_string (g_build_filenamev (args), "x"U"y"U);
args[0] = U"x"U; args[1] = U"y"U; args[2] = NULL;
check_string (g_build_filenamev (args), U"x"U"y"U);
args[0] = U"x"U U; args[1] = U U"y"U; args[2] = NULL;
check_string (g_build_filenamev (args), U"x"U"y"U);
args[0] = "x"; args[1] = U; args[2] = "y", args[3] = NULL;
check_string (g_build_filenamev (args), "x"U"y");
args[0] = "x"; args[1] = U U; args[2] = "y", args[3] = NULL;
check_string (g_build_filenamev (args), "x"U"y");
args[0] = "x"; args[1] = U S; args[2] = "y", args[3] = NULL;
check_string (g_build_filenamev (args), "x"S"y");
args[0] = "x"; args[1] = S U; args[2] = "y", args[3] = NULL;
check_string (g_build_filenamev (args), "x"U"y");
args[0] = "x"; args[1] = U "y"; args[2] = "z", args[3] = NULL;
check_string (g_build_filenamev (args), "x"U"y"U"z");
args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = NULL;
check_string (g_build_filenamev (args), "x"S"y"S"z");
args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = U;
args[4] = "a"; args[5] = "b"; args[6] = NULL;
check_string (g_build_filenamev (args), "x"S"y"S"z"U"a"U"b");
args[0] = U"x"U; args[1] = U"y"U; args[2] = U"z"U, args[3] = NULL;
check_string (g_build_filenamev (args), U"x"U"y"U"z"U);
args[0] = U U"x"U U; args[1] = U U"y"U U; args[2] = U U"z"U U, args[3] = NULL;
check_string (g_build_filenamev (args), U U"x"U"y"U"z"U U);
#undef U
#endif /* G_OS_WIN32 */
}
#undef S
static void
test_mkdir_with_parents_1 (const gchar *base)
{
char *p0 = g_build_filename (base, "fum", NULL);
char *p1 = g_build_filename (p0, "tem", NULL);
char *p2 = g_build_filename (p1, "zap", NULL);
FILE *f;
g_remove (p2);
g_remove (p1);
g_remove (p0);
if (g_file_test (p0, G_FILE_TEST_EXISTS))
g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p0);
if (g_file_test (p1, G_FILE_TEST_EXISTS))
g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p1);
if (g_file_test (p2, G_FILE_TEST_EXISTS))
g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p2);
if (g_mkdir_with_parents (p2, 0777) == -1)
g_error ("failed, g_mkdir_with_parents(%s) failed: %s\n", p2, g_strerror (errno));
if (!g_file_test (p2, G_FILE_TEST_IS_DIR))
g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p2);
if (!g_file_test (p1, G_FILE_TEST_IS_DIR))
g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p1);
if (!g_file_test (p0, G_FILE_TEST_IS_DIR))
g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p0);
g_rmdir (p2);
if (g_file_test (p2, G_FILE_TEST_EXISTS))
g_error ("failed, did g_rmdir(%s), but %s is still there\n", p2, p2);
g_rmdir (p1);
if (g_file_test (p1, G_FILE_TEST_EXISTS))
g_error ("failed, did g_rmdir(%s), but %s is still there\n", p1, p1);
f = g_fopen (p1, "w");
if (f == NULL)
g_error ("failed, couldn't create file %s\n", p1);
fclose (f);
if (g_mkdir_with_parents (p1, 0666) == 0)
g_error ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p1, p1);
if (g_mkdir_with_parents (p2, 0666) == 0)
g_error("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p2, p1);
g_remove (p2);
g_remove (p1);
g_remove (p0);
}
static void
test_mkdir_with_parents (void)
{
gchar *cwd;
if (g_test_verbose())
g_print ("checking g_mkdir_with_parents() in subdir ./hum/");
test_mkdir_with_parents_1 ("hum");
g_remove ("hum");
if (g_test_verbose())
g_print ("checking g_mkdir_with_parents() in subdir ./hii///haa/hee/");
test_mkdir_with_parents_1 ("hii///haa/hee");
g_remove ("hii/haa/hee");
g_remove ("hii/haa");
g_remove ("hii");
cwd = g_get_current_dir ();
if (g_test_verbose())
g_print ("checking g_mkdir_with_parents() in cwd: %s", cwd);
test_mkdir_with_parents_1 (cwd);
g_free (cwd);
}
static void
test_format_size_for_display (void)
{
check_string (g_format_size_for_display (0), "0 bytes");
check_string (g_format_size_for_display (1), "1 byte");
check_string (g_format_size_for_display (2), "2 bytes");
check_string (g_format_size_for_display (1024), "1.0 KB");
check_string (g_format_size_for_display (1024 * 1024), "1.0 MB");
check_string (g_format_size_for_display (1024 * 1024 * 1024), "1.0 GB");
}
int
main (int argc,
char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/fileutils/build-path", test_build_path);
g_test_add_func ("/fileutils/build-pathv", test_build_pathv);
g_test_add_func ("/fileutils/build-filename", test_build_filename);
g_test_add_func ("/fileutils/build-filenamev", test_build_filenamev);
g_test_add_func ("/fileutils/mkdir-with-parents", test_mkdir_with_parents);
g_test_add_func ("/fileutils/format-size-for-display", test_format_size_for_display);
return g_test_run();
}

1053
glib/tests/strfuncs.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -137,10 +137,7 @@ test_programs = \
slice-threadinit \
spawn-test \
$(spawn_test_win32_gui) \
strfunc-test \
string-test \
strtod-test \
strtoll-test \
thread-test \
threadpool-test \
tree-test \
@ -213,10 +210,7 @@ slice_concurrent_LDADD = $(thread_ldadd)
slice_threadinit_SOURCES = slice-threadinit.c
slice_threadinit_LDADD = $(thread_ldadd)
spawn_test_LDADD = $(progs_ldadd)
strfunc_test_LDADD = $(progs_ldadd)
string_test_LDADD = $(progs_ldadd)
strtod_test_LDADD = $(progs_ldadd) -lm
strtoll_test_LDADD = $(progs_ldadd) -lm
thread_test_LDADD = $(thread_ldadd)
threadpool_test_LDADD = $(thread_ldadd)
tree_test_LDADD = $(progs_ldadd)

View File

@ -1,775 +0,0 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN
#include <stdio.h>
#include <string.h>
#include "glib.h"
#include <stdarg.h>
#include <ctype.h>
static gboolean any_failed = FALSE;
static gboolean failed = FALSE;
#define TEST(m,cond) G_STMT_START { failed = !(cond); \
if (failed) \
{ if (!m) \
g_print ("(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \
else \
g_print ("(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), m ? (gchar*)m : ""); \
fflush (stdout); \
any_failed = TRUE; \
} \
} G_STMT_END
#define TEST_FAILED(message) \
G_STMT_START { g_print ("Error: "); g_print message; g_print ("\n"); any_failed = TRUE; } G_STMT_END
#define GLIB_TEST_STRING "el dorado "
static gboolean
strv_check (gchar **strv, ...)
{
gboolean ok = TRUE;
gint i = 0;
va_list list;
va_start (list, strv);
while (ok)
{
const gchar *str = va_arg (list, const char *);
if (strv[i] == NULL)
{
ok = str == NULL;
break;
}
if (str == NULL)
ok = FALSE;
else if (strcmp (strv[i], str) != 0)
ok = FALSE;
i++;
}
va_end (list);
g_strfreev (strv);
return ok;
}
static gboolean
str_check (gchar *str,
gchar *expected)
{
gboolean ok = (strcmp (str, expected) == 0);
g_free (str);
return ok;
}
static gboolean
strchomp_check (gchar *str,
gchar *expected)
{
gchar *tmp = strdup (str);
gboolean ok;
g_strchomp (tmp);
ok = (strcmp (tmp, expected) == 0);
g_free (tmp);
return ok;
}
#define FOR_ALL_CTYPE(macro) \
macro(isalnum) \
macro(isalpha) \
macro(iscntrl) \
macro(isdigit) \
macro(isgraph) \
macro(islower) \
macro(isprint) \
macro(ispunct) \
macro(isspace) \
macro(isupper) \
macro(isxdigit)
#define DEFINE_CALL_CTYPE(function) \
static int \
call_##function (int c) \
{ \
return function (c); \
}
#define DEFINE_CALL_G_ASCII_CTYPE(function) \
static gboolean \
call_g_ascii_##function (gchar c) \
{ \
return g_ascii_##function (c); \
}
FOR_ALL_CTYPE (DEFINE_CALL_CTYPE)
FOR_ALL_CTYPE (DEFINE_CALL_G_ASCII_CTYPE)
static void
test_is_function (const char *name,
gboolean (* ascii_function) (gchar),
int (* c_library_function) (int),
gboolean (* unicode_function) (gunichar))
{
int c;
for (c = 0; c <= 0x7F; c++)
{
gboolean ascii_result = ascii_function ((gchar)c);
gboolean c_library_result = c_library_function (c) != 0;
gboolean unicode_result = unicode_function ((gunichar) c);
if (ascii_result != c_library_result && c != '\v')
TEST_FAILED (("g_ascii_%s returned %d and %s returned %d for 0x%X",
name, ascii_result, name, c_library_result, c));
if (ascii_result != unicode_result)
TEST_FAILED (("g_ascii_%s returned %d and g_unichar_%s returned %d for 0x%X",
name, ascii_result, name, unicode_result, c));
}
for (c = 0x80; c <= 0xFF; c++)
{
gboolean ascii_result = ascii_function ((gchar)c);
if (ascii_result)
TEST_FAILED (("g_ascii_%s returned TRUE for 0x%X",
name, c));
}
}
static void
test_to_function (const char *name,
gchar (* ascii_function) (gchar),
int (* c_library_function) (int),
gunichar (* unicode_function) (gunichar))
{
int c;
for (c = 0; c <= 0x7F; c++)
{
int ascii_result = (guchar) ascii_function ((gchar) c);
int c_library_result = c_library_function (c);
int unicode_result = unicode_function ((gunichar) c);
if (ascii_result != c_library_result)
TEST_FAILED (("g_ascii_%s returned 0x%X and %s returned 0x%X for 0x%X",
name, ascii_result, name, c_library_result, c));
if (ascii_result != unicode_result)
TEST_FAILED (("g_ascii_%s returned 0x%X and g_unichar_%s returned 0x%X for 0x%X",
name, ascii_result, name, unicode_result, c));
}
for (c = 0x80; c <= 0xFF; c++)
{
int ascii_result = (guchar) ascii_function ((gchar) c);
if (ascii_result != c)
TEST_FAILED (("g_ascii_%s returned 0x%X for 0x%X",
name, ascii_result, c));
}
}
static void
test_digit_function (const char *name,
int (* ascii_function) (gchar),
int (* unicode_function) (gunichar))
{
int c;
for (c = 0; c <= 0x7F; c++)
{
int ascii_result = ascii_function ((gchar) c);
int unicode_result = unicode_function ((gunichar) c);
if (ascii_result != unicode_result)
TEST_FAILED (("g_ascii_%s_value returned %d and g_unichar_%s_value returned %d for 0x%X",
name, ascii_result, name, unicode_result, c));
}
for (c = 0x80; c <= 0xFF; c++)
{
int ascii_result = ascii_function ((gchar) c);
if (ascii_result != -1)
TEST_FAILED (("g_ascii_%s_value returned %d for 0x%X",
name, ascii_result, c));
}
}
int
main (int argc,
char *argv[])
{
gchar *string;
gchar *vec[] = { "Foo", "Bar", NULL };
gchar **copy;
gchar *args[10];
TEST (NULL, g_ascii_strcasecmp ("FroboZZ", "frobozz") == 0);
TEST (NULL, g_ascii_strcasecmp ("frobozz", "frobozz") == 0);
TEST (NULL, g_ascii_strcasecmp ("frobozz", "FROBOZZ") == 0);
TEST (NULL, g_ascii_strcasecmp ("FROBOZZ", "froboz") != 0);
TEST (NULL, g_ascii_strcasecmp ("", "") == 0);
TEST (NULL, g_ascii_strcasecmp ("!#%&/()", "!#%&/()") == 0);
TEST (NULL, g_ascii_strcasecmp ("a", "b") < 0);
TEST (NULL, g_ascii_strcasecmp ("a", "B") < 0);
TEST (NULL, g_ascii_strcasecmp ("A", "b") < 0);
TEST (NULL, g_ascii_strcasecmp ("A", "B") < 0);
TEST (NULL, g_ascii_strcasecmp ("b", "a") > 0);
TEST (NULL, g_ascii_strcasecmp ("b", "A") > 0);
TEST (NULL, g_ascii_strcasecmp ("B", "a") > 0);
TEST (NULL, g_ascii_strcasecmp ("B", "A") > 0);
TEST (NULL, g_strdup (NULL) == NULL);
string = g_strdup (GLIB_TEST_STRING);
TEST (NULL, string != NULL);
TEST (NULL, strcmp (string, GLIB_TEST_STRING) == 0);
g_free(string);
string = g_strconcat (GLIB_TEST_STRING, NULL);
TEST (NULL, string != NULL);
TEST (NULL, strcmp (string, GLIB_TEST_STRING) == 0);
g_free(string);
string = g_strconcat (GLIB_TEST_STRING, GLIB_TEST_STRING,
GLIB_TEST_STRING, NULL);
TEST (NULL, string != NULL);
TEST (NULL, strcmp (string, GLIB_TEST_STRING GLIB_TEST_STRING
GLIB_TEST_STRING) == 0);
g_free(string);
string = g_strdup_printf ("%05d %-5s", 21, "test");
TEST (NULL, string != NULL);
TEST (NULL, strcmp(string, "00021 test ") == 0);
g_free (string);
TEST (NULL, strcmp
(g_strcompress ("abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313\\12345z"),
"abc\\\"\b\f\n\r\t\003\177\234\313\12345z") == 0);
TEST (NULL, strcmp (g_strescape("abc\\\"\b\f\n\r\t\003\177\234\313", NULL),
"abc\\\\\\\"\\b\\f\\n\\r\\t\\003\\177\\234\\313") == 0);
TEST (NULL, strcmp(g_strescape("abc\\\"\b\f\n\r\t\003\177\234\313",
"\b\f\001\002\003\004"),
"abc\\\\\\\"\b\f\\n\\r\\t\003\\177\\234\\313") == 0);
copy = g_strdupv (vec);
TEST (NULL, strcmp (copy[0], "Foo") == 0);
TEST (NULL, strcmp (copy[1], "Bar") == 0);
TEST (NULL, copy[2] == NULL);
g_strfreev (copy);
TEST (NULL, strcmp (g_strstr_len ("FooBarFooBarFoo", 6, "Bar"),
"BarFooBarFoo") == 0);
TEST (NULL, strcmp (g_strrstr ("FooBarFooBarFoo", "Bar"),
"BarFoo") == 0);
TEST (NULL, strcmp (g_strrstr_len ("FooBarFooBarFoo", 14, "BarFoo"),
"BarFooBarFoo") == 0);
/* Test g_strsplit() */
TEST (NULL, strv_check (g_strsplit ("", ",", 0), NULL));
TEST (NULL, strv_check (g_strsplit ("x", ",", 0), "x", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y", ",", 0), "x", "y", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y,", ",", 0), "x", "y", "", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y", ",", 0), "", "x", "y", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y,", ",", 0), "", "x", "y", "", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y,z", ",", 0), "x", "y", "z", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y,z,", ",", 0), "x", "y", "z", "", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y,z", ",", 0), "", "x", "y", "z", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y,z,", ",", 0), "", "x", "y", "z", "", NULL));
TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",", 0), "", "", "x", "", "y", "", "z", "", "", NULL));
TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",,", 0), "", "x", "y", "z", "", NULL));
TEST (NULL, strv_check (g_strsplit ("", ",", 1), NULL));
TEST (NULL, strv_check (g_strsplit ("x", ",", 1), "x", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y", ",", 1), "x,y", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y,", ",", 1), "x,y,", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y", ",", 1), ",x,y", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y,", ",", 1), ",x,y,", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y,z", ",", 1), "x,y,z", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y,z,", ",", 1), "x,y,z,", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y,z", ",", 1), ",x,y,z", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y,z,", ",", 1), ",x,y,z,", NULL));
TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",", 1), ",,x,,y,,z,,", NULL));
TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",,", 1), ",,x,,y,,z,,", NULL));
TEST (NULL, strv_check (g_strsplit ("", ",", 2), NULL));
TEST (NULL, strv_check (g_strsplit ("x", ",", 2), "x", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y", ",", 2), "x", "y", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y,", ",", 2), "x", "y,", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y", ",", 2), "", "x,y", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y,", ",", 2), "", "x,y,", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y,z", ",", 2), "x", "y,z", NULL));
TEST (NULL, strv_check (g_strsplit ("x,y,z,", ",", 2), "x", "y,z,", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y,z", ",", 2), "", "x,y,z", NULL));
TEST (NULL, strv_check (g_strsplit (",x,y,z,", ",", 2), "", "x,y,z,", NULL));
TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL));
TEST (NULL, strv_check (g_strsplit (",,x,,y,,z,,", ",,", 2), "", "x,,y,,z,,", NULL));
/* Test g_strsplit_set() */
TEST (NULL, strv_check (g_strsplit_set ("", ",/", 0), NULL));
TEST (NULL, strv_check (g_strsplit_set (":def/ghi:", ":/", -1), "", "def", "ghi", "", NULL));
TEST (NULL, strv_check (g_strsplit_set ("abc:def/ghi", ":/", -1), "abc", "def", "ghi", NULL));
TEST (NULL, strv_check (g_strsplit_set (",;,;,;,;", ",;", -1), "", "", "", "", "", "", "", "", "", NULL));
TEST (NULL, strv_check (g_strsplit_set (",,abc.def", ".,", -1), "", "", "abc", "def", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x.y", ",.", 0), "", "x", "y", NULL));
TEST (NULL, strv_check (g_strsplit_set (".x,y,", ",.", 0), "", "x", "y", "", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y.z", ",.", 0), "x", "y", "z", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x.y,z,", ",.", 0), "x", "y", "z", "", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x.y,z", ",.", 0), "", "x", "y", "z", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y,z,", ",.", 0), "", "x", "y", "z", "", NULL));
TEST (NULL, strv_check (g_strsplit_set (",.x,,y,;z..", ".,;", 0), "", "", "x", "", "y", "", "z", "", "", NULL));
TEST (NULL, strv_check (g_strsplit_set (",,x,,y,,z,,", ",,", 0), "", "", "x", "", "y", "", "z", "", "", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y.z", ",.", 1), "x,y.z", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x.y,z,", ",.", 1), "x.y,z,", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y,z", ",.", 1), ",x,y,z", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y.z,", ",.", 1), ",x,y.z,", NULL));
TEST (NULL, strv_check (g_strsplit_set (",,x,.y,,z,,", ",.", 1), ",,x,.y,,z,,", NULL));
TEST (NULL, strv_check (g_strsplit_set (",.x,,y,,z,,", ",,..", 1), ",.x,,y,,z,,", NULL));
TEST (NULL, strv_check (g_strsplit_set ("", ",", 0), NULL));
TEST (NULL, strv_check (g_strsplit_set ("x", ",", 0), "x", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y", ",", 0), "x", "y", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y,", ",", 0), "x", "y", "", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y", ",", 0), "", "x", "y", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y,", ",", 0), "", "x", "y", "", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y,z", ",", 0), "x", "y", "z", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y,z,", ",", 0), "x", "y", "z", "", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y,z", ",", 0), "", "x", "y", "z", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y,z,", ",", 0), "", "x", "y", "z", "", NULL));
TEST (NULL, strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 0), "", "", "x", "", "y", "", "z", "", "", NULL));
TEST (NULL, strv_check (g_strsplit_set ("", ",", 1), NULL));
TEST (NULL, strv_check (g_strsplit_set ("x", ",", 1), "x", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y", ",", 1), "x,y", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y,", ",", 1), "x,y,", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y", ",", 1), ",x,y", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y,", ",", 1), ",x,y,", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y,z", ",", 1), "x,y,z", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y,z,", ",", 1), "x,y,z,", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y,z", ",", 1), ",x,y,z", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y,z,", ",", 1), ",x,y,z,", NULL));
TEST (NULL, strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 1), ",,x,,y,,z,,", NULL));
TEST (NULL, strv_check (g_strsplit_set (",,x,,y,,z,,", ",,", 1), ",,x,,y,,z,,", NULL));
TEST (NULL, strv_check (g_strsplit_set ("", ",", 2), NULL));
TEST (NULL, strv_check (g_strsplit_set ("x", ",", 2), "x", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y", ",", 2), "x", "y", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y,", ",", 2), "x", "y,", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y", ",", 2), "", "x,y", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y,", ",", 2), "", "x,y,", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y,z", ",", 2), "x", "y,z", NULL));
TEST (NULL, strv_check (g_strsplit_set ("x,y,z,", ",", 2), "x", "y,z,", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y,z", ",", 2), "", "x,y,z", NULL));
TEST (NULL, strv_check (g_strsplit_set (",x,y,z,", ",", 2), "", "x,y,z,", NULL));
TEST (NULL, strv_check (g_strsplit_set (",,x,,y,,z,,", ",", 2), "", ",x,,y,,z,,", NULL));
TEST (NULL, strv_check (g_strsplit_set (",,x,.y,..z,,", ",.", 3), "", "", "x,.y,..z,,", NULL));
#define TEST_IS(name) test_is_function (#name, call_g_ascii_##name, call_##name, g_unichar_##name);
FOR_ALL_CTYPE(TEST_IS)
#undef TEST_IS
#define TEST_TO(name) test_to_function (#name, g_ascii_##name, name, g_unichar_##name)
TEST_TO (tolower);
TEST_TO (toupper);
#undef TEST_TO
#define TEST_DIGIT(name) test_digit_function (#name, g_ascii_##name##_value, g_unichar_##name##_value)
TEST_DIGIT (digit);
TEST_DIGIT (xdigit);
#undef TEST_DIGIT
/* Tests for strchomp () */
TEST (NULL, strchomp_check ("", ""));
TEST (NULL, strchomp_check (" ", ""));
TEST (NULL, strchomp_check (" \t\r\n", ""));
TEST (NULL, strchomp_check ("a ", "a"));
TEST (NULL, strchomp_check ("a ", "a"));
TEST (NULL, strchomp_check ("a a", "a a"));
TEST (NULL, strchomp_check ("a a ", "a a"));
/* Tests for g_build_path, g_build_filename */
TEST (NULL, str_check (g_build_path ("", NULL), ""));
TEST (NULL, str_check (g_build_path ("", "", NULL), ""));
TEST (NULL, str_check (g_build_path ("", "x", NULL), "x"));
TEST (NULL, str_check (g_build_path ("", "x", "y", NULL), "xy"));
TEST (NULL, str_check (g_build_path ("", "x", "y", "z", NULL), "xyz"));
TEST (NULL, str_check (g_build_path (":", NULL), ""));
TEST (NULL, str_check (g_build_path (":", ":", NULL), ":"));
TEST (NULL, str_check (g_build_path (":", ":x", NULL), ":x"));
TEST (NULL, str_check (g_build_path (":", "x:", NULL), "x:"));
TEST (NULL, str_check (g_build_path (":", "", "x", NULL), "x"));
TEST (NULL, str_check (g_build_path (":", "", ":x", NULL), ":x"));
TEST (NULL, str_check (g_build_path (":", ":", "x", NULL), ":x"));
TEST (NULL, str_check (g_build_path (":", "::", "x", NULL), "::x"));
TEST (NULL, str_check (g_build_path (":", "x", "", NULL), "x"));
TEST (NULL, str_check (g_build_path (":", "x:", "", NULL), "x:"));
TEST (NULL, str_check (g_build_path (":", "x", ":", NULL), "x:"));
TEST (NULL, str_check (g_build_path (":", "x", "::", NULL), "x::"));
TEST (NULL, str_check (g_build_path (":", "x", "y", NULL), "x:y"));
TEST (NULL, str_check (g_build_path (":", ":x", "y", NULL), ":x:y"));
TEST (NULL, str_check (g_build_path (":", "x", "y:", NULL), "x:y:"));
TEST (NULL, str_check (g_build_path (":", ":x:", ":y:", NULL), ":x:y:"));
TEST (NULL, str_check (g_build_path (":", ":x::", "::y:", NULL), ":x:y:"));
TEST (NULL, str_check (g_build_path (":", "x", "","y", NULL), "x:y"));
TEST (NULL, str_check (g_build_path (":", "x", ":", "y", NULL), "x:y"));
TEST (NULL, str_check (g_build_path (":", "x", "::", "y", NULL), "x:y"));
TEST (NULL, str_check (g_build_path (":", "x", "y", "z", NULL), "x:y:z"));
TEST (NULL, str_check (g_build_path (":", ":x:", ":y:", ":z:", NULL), ":x:y:z:"));
TEST (NULL, str_check (g_build_path (":", "::x::", "::y::", "::z::", NULL), "::x:y:z::"));
TEST (NULL, str_check (g_build_path ("::", NULL), ""));
TEST (NULL, str_check (g_build_path ("::", "::", NULL), "::"));
TEST (NULL, str_check (g_build_path ("::", ":::", NULL), ":::"));
TEST (NULL, str_check (g_build_path ("::", "::x", NULL), "::x"));
TEST (NULL, str_check (g_build_path ("::", "x::", NULL), "x::"));
TEST (NULL, str_check (g_build_path ("::", "", "x", NULL), "x"));
TEST (NULL, str_check (g_build_path ("::", "", "::x", NULL), "::x"));
TEST (NULL, str_check (g_build_path ("::", "::", "x", NULL), "::x"));
TEST (NULL, str_check (g_build_path ("::", "::::", "x", NULL), "::::x"));
TEST (NULL, str_check (g_build_path ("::", "x", "", NULL), "x"));
TEST (NULL, str_check (g_build_path ("::", "x::", "", NULL), "x::"));
TEST (NULL, str_check (g_build_path ("::", "x", "::", NULL), "x::"));
/* This following is weird, but keeps the definition simple */
TEST (NULL, str_check (g_build_path ("::", "x", ":::", NULL), "x:::::"));
TEST (NULL, str_check (g_build_path ("::", "x", "::::", NULL), "x::::"));
TEST (NULL, str_check (g_build_path ("::", "x", "y", NULL), "x::y"));
TEST (NULL, str_check (g_build_path ("::", "::x", "y", NULL), "::x::y"));
TEST (NULL, str_check (g_build_path ("::", "x", "y::", NULL), "x::y::"));
TEST (NULL, str_check (g_build_path ("::", "::x::", "::y::", NULL), "::x::y::"));
TEST (NULL, str_check (g_build_path ("::", "::x:::", ":::y::", NULL), "::x::::y::"));
TEST (NULL, str_check (g_build_path ("::", "::x::::", "::::y::", NULL), "::x::y::"));
TEST (NULL, str_check (g_build_path ("::", "x", "", "y", NULL), "x::y"));
TEST (NULL, str_check (g_build_path ("::", "x", "::", "y", NULL), "x::y"));
TEST (NULL, str_check (g_build_path ("::", "x", "::::", "y", NULL), "x::y"));
TEST (NULL, str_check (g_build_path ("::", "x", "y", "z", NULL), "x::y::z"));
TEST (NULL, str_check (g_build_path ("::", "::x::", "::y::", "::z::", NULL), "::x::y::z::"));
TEST (NULL, str_check (g_build_path ("::", ":::x:::", ":::y:::", ":::z:::", NULL), ":::x::::y::::z:::"));
TEST (NULL, str_check (g_build_path ("::", "::::x::::", "::::y::::", "::::z::::", NULL), "::::x::y::z::::"));
args[0] = NULL;
TEST (NULL, str_check (g_build_pathv ("", args), ""));
args[0] = ""; args[1] = NULL;
TEST (NULL, str_check (g_build_pathv ("", args), ""));
args[0] = "x"; args[1] = NULL;
TEST (NULL, str_check (g_build_pathv ("", args), "x"));
args[0] = "x"; args[1] = "y"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("", args), "xy"));
args[0] = "x"; args[1] = "y"; args[2] = "z", args[3] = NULL;
TEST (NULL, str_check (g_build_pathv ("", args), "xyz"));
args[0] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), ""));
args[0] = ":"; args[1] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), ":"));
args[0] = ":x"; args[1] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), ":x"));
args[0] = "x:"; args[1] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x:"));
args[0] = ""; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x"));
args[0] = ""; args[1] = ":x"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), ":x"));
args[0] = ":"; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), ":x"));
args[0] = "::"; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "::x"));
args[0] = "x"; args[1] = ""; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x"));
args[0] = "x:"; args[1] = ""; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x:"));
args[0] = "x"; args[1] = ":"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x:"));
args[0] = "x"; args[1] = "::"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x::"));
args[0] = "x"; args[1] = "y"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x:y"));
args[0] = ":x"; args[1] = "y"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), ":x:y"));
args[0] = "x"; args[1] = "y:"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x:y:"));
args[0] = ":x:"; args[1] = ":y:"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), ":x:y:"));
args[0] = ":x::"; args[1] = "::y:"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), ":x:y:"));
args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x:y"));
args[0] = "x"; args[1] = ":"; args[2] = "y"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x:y"));
args[0] = "x"; args[1] = "::"; args[2] = "y"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x:y"));
args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "x:y:z"));
args[0] = ":x:"; args[1] = ":y:"; args[2] = ":z:"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), ":x:y:z:"));
args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv (":", args), "::x:y:z::"));
args[0] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), ""));
args[0] = "::"; args[1] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "::"));
args[0] = ":::"; args[1] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), ":::"));
args[0] = "::x"; args[1] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "::x"));
args[0] = "x::"; args[1] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x::"));
args[0] = ""; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x"));
args[0] = ""; args[1] = "::x"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "::x"));
args[0] = "::"; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "::x"));
args[0] = "::::"; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "::::x"));
args[0] = "x"; args[1] = ""; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x"));
args[0] = "x::"; args[1] = ""; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x::"));
args[0] = "x"; args[1] = "::"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x::"));
/* This following is weird, but keeps the definition simple */
args[0] = "x"; args[1] = ":::"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x:::::"));
args[0] = "x"; args[1] = "::::"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x::::"));
args[0] = "x"; args[1] = "y"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x::y"));
args[0] = "::x"; args[1] = "y"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "::x::y"));
args[0] = "x"; args[1] = "y::"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x::y::"));
args[0] = "::x::"; args[1] = "::y::"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "::x::y::"));
args[0] = "::x:::"; args[1] = ":::y::"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "::x::::y::"));
args[0] = "::x::::"; args[1] = "::::y::"; args[2] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "::x::y::"));
args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x::y"));
args[0] = "x"; args[1] = "::"; args[2] = "y"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x::y"));
args[0] = "x"; args[1] = "::::"; args[2] = "y"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x::y"));
args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "x::y::z"));
args[0] = "::x::"; args[1] = "::y::"; args[2] = "::z::"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "::x::y::z::"));
args[0] = ":::x:::"; args[1] = ":::y:::"; args[2] = ":::z:::"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), ":::x::::y::::z:::"));
args[0] = "::::x::::"; args[1] = "::::y::::"; args[2] = "::::z::::"; args[3] = NULL;
TEST (NULL, str_check (g_build_pathv ("::", args), "::::x::y::z::::"));
#define S G_DIR_SEPARATOR_S
TEST (NULL, str_check (g_build_filename (NULL), ""));
TEST (NULL, str_check (g_build_filename (S, NULL), S));
TEST (NULL, str_check (g_build_filename (S"x", NULL), S"x"));
TEST (NULL, str_check (g_build_filename ("x"S, NULL), "x"S));
TEST (NULL, str_check (g_build_filename ("", "x", NULL), "x"));
TEST (NULL, str_check (g_build_filename ("", S"x", NULL), S"x"));
TEST (NULL, str_check (g_build_filename (S, "x", NULL), S"x"));
TEST (NULL, str_check (g_build_filename (S S, "x", NULL), S S"x"));
TEST (NULL, str_check (g_build_filename ("x", "", NULL), "x"));
TEST (NULL, str_check (g_build_filename ("x"S, "", NULL), "x"S));
TEST (NULL, str_check (g_build_filename ("x", S, NULL), "x"S));
TEST (NULL, str_check (g_build_filename ("x", S S, NULL), "x"S S));
TEST (NULL, str_check (g_build_filename ("x", "y", NULL), "x"S"y"));
TEST (NULL, str_check (g_build_filename (S"x", "y", NULL), S"x"S"y"));
TEST (NULL, str_check (g_build_filename ("x", "y"S, NULL), "x"S"y"S));
TEST (NULL, str_check (g_build_filename (S"x"S, S"y"S, NULL), S"x"S"y"S));
TEST (NULL, str_check (g_build_filename (S"x"S S, S S"y"S, NULL), S"x"S"y"S));
TEST (NULL, str_check (g_build_filename ("x", "", "y", NULL), "x"S"y"));
TEST (NULL, str_check (g_build_filename ("x", S, "y", NULL), "x"S"y"));
TEST (NULL, str_check (g_build_filename ("x", S S, "y", NULL), "x"S"y"));
TEST (NULL, str_check (g_build_filename ("x", "y", "z", NULL), "x"S"y"S"z"));
TEST (NULL, str_check (g_build_filename (S"x"S, S"y"S, S"z"S, NULL), S"x"S"y"S"z"S));
TEST (NULL, str_check (g_build_filename (S S"x"S S, S S"y"S S, S S"z"S S, NULL), S S"x"S"y"S"z"S S));
args[0] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), ""));
args[0] = S; args[1] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), S));
args[0] = S"x"; args[1] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), S"x"));
args[0] = "x"S; args[1] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S));
args[0] = ""; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"));
args[0] = ""; args[1] = S"x"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), S"x"));
args[0] = S; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), S"x"));
args[0] = S S; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), S S"x"));
args[0] = "x"; args[1] = ""; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"));
args[0] = "x"S; args[1] = ""; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S));
args[0] = "x"; args[1] = S; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S));
args[0] = "x"; args[1] = S S; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S S));
args[0] = "x"; args[1] = "y"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S"y"));
args[0] = S"x"; args[1] = "y"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), S"x"S"y"));
args[0] = "x"; args[1] = "y"S; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S"y"S));
args[0] = S"x"S; args[1] = S"y"S; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), S"x"S"y"S));
args[0] = S"x"S S; args[1] = S S"y"S; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), S"x"S"y"S));
args[0] = "x"; args[1] = ""; args[2] = "y"; args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S"y"));
args[0] = "x"; args[1] = S; args[2] = "y"; args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S"y"));
args[0] = "x"; args[1] = S S; args[2] = "y"; args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S"y"));
args[0] = "x"; args[1] = "y"; args[2] = "z"; args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S"y"S"z"));
args[0] = S"x"S; args[1] = S"y"S; args[2] = S"z"S; args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), S"x"S"y"S"z"S));
args[0] = S S"x"S S; args[1] = S S"y"S S; args[2] = S S"z"S S; args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), S S"x"S"y"S"z"S S));
#ifdef G_OS_WIN32
/* Test also using the slash as file name separator */
#define U "/"
TEST (NULL, str_check (g_build_filename (NULL), ""));
TEST (NULL, str_check (g_build_filename (U, NULL), U));
TEST (NULL, str_check (g_build_filename (U"x", NULL), U"x"));
TEST (NULL, str_check (g_build_filename ("x"U, NULL), "x"U));
TEST (NULL, str_check (g_build_filename ("", U"x", NULL), U"x"));
TEST (NULL, str_check (g_build_filename ("", U"x", NULL), U"x"));
TEST (NULL, str_check (g_build_filename (U, "x", NULL), U"x"));
TEST (NULL, str_check (g_build_filename (U U, "x", NULL), U U"x"));
TEST (NULL, str_check (g_build_filename (U S, "x", NULL), U S"x"));
TEST (NULL, str_check (g_build_filename ("x"U, "", NULL), "x"U));
TEST (NULL, str_check (g_build_filename ("x"S"y", "z"U"a", NULL), "x"S"y"S"z"U"a"));
TEST (NULL, str_check (g_build_filename ("x", U, NULL), "x"U));
TEST (NULL, str_check (g_build_filename ("x", U U, NULL), "x"U U));
TEST (NULL, str_check (g_build_filename ("x", S U, NULL), "x"S U));
TEST (NULL, str_check (g_build_filename (U"x", "y", NULL), U"x"U"y"));
TEST (NULL, str_check (g_build_filename ("x", "y"U, NULL), "x"U"y"U));
TEST (NULL, str_check (g_build_filename (U"x"U, U"y"U, NULL), U"x"U"y"U));
TEST (NULL, str_check (g_build_filename (U"x"U U, U U"y"U, NULL), U"x"U"y"U));
TEST (NULL, str_check (g_build_filename ("x", U, "y", NULL), "x"U"y"));
TEST (NULL, str_check (g_build_filename ("x", U U, "y", NULL), "x"U"y"));
TEST (NULL, str_check (g_build_filename ("x", U S, "y", NULL), "x"S"y"));
TEST (NULL, str_check (g_build_filename ("x", S U, "y", NULL), "x"U"y"));
TEST (NULL, str_check (g_build_filename ("x", U "y", "z", NULL), "x"U"y"U"z"));
TEST (NULL, str_check (g_build_filename ("x", S "y", "z", NULL), "x"S"y"S"z"));
TEST (NULL, str_check (g_build_filename ("x", S "y", "z", U, "a", "b", NULL), "x"S"y"S"z"U"a"U"b"));
TEST (NULL, str_check (g_build_filename (U"x"U, U"y"U, U"z"U, NULL), U"x"U"y"U"z"U));
TEST (NULL, str_check (g_build_filename (U U"x"U U, U U"y"U U, U U"z"U U, NULL), U U"x"U"y"U"z"U U));
args[0] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), ""));
args[0] = U; args[1] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U));
args[0] = U"x"; args[1] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U"x"));
args[0] = "x"U; args[1] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"U));
args[0] = ""; args[1] = U"x"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U"x"));
args[0] = ""; args[1] = U"x"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U"x"));
args[0] = U; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U"x"));
args[0] = U U; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U U"x"));
args[0] = U S; args[1] = "x"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U S"x"));
args[0] = "x"U; args[1] = ""; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"U));
args[0] = "x"S"y"; args[1] = "z"U"a"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S"y"S"z"U"a"));
args[0] = "x"; args[1] = U; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"U));
args[0] = "x"; args[1] = U U; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"U U));
args[0] = "x"; args[1] = S U; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S U));
args[0] = U"x"; args[1] = "y"; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U"x"U"y"));
args[0] = "x"; args[1] = "y"U; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"U"y"U));
args[0] = U"x"U; args[1] = U"y"U; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U"x"U"y"U));
args[0] = U"x"U U; args[1] = U U"y"U; args[2] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U"x"U"y"U));
args[0] = "x"; args[1] = U; args[2] = "y", args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"U"y"));
args[0] = "x"; args[1] = U U; args[2] = "y", args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"U"y"));
args[0] = "x"; args[1] = U S; args[2] = "y", args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S"y"));
args[0] = "x"; args[1] = S U; args[2] = "y", args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"U"y"));
args[0] = "x"; args[1] = U "y"; args[2] = "z", args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"U"y"U"z"));
args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S"y"S"z"));
args[0] = "x"; args[1] = S "y"; args[2] = "z", args[3] = U;
args[4] = "a"; args[5] = "b"; args[6] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), "x"S"y"S"z"U"a"U"b"));
args[0] = U"x"U; args[1] = U"y"U; args[2] = U"z"U, args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U"x"U"y"U"z"U));
args[0] = U U"x"U U; args[1] = U U"y"U U; args[2] = U U"z"U U, args[3] = NULL;
TEST (NULL, str_check (g_build_filenamev (args), U U"x"U"y"U"z"U U));
#endif /* G_OS_WIN32 */
#undef S
{
gchar buf[5];
TEST (NULL, 3 == g_snprintf (buf, 0, "%s", "abc"));
TEST (NULL, 3 == g_snprintf (NULL,0, "%s", "abc"));
TEST (NULL, 3 == g_snprintf (buf, 5, "%s", "abc"));
TEST (NULL, 4 == g_snprintf (buf, 5, "%s", "abcd"));
TEST (NULL, 9 == g_snprintf (buf, 5, "%s", "abcdefghi"));
}
TEST (NULL, g_strv_length (g_strsplit ("1,2,3,4", ",", -1)) == 4);
return any_failed;
}

View File

@ -301,22 +301,6 @@ main (int argc,
g_string_free (string1, TRUE);
g_string_free (string2, TRUE);
g_assert (g_str_has_prefix("foobar", "gazonk") == FALSE);
g_assert (g_str_has_prefix("xyzzy", "xyzzy") == TRUE);
g_assert (g_str_has_prefix("xyzzy", "xy") == TRUE);
g_assert (g_str_has_prefix("xyzzy", "") == TRUE);
g_assert (g_str_has_prefix("xyz", "xyzzy") == FALSE);
g_assert (g_str_has_prefix("", "xyzzy") == FALSE);
g_assert (g_str_has_prefix("", "") == TRUE);
g_assert (g_str_has_suffix("foobar", "gazonk") == FALSE);
g_assert (g_str_has_suffix("xyzzy", "xyzzy") == TRUE);
g_assert (g_str_has_suffix("xyzzy", "zy") == TRUE);
g_assert (g_str_has_suffix("xyzzy", "") == TRUE);
g_assert (g_str_has_suffix("zzy", "xyzzy") == FALSE);
g_assert (g_str_has_suffix("", "xyzzy") == FALSE);
g_assert (g_str_has_suffix("", "") == TRUE);
tmp_string = (gchar *) g_malloc (10);
g_snprintf (tmp_string, 10, "%2$s %1$s", "a", "b");

View File

@ -1,146 +0,0 @@
#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN
/* for NAN and INFINITY */
#define _ISOC99_SOURCE
#include <glib.h>
#include <locale.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
static char *locales[] = {"sv_SE", "en_US", "fa_IR", "C", "ru_RU"};
void
test_string (char *number, double res, gboolean check_end, int correct_len)
{
double d;
int l;
char *dummy;
/* we try a copy of number, with some free space for malloc before that.
* This is supposed to smash the some wrong pointer calculations. */
dummy = g_malloc (100000);
number = g_strdup (number);
g_free (dummy);
for (l = 0; l < G_N_ELEMENTS (locales); l++)
{
gboolean ok;
char *end = "(unset)";
setlocale (LC_NUMERIC, locales[l]);
d = g_ascii_strtod (number, &end);
ok = isnan (res) ? isnan (d) : (d == res);
if (!ok)
{
g_print ("g_ascii_strtod on \"%s\" for locale %s failed\n", number, locales[l]);
g_print ("expected %f (nan %d) actual %f (nan %d)\n",
res, isnan (res),
d, isnan (d));
}
ok = (end - number) == (check_end ? correct_len : strlen (number));
if (!ok) {
if (end == NULL)
g_print ("g_ascii_strtod on \"%s\" for locale %s endptr was NULL\n",
number, locales[l]);
else if (end >= number && end <= number + strlen (number))
g_print ("g_ascii_strtod on \"%s\" for locale %s endptr was wrong, leftover: \"%s\"\n",
number, locales[l], end);
else
g_print ("g_ascii_strtod on \"%s\" for locale %s endptr was REALLY wrong (number=%p, end=%p)\n",
number, locales[l], number, end);
}
}
g_free (number);
}
static void
test_number (gdouble num, gchar *fmt, gchar *str)
{
int l;
gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
for (l = 0; l < G_N_ELEMENTS (locales); l++)
{
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, fmt, num);
g_assert (strcmp (buf, str) == 0);
}
}
int
main ()
{
gdouble d, our_nan, our_inf;
char buffer[G_ASCII_DTOSTR_BUF_SIZE];
#ifdef NAN
our_nan = NAN;
#else
/* Do this before any call to setlocale. */
our_nan = atof ("NaN");
#endif
g_assert (isnan (our_nan));
#ifdef INFINITY
our_inf = INFINITY;
#else
our_inf = atof ("Infinity");
#endif
g_assert (our_inf > 1 && our_inf == our_inf / 2);
test_string ("123.123", 123.123, FALSE, 0);
test_string ("123.123e2", 123.123e2, FALSE, 0);
test_string ("123.123e-2", 123.123e-2, FALSE, 0);
test_string ("-123.123", -123.123, FALSE, 0);
test_string ("-123.123e2", -123.123e2, FALSE, 0);
test_string ("-123.123e-2", -123.123e-2, FALSE, 0);
test_string ("5.4", 5.4, TRUE, 3);
test_string ("5.4,5.5", 5.4, TRUE, 3);
test_string ("5,4", 5.0, TRUE, 1);
/* the following are for #156421 */
test_string ("1e1", 1e1, FALSE, 0);
test_string ("NAN", our_nan, FALSE, 0);
test_string ("-nan", -our_nan, FALSE, 0);
test_string ("INF", our_inf, FALSE, 0);
test_string ("-infinity", -our_inf, FALSE, 0);
test_string ("-.75,0", -0.75, TRUE, 4);
d = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
d = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
d = pow (2.0, -1024.1);
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
d = -pow (2.0, -1024.1);
g_assert (d == g_ascii_strtod (g_ascii_dtostr (buffer, sizeof (buffer), d), NULL));
/* for #343899 */
test_string (" 0.75", 0.75, FALSE, 0);
test_string (" +0.75", 0.75, FALSE, 0);
test_string (" -0.75", -0.75, FALSE, 0);
test_string ("\f0.75", 0.75, FALSE, 0);
test_string ("\n0.75", 0.75, FALSE, 0);
test_string ("\r0.75", 0.75, FALSE, 0);
test_string ("\t0.75", 0.75, FALSE, 0);
#if 0
/* g_ascii_isspace() returns FALSE for vertical tab, see #59388 */
test_string ("\v0.75", 0.75, FALSE, 0);
#endif
/* for #343899 */
test_number (0.75, "%0.2f", "0.75");
test_number (0.75, "%5.2f", " 0.75");
test_number (-0.75, "%0.2f", "-0.75");
test_number (-0.75, "%5.2f", "-0.75");
test_number (1e99, "%.0e", "1e+99");
return 0;
}

View File

@ -1,71 +0,0 @@
#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN
#include <errno.h>
#include <string.h>
#include <glib.h>
static void
test_uint64 (const gchar *str,
const gchar *end,
gint base,
guint64 result,
gint error)
{
guint64 actual;
gchar *endptr = NULL;
gint err;
errno = 0;
actual = g_ascii_strtoull (str, &endptr, base);
err = errno;
g_assert (actual == result);
g_assert (strcmp (end, endptr) == 0);
g_assert (err == error);
}
static void
test_int64 (const gchar *str,
const gchar *end,
gint base,
gint64 result,
gint error)
{
gint64 actual;
gchar *endptr = NULL;
gint err;
errno = 0;
actual = g_ascii_strtoll (str, &endptr, base);
err = errno;
g_assert (actual == result);
g_assert (strcmp (end, endptr) == 0);
g_assert (err == error);
}
int
main (int argc, char *argv[])
{
test_uint64 ("0", "", 10, 0, 0);
test_uint64 ("+0", "", 10, 0, 0);
test_uint64 ("-0", "", 10, 0, 0);
test_uint64 ("18446744073709551615", "", 10, G_MAXUINT64, 0);
test_uint64 ("18446744073709551616", "", 10, G_MAXUINT64, ERANGE);
test_uint64 ("20xyz", "xyz", 10, 20, 0);
test_uint64 ("-1", "", 10, G_MAXUINT64, 0);
test_int64 ("0", "", 10, 0, 0);
test_int64 ("9223372036854775807", "", 10, G_MAXINT64, 0);
test_int64 ("9223372036854775808", "", 10, G_MAXINT64, ERANGE);
test_int64 ("-9223372036854775808", "", 10, G_MININT64, 0);
test_int64 ("-9223372036854775809", "", 10, G_MININT64, ERANGE);
test_int64 ("32768", "", 10, 32768, 0);
test_int64 ("-32768", "", 10, -32768, 0);
test_int64 ("001", "", 10, 1, 0);
test_int64 ("-001", "", 10, -1, 0);
return 0;
}

View File

@ -506,85 +506,6 @@ find_first_that(gpointer key,
return (*v == *test);
}
static void
test_g_mkdir_with_parents_1 (const gchar *base)
{
char *p0 = g_build_filename (base, "fum", NULL);
char *p1 = g_build_filename (p0, "tem", NULL);
char *p2 = g_build_filename (p1, "zap", NULL);
FILE *f;
g_remove (p2);
g_remove (p1);
g_remove (p0);
if (g_file_test (p0, G_FILE_TEST_EXISTS))
g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p0);
if (g_file_test (p1, G_FILE_TEST_EXISTS))
g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p1);
if (g_file_test (p2, G_FILE_TEST_EXISTS))
g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p2);
if (g_mkdir_with_parents (p2, 0777) == -1)
g_error ("failed, g_mkdir_with_parents(%s) failed: %s\n", p2, g_strerror (errno));
if (!g_file_test (p2, G_FILE_TEST_IS_DIR))
g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p2);
if (!g_file_test (p1, G_FILE_TEST_IS_DIR))
g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p1);
if (!g_file_test (p0, G_FILE_TEST_IS_DIR))
g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p0);
g_rmdir (p2);
if (g_file_test (p2, G_FILE_TEST_EXISTS))
g_error ("failed, did g_rmdir(%s), but %s is still there\n", p2, p2);
g_rmdir (p1);
if (g_file_test (p1, G_FILE_TEST_EXISTS))
g_error ("failed, did g_rmdir(%s), but %s is still there\n", p1, p1);
f = g_fopen (p1, "w");
if (f == NULL)
g_error ("failed, couldn't create file %s\n", p1);
fclose (f);
if (g_mkdir_with_parents (p1, 0666) == 0)
g_error ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p1, p1);
if (g_mkdir_with_parents (p2, 0666) == 0)
g_error("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p2, p1);
g_remove (p2);
g_remove (p1);
g_remove (p0);
}
static void
test_g_mkdir_with_parents (void)
{
gchar *cwd;
if (g_test_verbose())
g_print ("checking g_mkdir_with_parents() in subdir ./hum/");
test_g_mkdir_with_parents_1 ("hum");
g_remove ("hum");
if (g_test_verbose())
g_print ("checking g_mkdir_with_parents() in subdir ./hii///haa/hee/");
test_g_mkdir_with_parents_1 ("hii///haa/hee");
g_remove ("hii/haa/hee");
g_remove ("hii/haa");
g_remove ("hii");
cwd = g_get_current_dir ();
if (g_test_verbose())
g_print ("checking g_mkdir_with_parents() in cwd: %s", cwd);
test_g_mkdir_with_parents_1 (cwd);
g_free (cwd);
}
static void
test_g_parse_debug_string (void)
{
@ -1601,7 +1522,6 @@ main (int argc,
g_test_add_func ("/testglib/Relation", relation_test);
g_test_add_func ("/testglib/File Paths", test_paths);
g_test_add_func ("/testglib/File Functions", test_file_functions);
g_test_add_func ("/testglib/Mkdir", test_g_mkdir_with_parents);
g_test_add_func ("/testglib/Parse Debug Strings", test_g_parse_debug_string);
g_test_add_func ("/testglib/GMemChunk (deprecated)", test_mem_chunks);
g_test_add_func ("/testglib/Warnings & Errors", log_warning_error_tests);