2 * Name : test_sequence_tracker
3 * Author : Chris Koeritz
4 * Purpose: Runs a couple of tests on the sequence tracker object.
6 * Copyright (c) 2003-$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 <mathematics/chaos.h>
19 #include <sockets/machine_uid.h>
20 #include <sockets/sequence_tracker.h>
21 #include <structures/set.h>
22 #include <structures/static_memory_gremlin.h>
23 #include <unit_test/unit_base.h>
28 using namespace application;
29 using namespace basis;
30 using namespace loggers;
31 using namespace mathematics;
32 using namespace sockets;
33 using namespace structures;
34 using namespace textual;
35 using namespace timely;
36 using namespace unit_test;
38 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
40 class test_sequence_tracker : public virtual unit_base, virtual public application_shell
43 test_sequence_tracker() {}
44 DEFINE_CLASS_NAME("test_sequence_tracker");
45 virtual int execute();
48 int test_sequence_tracker::execute()
51 // some arbitrary ip addresses.
52 abyte arb1[] = { 127, 0, 0, 1 };
53 abyte arb2[] = { 192, 168, 0, 1 };
54 abyte arb3[] = { 28, 42, 56, 253 };
56 machine_uid eep(machine_uid::TCPIP_LOCATION, byte_array(4, arb1));
57 machine_uid op(machine_uid::TCPIP_LOCATION, byte_array(4, arb2));
58 machine_uid ork(machine_uid::TCPIP_LOCATION, byte_array(4, arb3));
60 sequence_tracker chevy(1 * MINUTE_ms, 10 * MINUTE_ms);
63 int adds = randomizer().inclusive(400, 900);
66 int seq = starter + randomizer().inclusive(1, 129);
68 chevy.add_pair(eep, seq);
72 adds = randomizer().inclusive(200, 600);
75 int seq = starter + randomizer().inclusive(1, 129);
77 chevy.add_pair(op, seq);
81 adds = randomizer().inclusive(200, 600);
84 int seq = starter + randomizer().inclusive(1, 129);
86 chevy.add_pair(ork, seq);
90 for (i = 0; i < eep_set.elements(); i++) {
92 if (!chevy.have_seen(eep, seq)) {
93 log(a_sprintf("missing sequence is %d", seq));
94 log(chevy.text_form(true));
95 deadly_error("test_sequence_tracker", "eep check", "missing sequence");
98 for (i = 0; i < op_set.elements(); i++) {
100 if (!chevy.have_seen(op, seq)) {
101 log(a_sprintf("missing sequence is %d", seq));
102 log(chevy.text_form(true));
103 deadly_error("test_sequence_tracker", "op check", "missing sequence");
106 for (i = 0; i < ork_set.elements(); i++) {
107 int seq = ork_set[i];
108 if (!chevy.have_seen(ork, seq)) {
109 log(a_sprintf("missing sequence is %d", seq));
110 log(chevy.text_form(true));
111 deadly_error("test_sequence_tracker", "ork check", "missing sequence");
115 return final_report();
118 HOOPLE_MAIN(test_sequence_tracker, )