ObjFW  Diff

Differences From Artifact [4f9ae6f06a]:

To Artifact [2042f99cd4]:


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
/*
 * Copyright (c) 2008
 *   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.
 */

#import "config.h"

#define _ISOC99_SOURCE

#import <string.h>
#import <wchar.h>

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

#define NUM_TESTS 5
#define SUCCESS								\
{									\
	wprintf(L"\r\033[1;%dmTests successful: %d/%d\033[0m",		\
	    (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS);		\
	fflush(stdout);							\
}
#define FAIL								\
{									\
	wprintf(L"\r\033[K\033[1;31mTest %d/%d failed!\033[m\n",	\
	    i + 1, NUM_TESTS);						\
	return 1;							\
}
#define CHECK(cond)							\
	if (cond)							\
		SUCCESS							\
	else								\
		FAIL							\
	i++;
 
const wchar_t *strings[] = {
	L"First String Object",
	L"Second String Object",
	L"Third String Object"
};

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

	list = [OFList new];
 
	[list addNew: [OFString newFromWideCString: strings[0]]];
	[list addNew: [OFString newFromWideCString: strings[1]]];
	[list addNew: [OFString newFromWideCString: strings[2]]];
 
	for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++)
		if (!wcscmp([(OFString*)[iter data] wideCString], strings[i]))
			SUCCESS
		else
			FAIL

	CHECK(!wcscmp([(OFString*)[[list first] data] wideCString], strings[0]))
	CHECK(!wcscmp([(OFString*)[[list last] data] wideCString], strings[2]))

	wprintf(L"\n");
 
	[list freeIncludingData];

	return 0;
}













<
<
|
|







|





|










|
|
|
|











|
|
|


|




|
|

|





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
/*
 * Copyright (c) 2008
 *   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.
 */

#import "config.h"



#import <stdio.h>
#import <string.h>

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

#define NUM_TESTS 5
#define SUCCESS								\
{									\
	printf("\r\033[1;%dmTests successful: %d/%d\033[0m",		\
	    (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS);		\
	fflush(stdout);							\
}
#define FAIL								\
{									\
	printf("\r\033[K\033[1;31mTest %d/%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([(OFString*)[iter data] cString], strings[i]))
			SUCCESS
		else
			FAIL

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

	puts("");
 
	[list freeIncludingData];

	return 0;
}