diff -r 000000000000 -r 2b3e5ec03512 test/unit_tests/prophet-list-test.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/unit_tests/prophet-list-test.cc Thu Apr 21 14:57:45 2011 +0100 @@ -0,0 +1,198 @@ +#include +#include +#include +#include +#include +#include + +#include "prophet/Ack.h" +#include "prophet/Node.h" +#include "prophet/Table.h" +#include "prophet/AckList.h" +#include "prophet/Dictionary.h" +#include "prophet/BundleCore.h" +#include "prophet/BundleTLVEntry.h" +#include "prophet/BundleTLVEntryList.h" + +#include "prophet/PointerList.h" + +using namespace oasys; + +size_t test_iterations = 10; +size_t table_iterations = 100; + +DECLARE_TEST(NodeList) { + prophet::NodeList list; + prophet::Node* node; + + for (size_t i=0; i < test_iterations; i++) { + oasys::StringBuffer str(128,"dtn://node-"); + str.appendf("%zu",i); + node = new prophet::Node(str.c_str()); + CHECK_EQUAL(i,list.size()); + list.push_back(node); + CHECK(i != list.size()); + } + + return UNIT_TEST_PASSED; +} + +DECLARE_TEST(Dictionary) { + prophet::Dictionary pd("dtn://sender","dtn://receiver"); + size_t testsize = test_iterations; + u_int16_t sid = 0xffff; + + // By definition, sender is string_id 0 + DO(sid = pd.find("dtn://sender")); + CHECK_EQUAL(sid,0); + CHECK_EQUALSTR("dtn://sender",pd.find(0).c_str()); + + // By definition, receiver is string_id 1 + DO(sid = pd.find("dtn://receiver")); + CHECK_EQUAL(sid,1); + CHECK_EQUALSTR("dtn://receiver",pd.find(1).c_str()); + + std::string tester; + for (size_t i=0; i 0.0); + printf("pt.p_value(b) == %.02f\n",pt.p_value(b)); + + prophet::Table *p2 = NULL; + { + prophet::Table p3(&core,"p2"); + p3.update_route(a); + p3.update_route(b); + p3.update_route(b); + p2 = new prophet::Table(p3); + } + CHECK(p2->p_value(a) == 0.75); + CHECK(p2->p_value(b) >= 0.75); + delete p2; + + // default is 0, quota disabled + prophet::Table p3(&core,"p3"); + + for (size_t i=0; i 0) { + p3.update_route(str.c_str()); + } + } + + p3.set_max_route(table_iterations/2); + CHECK_EQUAL(p3.size(), table_iterations/2); + + prophet::Table::heap_iterator hi = p3.heap_begin(); + std::vector list(p3.heap_begin(),p3.heap_end()); + struct prophet::heap_compare c; + CHECK( (prophet::Heap, + struct prophet::heap_compare>::is_heap(list,c)) ); + return UNIT_TEST_PASSED; +} + +DECLARE_TEST(BundleTLVList) { + prophet::BundleOfferList bol; + for(size_t i = test_iterations; i>0; --i) { + CHECK(bol.add_offer(0xffff+i,i,i,false,false)); + CHECK(!bol.add_offer(0xffff+i,i,i,true,true)); + CHECK_LTU(bol.size(),test_iterations - i + 1); + } + + prophet::BundleResponseList brl; + for(size_t i = test_iterations; i>0; --i) { + CHECK(brl.add_response(0xffff+i,i,i,false,true)); + CHECK(!brl.add_response(0xffff+i,i,i,true,false)); + CHECK_LTU(brl.size(),test_iterations - i + 1); + } + + CHECK(bol.size() == test_iterations); + for(prophet::BundleOfferList::iterator i = bol.begin(); + i != bol.end(); + i++) + { + prophet::BundleOfferEntry* bo = *i; + CHECK(bol.find(bo->creation_ts(),bo->seqno(),bo->sid()) != NULL); + } + bol.clear(); + CHECK(bol.size() == 0); + return UNIT_TEST_PASSED; +} + +DECLARE_TEST(AckList) { + prophet::PointerList clone; + prophet::AckList pl; + for(size_t i = 0; idest_id().c_str()); + clone.clear(); + } + CHECK_EQUAL(pl.size(),test_iterations); + CHECK_EQUAL(pl.expire(),test_iterations); + CHECK_EQUAL(0,pl.size()); + CHECK(pl.empty()); + return UNIT_TEST_PASSED; +} + +DECLARE_TESTER(ProphetListTest) { + ADD_TEST(NodeList); + ADD_TEST(Dictionary); + ADD_TEST(Table); + ADD_TEST(BundleTLVList); + ADD_TEST(AckList); +} + +DECLARE_TEST_FILE(ProphetListTest, "prophet list test");