@@ -148,6 +148,67 @@ LT_BEGIN_AUTO_TEST(http_utils_suite, get_port_null)
148148 LT_CHECK_THROW(http::get_port((struct sockaddr *) 0x0));
149149LT_END_AUTO_TEST (get_port_null)
150150
151+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation4_str)
152+ http::ip_representation test_ip(" 192.168.5.5" );
153+
154+ LT_CHECK_EQ (test_ip.ip_version, http::http_utils::IPV4);
155+
156+ for (int i = 0 ; i < 12 ; i++) {
157+ LT_CHECK_EQ (test_ip.pieces [i], 0 );
158+ }
159+
160+ LT_CHECK_EQ (test_ip.pieces[12 ], 192 );
161+ LT_CHECK_EQ (test_ip.pieces[13 ], 168 );
162+ LT_CHECK_EQ (test_ip.pieces[14 ], 5 );
163+ LT_CHECK_EQ (test_ip.pieces[15 ], 5 );
164+
165+ LT_CHECK_EQ (test_ip.mask, 0xFFFF );
166+ LT_END_AUTO_TEST (ip_representation4_str)
167+
168+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation4_str_mask)
169+ http::ip_representation test_ip(" 192.168.*.*" );
170+
171+ LT_CHECK_EQ (test_ip.ip_version, http::http_utils::IPV4);
172+
173+ for (int i = 0 ; i < 12 ; i++) {
174+ LT_CHECK_EQ (test_ip.pieces [i], 0 );
175+ }
176+
177+ LT_CHECK_EQ (test_ip.pieces[12 ], 192 );
178+ LT_CHECK_EQ (test_ip.pieces[13 ], 168 );
179+ LT_CHECK_EQ (test_ip.pieces[14 ], 0 );
180+ LT_CHECK_EQ (test_ip.pieces[15 ], 0 );
181+
182+ LT_CHECK_EQ (test_ip.mask, 0x3FFF );
183+ LT_END_AUTO_TEST (ip_representation4_str_mask)
184+
185+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation4_str_invalid)
186+ LT_CHECK_THROW(http::ip_representation(" 192.168.5.5.5" ));
187+ LT_END_AUTO_TEST (ip_representation4_str_invalid)
188+
189+ LT_BEGIN_AUTO_TEST(http_utils_suite, ip_representation6_str)
190+ http::ip_representation test_ip(" 2001:db8:8714:3a90::12" );
191+
192+ LT_CHECK_EQ (test_ip.ip_version, http::http_utils::IPV6);
193+
194+ LT_CHECK_EQ (test_ip.pieces[0 ], 32 );
195+ LT_CHECK_EQ (test_ip.pieces[1 ], 1 );
196+ LT_CHECK_EQ (test_ip.pieces[2 ], 13 );
197+ LT_CHECK_EQ (test_ip.pieces[3 ], 184 );
198+ LT_CHECK_EQ (test_ip.pieces[4 ], 135 );
199+ LT_CHECK_EQ (test_ip.pieces[5 ], 20 );
200+ LT_CHECK_EQ (test_ip.pieces[6 ], 58 );
201+ LT_CHECK_EQ (test_ip.pieces[7 ], 144 );
202+ LT_CHECK_EQ (test_ip.pieces[8 ], 0 );
203+ LT_CHECK_EQ (test_ip.pieces[9 ], 0 );
204+ LT_CHECK_EQ (test_ip.pieces[10 ], 0 );
205+ LT_CHECK_EQ (test_ip.pieces[11 ], 0 );
206+ LT_CHECK_EQ (test_ip.pieces[12 ], 18 );
207+ LT_CHECK_EQ (test_ip.pieces[13 ], 0 );
208+ LT_CHECK_EQ (test_ip.pieces[14 ], 0 );
209+ LT_CHECK_EQ (test_ip.pieces[15 ], 0 );
210+ LT_END_AUTO_TEST (ip_representation6_str)
211+
151212LT_BEGIN_AUTO_TEST_ENV()
152213 AUTORUN_TESTS()
153214LT_END_AUTO_TEST_ENV()
0 commit comments