ObjFW  Check-in [6d64cca782]

Overview
Comment:Migrate OFMatrix4x4Tests to ObjFWTest
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | objfwtest
Files: files | file ages | folders
SHA3-256: 6d64cca78227bb95888dd1670f0d9295dbea7ede5bad5ee72012bc795d393a3f
User & Date: js on 2024-02-11 15:49:13
Other Links: branch diff | manifest | tags
Context
2024-02-11
16:23
Migrate OFSocketTests to ObjFWTest check-in: 10ece67a08 user: js tags: objfwtest
15:49
Migrate OFMatrix4x4Tests to ObjFWTest check-in: 6d64cca782 user: js tags: objfwtest
15:32
Migrate OFInvocationTests to ObjFWTest check-in: 34e6ff9e0b user: js tags: objfwtest
Changes

Modified new_tests/Makefile from [2edeeab174] to [056044a35b].

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17









+







include ../extra.mk

SUBDIRS = ${TESTPLUGIN}

PROG_NOINST = tests${PROG_SUFFIX}
SRCS = OFCharacterSetTests.m	\
       OFColorTests.m		\
       OFIRITests.m		\
       OFInvocationTests.m	\
       OFMatrix4x4Tests.m	\
       OFMethodSignatureTests.m	\
       OFNumberTests.m		\
       OFPBKDF2Tests.m		\
       OFPropertyListTests.m	\
       OFScryptTests.m		\
       ${USE_SRCS_PLUGINS}
SRCS_PLUGINS = OFPluginTests.m

Renamed and modified tests/OFMatrix4x4Tests.m [29d0338fbf] to new_tests/OFMatrix4x4Tests.m [d36d37a6ea].

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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154







-
-
+
+
-

-
-
+

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




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




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

-
+





-
-
-
-
+
+
+




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


 * 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"
static OFString *const module = @"OFMatrix4x4Tests";

@implementation TestsAppDelegate (OFMatrix4x4Tests)
- (void)matrix4x4Tests
@interface OFMatrix4x4Tests: OTTestCase
{
	void *pool = objc_autoreleasePoolPush();
	OFMatrix4x4 *matrix, *matrix2;
	OFMatrix4x4 *_matrix;
	OFVector4D point;
	OFVector4D points[2] = {{ 1, 2, 3, 1 }, { 7, 8, 9, 2 }};

	TEST(@"+[identityMatrix]",
	    memcmp([[OFMatrix4x4 identityMatrix] values], (const float [4][4]){
}
@end

@implementation OFMatrix4x4Tests
		{ 1, 0, 0, 0 },
		{ 0, 1, 0, 0 },
		{ 0, 0, 1, 0 },
		{ 0, 0, 0, 1 }
	    }, 16 * sizeof(float)) == 0)

- (void)setUp
{
	TEST(@"+[matrixWithValues:]",
	    (matrix = [OFMatrix4x4 matrixWithValues: (const float [4][4]){
	_matrix = [[OFMatrix4x4 alloc] initWithValues: (const float [4][4]){
		{  1,  2,  3,  4 },
		{  5,  6,  7,  8 },
		{  9, 10, 11, 12 },
		{ 13, 14, 15, 16 }
	    }]))

	TEST(@"-[description]",
	    [matrix.description isEqual: @"<OFMatrix4x4: {\n"
					 @"\t1 2 3 4\n"
					 @"\t5 6 7 8\n"
					 @"\t9 10 11 12\n"
					 @"\t13 14 15 16\n"
					 @"}>"])

	TEST(@"-[isEqual:]", [[OFMatrix4x4 identityMatrix] isEqual:
	    [OFMatrix4x4 matrixWithValues: (const float [4][4]){
	}];
}

- (void)dealloc
{
	[_matrix release];

	[super dealloc];
}

- (void)testIdentityMatrix
{
	OTAssertEqual(memcmp([[OFMatrix4x4 identityMatrix] values],
	    (const float [4][4]){
		{ 1, 0, 0, 0 },
		{ 0, 1, 0, 0 },
		{ 0, 0, 1, 0 },
		{ 0, 0, 0, 1 }
	    }, 16 * sizeof(float)),
	    0);
}

- (void)testDescription
{
	OTAssertEqualObjects(_matrix.description,
	    @"<OFMatrix4x4: {\n"
	    @"\t1 2 3 4\n"
	    @"\t5 6 7 8\n"
	    @"\t9 10 11 12\n"
	    @"\t13 14 15 16\n"
	    @"}>");
}

- (void)testIsEqual
{
	OTAssertEqualObjects([OFMatrix4x4 identityMatrix],
	    ([OFMatrix4x4 matrixWithValues: (const float [4][4]){
		{ 1, 0, 0, 0 },
		{ 0, 1, 0, 0 },
		{ 0, 0, 1, 0 },
		{ 0, 0, 0, 1 }
	    }]])

	TEST(@"-[copy]", (matrix2 = [[matrix copy] autorelease]) &&
	    [matrix2 isEqual: matrix])

	TEST(@"-[multiplyWithMatrix:] #1",
	    R([matrix2 multiplyWithMatrix: [OFMatrix4x4 identityMatrix]]) &&
	    [matrix2 isEqual: matrix])
	    }]));
}

/* TODO: testHash */

- (void)testCopy
{
	OTAssertEqualObjects(_matrix, [[_matrix copy] autorelease]);
}

