ObjFW  Check-in [a3bfa21725]

Overview
Comment:Migration of OFDictionary tests to new testing framework.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a3bfa21725a130ddbf2bcf9d56c3882e235a8e5d63aeacbaff6a0d1330da618a
User & Date: js on 2009-09-26 13:27:12
Other Links: manifest | tags
Context
2009-09-27
11:42
Migration of OFArray tests to new testing framework. check-in: dbb0223586 user: js tags: trunk
2009-09-26
13:27
Migration of OFDictionary tests to new testing framework. check-in: a3bfa21725 user: js tags: trunk
2009-09-21
20:35
A few minor Win32 fixes. check-in: 59969f5450 user: js tags: trunk
Changes

Modified tests/Makefile from [c768dbff65] to [ec507306f8].

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

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




<







1
2
3
4

5
6
7
8
9
10
11
include ../extra.mk

SUBDIRS = OFDataArray		\
	  OFArray		\

	  OFHashes		\
	  ${OFPLUGIN}		\
	  OFTCPSocket		\
	  OFThread		\
	  OFList		\
	  OFXMLElement		\
	  OFXMLParser		\

Deleted tests/OFDictionary/Makefile version [32272b1649].

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 = ofdictionary${PROG_SUFFIX}
SRCS = OFDictionary.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/OFDictionary/OFDictionary.m version [cdca107008].

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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * 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 "OFAutoreleasePool.h"
#import "OFDictionary.h"
#import "OFString.h"
#import "OFExceptions.h"

#define TESTS 14

