Fix test, make it independent on the sort order of readdir.

This commit is contained in:
Klaas Freitag 2015-07-27 13:28:21 +02:00
Родитель 28ab3666d3
Коммит 3b510969a2
1 изменённых файлов: 31 добавлений и 20 удалений

Просмотреть файл

@ -175,9 +175,12 @@ static void create_dirs( const char *path )
*
* It appends a listing to the result member of the incoming struct in *state
* that can be compared later to what was expected in the calling functions.
*
* The int parameter cnt contains the number of seen files (not dirs) in the
* whole tree.
*
*/
static void traverse_dir(void **state, const char *dir)
static void traverse_dir(void **state, const char *dir, int *cnt)
{
csync_vio_handle_t *dh;
csync_vio_file_stat_t *dirent;
@ -216,20 +219,24 @@ static void traverse_dir(void **state, const char *dir)
is_dir ? "<DIR>":" ",
subdir), -1 );
if( !sv->result ) {
sv->result = c_strdup( subdir_out);
} else {
int newlen = 1+strlen(sv->result)+strlen(subdir_out);
char *tmp = sv->result;
sv->result = c_malloc(newlen);
strcpy( sv->result, tmp);
SAFE_FREE(tmp);
if( is_dir ) {
if( !sv->result ) {
sv->result = c_strdup( subdir_out);
} else {
int newlen = 1+strlen(sv->result)+strlen(subdir_out);
char *tmp = sv->result;
sv->result = c_malloc(newlen);
strcpy( sv->result, tmp);
SAFE_FREE(tmp);
strcat( sv->result, subdir_out );
strcat( sv->result, subdir_out );
}
} else {
*cnt = *cnt +1;
}
output(subdir_out);
if( is_dir ) {
traverse_dir( state, subdir);
traverse_dir( state, subdir, cnt);
}
SAFE_FREE(subdir);
@ -295,8 +302,9 @@ static void check_readdir_shorttree(void **state)
const char *t1 = "alibaba/und/die/vierzig/räuber/";
create_dirs( t1 );
traverse_dir(state, CSYNC_TEST_DIR);
int files_cnt = 0;
traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
assert_string_equal( sv->result,
"<DIR> C:/tmp/csync_test/alibaba"
@ -304,11 +312,13 @@ static void check_readdir_shorttree(void **state)
"<DIR> C:/tmp/csync_test/alibaba/und/die"
"<DIR> C:/tmp/csync_test/alibaba/und/die/vierzig"
"<DIR> C:/tmp/csync_test/alibaba/und/die/vierzig/räuber" );
assert_int_equal(files_cnt, 0);
}
static void check_readdir_with_content(void **state)
{
statevar *sv = (statevar*) *state;
int files_cnt = 0;
const char *t1 = "warum/nur/40/Räuber/";
create_dirs( t1 );
@ -317,15 +327,16 @@ static void check_readdir_with_content(void **state)
create_file( t1, "пя́тница.txt", "Am Freitag tanzt der Ürk");
traverse_dir(state, CSYNC_TEST_DIR);
traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
assert_string_equal( sv->result,
"<DIR> C:/tmp/csync_test/warum"
"<DIR> C:/tmp/csync_test/warum/nur"
"<DIR> C:/tmp/csync_test/warum/nur/40"
"<DIR> C:/tmp/csync_test/warum/nur/40/Räuber"
" C:/tmp/csync_test/warum/nur/40/Räuber/Räuber Max.txt"
" C:/tmp/csync_test/warum/nur/40/Räuber/пя́тница.txt");
"<DIR> C:/tmp/csync_test/warum/nur/40/Räuber");
/* " C:/tmp/csync_test/warum/nur/40/Räuber/Räuber Max.txt"
" C:/tmp/csync_test/warum/nur/40/Räuber/пя́тница.txt"); */
assert_int_equal(files_cnt, 2); /* Two files in the sub dir */
}
static void check_readdir_longtree(void **state)
@ -390,7 +401,7 @@ static void check_readdir_longtree(void **state)
/* assemble the result string ... */
int overall_len = 1+strlen(r1)+strlen(r2)+strlen(r3);
int files_cnt = 0;
char *result = c_malloc(overall_len);
*result = '\0';
@ -398,8 +409,8 @@ static void check_readdir_longtree(void **state)
strcat(result, r2);
strcat(result, r3);
traverse_dir(state, CSYNC_TEST_DIR);
traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
assert_int_equal(files_cnt, 0);
/* and compare. */
assert_string_equal( sv->result, result);
}