11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#import "config.h"
#import <string.h>
#import "OFString.h"
#import "OFExceptions.h"
#import <stdio.h>
#ifndef _WIN32
#define ZD "%zd"
#else
#define ZD "%u"
|
>
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#import "config.h"
#import <string.h>
#import "OFString.h"
#import "OFExceptions.h"
#import "OFAutoreleasePool.h"
#import <stdio.h>
#ifndef _WIN32
#define ZD "%zd"
#else
#define ZD "%u"
|
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
|
i++;
int
main()
{
size_t i = 0;
OFString *s1 = [OFString newFromCString: "test"];
OFString *s2 = [OFString newFromCString: ""];
OFString *s3;
OFString *s4 = [OFString new];
s3 = [s1 clone];
CHECK(![s1 compareTo: s3])
[s2 appendCString: "123"];
[s4 setTo: s2];
CHECK(![s2 compareTo: s4])
CHECK(!strcmp([[s1 append: s2] cString], "test123"))
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"))
/* Also clears all the memory of the returned C strings */
[s1 free];
[s2 free];
[s3 free];
[s4 free];
/* UTF-8 tests */
CHECK_EXCEPT(s1 = [OFString newFromCString: "\xE0\x80"],
OFInvalidEncodingException)
CHECK_EXCEPT(s1 = [OFString newFromCString: "\xF0\x80\x80\xC0"],
OFInvalidEncodingException)
s1 = [OFString newFromCString: "äöü€𝄞"];
CHECK(!strcmp([[s1 reverse] cString], "𝄞€üöä"))
[s1 free];
/* Format tests */
s1 = [OFString newFromFormatCString: "%s: %d", "test", 123];
CHECK(!strcmp([s1 cString], "test: 123"))
[s1 appendWithFormatCString: "%02X", 15];
CHECK(!strcmp([s1 cString], "test: 1230F"))
puts("");
return 0;
}
|
>
|
|
|
|
<
<
<
|
|
|
|
|
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
|
i++;
int
main()
{
size_t i = 0;
OFAutoreleasePool *pool = [OFAutoreleasePool new];
OFString *s1 = [OFString stringWithCString: "test"];
OFString *s2 = [OFString stringWithCString: ""];
OFString *s3;
OFString *s4 = [OFString string];
s3 = [s1 clone];
CHECK(![s1 compareTo: s3])
[s2 appendCString: "123"];
[s4 setTo: s2];
CHECK(![s2 compareTo: s4])
CHECK(!strcmp([[s1 append: s2] cString], "test123"))
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"))
/* 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 = [OFString stringWithCString: "äöü€𝄞"];
CHECK(!strcmp([[s1 reverse] cString], "𝄞€üöä"))
[s1 free];
/* Format tests */
s1 = [OFString stringWithFormat: "%s: %d", "test", 123];
CHECK(!strcmp([s1 cString], "test: 123"))
[s1 appendWithFormatCString: "%02X", 15];
CHECK(!strcmp([s1 cString], "test: 1230F"))
puts("");
return 0;
}
|