ObjFW  Check-in [a58692ecce]

Overview
Comment:Never rely on messing with OFHashSeed in tests
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | objfwtest
Files: files | file ages | folders
SHA3-256: a58692ecce7e3c4dd0a40a70a2e0604df10c804d9db5221579cc92f86014a2f2
User & Date: js on 2024-02-12 20:10:19
Other Links: branch diff | manifest | tags
Context
2024-02-12
21:31
Migrate OFSetTests to ObjFWTest check-in: a7780ddefc user: js tags: objfwtest
20:10
Never rely on messing with OFHashSeed in tests check-in: a58692ecce user: js tags: objfwtest
2024-02-11
22:32
Migrate OFINIFileTests to ObjFWTest check-in: cc7c76d3c2 user: js tags: objfwtest
Changes

Modified new_tests/OFArrayTests.h from [418a1a5a2c] to [8f8b5c5038].

17
18
19
20
21
22
23
24

25
17
18
19
20
21
22
23

24
25







-
+

#import "ObjFWTest.h"

@interface OFArrayTests: OTTestCase
{
	OFArray *_array;
}

- (Class)arrayClass;
@property (readonly, nonatomic) Class arrayClass;
@end

Modified new_tests/OFJSONTests.m from [125230cf82] to [fbfa925551].

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







-




-
-








-
-
-












-
-
-
-
-
-
-














-
-
+
+
+
+
+
+
+




-
-
+
+
+
+
+

-
+
+
+
+




-
-
-
+
+
+
+
+
+
+
+







#include "config.h"

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

@interface OFJSONTests: OTTestCase
{
	unsigned long long _hashSeed;
	OFDictionary *_dictionary;
}
@end

extern unsigned long long OFHashSeed;

static OFString *string = @"{\"foo\"\t:'b\\na\\r', \"x\":/*foo*/ [.5\r,0xF,"
    @"null//bar\n,\"foo\",false]}";

@implementation OFJSONTests
- (void)setUp
{
	[super setUp];

	_hashSeed = OFHashSeed;
	OFHashSeed = 0;

	_dictionary = [[OFDictionary alloc] initWithKeysAndObjects:
	    @"foo", @"b\na\r",
	    @"x", [OFArray arrayWithObjects:
		[OFNumber numberWithFloat: .5f],
		[OFNumber numberWithInt: 0xF],
		[OFNull null],
		@"foo",
		[OFNumber numberWithBool: false],
		nil],
	    nil];
}

- (void)tearDown
{
	OFHashSeed = _hashSeed;

	[super tearDown];
}

- (void)dealloc
{
	[_dictionary release];

	[super dealloc];
}

- (void)testObjectByParsingJSON
{
	OTAssertEqualObjects(string.objectByParsingJSON, _dictionary);
}

- (void)testJSONRepresentation
{
	OTAssertEqualObjects(_dictionary.JSONRepresentation,
	    @"{\"x\":[0.5,15,null,\"foo\",false],\"foo\":\"b\\na\\r\"}");
	OFString *representation = _dictionary.JSONRepresentation;

	OTAssert(
	    [representation isEqual:
	    @"{\"x\":[0.5,15,null,\"foo\",false],\"foo\":\"b\\na\\r\"}"] ||
	    [representation isEqual:
	    @"{\"foo\":\"b\\na\\r\",\"x\":[0.5,15,null,\"foo\",false]}"]);
}

- (void)testPrettyJSONRepresentation
{
	OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions:
	    OFJSONRepresentationOptionPretty],
	OFString *representation = [_dictionary JSONRepresentationWithOptions:
	    OFJSONRepresentationOptionPretty];

	OTAssert(
	    [representation isEqual:
	    @"{\n\t\"x\": [\n\t\t0.5,\n\t\t15,\n\t\tnull,\n\t\t"
	    @"\"foo\",\n\t\tfalse\n\t],\n\t\"foo\": \"b\\na\\r\"\n}");
	    @"\"foo\",\n\t\tfalse\n\t],\n\t\"foo\": \"b\\na\\r\"\n}"] ||
	    [representation isEqual:
	    @"{\n\t\"foo\": \"b\\na\\r\",\n\t\"x\": [\n\t\t0.5,\n\t\t15,"
	    @"\n\t\tnull,\n\t\t\"foo\",\n\t\tfalse\n\t]\n}"]);
}

- (void)testJSON5Representation
{
	OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions:
	    OFJSONRepresentationOptionJSON5],
	    @"{x:[0.5,15,null,\"foo\",false],foo:\"b\\\na\\r\"}");
	OFString *representation = [_dictionary JSONRepresentationWithOptions:
	    OFJSONRepresentationOptionJSON5];

	OTAssert(
	    [representation isEqual:
	    @"{x:[0.5,15,null,\"foo\",false],foo:\"b\\\na\\r\"}"] ||
	    [representation isEqual:
	    @"{foo:\"b\\\na\\r\",x:[0.5,15,null,\"foo\",false]}"]);
}

- (void)testObjectByParsingJSONFailsWithInvalidJSON
{
	OTAssertThrowsSpecific([@"{" objectByParsingJSON],
	    OFInvalidJSONException);

Modified new_tests/OFNumberTests.m from [03fbf0fe79] to [79e5b7d8e7].

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







+
+
+


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

+
-
-
+
+
+
+
+
+
+




-
-
-
-
-
+
-
-
-
+




-
-
+




-
-
+








#include "config.h"

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

@interface OFNumberTests: OTTestCase
{
	OFNumber *_number;
}
@end

@implementation OFNumberTests
- (void)setUp
{
	[super setUp];
extern unsigned long long OFHashSeed;

@implementation OFNumberTests
- (void)testIsEqual

	_number = [[OFNumber alloc] initWithLongLong: 123456789];
}

- (void)dealloc
{
	[_number release];
	OFNumber *number = [OFNumber numberWithLongLong: 123456789];
	OTAssertEqualObjects(number, [OFNumber numberWithLong: 123456789]);

	[super dealloc];
}

- (void)testIsEqual
{
	OTAssertEqualObjects(_number, [OFNumber numberWithLong: 123456789]);
}

- (void)testHash
{
	unsigned long long hashSeed = OFHashSeed;
	OFHashSeed = 0;
	@try {
		OFNumber *number = [OFNumber numberWithLongLong: 123456789];
		OTAssertEqual(number.hash, 0x82D8BC42);
	OTAssertEqual(_number.hash,
	} @finally {
		OFHashSeed = hashSeed;
	};
	    [[OFNumber numberWithLong: 123456789] hash]);
}

- (void)testCharValue
{
	OFNumber *number = [OFNumber numberWithLongLong: 123456789];
	OTAssertEqual(number.charValue, 21);
	OTAssertEqual(_number.charValue, 21);
}

- (void)testDoubleValue
{
	OFNumber *number = [OFNumber numberWithLongLong: 123456789];
	OTAssertEqual(number.doubleValue, 123456789.L);
	OTAssertEqual(_number.doubleValue, 123456789.L);
}

- (void)testSignedCharMinAndMaxUnmodified
{
	OTAssertEqual([[OFNumber numberWithChar: SCHAR_MIN] charValue],
	    SCHAR_MIN);
	OTAssertEqual([[OFNumber numberWithChar: SCHAR_MAX] charValue],