t_sequence_tracker.cpp

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

Generated on Fri Nov 28 04:29:34 2008 for HOOPLE Libraries by  doxygen 1.5.1