X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tests%2Ffile-test.c;h=62f712c1111983cd18aa24cc78b34bcf123ddd1d;hb=b76bb6713ba12a88fbccdaaf063d916ecd3af0b2;hp=adab1f20f9b1bb9bf54c129754540533c9677e2f;hpb=8377a886857396854069fb7a8309baeb77f144c2;p=platform%2Fupstream%2Fglib.git diff --git a/tests/file-test.c b/tests/file-test.c index adab1f2..62f712c 100644 --- a/tests/file-test.c +++ b/tests/file-test.c @@ -43,6 +43,8 @@ #include #endif +#include /* For open() */ + #ifdef G_OS_WIN32 #include /* For read(), write() etc */ #endif @@ -96,6 +98,55 @@ test_mkstemp (void) } static void +test_mkdtemp (void) +{ + char template[32], *retval; + int fd; + int i; + + strcpy (template, "foodir"); + retval = g_mkdtemp (template); + if (retval != NULL) + { + g_warning ("g_mkdtemp works even if template doesn't contain XXXXXX"); + g_rmdir (retval); + } + + strcpy (template, "foodir"); + retval = g_mkdtemp (template); + if (retval != NULL) + { + g_warning ("g_mkdtemp works even if template contains less than six X"); + g_rmdir (retval); + } + + strcpy (template, "fooXXXXXX"); + retval = g_mkdtemp (template); + g_assert (retval != NULL && "g_mkdtemp didn't work for template fooXXXXXX"); + g_assert (retval == template && "g_mkdtemp allocated the resulting string?"); + g_assert (!g_file_test (template, G_FILE_TEST_IS_REGULAR)); + g_assert (g_file_test (template, G_FILE_TEST_IS_DIR)); + + strcat (template, "/abc"); + fd = g_open (template, O_WRONLY | O_CREAT, 0600); + g_assert (fd != -1 && "couldn't open file in temporary directory"); + close (fd); + g_assert (g_file_test (template, G_FILE_TEST_IS_REGULAR)); + i = g_unlink (template); + g_assert (i != -1 && "couldn't unlink file in temporary directory"); + + template[9] = '\0'; + i = g_rmdir (template); + g_assert (i != -1 && "couldn't remove temporary directory"); + + strcpy (template, "fooXXXXXX.dir"); + retval = g_mkdtemp (template); + g_assert (retval != NULL && "g_mkdtemp didn't work for template fooXXXXXX.dir"); + g_assert (g_file_test (template, G_FILE_TEST_IS_DIR)); + g_rmdir (template); +} + +static void test_readlink (void) { #ifdef HAVE_SYMLINK @@ -173,6 +224,7 @@ int main (int argc, char *argv[]) { test_mkstemp (); + test_mkdtemp (); test_readlink (); test_get_contents ();