From d8cd3577a7902666e26947f7f95f82097222421e Mon Sep 17 00:00:00 2001 From: matrevis Date: Thu, 22 Jun 2006 10:47:23 +0000 Subject: [PATCH] Arthur Dent: completed test-history, merging with Matteo's. git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@651 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/testsuite/test-history.cc | 69 +++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/src/testsuite/test-history.cc b/src/testsuite/test-history.cc index e027cf9..0ffef68 100644 --- a/src/testsuite/test-history.cc +++ b/src/testsuite/test-history.cc @@ -26,6 +26,7 @@ #include #include #include +#include #include "config.h" #include "gettext.h" #include "glibmm/ustring.h" @@ -37,15 +38,21 @@ #include "backend/observed_subject.hh" #include "backend/schedulable_queue.hh" #include "backend/dynamic_schedulable.hh" - -#include "smartp.hh" +#include "templates/smartp.hh" using namespace sgpem; using namespace std; +/** An HistoryTester object offers a simple interface to test the History class. + * + * + * + */ class HistoryTester { -public: + public: + + HistoryTester(SchedulableQueue sl) : _history_length(-1), _internal_schedulable_queue(sl) {} @@ -54,7 +61,8 @@ public: * checking for anomalies. * E stands for EnqueueSlice, R for randomize input, T for truncate the last insertion */ - void test(std::string commands_sequence) + void + test(std::string commands_sequence) { // prints the test sequence std::cout << commands_sequence << endl; @@ -89,25 +97,33 @@ public: // looks for anomalies - void _standard_test() + void + _standard_test() { // checks if the Singleton Pattern has been actually implemented - if (&History::get_instance() != &History::get_instance()) std::cout << "get_instance" << endl; + if (&History::get_instance() != &History::get_instance()) std::cout << "\nget_instance"; // checks if the History is long how it should be - if (History::get_instance().get_current_time() != _history_length) std::cout << "get_current_time" << endl <has_same_objects( *_get_simulation_status_at[i]) + ) + ) { - std::cout << "get_simulation_status_at" << endl; + std::cout << "\nget_simulation_status_at"; } - if (History::get_instance().get_scheduled_at(i) != memory::smart_ptr(NULL) && !(*History::get_instance().get_scheduled_at(i) == *_get_scheduled_at[i])) + if (History::get_instance().get_scheduled_at(i) != memory::smart_ptr(NULL) && !(*(History::get_instance().get_scheduled_at(i)) == *(_get_scheduled_at[i]))) { - std::cout << "get_simulation_status_at" << endl; + std::cout << "\nget_scheduled_at"; } } return; @@ -123,7 +139,7 @@ public: _get_simulation_status_at[_history_length] = new SchedulableQueue(status); if (History::get_instance().get_scheduled_at(_history_length) != memory::smart_ptr(NULL)) - _get_scheduled_at[_history_length] = new DynamicSchedulable(*(status.top())); + _get_scheduled_at[_history_length] = new DynamicSchedulable(*(History::get_instance().get_scheduled_at(_history_length))); else _get_scheduled_at[_history_length] = NULL; return; @@ -174,8 +190,8 @@ public: } _history_length = _history_length - 1; + History::get_instance().truncate_at(_history_length-1); } - History::get_instance().truncate_at(_history_length); return; } @@ -186,10 +202,9 @@ main(int argc, char** argv) { using namespace sgpem; using Glib::Module; - - - std::string command("ERERERT"); // the sequence of commands to test + + //std::string command("ERERERT"); // the sequence of commands to test if(argc > 1) command = argv[1]; @@ -256,8 +271,24 @@ main(int argc, char** argv) initial.add_at_bottom(ss18); HistoryTester HT(initial); - HT.test(command); + //HT.test("EEEEREREEEERERRREEEEEEEETERRERERTTT"); + HT.test("E"); + HT.test("EE"); + HT.test("EERE"); + HT.test("EEEREE"); + HT.test("EEEREE"); + HT.test("EEER"); + HT.test("EEEERER"); + HT.test("EEER"); + HT.test("EREE"); + HT.test("EEEERERT"); + HT.test("EEEERERTEEEERERT"); + HT.test("EEEERERTEEETRERERT"); + HT.test("EEEERERTEEEERRRERT"); + HT.test("EEEEEEERERTERERT"); + HT.test("EEEEREREEEERERRREEEEEEEETERRERERTTT"); + //HT.test(command); - cout << std::endl << "end of test\n"; + cout << std::endl << "\nend of test!\n"; exit(0); }