ObjFW  Check-in [814d957cdc]

Overview
Comment:Migrate OFMemoryStreamTests to ObjFWTest
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | objfwtest
Files: files | file ages | folders
SHA3-256: 814d957cdc7e093053c15ee218cb6e9dcb65887fb39749c32a4162b6671c20d6
User & Date: js on 2024-02-18 17:56:31
Other Links: branch diff | manifest | tags
Context
2024-02-18
18:27
Migrate OFXMLParserTests to ObjFWTest check-in: cd1532bb40 user: js tags: objfwtest
17:56
Migrate OFMemoryStreamTests to ObjFWTest check-in: 814d957cdc user: js tags: objfwtest
17:44
Migrate OFDataTests to ObjFWTest check-in: f3bfdcf17a user: js tags: objfwtest
Changes

Modified new_tests/Makefile from [a32f707fdb] to [cd9494fed3].

31
32
33
34
35
36
37

38
39
40
41
42
43
44
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45







+







       OFINIFileTests.m				\
       OFIRITests.m				\
       OFInvocationTests.m			\
       OFJSONTests.m				\
       OFListTests.m				\
       OFLocaleTests.m				\
       OFMatrix4x4Tests.m			\
       OFMemoryStreamTests.m			\
       OFMethodSignatureTests.m			\
       OFMutableArrayTests.m			\
       OFMutableDataTests.m			\
       OFMutableDictionaryTests.m		\
       OFMutableSetTests.m			\
       OFMutableStringTests.m			\
       OFMutableUTF8StringTests.m		\

Renamed and modified tests/OFMemoryStreamTests.m [8479ce3790] to new_tests/OFMemoryStreamTests.m [be569a5484].

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







-
+
+

+
+
-
+


-
-
+
+

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






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

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

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




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

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

 * 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 OFMemoryStreamTests: OTTestCase
@end
static OFString *const module = @"OFMemoryStream";

static const char string[] = "abcdefghijkl";

@implementation TestsAppDelegate (OFMemoryStreamTests)
- (void)memoryStreamTests
@implementation OFMemoryStreamTests
- (void)testReadOnlyMemoryStream
{
	void *pool = objc_autoreleasePoolPush();
	OFMemoryStream *stream;
	OFMemoryStream *stream = [OFMemoryStream
	char buffer[10];
	OFMutableData *data;

	TEST(@"+[streamWithMemoryAddress:size:writable:]",
	    (stream = [OFMemoryStream streamWithMemoryAddress: (char *)string
							 size: sizeof(string)
						     writable: false]));
	    streamWithMemoryAddress: (char *)string
			       size: sizeof(string)
			   writable: false];
	char buffer[10];

	/*
	 * Test the lowlevel methods, as otherwise OFStream will do one big
	 * read and we will not test OFMemoryStream.
	 */

	TEST(@"-[lowlevelReadIntoBuffer:length:]",
	    [stream lowlevelReadIntoBuffer: buffer length: 5] == 5 &&
	    memcmp(buffer, "abcde", 5) == 0 &&
	    [stream lowlevelReadIntoBuffer: buffer length: 3] == 3 &&
	    memcmp(buffer, "fgh", 3) == 0 &&
	    [stream lowlevelReadIntoBuffer: buffer length: 10] == 5 &&
	    memcmp(buffer, "ijkl", 5) == 0)
	OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 5], 5);
	OTAssertEqual(memcmp(buffer, "abcde", 5), 0);
	OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 3], 3);
	OTAssertEqual(memcmp(buffer, "fgh", 3), 0);
	OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 10], 5);
	OTAssertEqual(memcmp(buffer, "ijkl", 5), 0);

	TEST(@"-[lowlevelIsAtEndOfStream]", [stream lowlevelIsAtEndOfStream])
	OTAssertTrue([stream lowlevelIsAtEndOfStream]);

	TEST(@"-[lowlevelSeekToOffset:whence:]",
	    [stream lowlevelSeekToOffset: 0 whence: OFSeekCurrent] ==
	    sizeof(string) && [stream lowlevelIsAtEndOfStream] &&
	    [stream lowlevelSeekToOffset: 4 whence: OFSeekSet] == 4 &&
	    ![stream lowlevelIsAtEndOfStream] &&
	    [stream lowlevelReadIntoBuffer: buffer length: 10] == 9 &&
	    memcmp(buffer, "efghijkl", 9) == 0 &&
	    [stream lowlevelSeekToOffset: -2 whence: OFSeekEnd] == 11 &&
	    [stream lowlevelReadIntoBuffer: buffer length: 10] == 2 &&
	    memcmp(buffer, "l", 2) == 0 &&
	    [stream lowlevelReadIntoBuffer: buffer length: 10] == 0)
	OTAssertEqual([stream lowlevelSeekToOffset: 0 whence: OFSeekCurrent],
	    sizeof(string));
	OTAssertTrue([stream lowlevelIsAtEndOfStream]);

	OTAssertEqual([stream lowlevelSeekToOffset: 4 whence: OFSeekSet], 4);
	OTAssertFalse([stream lowlevelIsAtEndOfStream]);
	OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 10], 9);
	OTAssertEqual(memcmp(buffer, "efghijkl", 9), 0);

	OTAssertEqual([stream lowlevelSeekToOffset: -2 whence: OFSeekEnd], 11);
	OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 10], 2);
	OTAssertEqual(memcmp(buffer, "l", 2), 0);
	OTAssertEqual([stream lowlevelReadIntoBuffer: buffer length: 10], 0);

	EXPECT_EXCEPTION(@"Writes rejected on read-only stream",
	    OFWriteFailedException, [stream lowlevelWriteBuffer: "" length: 1])

	data = [OFMutableData dataWithCapacity: 13];
	OTAssertThrowsSpecific([stream lowlevelWriteBuffer: "" length: 1],
	    OFWriteFailedException);
}

