ReactOS  0.4.14-dev-815-ge410a12
TcpIp_user.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: User mode part of the TcpIp.sys test suite
5  * PROGRAMMER: Jérôme Gardou <jerome.gardou@reactos.org>
6  */
7 
8 #include <kmt_test.h>
9 #include <winsock2.h>
10 
11 #include "tcpip.h"
12 
13 static
14 void
16 {
17  /* Start the special-purpose driver */
18  KmtLoadDriver(L"TcpIp", FALSE);
19  KmtOpenDriver();
20 }
21 
22 static
23 void
25 {
26  /* Stop the driver. */
29 }
30 
31 START_TEST(TcpIpTdi)
32 {
33  DWORD Error;
34 
36 
39 
41 }
42 
43 static
44 DWORD
45 WINAPI
48 {
49  WORD WinsockVersion;
50  WSADATA WsaData;
51  int Error;
52  SOCKET ListenSocket, AcceptSocket;
53  struct sockaddr_in ListenAddress, AcceptAddress;
54  int AcceptAddressLength;
55  HANDLE ReadyToConnectEvent = (HANDLE)Parameter;
56 
57  /* Initialize winsock */
58  WinsockVersion = MAKEWORD(2, 0);
59  Error = WSAStartup(WinsockVersion, &WsaData);
60  ok_eq_int(Error, 0);
61 
62  ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
63  ok(ListenSocket != INVALID_SOCKET, "socket failed\n");
64 
65  ZeroMemory(&ListenAddress, sizeof(ListenAddress));
66  ListenAddress.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
67  ListenAddress.sin_port = htons(TEST_CONNECT_SERVER_PORT);
68  ListenAddress.sin_family = AF_INET;
69 
70  Error = bind(ListenSocket, (struct sockaddr*)&ListenAddress, sizeof(ListenAddress));
71  ok_eq_int(Error, 0);
72 
73  Error = listen(ListenSocket, 1);
74  ok_eq_int(Error, 0);
75 
76  SetEvent(ReadyToConnectEvent);
77 
78  AcceptAddressLength = sizeof(AcceptAddress);
79  AcceptSocket = accept(ListenSocket, (struct sockaddr*)&AcceptAddress, &AcceptAddressLength);
80  ok(AcceptSocket != INVALID_SOCKET, "accept failed\n");
81  ok_eq_long(AcceptAddressLength, sizeof(AcceptAddress));
82  ok_eq_hex(AcceptAddress.sin_addr.S_un.S_addr, inet_addr("127.0.0.1"));
83  ok_eq_hex(AcceptAddress.sin_port, htons(TEST_CONNECT_CLIENT_PORT));
84 
85  return 0;
86 }
87 
88 START_TEST(TcpIpConnect)
89 {
90  HANDLE AcceptThread;
91  HANDLE ReadyToConnectEvent;
92  DWORD Error;
93 
94  ReadyToConnectEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
95  ok(ReadyToConnectEvent != NULL, "CreateEvent failed\n");
96 
97  AcceptThread = CreateThread(NULL, 0, AcceptProc, (PVOID)ReadyToConnectEvent, 0, NULL);
98  ok(AcceptThread != NULL, "CreateThread failed\n");
99 
100  WaitForSingleObject(ReadyToConnectEvent, INFINITE);
101 
103 
106 
107  WaitForSingleObject(AcceptThread, INFINITE);
108 
110 
111  WSACleanup();
112 }
#define CreateEvent
Definition: winbase.h:3582
#define ok_eq_ulong(value, expected)
#define TRUE
Definition: types.h:120
#define IOCTL_TEST_TDI
Definition: tcpip.h:2
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
u_short sin_port
Definition: winsock.h:511
#define inet_addr(cp)
Definition: inet.h:98
#define ERROR_SUCCESS
Definition: deptool.c:10
#define MAKEWORD(a, b)
Definition: typedefs.h:247
#define ok_eq_int(value, expected)
Definition: kmt_test.h:238
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define ZeroMemory
Definition: winbase.h:1642
_In_ PVOID Parameter
Definition: ldrtypes.h:241
#define TEST_CONNECT_CLIENT_PORT
Definition: tcpip.h:7
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:136
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
smooth NULL
Definition: ftsmooth.c:416
START_TEST(TcpIpTdi)
Definition: TcpIp_user.c:31
VOID KmtCloseDriver(VOID)
Definition: support.c:200
#define INVALID_SOCKET
Definition: winsock.h:332
static DWORD WINAPI AcceptProc(_In_ LPVOID Parameter)
Definition: TcpIp_user.c:46
#define WINAPI
Definition: msvc.h:6
unsigned short WORD
Definition: ntddk_ex.h:93
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
static const WCHAR L[]
Definition: oid.c:1250
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
static void UnloadTcpIpTestDriver(void)
Definition: TcpIp_user.c:24
struct in_addr sin_addr
Definition: winsock.h:512
#define _In_
Definition: no_sal2.h:204
DWORD KmtSendToDriver(IN DWORD ControlCode)
Definition: support.c:224
VOID KmtUnloadDriver(VOID)
Definition: support.c:155
#define TEST_CONNECT_SERVER_PORT
Definition: tcpip.h:6
#define ok(value,...)
Definition: atltest.h:57
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
#define AF_INET
Definition: tcpip.h:117
UINT_PTR SOCKET
Definition: winsock.h:47
#define ok_eq_hex(value, expected)
#define SOCK_STREAM
Definition: tcpip.h:118
VOID KmtLoadDriver(IN PCWSTR ServiceName, IN BOOLEAN RestartIfRunning)
Definition: support.c:127
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _In_opt_ PWSK_SOCKET AcceptSocket
Definition: wsk.h:170
#define htons(x)
Definition: module.h:213
VOID KmtOpenDriver(VOID)
Definition: support.c:174
#define INFINITE
Definition: serial.h:102
#define ok_eq_long(value, expected)
Definition: kmt_test.h:240
#define IOCTL_TEST_CONNECT
Definition: tcpip.h:3
short sin_family
Definition: winsock.h:510
static void LoadTcpIpTestDriver(void)
Definition: TcpIp_user.c:15