ObjFW  Check-in [cb8e2e3fa6]

Overview
Comment:Add OFMessagePackTests

Only tests for numbers so far.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cb8e2e3fa6f9939789b184914ac624e5e7db70f64abecbe4e5a7dbef9f49c0e9
User & Date: js on 2024-03-17 22:40:58
Other Links: manifest | tags
References
2024-03-23
16:45 Fixed ticket [8a4a9631fd]: Write tests for MessagePack plus 4 other changes artifact: e7b53a18cd user: js
Context
2024-03-23
16:43
OFMessagePackTests: Add more tests check-in: 66f22a2831 user: js tags: trunk
2024-03-17
22:40
Add OFMessagePackTests check-in: cb8e2e3fa6 user: js tags: trunk
22:40
-[objectByParsingMessagePack]: Fix signed numbers check-in: e3001a706c user: js tags: trunk
Changes

Modified tests/Makefile from [aac9ffbef2] to [f0a82101d7].

38
39
40
41
42
43
44

45
46
47
48
49
50
51
       OFInvocationTests.m			\
       OFJSONTests.m				\
       OFLHAArchiveTests.m			\
       OFListTests.m				\
       OFLocaleTests.m				\
       OFMatrix4x4Tests.m			\
       OFMemoryStreamTests.m			\

       OFMethodSignatureTests.m			\
       OFMutableArrayTests.m			\
       OFMutableDataTests.m			\
       OFMutableDictionaryTests.m		\
       OFMutableSetTests.m			\
       OFMutableStringTests.m			\
       OFMutableUTF8StringTests.m		\







>







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
       OFInvocationTests.m			\
       OFJSONTests.m				\
       OFLHAArchiveTests.m			\
       OFListTests.m				\
       OFLocaleTests.m				\
       OFMatrix4x4Tests.m			\
       OFMemoryStreamTests.m			\
       OFMessagePackTests.m			\
       OFMethodSignatureTests.m			\
       OFMutableArrayTests.m			\
       OFMutableDataTests.m			\
       OFMutableDictionaryTests.m		\
       OFMutableSetTests.m			\
       OFMutableStringTests.m			\
       OFMutableUTF8StringTests.m		\

Added tests/OFMessagePackTests.m version [f63bfb7b62].















































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * 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 "ObjFW.h"
#import "ObjFWTest.h"

@interface OFMessagePackTests: OTTestCase
@end

@implementation OFMessagePackTests
- (void)testMessagePackRepresentationForNumber
{
	OTAssertEqualObjects([[OFNumber numberWithChar: -30]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\xE2" count: 1]);

	OTAssertEqualObjects([[OFNumber numberWithChar: -33]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\xD0\xDF" count: 2]);

	OTAssertEqualObjects([[OFNumber numberWithUnsignedChar: 127]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\x7F" count: 1]);

	OTAssertEqualObjects([[OFNumber numberWithUnsignedChar: 128]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\xCC\x80" count: 2]);

	OTAssertEqualObjects([[OFNumber numberWithShort: -129]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\xD1\xFF\x7F" count: 3]);

	OTAssertEqualObjects([[OFNumber numberWithUnsignedShort: 256]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\xCD\x01\x00" count: 3]);

	OTAssertEqualObjects([[OFNumber numberWithLong: -32769]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\xD2\xFF\xFF\x7F\xFF" count: 5]);

	OTAssertEqualObjects([[OFNumber numberWithUnsignedLong: 65536]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\xCE\x00\x01\x00\x00" count: 5]);

	OTAssertEqualObjects([[OFNumber numberWithLongLong: -2147483649]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\xD3\xFF\xFF\xFF\xFF\x7F\xFF\xFF\xFF"
			    count: 9]);

	OTAssertEqualObjects([[OFNumber numberWithUnsignedLongLong: 4294967296]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\xCF\x00\x00\x00\x01\x00\x00\x00\x00"
			    count: 9]);

	OTAssertEqualObjects([[OFNumber numberWithFloat: 1.25f]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\xCA\x3F\xA0\x00\x00" count: 5]);

	OTAssertEqualObjects([[OFNumber numberWithDouble: 1.25]
	    messagePackRepresentation],
	    [OFData dataWithItems: "\xCB\x3F\xF4\x00\x00\x00\x00\x00\x00"
			    count: 9]);
}

- (void)testObjectByParsingMessagePackForNumber
{
	OTAssertEqualObjects([[OFData dataWithItems: "\xE2" count: 1]
	    objectByParsingMessagePack],
	    [OFNumber numberWithChar: -30]);

	OTAssertEqualObjects([[OFData dataWithItems: "\xD0\xDF" count: 2]
	    objectByParsingMessagePack],
	    [OFNumber numberWithChar: -33]);

	OTAssertEqualObjects([[OFData dataWithItems: "\x7F" count: 1]
	    objectByParsingMessagePack],
	    [OFNumber numberWithUnsignedChar: 127]);

	OTAssertEqualObjects([[OFData dataWithItems: "\xCC\x80" count: 2]
	    objectByParsingMessagePack],
	    [OFNumber numberWithUnsignedChar: 128]);

	OTAssertEqualObjects([[OFData dataWithItems: "\xD1\xFF\x7F" count: 3]
	    objectByParsingMessagePack],
	    [OFNumber numberWithShort: -129]);

	OTAssertEqualObjects([[OFData dataWithItems: "\xCD\x01\x00" count: 3]
	    objectByParsingMessagePack],
	    [OFNumber numberWithUnsignedShort: 256]);

	OTAssertEqualObjects(
	    [[OFData dataWithItems: "\xD2\xFF\xFF\x7F\xFF"
			     count: 5] objectByParsingMessagePack],
	    [OFNumber numberWithLong: -32769]);

	OTAssertEqualObjects(
	    [[OFData dataWithItems: "\xCE\x00\x01\x00\x00"
			     count: 5] objectByParsingMessagePack],
	    [OFNumber numberWithUnsignedLong: 65536]);

	OTAssertEqualObjects(
	    [[OFData dataWithItems: "\xD3\xFF\xFF\xFF\xFF\x7F\xFF\xFF\xFF"
			     count: 9] objectByParsingMessagePack],
	    [OFNumber numberWithLongLong: -2147483649]);

	OTAssertEqualObjects(
	    [[OFData dataWithItems: "\xCF\x00\x00\x00\x01\x00\x00\x00\x00"
			     count: 9] objectByParsingMessagePack],
	    [OFNumber numberWithUnsignedLongLong: 4294967296]);

	OTAssertEqualObjects(
	    [[OFData dataWithItems: "\xCA\x3F\xA0\x00\x00"
			     count: 5] objectByParsingMessagePack],
	    [OFNumber numberWithFloat: 1.25f]);

	OTAssertEqualObjects(
	    [[OFData dataWithItems: "\xCB\x3F\xF4\x00\x00\x00\x00\x00\x00"
			     count: 9] objectByParsingMessagePack],
	    [OFNumber numberWithDouble: 1.25]);
}
@end