/src/test/fs_test.c

http://ftk.googlecode.com/ · C · 40 lines · 35 code · 5 blank · 0 comment · 22 complexity · 918dde16d87db60c990ecb70f21a6db7 MD5 · raw file

  1. #include "ftk_globals.h"
  2. #include "ftk_file_system.h"
  3. #include "ftk_allocator_default.h"
  4. int main(int argc, char* argv[])
  5. {
  6. char text[100] = {0};
  7. char cwd[FTK_MAX_PATH+1];
  8. char cwd1[FTK_MAX_PATH+1];
  9. FtkFsHandle handle = NULL;
  10. const char* mime_type = NULL;
  11. ftk_set_allocator(ftk_allocator_default_create());
  12. assert((mime_type = ftk_file_get_mime_type("test.jpg")) != NULL && strcmp(mime_type, "image/jpeg") == 0);
  13. assert((mime_type = ftk_file_get_mime_type("test.txt")) != NULL && strcmp(mime_type, "text/plain") == 0);
  14. assert(ftk_fs_get_cwd(cwd) == RET_OK);
  15. assert(ftk_fs_create_dir("./testdir/a/b/c") == RET_OK);
  16. assert(ftk_fs_change_dir("./testdir/a/b/c") == RET_OK);
  17. handle = ftk_file_open("fstest.txt", "wb+");
  18. assert(handle != NULL);
  19. assert(ftk_file_write(handle, "test", 4) == 4);
  20. ftk_file_close(handle);
  21. assert(ftk_fs_change_dir(cwd) == RET_OK);
  22. assert(ftk_fs_move("./testdir/a", "./testdir/d") == RET_OK);
  23. handle = ftk_file_open("./testdir/d/b/c/fstest.txt", "r");
  24. assert(handle != NULL);
  25. assert(ftk_file_read(handle, text, 4) == 4);
  26. assert(strncmp(text, "test", 4) == 0);
  27. ftk_file_close(handle);
  28. assert(ftk_fs_get_cwd(cwd1) == RET_OK);
  29. assert(strcmp(cwd, cwd1) == 0);
  30. assert(ftk_fs_delete("./testdir/d/b/c") == RET_OK);
  31. assert(ftk_fs_get_cwd(cwd1) == RET_OK);
  32. assert(strcmp(cwd, cwd1) == 0);
  33. assert(ftk_fs_delete("./testdir/d") == RET_OK);
  34. return 0;
  35. }