⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileutils.c

📁 this is a glib for c language
💻 C
📖 第 1 页 / 共 2 页
字号:
/* 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_Sstatic voidcheck_string (gchar *str, gchar *expected){  g_assert (str != NULL);  g_assert_cmpstr (str, ==, expected);  g_free (str);}static voidtest_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 voidtest_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 voidtest_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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -