ObjFW  Check-in [0c3f6027a2]

Overview
Comment:Migrate OFUNIXDatagramSocketTests to ObjFWTest
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | objfwtest
Files: files | file ages | folders
SHA3-256: 0c3f6027a2ec5b68b0f0fc114134b1f7071ebc0d262a2200c7c73375a07f36c3
User & Date: js on 2024-02-13 23:41:39
Other Links: branch diff | manifest | tags
Context
2024-02-13
23:48
Migrate OFUNIXStreamSocketTests to ObjFWTest check-in: b77972796e user: js tags: objfwtest
23:41
Migrate OFUNIXDatagramSocketTests to ObjFWTest check-in: 0c3f6027a2 user: js tags: objfwtest
23:41
ObjFWTest: Add OTSkip() check-in: f45bd96383 user: js tags: objfwtest
Changes

Modified new_tests/Makefile from [56338b20e7] to [9ff0bc1e70].

46
47
48
49
50
51
52
53


54
55
56
57
58
59
60
       ${USE_SRCS_THREADS}		\
       testfile_bin.m			\
       testfile_ini.m
SRCS_PLUGINS = OFPluginTests.m
SRCS_SOCKETS = OFDNSResolverTests.m	\
	       OFSocketTests.m		\
	       OFTCPSocketTests.m	\
	       OFUDPSocketTests.m


SRCS_SUBPROCESSES = OFSubprocessTests.m
SRCS_THREADS = OFThreadTests.m

include ../buildsys.mk

testfile_bin.m: testfile.bin
	${SHELL} ../utils/objfw-embed testfile.bin testfile.bin $@







|
>
>







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
       ${USE_SRCS_THREADS}		\
       testfile_bin.m			\
       testfile_ini.m
SRCS_PLUGINS = OFPluginTests.m
SRCS_SOCKETS = OFDNSResolverTests.m	\
	       OFSocketTests.m		\
	       OFTCPSocketTests.m	\
	       OFUDPSocketTests.m	\
	       ${USE_SRCS_UNIX_SOCKETS}
SRCS_UNIX_SOCKETS = OFUNIXDatagramSocketTests.m
SRCS_SUBPROCESSES = OFSubprocessTests.m
SRCS_THREADS = OFThreadTests.m

include ../buildsys.mk

testfile_bin.m: testfile.bin
	${SHELL} ../utils/objfw-embed testfile.bin testfile.bin $@

Renamed and modified tests/OFUNIXDatagramSocketTests.m [588aa866e4] to new_tests/OFUNIXDatagramSocketTests.m [380c509734].

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
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <errno.h>


#import "TestsAppDelegate.h"


static OFString *const module = @"OFUNIXDatagramSocket";


@implementation TestsAppDelegate (OFUNIXDatagramSocketTests)
- (void)UNIXDatagramSocketTests
{
	void *pool = objc_autoreleasePoolPush();

	OFString *path;
	OFUNIXDatagramSocket *sock;
	OFSocketAddress address1, address2;
	char buffer[5];

#if defined(OF_HAVE_FILES) && !defined(OF_IOS)
	path = [[OFSystemInfo temporaryDirectoryIRI]
	    IRIByAppendingPathComponent: [[OFUUID UUID] UUIDString]]
	    .fileSystemRepresentation;
#else
	/*
	 * We can have sockets, including UNIX sockets, while file support is
	 * disabled.
	 *
	 * We also use this code path for iOS, as the temporaryDirectoryIRI is
	 * too long on the iOS simulator.
	 */
	path = [OFString stringWithFormat: @"/tmp/%@",
					   [[OFUUID UUID] UUIDString]];
#endif

	TEST(@"+[socket]", (sock = [OFUNIXDatagramSocket socket]))

	@try {
		TEST(@"-[bindToPath:]", R(address1 = [sock bindToPath: path]))
	} @catch (OFBindSocketFailedException *e) {
		switch (e.errNo) {
		case EAFNOSUPPORT:
		case EPERM:
			[OFStdOut setForegroundColor: [OFColor lime]];
			[OFStdOut writeLine:
			    @"\r[OFUNIXDatagramSocket] -[bindToPath:]: "
			    @"UNIX datagram sockets unsupported, skipping "
			    @"tests"];

			objc_autoreleasePoolPop(pool);
			return;
		default:
			@throw e;
		}
	}

	@try {
		TEST(@"-[sendBuffer:length:receiver:]",
		    R([sock sendBuffer: "Hello" length: 5 receiver: &address1]))

		TEST(@"-[receiveIntoBuffer:length:sender:]",
		    [sock receiveIntoBuffer: buffer
				     length: 5
				     sender: &address2] == 5 &&
		    memcmp(buffer, "Hello", 5) == 0 &&
		    OFSocketAddressEqual(&address1, &address2) &&
		    OFSocketAddressHash(&address1) ==
		    OFSocketAddressHash(&address2))
	} @finally {
#ifdef OF_HAVE_FILES
		[[OFFileManager defaultManager] removeItemAtPath: path];
#endif
	}

	objc_autoreleasePoolPop(pool);
}
@end







>

|
>

|
>

|
|

<
>

<



















<
<

|




<
<
<
|
<
<
<







<
|

<
|
|
|
|
|
|
|





