check_vio_ext.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*
  2. * libcsync -- a library to sync a directory with another
  3. *
  4. * Copyright (c) 2015-2013 by Klaas Freitag <freitag@owncloud.com>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22. #include <fcntl.h>
  23. #include <string.h>
  24. #include <errno.h>
  25. #include <unistd.h>
  26. #include <stdio.h>
  27. #include "torture.h"
  28. #include "csync_private.h"
  29. #include "vio/csync_vio.h"
  30. #ifdef _WIN32
  31. #include <windows.h>
  32. #define CSYNC_TEST_DIR "C:/tmp/csync_test"
  33. #else
  34. #define CSYNC_TEST_DIR "/tmp/csync_test"
  35. #endif
  36. #define MKDIR_MASK (S_IRWXU |S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
  37. #define WD_BUFFER_SIZE 255
  38. static mbchar_t wd_buffer[WD_BUFFER_SIZE];
  39. typedef struct {
  40. CSYNC *csync;
  41. char *result;
  42. } statevar;
  43. /* remove the complete test dir */
  44. static int wipe_testdir()
  45. {
  46. int rc = 0;
  47. #ifdef _WIN32
  48. /* The windows system call to rd bails out if the dir is not existing
  49. * Check first.
  50. */
  51. WIN32_FIND_DATA FindFileData;
  52. mbchar_t *dir = c_utf8_path_to_locale(CSYNC_TEST_DIR);
  53. HANDLE handle = FindFirstFile(dir, &FindFileData);
  54. c_free_locale_string(dir);
  55. int found = handle != INVALID_HANDLE_VALUE;
  56. if(found) {
  57. FindClose(handle);
  58. rc = system("rd /s /q C:\\tmp\\csync_test");
  59. }
  60. #else
  61. rc = system("rm -rf /tmp/csync_test/");
  62. #endif
  63. return rc;
  64. }
  65. static void setup_testenv(void **state) {
  66. int rc;
  67. rc = wipe_testdir();
  68. assert_int_equal(rc, 0);
  69. mbchar_t *dir = c_utf8_path_to_locale(CSYNC_TEST_DIR);
  70. rc = _tmkdir(dir, MKDIR_MASK);
  71. assert_int_equal(rc, 0);
  72. assert_non_null(_tgetcwd(wd_buffer, WD_BUFFER_SIZE));
  73. rc = _tchdir(dir);
  74. assert_int_equal(rc, 0);
  75. c_free_locale_string(dir);
  76. /* --- initialize csync */
  77. statevar *mystate = malloc( sizeof(statevar) );
  78. mystate->result = NULL;
  79. rc = csync_create(&(mystate->csync), "/tmp/csync1", "/tmp/csync2");
  80. assert_int_equal(rc, 0);
  81. mystate->csync->replica = LOCAL_REPLICA;
  82. *state = mystate;
  83. }
  84. static void output( const char *text )
  85. {
  86. mbchar_t *wtext = c_utf8_string_to_locale(text);
  87. #ifdef _WIN32
  88. wprintf(L"OOOO %ls (%ld)\n", wtext, strlen(text));
  89. #else
  90. printf("%s\n", wtext);
  91. #endif
  92. c_free_locale_string(wtext);
  93. }
  94. static void teardown(void **state) {
  95. statevar *sv = (statevar*) *state;
  96. CSYNC *csync = sv->csync;
  97. int rc;
  98. output("================== Tearing down!\n");
  99. rc = csync_destroy(csync);
  100. assert_int_equal(rc, 0);
  101. rc = _tchdir(wd_buffer);
  102. assert_int_equal(rc, 0);
  103. rc = wipe_testdir();
  104. assert_int_equal(rc, 0);
  105. *state = NULL;
  106. }
  107. /* This function takes a relative path, prepends it with the CSYNC_TEST_DIR
  108. * and creates each sub directory.
  109. */
  110. static void create_dirs( const char *path )
  111. {
  112. int rc;
  113. char *mypath = c_malloc( 2+strlen(CSYNC_TEST_DIR)+strlen(path));
  114. *mypath = '\0';
  115. strcat(mypath, CSYNC_TEST_DIR);
  116. strcat(mypath, "/");
  117. strcat(mypath, path);
  118. char *p = mypath+strlen(CSYNC_TEST_DIR)+1; /* start behind the offset */
  119. int i = 0;
  120. assert_non_null(path);
  121. while( *(p+i) ) {
  122. if( *(p+i) == '/' ) {
  123. p[i] = '\0';
  124. mbchar_t *mb_dir = c_utf8_path_to_locale(mypath);
  125. /* wprintf(L"OOOO %ls (%ld)\n", mb_dir, strlen(mypath)); */
  126. rc = _tmkdir(mb_dir, MKDIR_MASK);
  127. c_free_locale_string(mb_dir);
  128. assert_int_equal(rc, 0);
  129. p[i] = '/';
  130. }
  131. i++;
  132. }
  133. SAFE_FREE(mypath);
  134. }
  135. /*
  136. * This function uses the vio_opendir, vio_readdir and vio_closedir functions
  137. * to traverse a file tree that was created before by the create_dir function.
  138. *
  139. * It appends a listing to the result member of the incoming struct in *state
  140. * that can be compared later to what was expected in the calling functions.
  141. *
  142. * The int parameter cnt contains the number of seen files (not dirs) in the
  143. * whole tree.
  144. *
  145. */
  146. static void traverse_dir(void **state, const char *dir, int *cnt)
  147. {
  148. csync_vio_handle_t *dh;
  149. csync_vio_file_stat_t *dirent;
  150. statevar *sv = (statevar*) *state;
  151. CSYNC *csync = sv->csync;
  152. char *subdir;
  153. char *subdir_out;
  154. int rc;
  155. int is_dir;
  156. /* Format: Smuggle in the C: for unix platforms as its urgently needed
  157. * on Windows and the test can be nicely cross platform this way. */
  158. #ifdef _WIN32
  159. const char *format_str = "%s %s";
  160. #else
  161. const char *format_str = "%s C:%s";
  162. #endif
  163. dh = csync_vio_opendir(csync, dir);
  164. assert_non_null(dh);
  165. while( (dirent = csync_vio_readdir(csync, dh)) ) {
  166. assert_non_null(dirent->name);
  167. assert_int_equal( dirent->fields & CSYNC_VIO_FILE_STAT_FIELDS_TYPE, CSYNC_VIO_FILE_STAT_FIELDS_TYPE );
  168. if( c_streq( dirent->name, "..") || c_streq( dirent->name, "." )) {
  169. continue;
  170. }
  171. is_dir = (dirent->type == CSYNC_VIO_FILE_TYPE_DIRECTORY) ? 1:0;
  172. assert_int_not_equal( asprintf( &subdir, "%s/%s", dir, dirent->name ), -1 );
  173. assert_int_not_equal( asprintf( &subdir_out, format_str,
  174. is_dir ? "<DIR>":" ",
  175. subdir), -1 );
  176. if( is_dir ) {
  177. if( !sv->result ) {
  178. sv->result = c_strdup( subdir_out);
  179. } else {
  180. int newlen = 1+strlen(sv->result)+strlen(subdir_out);
  181. char *tmp = sv->result;
  182. sv->result = c_malloc(newlen);
  183. strcpy( sv->result, tmp);
  184. SAFE_FREE(tmp);
  185. strcat( sv->result, subdir_out );
  186. }
  187. } else {
  188. *cnt = *cnt +1;
  189. }
  190. output(subdir_out);
  191. if( is_dir ) {
  192. traverse_dir( state, subdir, cnt);
  193. }
  194. SAFE_FREE(subdir);
  195. SAFE_FREE(subdir_out);
  196. }
  197. csync_vio_file_stat_destroy(dirent);
  198. rc = csync_vio_closedir(csync, dh);
  199. assert_int_equal(rc, 0);
  200. }
  201. static void create_file( const char *path, const char *name, const char *content)
  202. {
  203. #ifdef _WIN32
  204. char *filepath = c_malloc( 2+strlen(CSYNC_TEST_DIR)+strlen(path) + strlen(name) );
  205. *filepath = '\0';
  206. strcpy(filepath, CSYNC_TEST_DIR);
  207. strcat(filepath, "/");
  208. strcat(filepath, path);
  209. strcat(filepath, name);
  210. DWORD dwWritten; // number of bytes written to file
  211. HANDLE hFile;
  212. mbchar_t *w_fname = c_utf8_path_to_locale(filepath);
  213. hFile=CreateFile(w_fname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, 0,
  214. CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  215. assert_int_equal( 0, hFile==INVALID_HANDLE_VALUE );
  216. int len = strlen(content);
  217. mbchar_t *dst = NULL;
  218. dst = c_utf8_string_to_locale(content);
  219. WriteFile(hFile, dst, len * sizeof(mbchar_t), &dwWritten, 0);
  220. CloseHandle(hFile);
  221. SAFE_FREE(dst);
  222. c_free_locale_string(w_fname);
  223. #else
  224. char *filepath = c_malloc( 1+strlen(path) + strlen(name) );
  225. *filepath = '\0';
  226. strcpy(filepath, path);
  227. strcat(filepath, name);
  228. FILE *sink;
  229. sink = fopen(filepath,"w");
  230. fprintf (sink, "we got: %s",content);
  231. fclose(sink);
  232. SAFE_FREE(filepath);
  233. #endif
  234. }
  235. static void check_readdir_shorttree(void **state)
  236. {
  237. statevar *sv = (statevar*) *state;
  238. const char *t1 = "alibaba/und/die/vierzig/räuber/";
  239. create_dirs( t1 );
  240. int files_cnt = 0;
  241. traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
  242. assert_string_equal( sv->result,
  243. "<DIR> C:/tmp/csync_test/alibaba"
  244. "<DIR> C:/tmp/csync_test/alibaba/und"
  245. "<DIR> C:/tmp/csync_test/alibaba/und/die"
  246. "<DIR> C:/tmp/csync_test/alibaba/und/die/vierzig"
  247. "<DIR> C:/tmp/csync_test/alibaba/und/die/vierzig/räuber" );
  248. assert_int_equal(files_cnt, 0);
  249. }
  250. static void check_readdir_with_content(void **state)
  251. {
  252. statevar *sv = (statevar*) *state;
  253. int files_cnt = 0;
  254. const char *t1 = "warum/nur/40/Räuber/";
  255. create_dirs( t1 );
  256. create_file( t1, "Räuber Max.txt", "Der Max ist ein schlimmer finger");
  257. create_file( t1, "пя́тница.txt", "Am Freitag tanzt der Ürk");
  258. traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
  259. assert_string_equal( sv->result,
  260. "<DIR> C:/tmp/csync_test/warum"
  261. "<DIR> C:/tmp/csync_test/warum/nur"
  262. "<DIR> C:/tmp/csync_test/warum/nur/40"
  263. "<DIR> C:/tmp/csync_test/warum/nur/40/Räuber");
  264. /* " C:/tmp/csync_test/warum/nur/40/Räuber/Räuber Max.txt"
  265. " C:/tmp/csync_test/warum/nur/40/Räuber/пя́тница.txt"); */
  266. assert_int_equal(files_cnt, 2); /* Two files in the sub dir */
  267. }
  268. static void check_readdir_longtree(void **state)
  269. {
  270. statevar *sv = (statevar*) *state;
  271. /* Strange things here: Compilers only support strings with length of 4k max.
  272. * The expected result string is longer, so it needs to be split up in r1, r2 and r3
  273. */
  274. /* create the test tree */
  275. const char *t1 = "vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln/VOLL RUM/";
  276. create_dirs( t1 );
  277. const char *r1 =
  278. "<DIR> C:/tmp/csync_test/vierzig"
  279. "<DIR> C:/tmp/csync_test/vierzig/mann"
  280. "<DIR> C:/tmp/csync_test/vierzig/mann/auf"
  281. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des"
  282. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten"
  283. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann"
  284. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste"
  285. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh"
  286. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and"
  287. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne"
  288. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle"
  289. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll"
  290. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum";
  291. const char *r2 =
  292. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und"
  293. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so"
  294. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen"
  295. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir"
  296. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG"
  297. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN"
  298. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF"
  299. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES"
  300. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN"
  301. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS"
  302. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE"
  303. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH";
  304. const char *r3 =
  305. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND"
  306. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE"
  307. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE"
  308. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL"
  309. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM"
  310. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen"
  311. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig"
  312. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns"
  313. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE"
  314. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh"
  315. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und"
  316. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER"
  317. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI"
  318. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln"
  319. "<DIR> C:/tmp/csync_test/vierzig/mann/auf/des/toten/Mann/kiste/ooooooooooooooooooooooh/and/ne/bottle/voll/rum/und/so/singen/wir/VIERZIG/MANN/AUF/DES/TOTEN/MANNS/KISTE/OOOOOOOOH/AND/NE/BOTTLE/VOLL/RUM/undnochmalallezusammen/VierZig/MannaufDesTotenManns/KISTE/ooooooooooooooooooooooooooohhhhhh/und/BESSER/ZWEI/Butteln/VOLL RUM";
  320. /* assemble the result string ... */
  321. int overall_len = 1+strlen(r1)+strlen(r2)+strlen(r3);
  322. int files_cnt = 0;
  323. char *result = c_malloc(overall_len);
  324. *result = '\0';
  325. strcat(result, r1);
  326. strcat(result, r2);
  327. strcat(result, r3);
  328. traverse_dir(state, CSYNC_TEST_DIR, &files_cnt);
  329. assert_int_equal(files_cnt, 0);
  330. /* and compare. */
  331. assert_string_equal( sv->result, result);
  332. }
  333. int torture_run_tests(void)
  334. {
  335. const UnitTest tests[] = {
  336. unit_test_setup_teardown(check_readdir_shorttree, setup_testenv, teardown),
  337. unit_test_setup_teardown(check_readdir_with_content, setup_testenv, teardown),
  338. unit_test_setup_teardown(check_readdir_longtree, setup_testenv, teardown),
  339. };
  340. return run_tests(tests);
  341. }