3 * Author : Chris Koeritz
4 * Purpose: Tests some attributes of the network_address class for correctness.
6 * Copyright (c) 2001-$now By Author. This program is free software; you can *
7 * redistribute it and/or modify it under the terms of the GNU General Public *
8 * License as published by the Free Software Foundation; either version 2 of *
9 * the License or (at your option) any later version. This is online at: *
10 * http://www.fsf.org/copyleft/gpl.html *
11 * Please send any updates to: fred@gruntose.com *
14 #include <application/hoople_main.h>
15 #include <basis/byte_array.h>
16 #include <basis/astring.h>
17 #include <loggers/program_wide_logger.h>
18 #include <structures/static_memory_gremlin.h>
19 #include <sockets/internet_address.h>
20 #include <unit_test/unit_base.h>
22 using namespace application;
23 using namespace basis;
24 //using namespace filesystem;
25 using namespace loggers;
26 using namespace mathematics;
27 using namespace sockets;
28 using namespace structures;
29 using namespace textual;
30 using namespace timely;
31 using namespace unit_test;
36 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
38 class test_address : public virtual unit_base, virtual public application_shell
42 DEFINE_CLASS_NAME("test_address");
43 virtual int execute();
46 int test_address::execute()
49 // testing is_valid_internet_address here...
51 bool all_zero = false;
53 astring to_test = "12.5.55.37";
54 if (!internet_address::is_valid_internet_address(to_test, ip_form, all_zero))
55 deadly_error(class_name(), "1st address",
56 "failed to say address was valid");
58 deadly_error(class_name(), "1st address", "said address was all zeros");
59 if ( (ip_form[0] != 12) || (ip_form[1] != 5) || (ip_form[2] != 55)
60 || (ip_form[3] != 37) )
61 deadly_error(class_name(), "1st address", "address had incorrect contents");
63 to_test = "12.5.55.372";
64 if (internet_address::is_valid_internet_address(to_test, ip_form, all_zero))
65 deadly_error(class_name(), "2nd address", "failed to say address was invalid");
67 to_test = "12.5.55.37.3";
68 if (internet_address::is_valid_internet_address(to_test, ip_form, all_zero))
69 deadly_error(class_name(), "3rd address", "failed to say address was invalid");
72 if (internet_address::is_valid_internet_address(to_test, ip_form, all_zero))
73 deadly_error(class_name(), "4th address", "failed to say address was invalid");
76 if (!internet_address::is_valid_internet_address(to_test, ip_form, all_zero))
77 deadly_error(class_name(), "5th address", "failed to say address was valid");
79 deadly_error(class_name(), "5th address", "said address was not all zeros");
80 if ( (ip_form[0] != 0) || (ip_form[1] != 0) || (ip_form[2] != 0)
81 || (ip_form[3] != 0) )
82 deadly_error(class_name(), "5th address", "address had incorrect contents");
85 if (!internet_address::is_valid_internet_address(to_test, ip_form, all_zero))
86 deadly_error(class_name(), "6th address", "failed to say address was valid");
88 deadly_error(class_name(), "6th address", "said address was all zeros");
89 if ( (ip_form[0] != 0) || (ip_form[1] != 0) || (ip_form[2] != 0)
90 || (ip_form[3] != 1) )
91 deadly_error(class_name(), "6th address", "address had incorrect contents");
94 if (internet_address::is_valid_internet_address(to_test, ip_form, all_zero))
95 deadly_error(class_name(), "7th address", "failed to say address was invalid");
98 if (internet_address::is_valid_internet_address(to_test, ip_form, all_zero))
99 deadly_error(class_name(), "7th address", "failed to say address was invalid");
101 to_test = "this may have. an ip address in it somewhere... 92.21. 23.123. 1235.6.3 9 oops hey where is it. 23.51.2 2.4 1.2.343 09023.2.3. marbles 23.15.123.5 manus kobble 23.1.5.2 sturp nort ation";
103 if (!internet_address::has_ip_address(to_test, found))
104 deadly_error(class_name(), "8th address", "failed to find ip address");
105 ASSERT_EQUAL(found, astring("23.15.123.5"), "8th address: ip address found should be correct");
107 to_test = "furples 92.23.1 9123.5.3 12398. 23 11 1 1 0202 2.4.1.5";
108 if (!internet_address::has_ip_address(to_test, found))
109 deadly_error(class_name(), "9th address", "failed to find ip address");
110 if (found != astring("2.4.1.5"))
111 deadly_error(class_name(), "9th address", astring("ip address found was wrong: ") + found + ", should have been 2.4.1.5");
113 to_test = "12.5.55.2\"";
114 if (!internet_address::has_ip_address(to_test, found))
115 deadly_error(class_name(), "10th address", "failed to find ip address");
116 if (found != astring("12.5.55.2"))
117 deadly_error(class_name(), "10th address", astring("ip address found was wrong: ") + found + ", should have been 12.5.55.2");
119 to_test = "12.5.55.2";
120 if (!internet_address::has_ip_address(to_test, found))
121 deadly_error(class_name(), "11th address", "failed to find ip address");
122 if (found != astring("12.5.55.2"))
123 deadly_error(class_name(), "11th address", astring("ip address found was wrong: ") + found + ", should have been 12.5.55.2");
125 return final_report();
128 HOOPLE_MAIN(test_address, )