00001 /* 00002 * TestBundleSummary.cpp 00003 * 00004 * Created on: 27.07.2010 00005 * Author: morgenro 00006 */ 00007 00008 #include "tests/TestBundleSummary.h" 00009 #include <ibrdtn/utils/Clock.h> 00010 #include "routing/BundleSummary.h" 00011 #include <sstream> 00012 00013 CPPUNIT_TEST_SUITE_REGISTRATION (TestBundleSummary); 00014 00015 void TestBundleSummary::setUp() 00016 { 00017 dtn::utils::Clock::quality = 1; 00018 } 00019 00020 void TestBundleSummary::tearDown() 00021 { 00022 } 00023 00024 void TestBundleSummary::expireTest(void) 00025 { 00026 dtn::routing::BundleSummary l; 00027 00028 CPPUNIT_ASSERT(l.size() == 0); 00029 00030 genbundles(l, 1000, 0, 500); 00031 genbundles(l, 1000, 600, 1000); 00032 00033 for (int i = 0; i < 550; i++) 00034 { 00035 l.expire(i); 00036 } 00037 00038 CPPUNIT_ASSERT(l.size() == 1000); 00039 00040 for (int i = 0; i < 1050; i++) 00041 { 00042 l.expire(i); 00043 } 00044 00045 CPPUNIT_ASSERT(l.size() == 0); 00046 00047 // std::stringstream bf; bf << l.getSummaryVector() << std::flush; 00048 // std::cout << getHex(bf) << std::endl; 00049 } 00050 00051 void TestBundleSummary::genbundles(dtn::routing::BundleSummary &l, int number, int offset, int max) 00052 { 00053 int range = max - offset; 00054 dtn::data::Bundle b; 00055 00056 for (int i = 0; i < number; i++) 00057 { 00058 int random_integer = offset + (rand() % range); 00059 00060 b._lifetime = random_integer; 00061 b._timestamp = 0; 00062 b._sequencenumber = random_integer; 00063 00064 stringstream ss; ss << rand(); 00065 00066 b._source = dtn::data::EID("dtn://node" + ss.str() + "/application"); 00067 00068 l.add(b); 00069 } 00070 } 00071 00072 std::string TestBundleSummary::getHex(std::istream &stream) 00073 { 00074 std::stringstream buf; 00075 unsigned int c = stream.get(); 00076 00077 while (!stream.eof()) 00078 { 00079 buf << std::hex << c << ":"; 00080 c = stream.get(); 00081 } 00082 00083 buf << std::flush; 00084 00085 return buf.str(); 00086 } 00087
1.6.3