コード例 #1
0
ファイル: tsllist.c プロジェクト: Logout22/Escape
static void test_9(void) {
	sSLList *list;
	size_t oldFree;

	test_caseStart("Testing sll_indexOf and sll_nodeWith");
	oldFree = heapspace();

	list = sll_create();
	sll_append(list,(void*)0x123);
	sll_append(list,(void*)0x456);
	sll_append(list,(void*)0x789);

	test_assertSSize(sll_indexOf(list,(void*)0x123),0);
	test_assertSSize(sll_indexOf(list,(void*)0x456),1);
	test_assertSSize(sll_indexOf(list,(void*)0x789),2);
	test_assertSSize(sll_indexOf(list,(void*)0x123123),-1);
	test_assertPtr(sll_nodeWith(list,(void*)0x123),sll_nodeAt(list,0));
	test_assertPtr(sll_nodeWith(list,(void*)0x456),sll_nodeAt(list,1));
	test_assertPtr(sll_nodeWith(list,(void*)0x789),sll_nodeAt(list,2));
	test_assertPtr(sll_nodeWith(list,(void*)0x123123),NULL);
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
コード例 #2
0
ファイル: tsllist.c プロジェクト: Logout22/Escape
static void test_8(void) {
	sSLList *list;
	size_t oldFree;
	sSLNode *n;

	test_caseStart("Walking through the list");
	oldFree = heapspace();

	list = sll_create();
	sll_append(list,(void*)0x123);
	sll_append(list,(void*)0x456);
	sll_append(list,(void*)0x789);

	n = sll_begin(list);
	test_assertPtr(n->data,(void*)0x123);
	n = n->next;
	test_assertPtr(n->data,(void*)0x456);
	n = n->next;
	test_assertPtr(n->data,(void*)0x789);
	n = n->next;
	test_assertPtr(n,NULL);

	n = sll_nodeAt(list,2);
	test_assertPtr(n->data,(void*)0x789);
	n = n->next;
	test_assertPtr(n,NULL);

	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
コード例 #3
0
ファイル: tsllist.c プロジェクト: Logout22/Escape
static void test_10(void) {
	sSLList *l1,*l2;
	size_t oldFree;
	test_caseStart("Testing sll_clone");
	oldFree = heapspace();

	l1 = sll_create();
	sll_append(l1,(void*)4);
	sll_append(l1,(void*)3);
	sll_append(l1,(void*)2);
	l2 = sll_clone(l1);
	test_assertSize(sll_length(l2),3);
	test_assertPtr(sll_get(l2,0),(void*)4);
	test_assertPtr(sll_get(l2,1),(void*)3);
	test_assertPtr(sll_get(l2,2),(void*)2);
	sll_destroy(l1,false);
	sll_destroy(l2,false);

	l1 = sll_create();
	l2 = sll_clone(l1);
	test_assertSize(sll_length(l2),0);
	sll_destroy(l2,false);
	sll_destroy(l1,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
コード例 #4
0
ファイル: tdir.c プロジェクト: Nils-TUD/Escape
static void test_dirname(void) {
	struct DirnameTest {
		const char *input;
		const char *expected;
	} tests[] = {
		{NULL,"."},
		{"","."},
		{"/","/"},
		{".","."},
		{"..","."},
		{"a","."},
		{"foo","."},
		{"/foo/bar","/foo"},
		{"/foo/bar/","/foo"},
		{"/foo/bar///","/foo"},
		{"/a/","/"},
		{"abc///","."},
		{"abc//def///","abc"},
		{"abc/def/.","abc/def"},
	};

	test_caseStart("Testing dirname");

	for(size_t i = 0; i < ARRAY_SIZE(tests); ++i) {
		char *cpy = tests[i].input ? strdup(tests[i].input) : NULL;
		test_assertTrue(tests[i].input == NULL || cpy != NULL);
		test_assertStr(dirname(cpy),tests[i].expected);
		free(cpy);
	}

	test_caseSucceeded();
}
コード例 #5
0
ファイル: tfs.c プロジェクト: jarn0x/Escape
static void test_basics(void) {
	struct stat info1;
	struct stat info2;
	test_caseStart("Testing fs");

	test_assertInt(mkdir("/newdir",DIR_DEF_MODE),0);

	fs_createFile("/newdir/file1","foobar");
	fs_readFile("/newdir/file1","foobar");
	test_assertInt(link("/newdir/file1","/newdir/file2"),0);
	test_assertInt(stat("/newdir/file1",&info1),0);
	test_assertInt(stat("/newdir/file2",&info2),0);
	test_assertInt(memcmp(&info1,&info2,sizeof(struct stat)),0);
	test_assertUInt(info1.st_nlink,2);
	test_assertInt(unlink("/newdir/file1"),0);
	test_assertInt(rmdir("/newdir"),-ENOTEMPTY);
	test_assertInt(stat("/newdir/file1",&info1),-ENOENT);
	test_assertInt(stat("/newdir/file2",&info2),0);
	test_assertUInt(info2.st_nlink,1);
	test_assertInt(unlink("/newdir/file2"),0);

	test_assertInt(rmdir("/newdir"),0);
	int fd = open("/",O_RDONLY);
	test_assertTrue(fd >= 0);
	test_assertInt(syncfs(fd),0);
	close(fd);

	test_caseSucceeded();
}
コード例 #6
0
ファイル: tsllist.c プロジェクト: Logout22/Escape
static void test_6(void) {
	ulong x = 0x100;
	size_t i,oldFree;
	sSLList *list;
	bool res = true;
	test_caseStart("Create & append & set somewhere & destroy");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 5; i++) {
		sll_append(list,(void*)x++);
	}
	sll_set(list,(void*)0x200,3);
	if(sll_get(list,3) != (void*)0x200)
		res = false;
	sll_set(list,(void*)0x201,2);
	if(sll_get(list,2) != (void*)0x201)
		res = false;
	sll_set(list,(void*)0x202,1);
	if(sll_get(list,1) != (void*)0x202)
		res = false;
	sll_set(list,(void*)0x203,0);
	if(sll_get(list,0) != (void*)0x203)
		res = false;
	sll_set(list,(void*)0x204,4);
	if(sll_get(list,4) != (void*)0x204)
		res = false;
	if(sll_length(list) != 5)
		res = false;
	sll_destroy(list,false);
	test_assertTrue(res);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
コード例 #7
0
ファイル: tsllist.c プロジェクト: Logout22/Escape
static void test_1(void) {
	ulong x = 0x100;
	size_t i,len,oldFree;
	bool res = true;
	sSLList *list;
	test_caseStart("Append & check & remove index 0");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 20; i++) {
		sll_append(list,(void*)x++);
	}
	x = 0x100;
	for(i = 0; i < 20; i++) {
		if(sll_get(list,i) != (void*)x++) {
			res = false;
			break;
		}
	}
	if(res) {
		for(i = 0; i < 20; i++) {
			sll_removeIndex(list,0);
		}
	}
	test_assertTrue(res);

	len = sll_length(list);
	test_assertSSize(len,0);
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
コード例 #8
0
ファイル: tfs.c プロジェクト: jarn0x/Escape
static void test_rename(void) {
	test_caseStart("Testing rename()");

	fs_createFile("/newfile","test!");
	test_assertCan("/newfile",O_READ);
	test_assertInt(rename("/newfile","/newerfile"),0);
	test_assertCanNot("/newfile",O_READ,-ENOENT);
	test_assertInt(unlink("/newerfile"),0);
	test_assertCanNot("/newerfile",O_READ,-ENOENT);

	test_caseSucceeded();
}
コード例 #9
0
ファイル: tmath.c プロジェクト: Nils-TUD/Escape
static void test_roundf(void) {
	test_caseStart("Testing roundf()");

	test_assertFloat(roundf(0.1f),0.0f);
	test_assertFloat(roundf(0.49f),0.0f);
	test_assertFloat(roundf(0.8f),1.0f);
	test_assertFloat(roundf(1.2f),1.0f);
	test_assertFloat(roundf(101.9f),102.0f);
	test_assertFloat(roundf(-3.1f),-3.0f);
	test_assertFloat(roundf(-10.6f),-11.0f);

	test_caseSucceeded();
}
コード例 #10
0
ファイル: tmath.c プロジェクト: Nils-TUD/Escape
static void test_round(void) {
	test_caseStart("Testing round()");

	test_assertDouble(round(0.1),0.0);
	test_assertDouble(round(0.49),0.0);
	test_assertDouble(round(0.8),1.0);
	test_assertDouble(round(1.2),1.0);
	test_assertDouble(round(101.9),102.0);
	test_assertDouble(round(-3.1),-3.0);
	test_assertDouble(round(-10.6),-11.0);

	test_caseSucceeded();
}
コード例 #11
0
ファイル: tfs.c プロジェクト: jarn0x/Escape
static void test_largeFile(void) {
	/* ensure that the blocksize is not a multiple of this array size */
	uint8_t pattern[62];
	uint8_t buf[62];
	/* reach some double indirect blocks */
	const size_t size = 12 * 1024 + 256 * 1024 + 256 * 1024;
	test_caseStart("Creating a large file and reading it back");

	for(size_t i = 0; i < ARRAY_SIZE(pattern); ++i)
		pattern[i] = i;

	/* write it */
	{
		FILE *f = fopen("/largefile","w");
		test_assertTrue(f != NULL);

		size_t rem = size;
		while(rem > 0) {
			size_t amount = MIN(rem,ARRAY_SIZE(pattern));
			test_assertSize(fwrite(pattern,1,amount,f),amount);
			rem -= amount;
		}

		/* flush buffer cache */
		test_assertInt(syncfs(fileno(f)),0);

		fclose(f);
	}

	/* read it back */
	{
		FILE *f = fopen("/largefile","r");
		test_assertTrue(f != NULL);

		size_t rem = size;
		while(rem > 0) {
			size_t amount = MIN(rem,ARRAY_SIZE(pattern));
			test_assertSize(fread(buf,1,amount,f),amount);
			for(size_t i = 0; i < amount; ++i)
				test_assertInt(buf[i],pattern[i]);
			rem -= amount;
		}
		fclose(f);
	}

	test_assertInt(unlink("/largefile"),0);

	test_caseSucceeded();
}
コード例 #12
0
ファイル: tdir.c プロジェクト: Nils-TUD/Escape
static void test_abspath(void) {
	char *p,path[MAX_PATH_LEN];

	test_caseStart("Testing abspath");

	setenv("CWD","/home/hrniels");

	p = abspath(path,sizeof(path),".");
	test_assertStr(p,"/home/hrniels/.");

	p = abspath(path,sizeof(path),"/");
	test_assertStr(p,"/");

	p = abspath(path,sizeof(path),"../..");
	test_assertStr(p,"/home/hrniels/../..");

	p = abspath(path,sizeof(path),"http://www.example.com");
	test_assertStr(p,"/dev/http/www.example.com");

	p = abspath(path,sizeof(path),"a://");
	test_assertStr(p,"/dev/a/");

	p = abspath(path,sizeof(path),"a:/");
	test_assertStr(p,"/home/hrniels/a:/");

	p = abspath(path,8,"/");
	test_assertStr(p,"/");

	p = abspath(path,8,"..");
	test_assertStr(p,"/home/h");

	p = abspath(path,8,"f://bar");
	test_assertStr(p,"/dev/f/");

	p = abspath(path,8,"foobar://bar");
	test_assertStr(p,"/dev/fo");

	p = abspath(path,2,"a://b");
	test_assertStr(p,"/");

	p = abspath(path,1,"a://b");
	test_assertStr(p,"");

	p = abspath(path,1,".");
	test_assertStr(p,"");

	test_caseSucceeded();
}
コード例 #13
0
ファイル: tdir.c プロジェクト: Nils-TUD/Escape
static void test_opendir(void) {
	DIR *dir;
	struct dirent e;
	test_caseStart("Testing opendir, readdir and closedir");

	dir = opendir("/bin");
	if(dir == NULL) {
		test_caseFailed("Unable to open '/bin'");
		return;
	}

	while(readdirto(dir,&e));
	closedir(dir);

	test_caseSucceeded();
}
コード例 #14
0
ファイル: tsllist.c プロジェクト: Logout22/Escape
static void test_4(void) {
	ulong x = 0x100;
	size_t i,oldFree;
	sSLList *list;
	test_caseStart("Create & append & destroy");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 200; i++) {
		sll_append(list,(void*)x++);
	}
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
コード例 #15
0
ファイル: tfs.c プロジェクト: Nils-TUD/Escape
static void test_basics(void) {
	struct stat info1;
	struct stat info2;
	test_caseStart("Testing fs");

	test_assertInt(mkdir("/newdir",DIR_DEF_MODE),0);

	fs_createFile("/newdir/file1","foobar");
	fs_readFile("/newdir/file1","foobar");
	test_assertInt(link("/newdir/file1","/newdir/file2"),0);
	test_assertInt(stat("/newdir/file1",&info1),0);
	test_assertInt(stat("/newdir/file2",&info2),0);

	// compare elements individually, because the structs might contain uninitialized padding
	test_assertUInt(info1.st_atime,info2.st_atime);
	test_assertUInt(info1.st_mtime,info2.st_mtime);
	test_assertUInt(info1.st_ctime,info2.st_ctime);
	test_assertUInt(info1.st_blocks,info2.st_blocks);
	test_assertUInt(info1.st_blksize,info2.st_blksize);
	test_assertUInt(info1.st_dev,info2.st_dev);
	test_assertUInt(info1.st_uid,info2.st_uid);
	test_assertUInt(info1.st_gid,info2.st_gid);
	test_assertUInt(info1.st_ino,info2.st_ino);
	test_assertUInt(info1.st_nlink,info2.st_nlink);
	test_assertUInt(info1.st_mode,info2.st_mode);
	test_assertUInt(info1.st_size,info2.st_size);

	test_assertUInt(info1.st_nlink,2);
	test_assertInt(unlink("/newdir/file1"),0);
	test_assertInt(rmdir("/newdir"),-ENOTEMPTY);
	test_assertInt(stat("/newdir/file1",&info1),-ENOENT);
	test_assertInt(stat("/newdir/file2",&info2),0);
	test_assertUInt(info2.st_nlink,1);
	test_assertInt(unlink("/newdir/file2"),0);

	test_assertInt(rmdir("/newdir"),0);
	int fd = open("/",O_RDONLY);
	test_assertTrue(fd >= 0);
	test_assertInt(syncfs(fd),0);
	close(fd);

	test_caseSucceeded();
}
コード例 #16
0
ファイル: tfileio.c プロジェクト: jarn0x/Escape
static void test_fileio_scan(void) {
	char s[200],c1,c2,c3,c4;
	uint x,o,b,u;
	int d1,d2,d3;
	int res;
	test_caseStart("Testing *scanf()");

	res = sscanf("ABC, 123","%x,%s",&x,s);
	if(!test_fileio_checkScan(res,2,"%x%s",x,0xABC,s,"123"))
		return;

	res = sscanf("test","");
	if(!test_fileio_checkScan(res,0,""))
		return;

	res = sscanf("x=deadBEEF, b=0011001, o=7124, d=-1023, u=748","x=%X, b=%b, o=%o, d=%d, u=%u",
			&x,&b,&o,&d1,&u);
	if(!test_fileio_checkScan(res,5,"%x%b%o%d%u",x,0xdeadbeef,b,0x19,o,07124,d1,-1023,u,748))
		return;

	res = sscanf("test","%c%c%c%c",&c1,&c2,&c3,&c4);
	if(!test_fileio_checkScan(res,4,"%c%c%c%c",c1,'t',c2,'e',c3,'s',c4,'t'))
		return;

	res = sscanf("str","%s",s);
	if(!test_fileio_checkScan(res,1,"%s",s,"str"))
		return;

	res = sscanf("str","%2s",s);
	if(!test_fileio_checkScan(res,1,"%s",s,"st"))
		return;

	res = sscanf("4/26/2009","%2d/%2d/%4d",&d1,&d2,&d3);
	if(!test_fileio_checkScan(res,3,"%d%d%d",d1,4,d2,26,d3,2009))
		return;

	res = sscanf("1234/5678/90123","%2d/%2d/%4d",&d1,&d2,&d3);
	if(!test_fileio_checkScan(res,1,"%d",d1,12))
		return;

	test_caseSucceeded();
}
コード例 #17
0
ファイル: tgroup.c プロジェクト: Logout22/Escape
static void test_errors(void) {
	const char *errors[] = {
		"",
		":root:0",
		":::",
		"0:::"
	};
	size_t i,count,oldFree;
	test_caseStart("Testing errors");

	for(i = 0; i < ARRAY_SIZE(errors); i++) {
		sGroup *g;
		oldFree = heapspace();
		g = group_parse(errors[i],&count);
		test_assertTrue(g == NULL);
		test_assertSize(heapspace(),oldFree);
	}

	test_caseSucceeded();
}
コード例 #18
0
ファイル: tsllist.c プロジェクト: Logout22/Escape
static void test_2(void) {
	ulong x = 0x100;
	size_t i,len,oldFree;
	sSLList *list;
	test_caseStart("Append & remove first (NULL)");
	oldFree = heapspace();

	list = sll_create();
	for(i = 0; i < 2; i++) {
		sll_append(list,(void*)x++);
	}
	for(i = 0; i < 2; i++) {
		sll_removeFirstWith(list,NULL);
	}

	len = sll_length(list);
	test_assertSize(len,0);
	sll_destroy(list,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
コード例 #19
0
ファイル: tsllist.c プロジェクト: Logout22/Escape
static void test_11(void) {
	sSLList *l1;
	size_t oldFree;
	test_caseStart("Testing sll_removeFirst");
	oldFree = heapspace();

	l1 = sll_create();
	sll_append(l1,(void*)4);
	sll_append(l1,(void*)3);
	sll_append(l1,(void*)2);
	test_assertSize(sll_length(l1),3);
	test_assertPtr(sll_removeFirst(l1),(void*)4);
	test_assertSize(sll_length(l1),2);
	test_assertPtr(sll_removeFirst(l1),(void*)3);
	test_assertSize(sll_length(l1),1);
	test_assertPtr(sll_removeFirst(l1),(void*)2);
	test_assertSize(sll_length(l1),0);
	test_assertPtr(sll_removeFirst(l1),NULL);
	sll_destroy(l1,false);

	test_assertSize(heapspace(),oldFree);
	test_caseSucceeded();
}
コード例 #20
0
ファイル: tfileio.c プロジェクト: jarn0x/Escape
static void test_fileio_print(void) {
	char str[200];
	int i,res;

	test_caseStart("Testing *printf()");

	res = snprintf(str,sizeof(str),"%d",4);
	if(!test_fileio_checkPrint(res,-1,str,"4"))
		return;

	res = snprintf(str,sizeof(str),"");
	if(!test_fileio_checkPrint(res,-1,str,""))
		return;

	res = snprintf(str,sizeof(str),"%i%d",123,456);
	if(!test_fileio_checkPrint(res,-1,str,"123456"))
		return;

	res = snprintf(str,sizeof(str),"_%d_%d_",1,2);
	if(!test_fileio_checkPrint(res,-1,str,"_1_2_"))
		return;

	res = snprintf(str,sizeof(str),"x=%x, X=%X, b=%b, o=%o, d=%d, u=%u",0xABC,0xDEF,0xF0F,0723,-675,412);
	if(!test_fileio_checkPrint(res,-1,str,"x=abc, X=DEF, b=111100001111, o=723, d=-675, u=412"))
		return;

	res = snprintf(str,sizeof(str),"'%s'_%c_","test",'f');
	if(!test_fileio_checkPrint(res,-1,str,"'test'_f_"))
		return;

	res = snprintf(str,sizeof(str),"%s","");
	if(!test_fileio_checkPrint(res,-1,str,""))
		return;

	res = snprintf(str,sizeof(str),"%s",NULL);
	if(!test_fileio_checkPrint(res,-1,str,"(null)"))
		return;

	res = snprintf(str,sizeof(str),"%.2s %8s",NULL,NULL);
	if(!test_fileio_checkPrint(res,-1,str,"(n   (null)"))
		return;

	res = snprintf(str,sizeof(str),"%10s","padme");
	if(!test_fileio_checkPrint(res,-1,str,"     padme"))
		return;

	res = snprintf(str,sizeof(str),"%02d, % 4x, %08b",9,0xff,0xf);
	if(!test_fileio_checkPrint(res,-1,str,"09,   ff, 00001111"))
		return;

	res = snprintf(str,sizeof(str),"%p%n, %hx",0xdeadbeef,&i,0x12345678);
	if(sizeof(uintptr_t) == 4) {
		if(!test_fileio_checkPrint(res,-1,str,"dead:beef, 5678") || !test_assertSize(i,9))
			return;
	}
	else if(sizeof(uintptr_t) == 8) {
		if(!test_fileio_checkPrint(res,-1,str,"0000:0000:dead:beef, 5678") || !test_assertSize(i,19))
			return;
	}
	else
		test_assertFalse(true);

	res = snprintf(str,sizeof(str),"%Ld, %017Ld, %-*Ld",1LL,8167127123123123LL,12,-81273123LL);
	if(!test_fileio_checkPrint(res,-1,str,"1, 08167127123123123, -81273123   "))
		return;

	res = snprintf(str,sizeof(str),"%Lu, %017Lx, %#-*LX",1ULL,0x7179bafed2122ULL,12,0x1234ABULL);
	if(!test_fileio_checkPrint(res,-1,str,"1, 00007179bafed2122, 0X1234AB    "))
		return;

	res = snprintf(str,sizeof(str),"%f, %f, %f, %f, %f, %f",0.f,1.f,-1.f,0.f,0.4f,18.4f);
	if(!test_fileio_checkPrint(res,-1,str,"0.000000, 1.000000, -1.000000, 0.000000, 0.400000, 18.399999"))
		return;

	res = snprintf(str,sizeof(str),"%f, %f, %f, %f",-1.231f,999.999f,1234.5678f,1189378123.78167213123f);
	if(!test_fileio_checkPrint(res,-1,str,"-1.230999, 999.999023, 1234.567749, 1189378176.000000"))
		return;

	res = snprintf(str,sizeof(str),"%lf, %lf, %lf, %lf, %lf, %lf",0.,1.,-1.,0.,0.4,18.4);
	if(!test_fileio_checkPrint(res,-1,str,"0.000000, 1.000000, -1.000000, 0.000000, 0.400000, 18.399999"))
		return;

	res = snprintf(str,sizeof(str),"%lf, %lf, %lf, %lf",-1.231,999.999,1234.5678,1189378123.78167213123);
	if(!test_fileio_checkPrint(res,-1,str,"-1.231000, 999.999000, 1234.567800, 1189378123.781672"))
		return;

	res = snprintf(str,sizeof(str),"%8.4lf, %8.1lf, %8.10lf",1.,-1.,0.);
	if(!test_fileio_checkPrint(res,-1,str,"  1.0000,     -1.0, 0.0000000000"))
		return;

	res = snprintf(str,sizeof(str),"%f, %f, %f",INFINITY,-INFINITY,NAN);
	if(!test_fileio_checkPrint(res,-1,str,"inf, -inf, nan"))
		return;

	res = snprintf(str,sizeof(str),"%10f, %5f, %-8f",INFINITY,-INFINITY,NAN);
	if(!test_fileio_checkPrint(res,-1,str,"       inf,  -inf, nan     "))
		return;

	res = snprintf(str,sizeof(str),"%3.0lf, %-06.1lf, %2.4lf, %10.10lf",-1.231,999.999,1234.5678,
			1189378123.78167213123);
	if(!test_fileio_checkPrint(res,-1,str,"-1., 999.90, 1234.5678, 1189378123.7816722393"))
		return;

	test_caseSucceeded();
}
コード例 #21
0
ファイル: tdir.c プロジェクト: Nils-TUD/Escape
static void test_canonpath(void) {
	char path[MAX_PATH_LEN];
	size_t count;

	test_caseStart("Testing canonpath");

	setenv("CWD","/");

	count = canonpath(path,sizeof(path),"/");
	test_assertUInt(count,SSTRLEN("/"));
	test_assertStr(path,"/");

	count = canonpath(path,sizeof(path),"/bin/ls");
	test_assertUInt(count,SSTRLEN("/bin/ls"));
	test_assertStr(path,"/bin/ls");

	count = canonpath(path,sizeof(path),"/../bin/../.././home");
	test_assertUInt(count,SSTRLEN("/home"));
	test_assertStr(path,"/home");

	count = canonpath(path,sizeof(path),"bin/..///.././home");
	test_assertUInt(count,SSTRLEN("/home"));
	test_assertStr(path,"/home");

	count = canonpath(path,sizeof(path),"bin/./ls");
	test_assertUInt(count,SSTRLEN("/bin/ls"));
	test_assertStr(path,"/bin/ls");

	setenv("CWD","/home");

	count = canonpath(path,sizeof(path),"hrniels/./scripts");
	test_assertUInt(count,SSTRLEN("/home/hrniels/scripts"));
	test_assertStr(path,"/home/hrniels/scripts");

	setenv("CWD","/home/");

	count = canonpath(path,sizeof(path),"hrniels/./scripts");
	test_assertUInt(count,SSTRLEN("/home/hrniels/scripts"));
	test_assertStr(path,"/home/hrniels/scripts");

	count = canonpath(path,sizeof(path),"..");
	test_assertUInt(count,SSTRLEN("/"));
	test_assertStr(path,"/");

	count = canonpath(path,sizeof(path),"../../.");
	test_assertUInt(count,SSTRLEN("/"));
	test_assertStr(path,"/");

	count = canonpath(path,sizeof(path),"./../bin");
	test_assertUInt(count,SSTRLEN("/bin"));
	test_assertStr(path,"/bin");

	count = canonpath(path,3,"/");
	if(count > 3)
		test_caseFailed("Copied too much");

	count = canonpath(path,8,"/bin/ls");
	if(count > 8)
		test_caseFailed("Copied too much");

	count = canonpath(path,8,"/bin/../home");
	if(count > 8)
		test_caseFailed("Copied too much");

	count = canonpath(path,8,"///../bin/ls");
	if(count > 8)
		test_caseFailed("Copied too much");

	test_caseSucceeded();
}
コード例 #22
0
ファイル: tfs.c プロジェクト: jarn0x/Escape
static void test_perms(void) {
	size_t i;
	struct stat info;
	struct {
		const char *dir;
		const char *file;
	} paths[] = {
		{"/newfile","/newfile/test"},
		{"/sys/newfile","/sys/newfile/test"}
	};
	test_caseStart("Testing permissions");

	for(i = 0; i < ARRAY_SIZE(paths); i++) {
		/* create new file */
		fs_createFile(paths[i].dir,"foobar");
		test_assertInt(chmod(paths[i].dir,0600),0);
		test_assertInt(chown(paths[i].dir,1,1),0);

		/* I'm the owner */
		test_assertInt(setegid(1),0);
		test_assertInt(seteuid(1),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCan(paths[i].dir,O_WRITE);

		/* I'm NOT the owner */
		test_assertInt(seteuid(0),0);
		test_assertInt(seteuid(2),0);

		test_assertCanNot(paths[i].dir,O_READ,-EACCES);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);

		/* give group read-perm */
		test_assertInt(seteuid(0),0);
		test_assertInt(chmod(paths[i].dir,0640),0);
		test_assertInt(seteuid(2),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);

		/* neither owner nor group */
		test_assertInt(seteuid(0),0);
		test_assertInt(setegid(0),0);
		test_assertInt(setegid(2),0);
		test_assertInt(seteuid(2),0);

		test_assertCanNot(paths[i].dir,O_READ,-EACCES);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);

		/* give others read+write perm */
		test_assertInt(seteuid(0),0);
		test_assertInt(chmod(paths[i].dir,0646),0);
		test_assertInt(seteuid(2),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCan(paths[i].dir,O_WRITE);

		/* delete it */
		test_assertInt(seteuid(0),0);
		test_assertInt(unlink(paths[i].dir),0);


		/* create new folder */
		test_assertInt(mkdir(paths[i].dir,DIR_DEF_MODE),0);
		test_assertInt(chmod(paths[i].dir,0700),0);
		test_assertInt(chown(paths[i].dir,1,1),0);

		/* I'm the owner */
		test_assertInt(setegid(1),0);
		test_assertInt(seteuid(1),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCan(paths[i].dir,O_WRITE);
		fs_createFile(paths[i].file,"foo");
		test_assertInt(stat(paths[i].file,&info),0);

		/* I'm NOT the owner */
		test_assertInt(seteuid(0),0);
		test_assertInt(seteuid(2),0);

		test_assertCanNot(paths[i].dir,O_READ,-EACCES);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);
		test_assertInt(stat(paths[i].file,&info),-EACCES);

		/* give group read-perm */
		test_assertInt(seteuid(0),0);
		test_assertInt(chmod(paths[i].dir,0740),0);
		test_assertInt(seteuid(2),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);
		test_assertInt(stat(paths[i].file,&info),-EACCES);

		/* neither owner nor group */
		test_assertInt(seteuid(0),0);
		test_assertInt(setegid(0),0);
		test_assertInt(setegid(2),0);
		test_assertInt(seteuid(2),0);

		test_assertCanNot(paths[i].dir,O_READ,-EACCES);
		test_assertCanNot(paths[i].dir,O_WRITE,-EACCES);
		test_assertInt(stat(paths[i].file,&info),-EACCES);

		/* give others read+write perm */
		test_assertInt(seteuid(0),0);
		test_assertInt(chmod(paths[i].dir,0747),0);
		test_assertInt(seteuid(2),0);

		test_assertCan(paths[i].dir,O_READ);
		test_assertCan(paths[i].dir,O_WRITE);
		test_assertInt(stat(paths[i].file,&info),0);

		/* delete it */
		test_assertInt(seteuid(0),0);
		test_assertInt(unlink(paths[i].file),0);
		test_assertInt(rmdir(paths[i].dir),0);
	}

	test_caseSucceeded();
}
コード例 #23
0
ファイル: tsort.c プロジェクト: jarn0x/Escape
static void test_qsort(void) {
	test_caseStart("Testing qsort");

	{
		int ints[] = {};
		qsort(ints,ARRAY_SIZE(ints),sizeof(int),intCompare);
	}

	{
		int ints[] = {1,1,1};
		qsort(ints,ARRAY_SIZE(ints),sizeof(int),intCompare);
		test_assertInt(ints[0],1);
		test_assertInt(ints[1],1);
		test_assertInt(ints[2],1);
	}

	{
		int ints[] = {1,2,3};
		qsort(ints,ARRAY_SIZE(ints),sizeof(int),intCompare);
		test_assertInt(ints[0],1);
		test_assertInt(ints[1],2);
		test_assertInt(ints[2],3);
	}

	{
		int ints[] = {6,7,3,4,2,1,5};
		qsort(ints,ARRAY_SIZE(ints),sizeof(int),intCompare);
		test_assertInt(ints[0],1);
		test_assertInt(ints[1],2);
		test_assertInt(ints[2],3);
		test_assertInt(ints[3],4);
		test_assertInt(ints[4],5);
		test_assertInt(ints[5],6);
		test_assertInt(ints[6],7);
	}

	{
		const char *strs[] = {
			"m3/m3-11.png",
			"m3/m3-03.png",
			"m3/m3-09.png",
			"m3/m3-20.png",
			"m3/m3-22.png",
			"m3/m3-17.png",
			"m3/m3-24.png",
			"m3/m3-12.png",
			"m3/m3-04.png",
			"m3/m3-23.png",
			"m3/m3-18.png",
			"m3/m3-01.png",
			"m3/m3-28.png",
			"m3/m3-14.png",
			"m3/m3-07.png",
			"m3/m3-26.png",
			"m3/m3-00.png",
			"m3/m3-05.png",
			"m3/m3-21.png",
			"m3/m3-16.png",
			"m3/m3-25.png",
			"m3/m3-08.png",
			"m3/m3-10.png",
			"m3/m3-02.png",
			"m3/m3-19.png",
			"m3/m3-06.png",
			"m3/m3-13.png",
			"m3/m3-15.png",
			"m3/m3-27.png",
		};
		qsort(strs,ARRAY_SIZE(strs),sizeof(int),strCompare);
		for(size_t i = 0; i < ARRAY_SIZE(strs); ++i) {
			const char *sno = strs[i] + SSTRLEN("m3/m3-");
			int no = atoi(sno);
			test_assertInt(no,i);
		}
	}

	test_caseSucceeded();
}
コード例 #24
0
ファイル: tgroup.c プロジェクト: Logout22/Escape
static void test_basics(void) {
	size_t count,oldFree;
	test_caseStart("Testing basics");

	{
		sGroup *g;
		oldFree = heapspace();
		g = group_parse("0:root:0",&count);
		test_assertTrue(g != NULL);
		test_assertSize(count,1);
		if(g) {
			test_assertTrue(g->next == NULL);
			test_assertUInt(g->gid,0);
			test_assertStr(g->name,"root");
			test_assertSize(g->userCount,1);
			test_assertUInt(g->users[0],0);
		}
		group_free(g);
		test_assertSize(heapspace(),oldFree);
	}

	{
		sGroup *g;
		oldFree = heapspace();
		g = group_parse("0:root\n",&count);
		test_assertTrue(g != NULL);
		test_assertSize(count,1);
		if(g) {
			test_assertTrue(g->next == NULL);
			test_assertUInt(g->gid,0);
			test_assertStr(g->name,"root");
			test_assertSize(g->userCount,0);
		}
		group_free(g);
		test_assertSize(heapspace(),oldFree);
	}

	{
		sGroup *g;
		oldFree = heapspace();
		g = group_parse("0:root:",&count);
		test_assertTrue(g != NULL);
		test_assertSize(count,1);
		if(g) {
			test_assertTrue(g->next == NULL);
			test_assertUInt(g->gid,0);
			test_assertStr(g->name,"root");
			test_assertSize(g->userCount,0);
		}
		group_free(g);
		test_assertSize(heapspace(),oldFree);
	}

	{
		sGroup *g;
		oldFree = heapspace();
		g = group_parse("2444:a:100:200",&count);
		test_assertTrue(g != NULL);
		test_assertSize(count,1);
		if(g) {
			test_assertTrue(g->next == NULL);
			test_assertUInt(g->gid,2444);
			test_assertStr(g->name,"a");
			test_assertSize(g->userCount,2);
			test_assertUInt(g->users[0],100);
			test_assertUInt(g->users[1],200);
		}
		group_free(g);
		test_assertSize(heapspace(),oldFree);
	}

	{
		sGroup *g,*res;
		oldFree = heapspace();
		res = group_parse("1:a:1:2\n\n2:b:4",&count);
		test_assertSize(count,2);
		g = res;
		test_assertTrue(g != NULL);
		if(g) {
			test_assertUInt(g->gid,1);
			test_assertStr(g->name,"a");
			test_assertSize(g->userCount,2);
			test_assertUInt(g->users[0],1);
			test_assertUInt(g->users[1],2);
			g = g->next;
		}
		test_assertTrue(g != NULL);
		if(g) {
			test_assertUInt(g->gid,2);
			test_assertStr(g->name,"b");
			test_assertSize(g->userCount,1);
			test_assertUInt(g->users[0],4);
		}
		group_free(res);
		test_assertSize(heapspace(),oldFree);
	}

	test_caseSucceeded();
}