xref: /reactos/modules/rostests/apitests/afd/send.c (revision d5b576b2)
1 /*
2  * PROJECT:     ReactOS API Tests
3  * LICENSE:     LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4  * PURPOSE:     Test for IOCTL_AFD_SEND/IOCTL_AFD_SEND_DATAGRAM
5  * COPYRIGHT:   Copyright 2015 Thomas Faber (thomas.faber@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
10 static
11 void
12 TestSend(void)
13 {
14     NTSTATUS Status;
15     HANDLE SocketHandle;
16     CHAR Buffer[32];
17     struct sockaddr_in addr;
18 
19     RtlZeroMemory(Buffer, sizeof(Buffer));
20 
21     Status = AfdCreateSocket(&SocketHandle, AF_INET, SOCK_STREAM, IPPROTO_TCP);
22     ok(Status == STATUS_SUCCESS, "AfdCreateSocket failed with %lx\n", Status);
23 
24     Status = AfdSend(SocketHandle, NULL, 0);
25     ok(Status == STATUS_INVALID_CONNECTION, "AfdSend failed with %lx\n", Status);
26 
27     Status = AfdSend(SocketHandle, Buffer, sizeof(Buffer));
28     ok(Status == STATUS_INVALID_CONNECTION, "AfdSend failed with %lx\n", Status);
29 
30     memset(&addr, 0, sizeof(addr));
31     addr.sin_family = AF_INET;
32     addr.sin_addr.s_addr = inet_addr("0.0.0.0");
33     addr.sin_port = htons(0);
34 
35     Status = AfdBind(SocketHandle, (const struct sockaddr *)&addr, sizeof(addr));
36     ok(Status == STATUS_SUCCESS, "AfdBind failed with %lx\n", Status);
37 
38     memset(&addr, 0, sizeof(addr));
39     addr.sin_family = AF_INET;
40     addr.sin_addr.s_addr = inet_addr("8.8.8.8");
41     addr.sin_port = htons(53);
42 
43     Status = AfdConnect(SocketHandle, (const struct sockaddr *)&addr, sizeof(addr));
44     ok(Status == STATUS_SUCCESS, "AfdConnect failed with %lx\n", Status);
45 
46     Status = AfdSend(SocketHandle, NULL, 0);
47     ok(Status == STATUS_SUCCESS, "AfdSend failed with %lx\n", Status);
48 
49     Status = AfdSend(SocketHandle, Buffer, sizeof(Buffer));
50     ok(Status == STATUS_SUCCESS, "AfdSend failed with %lx\n", Status);
51 
52     NtClose(SocketHandle);
53 }
54 
55 static
56 void
57 TestSendTo(void)
58 {
59     NTSTATUS Status;
60     HANDLE SocketHandle;
61     CHAR Buffer[32];
62     struct sockaddr_in addr;
63 
64     RtlZeroMemory(Buffer, sizeof(Buffer));
65 
66     Status = AfdCreateSocket(&SocketHandle, AF_INET, SOCK_DGRAM, IPPROTO_UDP);
67     ok(Status == STATUS_SUCCESS, "AfdCreateSocket failed with %lx\n", Status);
68 
69     memset(&addr, 0, sizeof(addr));
70     addr.sin_family = AF_INET;
71     addr.sin_addr.s_addr = inet_addr("0.0.0.0");
72     addr.sin_port = htons(0);
73 
74     Status = AfdBind(SocketHandle, (const struct sockaddr *)&addr, sizeof(addr));
75     ok(Status == STATUS_SUCCESS, "AfdBind failed with %lx\n", Status);
76 
77     memset(&addr, 0, sizeof(addr));
78     addr.sin_family = AF_INET;
79     addr.sin_addr.s_addr = inet_addr("8.8.8.8");
80     addr.sin_port = htons(53);
81 
82     Status = AfdSendTo(SocketHandle, NULL, 0, (const struct sockaddr *)&addr, sizeof(addr));
83     ok(Status == STATUS_SUCCESS, "AfdSendTo failed with %lx\n", Status);
84 
85     Status = AfdSendTo(SocketHandle, Buffer, sizeof(Buffer), (const struct sockaddr *)&addr, sizeof(addr));
86     ok(Status == STATUS_SUCCESS, "AfdSendTo failed with %lx\n", Status);
87 
88     NtClose(SocketHandle);
89 }
90 
91 START_TEST(send)
92 {
93     TestSend();
94     TestSendTo();
95 }
96