Esempio n. 1
0
void testStage2(void) {
	char c_str1[20] = "hello";
	char* ut_str1;
	char* ut_str2;

	printf("Starting stage 2 tests\n");
	strcat(c_str1, " world");
	printf("%s\n", c_str1); // nothing exciting, prints "hello world"

	ut_str1 = utstrdup("hello ");
	ut_str1 = utstrrealloc(ut_str1, 20);
	utstrcat(ut_str1, c_str1);
	printf("%s\n", ut_str1); // slightly more exciting, prints "hello hello world"

	utstrcat(ut_str1, " world");
	printf("%s\n", ut_str1); // exciting, should print "hello hello world wo", 'cause there's not enough room for the second world

	ut_str2 = utstrdup("");
	ut_str2 = utstrrealloc(ut_str2, 11);
	utstrcpy(ut_str2, ut_str1 + 6);
	printf("%s\n", ut_str2); // back to "hello world"

	ut_str2 = utstrrealloc(ut_str2, 23);
	utstrcat(ut_str2, " ");
	utstrcat(ut_str2, ut_str1);
	printf("%s\n", ut_str2); // now should be "hello world hello hello"
 
	utstrfree(ut_str1);
	utstrfree(ut_str2);
}
Esempio n. 2
0
void testStage1(void) {
	char p[12];
	const char* q = "Hello World";
	char* s; 
	char* t; 
	unsigned k;
	
	printf("this test should print Hello World three times\n");

	for (k = 0; k < 12; k += 1) {
		p[k] = q[k];
	}
	s = utstrdup(p);
	printf(s);
	printf("\n");

	q = "you goofed!";
	for (k = 0; k < 12; k += 1) {
		p[k] = q[k];
	}
	printf(s);
	printf("\n");
	
	t = utstrdup(s);
	utstrfree(s);

	printf(t);	
	printf("\n");
	utstrfree(t);
}	
Esempio n. 3
0
void myTest(void) {
	char* str1 = utstrdup("apple");
	printf("%s\n", str1);
	char* str2 = utstrdup("");
	printf("%s\n", str2);
	uint32_t str1_len = utstrlen(str1);
	printf("%d\n", str1_len);
	uint32_t str2_len = utstrlen(str2);
	printf("%d\n", str2_len);
	char* str3 = utstrcat(str1, " pickle");
	printf("%s\n", str3);
	char* str4 = utstrcat(str1, "");
	printf("%s\n", str4);
	utstrcpy(str1, "pie");
	printf("%s\n", str1);
	utstrcpy(str1, "big old massive hunk of yummy pie");
	printf("%s\n", str1);
	utstrcpy(str1, "");
	printf("%s\n", str1);
	utstrfree(str2);
	char* str5 = utstrrealloc(str1, 20);
	printf("%s\n", str5);
	utstrcpy(str5, "big old massive hunk of yummy pie");
	printf("%s\n", str5);
	str5 = utstrrealloc(str5, 0);
	printf("%s\n", str5);
	utstrcpy(str5, "big old massive hunk of yummy pie");
	printf("%s\n", str5);
	//str4 = utstrrealloc(str5, -1); //should crash program
	printf("%s\n", str4);
}
Esempio n. 4
0
void testStage3(void) {
	int k;
	char* ut_str1 = utstrdup("");
	ut_str1 = utstrrealloc(ut_str1, BIG); // big, big string

	printf("attempting stage 3 test. This shouldn't take long...\n");
	printf("(no really, it shouldn't take long, if it does, you fail this test)\n");
	fflush(stdout);

	for (k = 0; k < BIG; k += 1) {
		utstrcat(ut_str1, "*");
	}
	if (ut_str1[BIG-1] != '*') {
		printf("stage3 fails for not copying all the characters\n");
	} else if (strlen(ut_str1) != BIG) {
		printf("Hmmm, stage3 has something wrong\n");
	} else {
		printf("grats, stage 3 passed (unless it took a long time to print this message)\n");
	}
	utstrfree(ut_str1);
}