From 21d6536a131ca9a8c90a9a4fec1e2f6fd3c1da48 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 23 Jun 2011 22:08:31 +1000 Subject: [PATCH] Compare our IP parser against inet_pton --- test/ip.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/ip.cpp b/test/ip.cpp index 78eab909..2b15df4d 100644 --- a/test/ip.cpp +++ b/test/ip.cpp @@ -4,6 +4,7 @@ #include "../debug.hpp" #include "../types.hpp" +#include #include @@ -21,8 +22,15 @@ main (int argc, char **argv) { { "127.0.0.1", { 127, 0, 0, 1 } } }; - for (unsigned int i = 0; i < elems (data); ++i) - check_hard (ipv4::ip::parse (data[i].str) == data[i].ip); + for (unsigned int i = 0; i < elems (data); ++i) { + ipv4::ip parsed (ipv4::ip::parse (data[i].str)); + check_hard (parsed == data[i].ip); + + uint32_t mine = *(uint32_t*)(parsed.m_octets), + theirs; + check_hard (inet_pton (AF_INET, data[i].str, &theirs) == 1); + check_hard (theirs == mine); + } return EXIT_SUCCESS; }