コード例 #1
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();
}
コード例 #2
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();
}
コード例 #3
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();
}
コード例 #4
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();
}
コード例 #5
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();
}
コード例 #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_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();
}
コード例 #8
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();
}
コード例 #9
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();
}
コード例 #10
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();
}
コード例 #11
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();
}
コード例 #12
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();
}