ObjFW  Diff

Differences From Artifact [5433dc7a16]:

To Artifact [d03a653eed]:


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







+

-
+
+

-
+
+

-
-
+
+

-




-
+


-
-
-
-
-
+
+
+
+




-
-
-
-
+
-
-

-
-
-
-
+
-
-



-
+
-
-
-
+
-
-
-
+

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

 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

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

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

static OFString *const module = @"OFDDPSocket";
@interface OFDDPSocketTests: OTTestCase
@end

@implementation TestsAppDelegate (OFDDPSocketTests)
- (void)DDPSocketTests
@implementation OFDDPSocketTests
- (void)testDDPSocket
{
	void *pool = objc_autoreleasePoolPush();
	OFDDPSocket *sock;
	OFSocketAddress address1, address2;
	char buffer[5];

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

	@try {
		TEST(@"-[bindToNetwork:node:port:]",
		    R(address1 = [sock bindToNetwork: 0
						node: 0
						port: 0
					protocolType: 11]))
		address1 = [sock bindToNetwork: 0
					  node: 0
					  port: 0
				  protocolType: 11];
	} @catch (OFBindSocketFailedException *e) {
		switch (e.errNo) {
		case EAFNOSUPPORT:
		case EPROTONOSUPPORT:
			[OFStdOut setForegroundColor: [OFColor lime]];
			[OFStdOut writeLine:
			    @"\r[OFDDPSocket] -[bindToNetwork:node:port:"
			    @"protocolType:] AppleTalk unsupported, skipping "
			OTSkip(@"AppleTalk unsupported");
			    @"tests"];
			break;
		case EADDRNOTAVAIL:
			[OFStdOut setForegroundColor: [OFColor lime]];
			[OFStdOut writeLine:
			    @"\r[OFDDPSocket] -[bindToNetwork:node:port:"
			    @"protocolType:] AppleTalk not configured, "
			OTSkip(@"AppleTalk not configured");
			    @"skipping tests"];
			break;
		default:
			@throw e;
		}

	}
		objc_autoreleasePoolPop(pool);
		return;
	}


	TEST(@"-[sendBuffer:length:receiver:]",
	    R([sock sendBuffer: "Hello" length: 5 receiver: &address1]))
	[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))

	OTAssertEqual([sock receiveIntoBuffer: buffer
				       length: 5
				       sender: &address2], 5);
	OTAssertEqual(memcmp(buffer, "Hello", 5), 0);
	OTAssertTrue(OFSocketAddressEqual(&address1, &address2));
	OTAssertEqual(OFSocketAddressHash(&address1),
	    OFSocketAddressHash(&address2));
}
	objc_autoreleasePoolPop(pool);
}
@end