ObjFW  Check-in [1d802bf56c]

Overview
Comment:Migration of OFList tests to new testing framework.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1d802bf56cdc333dac97ce32623c0d92fc98dd39d9c3e6bc49b13d4ae41d29ec
User & Date: js on 2009-09-28 07:55:55
Other Links: manifest | tags
Context
2009-09-30
13:23
Migration of OFTCPSocket tests to new testing framework. check-in: 67cf530ed3 user: js tags: trunk
2009-09-28
07:55
Migration of OFList tests to new testing framework. check-in: 1d802bf56c user: js tags: trunk
2009-09-27
15:04
Small documentation addendum. check-in: ada9f37216 user: js tags: trunk
Changes

Modified tests/Makefile from [fa107a94eb] to [65d045983b].

1
2
3
4
5
6
7
8
9
10
11
12
13
include ../extra.mk

SUBDIRS = OFDataArray		\
	  OFHashes		\
	  ${OFPLUGIN}		\
	  OFTCPSocket		\
	  OFThread		\
	  OFList		\
	  OFXMLElement		\
	  OFXMLParser		\
	  ${OBJC_SYNC}

include ../buildsys.mk







<





1
2
3
4
5
6
7

8
9
10
11
12
include ../extra.mk

SUBDIRS = OFDataArray		\
	  OFHashes		\
	  ${OFPLUGIN}		\
	  OFTCPSocket		\
	  OFThread		\

	  OFXMLElement		\
	  OFXMLParser		\
	  ${OBJC_SYNC}

include ../buildsys.mk

Deleted tests/OFList/Makefile version [e6690a0819].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
PROG_NOINST = oflist${PROG_SUFFIX}
SRCS = OFList.m

include ../../buildsys.mk
include ../../extra.mk

CPPFLAGS += -I../../src -I../..
LIBS := -L../../src -lobjfw ${LIBS}

.PHONY: run

all: run
run: ${PROG_NOINST}
	rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib
	if test -f ../../src/libobjfw.so; then \
		ln -s ../../src/libobjfw.so libobjfw.so.0; \
		ln -s ../../src/libobjfw.so libobjfw.so.0.1; \
	fi
	if test -f ../../src/libobjfw.dll; then \
		ln ../../src/libobjfw.dll libobjfw.dll; \
	fi
	if test -f ../../src/libobjfw.dylib; then \
		ln -s ../../src/libobjfw.dylib libobjfw.dylib; \
	fi
	LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \
	DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \
	${TEST_LAUNCHER} ./${PROG_NOINST}; EXIT=$$?; \
	rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib; \
	exit $$EXIT
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


























































Deleted tests/OFList/OFList.m version [c3c7e77f4a].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <stdio.h>
#include <string.h>

#import "OFString.h"
#import "OFList.h"

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

#define NUM_TESTS 27
#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 OFString *strings[] = {
	@"First String Object",
	@"Second String Object",
	@"Third String Object"
};

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

	list = [OFList list];

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

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

	CHECK([[list first]->object isEqual: strings[0]])
	CHECK([[list last]->object isEqual: strings[2]])

	[list remove: [list last]];
	CHECK([[list last]->object isEqual: strings[1]])

	[list remove: [list first]];
	CHECK([[list first]->object isEqual: [list last]->object])

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

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

	CHECK([list count] == 3)

	list2 = [list copy];
	CHECK([list2 count] == 3)
	[list2 remove: [list2 last]];
	CHECK([list2 count] == 2)
	[list2 remove: [list2 first]->next];
	CHECK([list2 count] == 1)
	[list2 remove: [list2 first]];
	CHECK([list2 count] == 0)

	list2 = [OFList list];

	[list2 append: strings[0]];
	[list2 append: strings[1]];
	[list2 append: strings[2]];
	CHECK([list2 isEqual: list]);

	[list2 remove: [list2 last]];
	CHECK(![list2 isEqual: list]);

	/*
	 * Only mutableCopy is guaranteed to return a real copy instead of just
	 * increasing the reference counter.
	 */
	[list2 append: [@"foo" mutableCopy]];
	CHECK(![list2 isEqual: list]);

	list3 = [list2 copy];
	CHECK([list2 isEqual: list3]);

	for (iter = [list2 first], iter2 = [list3 first];
	    iter != NULL && iter2 != NULL;
	    iter = iter->next, iter2 = iter2->next) {
		CHECK(iter != iter2)
		CHECK(iter->object == iter2->object)
	}
	CHECK(iter == NULL && iter2 == NULL)
	CHECK([[list2 last]->object retainCount] == 3)

	puts("");

	return 0;
}
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










































































































































































































































































