ObjFW  Check-in [30f4a8d985]

Overview
Comment:Migrate OFPropertyListTests to ObjFWTest
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | objfwtest
Files: files | file ages | folders
SHA3-256: 30f4a8d985460fda2fc735d323c36fe04735564f63303731fefdb77322a9383f
User & Date: js on 2024-02-10 15:32:30
Other Links: branch diff | manifest | tags
Context
2024-02-11
09:33
Fix linking tests for Wii U check-in: 7c33f33d80 user: js tags: objfwtest
2024-02-10
15:32
Migrate OFPropertyListTests to ObjFWTest check-in: 30f4a8d985 user: js tags: objfwtest
14:48
OFNumberTests: Fix type mismatch check-in: 14bc00f118 user: js tags: objfwtest
Changes

Modified new_tests/Makefile from [fa4014942b] to [013af67a80].

1
2
3



4
5
6
7
8
9
10
1


2
3
4
5
6
7
8
9
10
11

-
-
+
+
+







PROG_NOINST = tests${PROG_SUFFIX}
SRCS = OFNumberTests.m	\
       OFPBKDF2Tests.m
SRCS = OFNumberTests.m		\
       OFPBKDF2Tests.m		\
       OFPropertyListTests.m

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

.PHONY: run run-on-ios run-on-android
run:
	rm -f libobjfw.so.${OBJFW_LIB_MAJOR}

Renamed and modified tests/OFPropertyListTests.m [f48a04b761] to new_tests/OFPropertyListTests.m [7815182aa6].

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
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







-
+
+
+
+
+









-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-

-










+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
-
+


 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "TestsAppDelegate.h"
#import "ObjFW.h"
#import "ObjFWTest.h"

@interface OFPropertyListTests: OTTestCase
@end

#define PLIST(x)							\
	@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"			\
	@"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" "	\
	@"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"		\
	@"<plist version=\"1.0\">\n"					\
	x @"\n"								\
	@"</plist>"

static OFString *const module = @"OFPropertyList";
@implementation OFPropertyListTests
static OFString *const PLIST1 = PLIST(@"<string>Hello</string>");
static OFString *const PLIST2 = PLIST(
    @"<array>"
    @" <string>Hello</string>"
    @" <data>V29ybGQh</data>"
    @" <date>2018-03-14T12:34:56Z</date>"
    @" <true/>"
    @" <false/>"
    @" <real>12.25</real>"
    @" <integer>-10</integer>"
    @"</array>");
static OFString *const PLIST3 = PLIST(
    @"<dict>"
    @" <key>array</key>"
    @" <array>"
    @"  <string>Hello</string>"
    @"  <data>V29ybGQh</data>"
    @"  <date>2018-03-14T12:34:56Z</date>"
    @"  <true/>"
    @"  <false/>"
    @"  <real>12.25</real>"
    @"  <integer>-10</integer>"
    @" </array>"
    @" <key>foo</key>"
    @" <string>bar</string>"
    @"</dict>");