|
<
<

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
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#include <errno.h>
#include <string.h>

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

@interface OFUNIXDatagramSocketTests: OTTestCase
@end

@implementation OFUNIXDatagramSocketTests
- (void)testUNIXDatagramSockets
{

	OFUNIXDatagramSocket *sock = [OFUNIXDatagramSocket socket];
	OFString *path;

	OFSocketAddress address1, address2;
	char buffer[5];

#if defined(OF_HAVE_FILES) && !defined(OF_IOS)
	path = [[OFSystemInfo temporaryDirectoryIRI]
	    IRIByAppendingPathComponent: [[OFUUID UUID] UUIDString]]
	    .fileSystemRepresentation;
#else
	/*
	 * We can have sockets, including UNIX sockets, while file support is
	 * disabled.
	 *
	 * We also use this code path for iOS, as the temporaryDirectoryIRI is
	 * too long on the iOS simulator.
	 */
	path = [OFString stringWithFormat: @"/tmp/%@",
					   [[OFUUID UUID] UUIDString]];
#endif



	@try {
		address1 = [sock bindToPath: path];
	} @catch (OFBindSocketFailedException *e) {
		switch (e.errNo) {
		case EAFNOSUPPORT:
		case EPERM:



			OTSkip(@"UNIX datagram sockets unsupported");



			return;
		default:
			@throw e;
		}
	}

	@try {

		[sock sendBuffer: "Hello" length: 5 receiver: &address1];


		OTAssertEqual([sock receiveIntoBuffer: buffer
					       length: 5
					       sender: &address2], 5);
		OTAssertEqual(memcmp(buffer, "Hello", 5), 0);
		OTAssertTrue(OFSocketAddressEqual(&address1, &address2));
		OTAssertEqual(OFSocketAddressHash(&address1),
		    OFSocketAddressHash(&address2));
	} @finally {
#ifdef OF_HAVE_FILES
		[[OFFileManager defaultManager] removeItemAtPath: path];
#endif
	}
}


@end

Modified tests/Makefile from [f4cad188bb] to [96a14c6d55].

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
	       ${USE_SRCS_APPLETALK}		\
	       ${USE_SRCS_IPX}			\
	       ${USE_SRCS_UNIX_SOCKETS}
SRCS_APPLETALK = OFDDPSocketTests.m
SRCS_IPX = OFIPXSocketTests.m		\
	   OFSPXSocketTests.m		\
	   OFSPXStreamSocketTests.m
SRCS_UNIX_SOCKETS = OFUNIXDatagramSocketTests.m	\
		    OFUNIXStreamSocketTests.m
SRCS_WINDOWS = OFWindowsRegistryKeyTests.m

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

include ../buildsys.mk








|
<







37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
	       ${USE_SRCS_APPLETALK}		\
	       ${USE_SRCS_IPX}			\
	       ${USE_SRCS_UNIX_SOCKETS}
SRCS_APPLETALK = OFDDPSocketTests.m
SRCS_IPX = OFIPXSocketTests.m		\
	   OFSPXSocketTests.m		\
	   OFSPXStreamSocketTests.m
SRCS_UNIX_SOCKETS = OFUNIXStreamSocketTests.m

SRCS_WINDOWS = OFWindowsRegistryKeyTests.m

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

include ../buildsys.mk

Modified tests/TestsAppDelegate.h from [748439022d] to [94c78fc85a].

123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
- (void)streamTests;
@end

@interface TestsAppDelegate (OFStringTests)
- (void)stringTests;
@end

@interface TestsAppDelegate (OFUNIXDatagramSocketTests)
- (void)UNIXDatagramSocketTests;
@end

@interface TestsAppDelegate (OFUNIXStreamSocketTests)
- (void)UNIXStreamSocketTests;
@end

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







<
<
<
<







123
124
125
126
127
128
129




130
131
132
133
134
135
136
- (void)streamTests;
@end

@interface TestsAppDelegate (OFStringTests)
- (void)stringTests;
@end





@interface TestsAppDelegate (OFUNIXStreamSocketTests)
- (void)UNIXStreamSocketTests;
@end

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

Modified tests/TestsAppDelegate.m from [bf28d3b6ff] to [bdc9d92508].

380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
	[self listTests];
	[self valueTests];
	[self streamTests];
	[self memoryStreamTests];
	[self notificationCenterTests];
#ifdef OF_HAVE_SOCKETS
# ifdef OF_HAVE_UNIX_SOCKETS
	[self UNIXDatagramSocketTests];
	[self UNIXStreamSocketTests];
# endif
# ifdef OF_HAVE_IPX
	[self IPXSocketTests];
	[self SPXSocketTests];
	[self SPXStreamSocketTests];
# endif







<







380
381
382
383
384
385
386

387
388
389
390
391
392
393
	[self listTests];
	[self valueTests];
	[self streamTests];
	[self memoryStreamTests];
	[self notificationCenterTests];
#ifdef OF_HAVE_SOCKETS
# ifdef OF_HAVE_UNIX_SOCKETS

	[self UNIXStreamSocketTests];
# endif
# ifdef OF_HAVE_IPX
	[self IPXSocketTests];
	[self SPXSocketTests];
	[self SPXStreamSocketTests];
# endif