ObjFW  Diff

Differences From Artifact [874d662a72]:

To Artifact [6d7b4e4936]:


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

#include "config.h"

#include <string.h>

#import "TestsAppDelegate.h"

static OFString *module = @"OFUDPSocket";

@implementation TestsAppDelegate (OFUDPSocketTests)
- (void)UDPSocketTests
{
	void *pool = objc_autoreleasePoolPush();
	OFUDPSocket *sock;
	uint16_t port1, port2;
	of_socket_address_t addr1, addr2, addr3;
	char buf[6];
	OFString *host;

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

	TEST(@"-[bindToHost:port:]",
	    (port1 = [sock bindToHost: @"127.0.0.1"
				 port: 0]))

	addr1 = of_socket_address_parse_ip(@"127.0.0.1", port1);

	TEST(@"-[sendBuffer:length:receiver:]",
	    R([sock sendBuffer: "Hello"
			length: 6
		      receiver: &addr1]))

	TEST(@"-[receiveIntoBuffer:length:sender:]",
	    [sock receiveIntoBuffer: buf
			     length: 6
			     sender: &addr2] == 6 &&
	    !memcmp(buf, "Hello", 6) &&
	    (host = of_socket_address_ip_string(&addr2, &port2)) &&
	    [host isEqual: @"127.0.0.1"] && port2 == port1)


	addr3 = of_socket_address_parse_ip(@"127.0.0.1", port1 + 1);

	/*
	 * TODO: Move those tests elsewhere as soon as the DNS resolving part
	 *	 is no longer in OFUDPSocket.
	 */
	TEST(@"of_socket_address_equal()",
	    of_socket_address_equal(&addr1, &addr2) &&
	    !of_socket_address_equal(&addr1, &addr3))

	TEST(@"of_socket_address_hash()",
	    of_socket_address_hash(&addr1) == of_socket_address_hash(&addr2) &&
	    of_socket_address_hash(&addr1) != of_socket_address_hash(&addr3))

	objc_autoreleasePoolPop(pool);
}
@end







|






|
|

<




|
<

|


|
<
<


|
<
<

<
|
>

|





|
|
|

|
|
|




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

#include "config.h"

#include <string.h>

#import "TestsAppDelegate.h"

static OFString *const module = @"OFUDPSocket";

@implementation TestsAppDelegate (OFUDPSocketTests)
- (void)UDPSocketTests
{
	void *pool = objc_autoreleasePoolPush();
	OFUDPSocket *sock;
	uint16_t port1;
	OFSocketAddress addr1, addr2, addr3;
	char buf[6];


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

	TEST(@"-[bindToHost:port:]",
	    (port1 = [sock bindToHost: @"127.0.0.1" port: 0]))


	addr1 = OFSocketAddressParseIP(@"127.0.0.1", port1);

	TEST(@"-[sendBuffer:length:receiver:]",
	    R([sock sendBuffer: "Hello" length: 6 receiver: &addr1]))



	TEST(@"-[receiveIntoBuffer:length:sender:]",
	    [sock receiveIntoBuffer: buf length: 6 sender: &addr2] == 6 &&


	    !memcmp(buf, "Hello", 6) &&

	    [OFSocketAddressString(&addr2) isEqual: @"127.0.0.1"] &&
	    OFSocketAddressPort(&addr2) == port1)

	addr3 = OFSocketAddressParseIP(@"127.0.0.1", port1 + 1);

	/*
	 * TODO: Move those tests elsewhere as soon as the DNS resolving part
	 *	 is no longer in OFUDPSocket.
	 */
	TEST(@"OFSocketAddressEqual()",
	    OFSocketAddressEqual(&addr1, &addr2) &&
	    !OFSocketAddressEqual(&addr1, &addr3))

	TEST(@"OFSocketAddressHash()",
	    OFSocketAddressHash(&addr1) == OFSocketAddressHash(&addr2) &&
	    OFSocketAddressHash(&addr1) != OFSocketAddressHash(&addr3))

	objc_autoreleasePoolPop(pool);
}
@end