ObjFW  Check-in [6a2551a704]

Overview
Comment:Get rid of strcmp and strlen calls in OFString tests.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6a2551a704e43843409d633f3894f39257ea9a7d85fb62572e9e27711c414b9b
User & Date: js on 2009-07-14 17:14:46
Other Links: manifest | tags
Context
2009-07-14
17:32
Add methods to handle C strings with length to OF(Mutable)String. check-in: dc7bb2d594 user: js tags: trunk
17:14
Get rid of strcmp and strlen calls in OFString tests. check-in: 6a2551a704 user: js tags: trunk
2009-06-30
22:21
Implement -[indexOf{First,Last}OccurrenceOfString:] for OFString. check-in: 9758677802 user: js tags: trunk
Changes

Modified tests/OFString/OFString.m from [5ed17a6543] to [859b6563cd].

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
8
9
10
11
12
13
14

15
16
17
18
19
20
21







-







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

#ifndef _WIN32
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
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







-
+
+

-
-
-
-
+
+
+











-
+




-
+


-
+







	CHECK([s1 hash] == [s3 hash])

	[s2 appendCString: "12"];
	[s2 appendString: @"3"];
	[s4 setToCString: [s2 cString]];

	CHECK(![s2 compare: s4])
	CHECK(!strcmp([[s1 appendString: s2] cString], "test123"))
	CHECK([[s1 appendString: s2] isEqual: @"test123"])
	CHECK([s1 length] == 7)
	CHECK([s1 hash] == 0xC44F49A4)
	CHECK(strlen([s1 cString]) == [s1 length] && [s1 length] == 7)
	CHECK(!strcmp([[s1 reverse] cString], "321tset"))
	CHECK(!strcmp([[s1 upper] cString], "321TSET"))
	CHECK(!strcmp([[s1 lower] cString], "321tset"))
	CHECK([[s1 reverse] isEqual: @"321tset"])
	CHECK([[s1 upper] isEqual: @"321TSET"])
	CHECK([[s1 lower] isEqual: @"321tset"])

	/* Also clears all the memory of the returned C strings */
	[pool release];

	/* UTF-8 tests */
	CHECK_EXCEPT(s1 = [OFString stringWithCString: "\xE0\x80"],
	    OFInvalidEncodingException)
	CHECK_EXCEPT(s1 = [OFString stringWithCString: "\xF0\x80\x80\xC0"],
	    OFInvalidEncodingException)

	s1 = [OFMutableString stringWithCString: "äöü€𝄞"];
	CHECK(!strcmp([[s1 reverse] cString], "𝄞€üöä"))
	CHECK([[s1 reverse] isEqual: @"𝄞€üöä"])
	[s1 dealloc];

	/* Format tests */
	s1 = [OFMutableString stringWithFormat: @"%s: %d", "test", 123];
	CHECK(!strcmp([s1 cString], "test: 123"))
	CHECK([s1 isEqual: @"test: 123"])

	[s1 appendWithFormat: @"%02X", 15];
	CHECK(!strcmp([s1 cString], "test: 1230F"))
	CHECK([s1 isEqual: @"test: 1230F"])

	/* Find index tests */
	CHECK([@"foo" indexOfFirstOccurrenceOfString: @"oo"] == 1)
	CHECK([@"foo" indexOfLastOccurrenceOfString: @"oo"] == 1)
	CHECK([@"foo" indexOfFirstOccurrenceOfString: @"o"] == 1)
	CHECK([@"foo" indexOfLastOccurrenceOfString: @"o"] == 2)
	CHECK([@"foo" indexOfFirstOccurrenceOfString: @"f"] == 0)