int
main()
{
	int i = 0;

	OFDictionary *dict = [OFMutableDictionary dictionary];
	OFDictionary *dict2;
	OFArray *keys, *objs;
	OFIterator *iter;
	of_iterator_pair_t pair[2];

	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFString *key1 = [OFString stringWithString: @"key1"];
	OFString *key2 = [OFString stringWithString: @"key2"];
	OFString *value1 = [OFString stringWithString: @"value1"];
	OFString *value2 = [OFString stringWithString: @"value2"];

	[dict setObject: value1
		 forKey: key1];
	[dict setObject: value2
		 forKey: key2];
	[pool release];

	i++;
	if (strcmp([[dict objectForKey: @"key1"] cString], "value1")) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	if (strcmp([[dict objectForKey: key2] cString], "value2")) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	iter = [dict iterator];
	pair[0] = [iter nextKeyObjectPair];
	pair[1] = [iter nextKeyObjectPair];
	if (![pair[0].key isEqual: @"key1"] ||
	    ![pair[0].object isEqual: @"value1"] ||
	    ![pair[1].key isEqual: @"key2"] ||
	    ![pair[1].object isEqual: @"value2"]) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	if ([dict count] != 2) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	if ([iter nextKeyObjectPair].object != nil) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	if ([dict objectForKey: @"key3"] != nil) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	[dict release];
	dict = [OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar",
							   @"baz", @"qux",
							   nil];

	if (![[dict objectForKey: @"foo"] isEqual: @"bar"]) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	if (![[dict objectForKey: @"baz"] isEqual: @"qux"]) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	[dict release];
	dict = [OFDictionary dictionaryWithObject: @"bar"
					   forKey: @"foo"];
	if (![[dict objectForKey: @"foo"] isEqual: @"bar"]) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	[dict release];
	keys = [OFArray arrayWithObjects: @"k1", @"k2", nil];
	objs = [OFArray arrayWithObjects: @"o1", @"o2", nil];
	dict = [OFDictionary dictionaryWithObjects: objs
					   forKeys: keys];
	if (![[dict objectForKey: @"k1"] isEqual: @"o1"]) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	if (![[dict objectForKey: @"k2"] isEqual: @"o2"]) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	dict2 = [dict copy];
	[dict release];
	if (![[dict2 objectForKey: @"k1"] isEqual: @"o1"] ||
	    ![[dict2 objectForKey: @"k2"] isEqual: @"o2"]) {
		printf("\033[K\033[1;31mTest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	dict = [dict2 mutableCopy];
	[dict2 release];
	if (![[dict objectForKey: @"k1"] isEqual: @"o1"] ||
	    ![[dict objectForKey: @"k2"] isEqual: @"o2"]) {
		printf("\033[k\033[1;31mtest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	i++;
	[dict setObject: @"o0" forKey: @"k1"];
	[dict setObject: @"o3" forKey: @"k3"];
	if (![[dict objectForKey: @"k1"] isEqual: @"o0"] ||
	    ![[dict objectForKey: @"k2"] isEqual: @"o2"] ||
	    ![[dict objectForKey: @"k3"] isEqual: @"o3"]) {
		printf("\033[k\033[1;31mtest %d/%d failed!\033[m\n", i, TESTS);
		return 1;
	}

	printf("\033[1;32mTests successful: %d/%d\033[0m\n", i, TESTS);

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






































































































































































































































































































































Modified tests_new/Makefile from [52c127904c] to [26538f9b0c].

1

2
3
4
5
6
7
8
9
10
PROG_NOINST = tests${PROG_SUFFIX}

SRCS = main.m	\
       object.m	\
       string.m

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

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

>
|
|







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

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

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

Added tests_new/dictionary.m version [bfcfbd3084].



















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 * 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 "OFDictionary.h"
#import "OFAutoreleasePool.h"
#import "OFString.h"
#import "OFExceptions.h"

#import "main.h"

static OFString *module = @"OFDictionary";
static OFString *keys[] = {
	@"key1",
	@"key2"
};
static OFString *values[] = {
	@"value1",
	@"value2"
};

void
dictionary_tests()
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFDictionary *dict = [OFMutableDictionary dictionary];
	OFIterator *iter;
	of_iterator_pair_t pair[3];
	OFArray *akeys, *avalues;

	[dict setObject: values[0]
		 forKey: keys[0]];
	[dict setObject: values[1]
		 forKey: keys[1]];

	TEST(@"-[objectForKey:]",
	    [[dict objectForKey: keys[0]] isEqual: values[0]] &&
	    [[dict objectForKey: keys[1]] isEqual: values[1]] &&
	    [dict objectForKey: @"key3"] == nil)

	TEST(@"-[iterator]", (iter = [dict iterator]))

	pair[0] = [iter nextKeyObjectPair];
	pair[1] = [iter nextKeyObjectPair];
	pair[2] = [iter nextKeyObjectPair];
	TEST(@"OFIterator's -[nextKeyObjectPair]",
	    [pair[0].key isEqual: keys[0]] &&
	    [pair[0].object isEqual: values[0]] &&
	    [pair[1].key isEqual: keys[1]] &&
	    [pair[1].object isEqual: values[1]] &&
	    pair[2].key == nil && pair[2].object == nil)

	TEST(@"-[count]", [dict count] == 2)

	TEST(@"+[dictionaryWithKeysAndObjects:]",
	    (dict = [OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar",
								@"baz", @"qux",
								nil]) &&
	    [[dict objectForKey: @"foo"] isEqual: @"bar"] &&
	    [[dict objectForKey: @"baz"] isEqual: @"qux"])

	TEST(@"+[dictionaryWithObject:forKey:]",
	    (dict = [OFDictionary dictionaryWithObject: @"bar"
						forKey: @"foo"]) &&
	    [[dict objectForKey: @"foo"] isEqual: @"bar"])

	akeys = [OFArray arrayWithObjects: keys[0], keys[1], nil];
	avalues = [OFArray arrayWithObjects: values[0], values[1], nil];
	TEST(@"+[dictionaryWithObjects:forKeys:]",
	    (dict = [OFDictionary dictionaryWithObjects: avalues
						forKeys: akeys]) &&
	    [[dict objectForKey: keys[0]] isEqual: values[0]] &&
	    [[dict objectForKey: keys[1]] isEqual: values[1]])

	TEST(@"-[copy]",
	    (dict = [[dict copy] autorelease]) &&
	    [[dict objectForKey: keys[0]] isEqual: values[0]] &&
	    [[dict objectForKey: keys[1]] isEqual: values[1]])

	TEST(@"-[mutableCopy]",
	    (dict = [[dict mutableCopy] autorelease]) &&
	    [[dict objectForKey: keys[0]] isEqual: values[0]] &&
	    [[dict objectForKey: keys[1]] isEqual: values[1]] &&
	    [dict setObject: @"value3"
		     forKey: @"key3"] &&
	    [[dict objectForKey: @"key3"] isEqual: @"value3"] &&
	    [dict setObject: @"foo"
		     forKey: keys[0]] &&
	    [[dict objectForKey: keys[0]] isEqual: @"foo"])

	TEST(@"-[removeObjectForKey:]",
	    [dict removeObjectForKey: keys[0]] &&
	    [dict objectForKey: keys[0]] == nil)

	[pool release];
}

Modified tests_new/main.m from [3bad531e54] to [f044fa8a49].

15
16
17
18
19
20
21

22
23
24
25
26
27
28
#include <stdio.h>
#endif
#include <stdlib.h>

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


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

static int fails = 0;

static void
output(OFString *str, int color)







>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#endif
#include <stdlib.h>

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

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

static int fails = 0;

static void
output(OFString *str, int color)
83
84
85
86
87
88
89

90
91
92
}

int
main()
{
	object_tests();
	string_tests();


	return fails;
}







>



84
85
86
87
88
89
90
91
92
93
94
}

int
main()
{
	object_tests();
	string_tests();
	dictionary_tests();

	return fails;
}