PageRenderTime 19ms CodeModel.GetById 1ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

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