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
|
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
|
-
-
-
-
-
-
-
-
-
-
-
+
+
|
* 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"
#include <stdlib.h>
#include <string.h>
#include <time.h>
#import "OFTCPSocket.h"
#import "OFString.h"
#import "OFAutoreleasePool.h"
#import "macros.h"
#import "TestsAppDelegate.h"
static OFString *module = @"OFTCPSocket";
@implementation TestsAppDelegate (OFTCPSocketTests)
- (void)TCPSocketTests
{
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFTCPSocket *server, *client = nil, *accepted;
OFString *msg;
uint16_t port;
char buf[6];
srand((unsigned)time(NULL));
port = (uint16_t)rand();
if (port < 1024)
port += 1024;
TEST(@"+[socket]", (server = [OFTCPSocket socket]) &&
(client = [OFTCPSocket socket]))
msg = [OFString stringWithFormat:
@"-[bindToPort:onHost:] (port %" @PRIu16 @")", port];
TEST(msg, R([server bindToPort: port
TEST(@"-[bindToPort:onHost:]",
(port = [server bindToPort: 0
onHost: @"127.0.0.1"]))
TEST(@"-[listen]", R([server listen]))
TEST(@"-[connectToHost:onPort:]",
R([client connectToHost: @"127.0.0.1"
onPort: port]))
|