| 1 |
/** |
| 2 |
* FreeDink test suite |
| 3 |
|
| 4 |
* Copyright (C) 2005, 2014, 2015 Sylvain Beucler |
| 5 |
|
| 6 |
* This file is part of GNU FreeDink |
| 7 |
|
| 8 |
* GNU FreeDink is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU General Public License as |
| 10 |
* published by the Free Software Foundation; either version 3 of the |
| 11 |
* License, or (at your option) any later version. |
| 12 |
|
| 13 |
* GNU FreeDink is distributed in the hope that it will be useful, but |
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* General Public License for more details. |
| 17 |
|
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see |
| 20 |
* <http://www.gnu.org/licenses/>. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifdef HAVE_CONFIG_H |
| 24 |
#include <config.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include "io_util.h" |
| 28 |
|
| 29 |
/* mkdir */ |
| 30 |
#include <sys/stat.h> |
| 31 |
#include <sys/types.h> |
| 32 |
#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ |
| 33 |
#include <direct.h> |
| 34 |
#define mkdir(name,mode) mkdir(name) |
| 35 |
#endif |
| 36 |
/* rmdir */ |
| 37 |
#include <unistd.h> |
| 38 |
|
| 39 |
#define PREFIX "check_freedink privateprefix/" |
| 40 |
#define TESTDIR PREFIX "subdir1/" |
| 41 |
class TestIOUtil : public CxxTest::TestSuite { |
| 42 |
public: |
| 43 |
void setUp() { |
| 44 |
mkdir(PREFIX, 0300); |
| 45 |
mkdir(TESTDIR, 0777); |
| 46 |
mkdir(TESTDIR "SubDir2", 0777); |
| 47 |
} |
| 48 |
void tearDown() { |
| 49 |
rmdir(TESTDIR "SubDir2"); |
| 50 |
rmdir(TESTDIR); |
| 51 |
rmdir(PREFIX); |
| 52 |
} |
| 53 |
|
| 54 |
int ciconvert_ext(const char* wrong_case, const char* good_case) |
| 55 |
{ |
| 56 |
/* Create file with proper case */ |
| 57 |
{ |
| 58 |
FILE *f = NULL; |
| 59 |
if ((f = fopen(good_case, "w")) == NULL) |
| 60 |
return 0; |
| 61 |
fclose(f); |
| 62 |
} |
| 63 |
|
| 64 |
/* Attempt to open it using wrong case */ |
| 65 |
int success = 0; |
| 66 |
{ |
| 67 |
FILE *f = NULL; |
| 68 |
char *fixed_case = strdup(wrong_case); |
| 69 |
ciconvert(fixed_case); |
| 70 |
if ((f = fopen(fixed_case, "r")) != NULL) |
| 71 |
success = 1; |
| 72 |
|
| 73 |
if (f != NULL) fclose(f); |
| 74 |
unlink(good_case); |
| 75 |
free(fixed_case); |
| 76 |
} |
| 77 |
return success; |
| 78 |
} |
| 79 |
|
| 80 |
void test_ioutil_ciconvert() { |
| 81 |
TS_ASSERT( ciconvert_ext(TESTDIR "toto", TESTDIR "toto")); |
| 82 |
TS_ASSERT( ciconvert_ext(TESTDIR "ToTo", TESTDIR "toto")); |
| 83 |
TS_ASSERT( ciconvert_ext(TESTDIR "ToTo", TESTDIR "TOTO")); |
| 84 |
TS_ASSERT( ciconvert_ext(TESTDIR "ToTo", TESTDIR "tOtO")); |
| 85 |
TS_ASSERT(!ciconvert_ext(TESTDIR "ToTo", TESTDIR "t0t0")); |
| 86 |
|
| 87 |
/* - with multiple slashes: .//file */ |
| 88 |
TS_ASSERT( ciconvert_ext(TESTDIR "/ToTo", TESTDIR "toto")); |
| 89 |
|
| 90 |
/* - absolute path */ |
| 91 |
char* dir = (char*)malloc(PATH_MAX); |
| 92 |
getcwd(dir, PATH_MAX); |
| 93 |
char* good_case = (char*)calloc(1, strlen(dir) + 1 + strlen(TESTDIR) + 4 + 1); |
| 94 |
char* wrong_case = (char*)calloc(1, strlen(dir) + 1 + strlen(TESTDIR) + 4 + 1); |
| 95 |
strcat(good_case, dir); |
| 96 |
strcat(good_case, "/"); |
| 97 |
strcat(good_case, TESTDIR); |
| 98 |
strcat(wrong_case, good_case); |
| 99 |
strcat(good_case, "toto"); |
| 100 |
strcat(wrong_case, "ToTo"); |
| 101 |
TS_ASSERT( ciconvert_ext(wrong_case, good_case)); |
| 102 |
free(good_case); |
| 103 |
free(wrong_case); |
| 104 |
free(dir); |
| 105 |
|
| 106 |
/* - access to subsubdirectories using '/' */ |
| 107 |
TS_ASSERT( ciconvert_ext(TESTDIR "SubdIr2/toto", TESTDIR "SubDir2/toto")); |
| 108 |
|
| 109 |
/* - access to subsubdirectories using '\' */ |
| 110 |
TS_ASSERT( ciconvert_ext(TESTDIR "SubdIr2\\toto", TESTDIR "SubDir2/toto")); |
| 111 |
|
| 112 |
/* - files containing '\' ... works on GNU/Linux but not on Windows, |
| 113 |
not portable, not supported */ |
| 114 |
/* ck_assert(?ciconvert_ext(TESTDIR "to\\to", TESTDIR "to\\to")); */ |
| 115 |
|
| 116 |
/* - with a file and a directory with the same name, in the same |
| 117 |
directory: currently we don't support that, as it didn't work on |
| 118 |
original Dink / woe anyway, and it's not portable */ |
| 119 |
/* ck_assert(?ciconvert_ext(TESTDIR "subdir", TESTDIR "subdir")); */ |
| 120 |
} |
| 121 |
}; |