- (void)testMultiplyWithMatrix
{
	OFMatrix4x4 *matrix;

	matrix = [[_matrix copy] autorelease];
	[matrix multiplyWithMatrix: [OFMatrix4x4 identityMatrix]];
	OTAssertEqualObjects(matrix, _matrix);

	matrix2 = [OFMatrix4x4 matrixWithValues: (const float [4][4]){
	matrix = [OFMatrix4x4 matrixWithValues: (const float [4][4]){
		{  100,  200,  300,  400 },
		{  500,  600,  700,  800 },
		{  900, 1000, 1100, 1200 },
		{ 1300, 1400, 1500, 1600 }
	}];
	TEST(@"-[multiplyWithMatrix:] #2",
	    R([matrix2 multiplyWithMatrix: matrix]) &&
	    [matrix2 isEqual:
	    [OFMatrix4x4 matrixWithValues: (const float [4][4]){
	[matrix multiplyWithMatrix: _matrix];
	OTAssertEqualObjects(matrix,
	    ([OFMatrix4x4 matrixWithValues: (const float [4][4]){
		{  9000, 10000, 11000, 12000 },
		{ 20200, 22800, 25400, 28000 },
		{ 31400, 35600, 39800, 44000 },
		{ 42600, 48400, 54200, 60000 }
	    }]])

	TEST(@"-[translateWithVector:]",
	    (matrix2 = [OFMatrix4x4 identityMatrix]) &&
	    R([matrix2 translateWithVector: OFMakeVector3D(1, 2, 3)]) &&
	    R(point =
	    [matrix2 transformedVector: OFMakeVector4D(2, 3, 4, 1)]) &&
	    point.x == 3 && point.y == 5 && point.z == 7 && point.w == 1)

	TEST(@"-[scaleWithVector:]",
	    R([matrix2 scaleWithVector: OFMakeVector3D(-1, 0.5f, 2)]) &&
	    R(point =
	    [matrix2 transformedVector: OFMakeVector4D(2, 3, 4, 1)]) &&
	    point.x == -3 && point.y == 2.5 && point.z == 14 && point.w == 1)

	TEST(@"-[transformVectors:count:]",
	    R([matrix transformVectors: points count: 2]) &&
	    points[0].x == 18 && points[0].y == 46 && points[0].z == 74 &&
	    points[0].w == 102 && points[1].x == 58 && points[1].y == 162 &&
	    points[1].z == 266 && points[1].w == 370)

	objc_autoreleasePoolPop(pool);
	    }]));
}

- (void)testTranslateWithVector
{
	OFMatrix4x4 *matrix = [OFMatrix4x4 identityMatrix];
	OFVector4D point;

	[matrix translateWithVector: OFMakeVector3D(1, 2, 3)];

	point = [matrix transformedVector: OFMakeVector4D(2, 3, 4, 1)];
	OTAssertEqual(point.x, 3);
	OTAssertEqual(point.y, 5);
	OTAssertEqual(point.z, 7);
	OTAssertEqual(point.w, 1);
}

- (void)testScaleWithVector
{
	OFMatrix4x4 *matrix = [OFMatrix4x4 identityMatrix];
	OFVector4D point;

	[matrix translateWithVector: OFMakeVector3D(1, 2, 3)];
	[matrix scaleWithVector: OFMakeVector3D(-1, 0.5f, 2)];

	point = [matrix transformedVector: OFMakeVector4D(2, 3, 4, 1)];
	OTAssertEqual(point.x, -3);
	OTAssertEqual(point.y, 2.5);
	OTAssertEqual(point.z, 14);
	OTAssertEqual(point.w, 1);
}

- (void)testTransformVectorsCount
{
	OFVector4D points[2] = {{ 1, 2, 3, 1 }, { 7, 8, 9, 2 }};

	[_matrix transformVectors: points count: 2];

	OTAssertEqual(points[0].x, 18);
	OTAssertEqual(points[0].y, 46);
	OTAssertEqual(points[0].z, 74);
	OTAssertEqual(points[0].w, 102);
	OTAssertEqual(points[1].x, 58);
	OTAssertEqual(points[1].y, 162);
	OTAssertEqual(points[1].z, 266);
	OTAssertEqual(points[1].w, 370);
}
@end

Modified tests/Makefile from [582d5b4a14] to [7a75fde9e9].

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
24
25
26
27
28
29
30

31
32
33
34
35
36
37







-







       OFDictionaryTests.m		\
       OFHMACTests.m			\
       OFINIFileTests.m			\
       OFJSONTests.m			\
       OFListTests.m			\
       OFLocaleTests.m			\
       OFMD5HashTests.m			\
       OFMatrix4x4Tests.m		\
       OFMemoryStreamTests.m		\
       OFNotificationCenterTests.m	\
       OFObjectTests.m			\
       OFRIPEMD160HashTests.m		\
       OFSHA1HashTests.m		\
       OFSHA224HashTests.m		\
       OFSHA256HashTests.m		\

Modified tests/TestsAppDelegate.h from [f8e34fd306] to [62b9475833].

131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
131
132
133
134
135
136
137




138
139
140
141
142
143
144







-
-
-
-







- (void)localeTests;
@end

@interface TestsAppDelegate (OFMD5HashTests)
- (void)MD5HashTests;
@end

@interface TestsAppDelegate (OFMatrix4x4Tests)
- (void)matrix4x4Tests;
@end

@interface TestsAppDelegate  (OFMemoryStreamTests)
- (void)memoryStreamTests;
@end

@interface TestsAppDelegate (OFNotificationCenterTests)
- (void)notificationCenterTests;
@end

Modified tests/TestsAppDelegate.m from [be2555a72f] to [3a33bc9fe5].

429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
429
430
431
432
433
434
435

436
437
438
439
440
441
442







-







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

#ifdef OF_HAVE_SUBPROCESSES
	[self subprocessTests];
#endif
#ifdef OF_WINDOWS
	[self windowsRegistryKeyTests];
#endif