Modified tests_new/Makefile from [11f3a0cee1] to [4ac30c970c].

1
2
3

4
5
6
7
8
9
10
PROG_NOINST = tests${PROG_SUFFIX}
SRCS = array.m		\
       dictionary.m	\

       main.m		\
       object.m		\
       string.m

include ../buildsys.mk
include ../extra.mk




>







1
2
3
4
5
6
7
8
9
10
11
PROG_NOINST = tests${PROG_SUFFIX}
SRCS = array.m		\
       dictionary.m	\
       list.m		\
       main.m		\
       object.m		\
       string.m

include ../buildsys.mk
include ../extra.mk

Added tests_new/list.m version [afc8552369].

















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#import "OFList.h"
#import "OFAutoreleasePool.h"
#import "OFString.h"
#import "OFExceptions.h"

#import "main.h"

static OFString *module = @"OFList";
static OFString *strings[] = {
	@"Foo",
	@"Bar",
	@"Baz"
};

void
list_tests()
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFList *list;

	TEST(@"+[list]", (list = [OFList list]))

	TEST(@"-[append:]", [list append: strings[0]] &&
	    [list append: strings[1]] && [list append: strings[2]])

	TEST(@"-[first]", [[list first]->object isEqual: strings[0]])

	TEST(@"-[first]->next",
	    [[list first]->next->object isEqual: strings[1]])

	TEST(@"-[last]", [[list last]->object isEqual: strings[2]])

	TEST(@"-[last]->prev", [[list last]->prev->object isEqual: strings[1]])

	TEST(@"-[remove:]", [list remove: [list last]] &&
	    [[list last]->object isEqual: strings[1]] &&
	    [list remove: [list first]] &&
	    [[list first]->object isEqual: [list last]->object])

	TEST(@"-[insert:before:]", [list insert: strings[0]
					 before: [list last]] &&
	    [[list last]->prev->object isEqual: strings[0]])


	TEST(@"-[insert:after:]", [list insert: strings[2]
					 after: [list first]->next] &&
	    [[list last]->object isEqual: strings[2]])

	TEST(@"-[count]", [list count] == 3)

	TEST(@"-[copy]", (list = [[list copy] autorelease]) &&
	    [[list first]->object isEqual: strings[0]] &&
	    [[list first]->next->object isEqual: strings[1]] &&
	    [[list last]->object isEqual: strings[2]])

	TEST(@"-[isEqual:]", [list isEqual: [[list copy] autorelease]])

	[pool release];
}

Modified tests_new/main.m from [fe239efee7] to [6c72294cec].

17
18
19
20
21
22
23

24
25
26
27
28
29
30
#include <stdlib.h>

#import "OFString.h"
#import "OFAutoreleasePool.h"

extern void array_tests();
extern void dictionary_tests();

extern void object_tests();
extern void string_tests();

static int fails = 0;

static void
output(OFString *str, int color)







>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdlib.h>

#import "OFString.h"
#import "OFAutoreleasePool.h"

extern void array_tests();
extern void dictionary_tests();
extern void list_tests();
extern void object_tests();
extern void string_tests();

static int fails = 0;

static void
output(OFString *str, int color)
87
88
89
90
91
92
93

94
95
96
int
main()
{
	object_tests();
	string_tests();
	array_tests();
	dictionary_tests();


	return fails;
}







>



88
89
90
91
92
93
94
95
96
97
98
int
main()
{
	object_tests();
	string_tests();
	array_tests();
	dictionary_tests();
	list_tests();

	return fails;
}