- (void)testObjectByParsingPropertyList
@implementation TestsAppDelegate (OFPLISTParser)
- (void)propertyListTests
{
	void *pool = objc_autoreleasePoolPush();
	OFArray *array = [OFArray arrayWithObjects:
	    @"Hello",
	    [OFData dataWithItems: "World!" count: 6],
	    [OFDate dateWithTimeIntervalSince1970: 1521030896],
	    [OFNumber numberWithBool: true],
	    [OFNumber numberWithBool: false],
	    [OFNumber numberWithFloat: 12.25f],
	    [OFNumber numberWithInt: -10],
	    nil];

	OTAssertEqualObjects([PLIST(
	TEST(@"-[objectByParsingPropertyList:] #1",
	    [PLIST1.objectByParsingPropertyList isEqual: @"Hello"])

	TEST(@"-[objectByParsingPropertyList:] #2",
	    [PLIST2.objectByParsingPropertyList isEqual: array])

	TEST(@"-[objectByParsingPropertyList:] #3",
	    @"<string>Hello</string>") objectByParsingPropertyList],
	    @"Hello");
	OTAssertEqualObjects([PLIST(
	    @"<array>"
	    @" <string>Hello</string>"
	    @" <data>V29ybGQh</data>"
	    @" <date>2018-03-14T12:34:56Z</date>"
	    @" <true/>"
	    @" <false/>"
	    @" <real>12.25</real>"
	    @" <integer>-10</integer>"
	    @"</array>") objectByParsingPropertyList],
	    array);
	OTAssertEqualObjects([PLIST(
	    @"<dict>"
	    @" <key>array</key>"
	    @" <array>"
	    @"  <string>Hello</string>"
	    @"  <data>V29ybGQh</data>"
	    @"  <date>2018-03-14T12:34:56Z</date>"
	    @"  <true/>"
	    @"  <false/>"
	    @"  <real>12.25</real>"
	    @"  <integer>-10</integer>"
	    @" </array>"
	    @" <key>foo</key>"
	    @" <string>bar</string>"
	    @"</dict>") objectByParsingPropertyList],
	    [PLIST3.objectByParsingPropertyList isEqual:
	    [OFDictionary dictionaryWithKeysAndObjects:
	    ([OFDictionary dictionaryWithKeysAndObjects:
	    @"array", array,
	    @"foo", @"bar",
	    nil]])

	EXPECT_EXCEPTION(@"Detecting unsupported version",
	    OFUnsupportedVersionException,
	    [[PLIST(@"<string/>") stringByReplacingOccurrencesOfString: @"1.0"
							    withString: @"1.1"]
	    objectByParsingPropertyList])

	EXPECT_EXCEPTION(
	    nil]));
}

- (void)testDetectUnsupportedVersion
{
	bool caught = false;
	@try {
		[[PLIST(@"<string/>")
		    stringByReplacingOccurrencesOfString: @"1.0"
					      withString: @"1.1"]
		objectByParsingPropertyList];
	} @catch (OFUnsupportedVersionException *e) {
		caught = true;
	}
	OTAssertTrue(caught);
}

	    @"-[objectByParsingPropertyList] detecting invalid format #1",
	    OFInvalidFormatException,
- (void)testDetectInvalidFormat
	    [PLIST(@"<string x='b'/>") objectByParsingPropertyList])

	EXPECT_EXCEPTION(
	    @"-[objectByParsingPropertyList] detecting invalid format #2",
	    OFInvalidFormatException,
	    [PLIST(@"<string xmlns='foo'/>") objectByParsingPropertyList])

	EXPECT_EXCEPTION(
	    @"-[objectByParsingPropertyList] detecting invalid format #3",
	    OFInvalidFormatException,
{
	bool caught;

	caught = false;
	@try {
		[PLIST(@"<string x='b'/>") objectByParsingPropertyList];
	} @catch (OFInvalidFormatException *e) {
		caught = true;
	}
	OTAssertTrue(caught);

	caught = false;
	@try {
		[PLIST(@"<string xmlns='foo'/>") objectByParsingPropertyList];
	} @catch (OFInvalidFormatException *e) {
		caught = true;
	}
	OTAssertTrue(caught);

	caught = false;
	@try {
		[PLIST(@"<dict count='0'/>") objectByParsingPropertyList];
	} @catch (OFInvalidFormatException *e) {
	    [PLIST(@"<dict count='0'/>") objectByParsingPropertyList])

	EXPECT_EXCEPTION(
		caught = true;
	}
	OTAssertTrue(caught);

	    @"-[objectByParsingPropertyList] detecting invalid format #4",
	    OFInvalidFormatException,
	    [PLIST(@"<dict><key/><string/><key/></dict>")
	    objectByParsingPropertyList])

	EXPECT_EXCEPTION(
	caught = false;
	@try {
		[PLIST(@"<dict><key/><string/><key/></dict>")
		    objectByParsingPropertyList];
	} @catch (OFInvalidFormatException *e) {
		caught = true;
	}
	OTAssertTrue(caught);

	    @"-[objectByParsingPropertyList] detecting invalid format #5",
	    OFInvalidFormatException,
	    [PLIST(@"<dict><key x='x'/><string/></dict>")
	    objectByParsingPropertyList])

	caught = false;
	@try {
		[PLIST(@"<dict><key x='x'/><string/></dict>")
		    objectByParsingPropertyList];
	} @catch (OFInvalidFormatException *e) {
		caught = true;
	}
	objc_autoreleasePoolPop(pool);
	OTAssertTrue(caught);
}
@end

Modified tests/Makefile from [9fdf4e0c2d] to [85de92b1ac].

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
34
35
36
37
38
39
40

41
42
43
44
45
46
47







-







       OFLocaleTests.m			\
       OFMD5HashTests.m			\
       OFMatrix4x4Tests.m		\
       OFMemoryStreamTests.m		\
       OFMethodSignatureTests.m		\
       OFNotificationCenterTests.m	\
       OFObjectTests.m			\
       OFPropertyListTests.m		\
       OFRIPEMD160HashTests.m		\
       OFSHA1HashTests.m		\
       OFSHA224HashTests.m		\
       OFSHA256HashTests.m		\
       OFSHA384HashTests.m		\
       OFSHA512HashTests.m		\
       OFScryptTests.m			\

Modified tests/TestsAppDelegate.h from [11d91f3d0d] to [e5f43624d0].

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
167
168
169
170
171
172
173




174
175
176
177
178
179
180







-
-
-
-







- (void)notificationCenterTests;
@end

@interface TestsAppDelegate (OFObjectTests)
- (void)objectTests;
@end

@interface TestsAppDelegate (OFPropertyListTests)
- (void)propertyListTests;
@end

@interface TestsAppDelegate (OFPluginTests)
- (void)pluginTests;
@end

@interface TestsAppDelegate (RuntimeTests)
- (void)runtimeTests;
@end

Modified tests/TestsAppDelegate.m from [0763de9d56] to [70afe01d23].

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
435
436
437
438
439
440
441

442
443
444
445
446
447
448







-







	[self HTTPCookieTests];
	[self HTTPCookieManagerTests];
#endif
	[self XMLParserTests];
	[self XMLNodeTests];
	[self XMLElementBuilderTests];
	[self JSONTests];
	[self propertyListTests];
	[self matrix4x4Tests];

#ifdef OF_HAVE_PLUGINS
	[self pluginTests];
#endif
#ifdef OF_HAVE_SUBPROCESSES
	[self subprocessTests];