test_sequence_tracker.cpp

Go to the documentation of this file.
00001 /*
00002 *  Name   : test_sequence_tracker
00003 *  Author : Chris Koeritz
00004 *  Purpose: Runs a couple of tests on the sequence tracker object.
00005 **
00006 * Copyright (c) 2003-$now By Author.  This program is free software; you can  *
00007 * redistribute it and/or modify it under the terms of the GNU General Public  *
00008 * License as published by the Free Software Foundation; either version 2 of   *
00009 * the License or (at your option) any later version.  This is online at:      *
00010 *     http://www.fsf.org/copyleft/gpl.html                                    *
00011 * Please send any updates to: fred@gruntose.com                               *
00012 */
00013 
00014 #include <application/hoople_main.h>
00015 #include <basis/byte_array.h>
00016 #include <basis/astring.h>
00017 #include <loggers/program_wide_logger.h>
00018 #include <mathematics/chaos.h>
00019 #include <sockets/machine_uid.h>
00020 #include <sockets/sequence_tracker.h>
00021 #include <structures/set.h>
00022 #include <structures/static_memory_gremlin.h>
00023 #include <unit_test/unit_base.h>
00024 
00025 //#include <stdio.h>
00026 //#include <string.h>
00027 
00028 using namespace application;
00029 using namespace basis;
00030 using namespace loggers;
00031 using namespace mathematics;
00032 using namespace sockets;
00033 using namespace structures;
00034 using namespace textual;
00035 using namespace timely;
00036 using namespace unit_test;
00037 
00038 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
00039 
00040 class test_sequence_tracker : public virtual unit_base, virtual public application_shell
00041 {
00042 public:
00043   test_sequence_tracker() {}
00044   DEFINE_CLASS_NAME("test_sequence_tracker");
00045   virtual int execute();
00046 };
00047 
00048 int test_sequence_tracker::execute()
00049 {
00050   FUNCDEF("execute");
00051   // some arbitrary ip addresses.
00052   abyte arb1[] = { 127, 0, 0, 1 };
00053   abyte arb2[] = { 192, 168, 0, 1 };
00054   abyte arb3[] = { 28, 42, 56, 253 };
00055 
00056   machine_uid eep(machine_uid::TCPIP_LOCATION, byte_array(4, arb1));
00057   machine_uid op(machine_uid::TCPIP_LOCATION, byte_array(4, arb2));
00058   machine_uid ork(machine_uid::TCPIP_LOCATION, byte_array(4, arb3));
00059 
00060   sequence_tracker chevy(1 * MINUTE_ms, 10 * MINUTE_ms);
00061 
00062   int_set eep_set;
00063   int adds = randomizer().inclusive(400, 900);
00064   int starter = 12092;
00065   while (adds--) {
00066     int seq = starter + randomizer().inclusive(1, 129);
00067     eep_set += seq;
00068     chevy.add_pair(eep, seq);
00069   }
00070 
00071   int_set op_set;
00072   adds = randomizer().inclusive(200, 600);
00073   starter = 1222;
00074   while (adds--) {
00075     int seq = starter + randomizer().inclusive(1, 129);
00076     op_set += seq;
00077     chevy.add_pair(op, seq);
00078   }
00079 
00080   int_set ork_set;
00081   adds = randomizer().inclusive(200, 600);
00082   starter = 992981;
00083   while (adds--) {
00084     int seq = starter + randomizer().inclusive(1, 129);
00085     ork_set += seq;
00086     chevy.add_pair(ork, seq);
00087   }
00088 
00089   int i;
00090   for (i = 0; i < eep_set.elements(); i++) {
00091     int seq = eep_set[i];
00092     if (!chevy.have_seen(eep, seq)) {
00093       log(a_sprintf("missing sequence is %d", seq));
00094       log(chevy.text_form(true));
00095       deadly_error("test_sequence_tracker", "eep check", "missing sequence");
00096     }
00097   }
00098   for (i = 0; i < op_set.elements(); i++) {
00099     int seq = op_set[i];
00100     if (!chevy.have_seen(op, seq)) {
00101       log(a_sprintf("missing sequence is %d", seq));
00102       log(chevy.text_form(true));
00103       deadly_error("test_sequence_tracker", "op check", "missing sequence");
00104     }
00105   }
00106   for (i = 0; i < ork_set.elements(); i++) {
00107     int seq = ork_set[i];
00108     if (!chevy.have_seen(ork, seq)) {
00109       log(a_sprintf("missing sequence is %d", seq));
00110       log(chevy.text_form(true));
00111       deadly_error("test_sequence_tracker", "ork check", "missing sequence");
00112     }
00113   }
00114 
00115   return final_report();
00116 }
00117 
00118 HOOPLE_MAIN(test_sequence_tracker, )
00119 
Generated on Sat Jan 28 04:22:55 2012 for hoople2 project by  doxygen 1.6.3