ObjFW  Diff

Differences From Artifact [ba45bed53f]:

To Artifact [147b8c86d0]:


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73















74
75
76
77
78
79
80

#ifndef _WIN32
#define ZD "%zd"
#else
#define ZD "%u"
#endif

#define NUM_TESTS 5
#define SUCCESS								\
{									\
	printf("\r\033[1;%dmTests successful: " ZD "/%d\033[0m",	\
	    (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS);		\
	fflush(stdout);							\
}
#define FAIL								\
{									\
	printf("\r\033[K\033[1;31mTest " ZD "/%d failed!\033[m\n",	\
	    i + 1, NUM_TESTS);						\
	return 1;							\
}
#define CHECK(cond)							\

	if (cond)							\
		SUCCESS							\
	else								\
		FAIL							\
	i++;


const char *strings[] = {
	"First String Object",
	"Second String Object",
	"Third String Object"
};

int
main()
{
	size_t	     i;
	OFList	     *list;
	OFListObject *iter;

	list = [OFList new];

	[list addNew: [OFString newFromCString: strings[0]]];
	[list addNew: [OFString newFromCString: strings[1]]];
	[list addNew: [OFString newFromCString: strings[2]]];

	for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++)
		if (!strcmp([[iter data] cString], strings[i]))
			SUCCESS
		else
			FAIL

	CHECK(!strcmp([[[list first] data] cString], strings[0]))
	CHECK(!strcmp([[[list last] data] cString], strings[2]))
















	puts("");

	[list freeIncludingData];

	return 0;
}







|













>




|
>










|
|
|



|
|
|

|
|




|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



<
<


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93


94
95

#ifndef _WIN32
#define ZD "%zd"
#else
#define ZD "%u"
#endif

#define NUM_TESTS 10
#define SUCCESS								\
{									\
	printf("\r\033[1;%dmTests successful: " ZD "/%d\033[0m",	\
	    (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS);		\
	fflush(stdout);							\
}
#define FAIL								\
{									\
	printf("\r\033[K\033[1;31mTest " ZD "/%d failed!\033[m\n",	\
	    i + 1, NUM_TESTS);						\
	return 1;							\
}
#define CHECK(cond)							\
{									\
	if (cond)							\
		SUCCESS							\
	else								\
		FAIL							\
	i++;								\
}

const char *strings[] = {
	"First String Object",
	"Second String Object",
	"Third String Object"
};

int
main()
{
	size_t i, j;
	OFList *list;
	of_list_object_t *iter;

	list = [OFList new];

	[list append: [OFString newFromCString: strings[0]]];
	[list append: [OFString newFromCString: strings[1]]];
	[list append: [OFString newFromCString: strings[2]]];

	for (iter = [list first], i = 0; iter != NULL; iter = iter->next, i++)
		if (!strcmp([iter->object cString], strings[i]))
			SUCCESS
		else
			FAIL

	CHECK(!strcmp([[list first]->object cString], strings[0]))
	CHECK(!strcmp([[list last]->object cString], strings[2]))

	[list remove: [list last]];
	CHECK(!strcmp([[list last]->object cString], strings[1]))

	[list remove: [list first]];
	CHECK(!strcmp([[list first]->object cString],
	    [[list last]->object cString]))

	[list insert: [OFString newFromCString: strings[0]]
	      before: [list last]];
	[list insert: [OFString newFromCString: strings[2]]
	       after: [list first]->next];

	for (iter = [list first], j = 0; iter != NULL; iter = iter->next, j++)
		CHECK(!strcmp([iter->object cString], strings[j]))

	puts("");



	return 0;
}