Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentest_tcp.c
Go to the documentation of this file.
00001 #include "test_tcp.h" 00002 00003 #include "lwip/tcp_impl.h" 00004 #include "lwip/stats.h" 00005 #include "tcp_helper.h" 00006 00007 #if !LWIP_STATS || !TCP_STATS || !MEMP_STATS 00008 #error "This tests needs TCP- and MEMP-statistics enabled" 00009 #endif 00010 00011 /* Setups/teardown functions */ 00012 00013 static void 00014 tcp_setup(void) 00015 { 00016 tcp_remove_all(); 00017 } 00018 00019 static void 00020 tcp_teardown(void) 00021 { 00022 tcp_remove_all(); 00023 } 00024 00025 00026 /* Test functions */ 00027 00029 START_TEST(test_tcp_new_abort) 00030 { 00031 struct tcp_pcb* pcb; 00032 LWIP_UNUSED_ARG(_i); 00033 00034 fail_unless(lwip_stats.memp[MEMP_TCP_PCB].used == 0); 00035 00036 pcb = tcp_new(); 00037 fail_unless(pcb != NULL); 00038 if (pcb != NULL) { 00039 fail_unless(lwip_stats.memp[MEMP_TCP_PCB].used == 1); 00040 tcp_abort(pcb); 00041 fail_unless(lwip_stats.memp[MEMP_TCP_PCB].used == 0); 00042 } 00043 } 00044 END_TEST 00045 00047 START_TEST(test_tcp_recv_inseq) 00048 { 00049 struct test_tcp_counters counters; 00050 struct tcp_pcb* pcb; 00051 struct pbuf* p; 00052 char data[] = {1, 2, 3, 4}; 00053 ip_addr_t remote_ip, local_ip; 00054 u16_t data_len; 00055 u16_t remote_port = 0x100, local_port = 0x101; 00056 struct netif netif; 00057 LWIP_UNUSED_ARG(_i); 00058 00059 /* initialize local vars */ 00060 memset(&netif, 0, sizeof(netif)); 00061 IP4_ADDR(&local_ip, 192, 168, 1, 1); 00062 IP4_ADDR(&remote_ip, 192, 168, 1, 2); 00063 data_len = sizeof(data); 00064 /* initialize counter struct */ 00065 memset(&counters, 0, sizeof(counters)); 00066 counters.expected_data_len = data_len; 00067 counters.expected_data = data; 00068 00069 /* create and initialize the pcb */ 00070 pcb = test_tcp_new_counters_pcb(&counters); 00071 EXPECT_RET(pcb != NULL); 00072 tcp_set_state(pcb, ESTABLISHED, &local_ip, &remote_ip, local_port, remote_port); 00073 00074 /* create a segment */ 00075 p = tcp_create_rx_segment(pcb, counters.expected_data, data_len, 0, 0, 0); 00076 EXPECT(p != NULL); 00077 if (p != NULL) { 00078 /* pass the segment to tcp_input */ 00079 test_tcp_input(p, &netif); 00080 /* check if counters are as expected */ 00081 EXPECT(counters.close_calls == 0); 00082 EXPECT(counters.recv_calls == 1); 00083 EXPECT(counters.recved_bytes == data_len); 00084 EXPECT(counters.err_calls == 0); 00085 } 00086 00087 /* make sure the pcb is freed */ 00088 EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 1); 00089 tcp_abort(pcb); 00090 EXPECT(lwip_stats.memp[MEMP_TCP_PCB].used == 0); 00091 } 00092 END_TEST 00093 00094 00096 Suite * 00097 tcp_suite(void) 00098 { 00099 TFun tests[] = { 00100 test_tcp_new_abort, 00101 test_tcp_recv_inseq, 00102 }; 00103 return create_suite("TCP", tests, sizeof(tests)/sizeof(TFun), tcp_setup, tcp_teardown); 00104 } Generated on Sat May 26 2012 04:35:02 for ReactOS by
1.7.6.1
|