00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <basis/array.h>
00016 #include <basis/function.h>
00017 #include <basis/guards.h>
00018 #include <data_struct/span_manager.h>
00019 #include <loggers/file_logger.h>
00020 #include <data_struct/static_memory_gremlin.h>
00021
00022 #define DEBUG_SPAN_MANAGER
00023
00024
00025 #define LOG(to_print) { program_wide_logger().log(to_print); }
00026
00027 HOOPLE_STARTUP_CODE;
00028
00029 #define WHERE __WHERE__.s()
00030
00031 #define MAX_SPANS 8
00032
00033
00034 #define INIT_STUFF int_array stuffer;
00035
00036
00037 #define STUFF(a, b) \
00038 if (stuffer.length() / 2 + 1 > MAX_SPANS) deadly_error(WHERE, "STUFF", "too many"); \
00039 stuffer.concatenate(a); stuffer.concatenate(b);
00040
00041
00042
00043 #define SEND(send_to) \
00044 send_to.update(stuffer); stuffer.reset(0);
00046
00047
00048 #define COMP(to_compare, i) \
00049 if (to_compare != rec_list[i]) \
00050 deadly_error(WHERE, "comparison", istring(istring::SPRINTF, \
00051 "index %d incorrect", i).s())
00052
00053 int main(int formal(argc), char *formal(argv)[])
00054 {
00055 span_manager fred(452);
00056
00057 INIT_STUFF;
00058
00059
00060 STUFF(8, 8);
00061 STUFF(27, 29);
00062 STUFF(28, 31);
00063 STUFF(3, 5);
00064 STUFF(80, 83);
00065 STUFF(96, 123);
00066 STUFF(3, 6);
00067 STUFF(212, 430);
00068 SEND(fred);
00069
00070
00071 STUFF(13, 17);
00072 STUFF(151, 250);
00073 SEND(fred);
00074
00075 #ifdef DEBUG_SPAN_MANAGER
00076 LOG(istring(istring::SPRINTF, "received sequence so far is %d",
00077 fred.received_sequence()));
00078 LOG("making received list:");
00079 #endif
00080
00081 int_array rec_list;
00082 fred.make_received_list(rec_list);
00083
00084 #ifdef DEBUG_SPAN_MANAGER
00085 LOG(fred.print_received_list());
00086 #endif
00087
00088
00089
00090 for (int i = 0; i < rec_list.length(); i += 2) {
00091 switch (i) {
00092 case 0: COMP(3, i); COMP(6, i+1); break;
00093 case 2: COMP(8, i); COMP(8, i+1); break;
00094 case 4: COMP(13, i); COMP(17, i+1); break;
00095 case 6: COMP(27, i); COMP(31, i+1); break;
00096 case 8: COMP(80, i); COMP(83, i+1); break;
00097 case 10: COMP(96, i); COMP(123, i+1); break;
00098 case 12: COMP(151, i); COMP(430, i+1); break;
00099 }
00100 }
00101
00102 if (fred.missing_sequence() != 0)
00103 deadly_error(WHERE, "missing", "wrong sequence");
00104
00105
00106 STUFF(0, 5);
00107 STUFF(7, 7);
00108 STUFF(9, 12);
00109 SEND(fred);
00110 if (fred.missing_sequence() != 18)
00111 deadly_error(WHERE, "missing 2", "wrong sequence");
00112 #ifdef DEBUG_SPAN_MANAGER
00113 LOG("here are the missing ones now:");
00114 LOG(fred.print_missing_list());
00115 #endif
00116 fred.make_missing_list(rec_list);
00117
00118
00119 for (int j = 0; j < rec_list.length(); j+=2) {
00120 switch (j) {
00121 case 0: COMP(18, j); COMP(26, j+1); break;
00122 case 2: COMP(32, j); COMP(79, j+1); break;
00123 case 4: COMP(84, j); COMP(95, j+1); break;
00124 case 6: COMP(124, j); COMP(150, j+1); break;
00125 case 8: COMP(431, j); COMP(451, j+1); break;
00126 }
00127 }
00128
00129 STUFF(0, 451);
00130 SEND(fred);
00131 #ifdef DEBUG_SPAN_MANAGER
00132 LOG("should be filled out now:");
00133 LOG(fred.print_received_list());
00134 #endif
00135 if (fred.received_sequence() != 451)
00136 deadly_error(WHERE, "received sequence", "wrong--should be filled out");
00137 guards::alert_message("span_manager:: works for those functions tested.");
00138 return 0;
00139 }
00140