- (void)testReadWriteMemoryStream
{
	OFMutableData *data = [OFMutableData dataWithCapacity: 13];
	OFMemoryStream *stream;

	[data increaseCountBy: 13];
	stream = [OFMemoryStream streamWithMemoryAddress: data.mutableItems
						    size: data.count
						writable: true];
	TEST(@"-[lowlevelWriteBuffer:length:]",
	    [stream lowlevelWriteBuffer: "abcde" length: 5] == 5 &&
	    [stream lowlevelWriteBuffer: "fgh" length: 3] == 3 &&
	    [stream lowlevelWriteBuffer: "ijkl" length: 5] == 5 &&
	    memcmp(data.items, string, data.count) == 0 &&
	    [stream lowlevelSeekToOffset: -3 whence: OFSeekEnd] == 10)

	OTAssertEqual([stream lowlevelWriteBuffer: "abcde" length: 5], 5);
	OTAssertEqual([stream lowlevelWriteBuffer: "fgh" length: 3], 3);
	OTAssertEqual([stream lowlevelWriteBuffer: "ijkl" length: 5], 5);
	OTAssertEqual(memcmp(data.items, string, data.count), 0);
	OTAssertEqual([stream lowlevelSeekToOffset: -3 whence: OFSeekEnd], 10);

	EXPECT_EXCEPTION(@"Out of bound writes rejected",
	    OFWriteFailedException,
	    [stream lowlevelWriteBuffer: "xyz" length: 4])

	OTAssertThrowsSpecific([stream lowlevelWriteBuffer: "xyz" length: 4],
	    OFWriteFailedException);
	TEST(@"Partial write for too long write",
	    memcmp(data.items, "abcdefghijxyz", 13) == 0)

}
	objc_autoreleasePoolPop(pool);
}
@end

Modified tests/Makefile from [6ddbfcb2e3] to [48c72a53ef].

9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
9
10
11
12
13
14
15


16
17
18
19
20
21
22
23







-
-
+







	${PROG_NOINST}.nds	\
	${PROG_NOINST}.nro	\
	${PROG_NOINST}.rpx
DISTCLEAN = Info.plist

PROG_NOINST = tests${PROG_SUFFIX}
STATIC_LIB_NOINST = ${TESTS_STATIC_LIB}
SRCS = OFMemoryStreamTests.m		\
       OFStreamTests.m			\
SRCS = OFStreamTests.m			\
       OFValueTests.m			\
       OFXMLNodeTests.m			\
       OFXMLParserTests.m		\
       TestsAppDelegate.m

IOS_USER ?= mobile
IOS_TMP ?= /tmp/objfw-test

Modified tests/TestsAppDelegate.h from [28928cdd08] to [91fcd8efb4].

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
55
56
57
58
59
60
61








62
63
64
65
66
67
68







-
-
-
-
-
-
-
-







}

- (void)outputTesting: (OFString *)test inModule: (OFString *)module;
- (void)outputSuccess: (OFString *)test inModule: (OFString *)module;
- (void)outputFailure: (OFString *)test inModule: (OFString *)module;
@end

@interface TestsAppDelegate (OFDataTests)
- (void)dataTests;
@end

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

@interface TestsAppDelegate (OFStreamTests)
- (void)streamTests;
@end

@interface TestsAppDelegate (OFValueTests)
- (void)valueTests;
@end

Modified tests/TestsAppDelegate.m from [b4ea34d386] to [fdc6390186].

366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
366
367
368
369
370
371
372

373
374

375
376
377
378
379
380
381







-


-







	    [OFString stringWithUTF8String: (const char *)resourcesPath]];
#endif
#if defined(OF_WII) && defined(OF_HAVE_FILES)
	[[OFFileManager defaultManager]
	    changeCurrentDirectoryPath: @"/apps/objfw-tests"];
#endif

	[self dataTests];
	[self valueTests];
	[self streamTests];
	[self memoryStreamTests];
	[self XMLParserTests];
	[self XMLNodeTests];

	[OFStdOut reset];

#if defined(OF_IOS)
	[OFStdOut writeFormat: @"%d tests failed!", _fails];