- ArthurDent - Test completato codice del test di history

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@517 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
matrevis 2006-03-09 16:25:21 +00:00
parent 0c2cba8bbe
commit bb1d465b34
2 changed files with 47 additions and 33 deletions

View File

@ -23,19 +23,14 @@
#include <glibmm/module.h> // ??
#include <glibmm/module.h>
#include <cassert>
#include <string>
#include "config.h"
#include "gettext.h"
#include "glibmm/ustring.h"
#include <vector>
#include <iostream>
#include "backend/history.hh"
#include "backend/process.hh"
#include "backend/slice.hh"
@ -55,7 +50,7 @@ public:
{}
/** this method gets a sequence of operations as a parameter and performs them
* checking for incongruences.
* checking for anomalies.
* E stands for EnqueueSlice, R for randomize input, T for truncate the last insertion
*/
void test(std::string commands_sequence)
@ -91,23 +86,25 @@ public:
SchedulableStatus* _get_scheduled_at[400]; // mirrors the correct content of the history
SchedulableList _internal_schedulable_list;
// looks for anomalies
void _standard_test()
{
// checks if the Singleton Pattern has been actually implemented
if (&History::get_instance() != &History::get_instance()) std::cout << "get_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";
if (History::get_instance().get_current_time() != _history_length) std::cout << "get_current_time" << endl <<History::get_instance().get_current_time() <<',' << _history_length<<endl;
// checks if the History contains the right stuff
for (int i = 0; i <= _history_length; i++)
for (int i = 0; i < _history_length+1; i++)
{
// watch out here, it's if (NOT ...) operator != was not available.
if (!(*History::get_instance().get_simulation_status_at(i) == *_get_simulation_status_at[i]))
{
std::cout << "get_simulation_status_at";
}
if (!(*History::get_instance().get_scheduled_at(i) == *_get_scheduled_at[i]))
if (History::get_instance().get_scheduled_at(i) != memory::smart_ptr<SchedulableStatus>(NULL) && !(*History::get_instance().get_scheduled_at(i) == *_get_scheduled_at[i]))
{
std::cout << "get_simulation_status_at";
}
@ -115,16 +112,24 @@ public:
return;
}
// saves the given SchedulableList into the history, and saves a copy of it into an array
void _insert(sgpem::SchedulableList& status)
{
History::get_instance().enqueue_slice(status);
_history_length = _history_length + 1;
// I hope the copy constructor is available..
_get_simulation_status_at[_history_length] = new SchedulableList(status);
if (History::get_instance().get_scheduled_at(_history_length) != memory::smart_ptr<SchedulableStatus>(NULL))
_get_scheduled_at[_history_length] = new SchedulableStatus(*(status.top()));
else
_get_scheduled_at[_history_length] = NULL;
return;
}
// modifies the given SchedulableList object in an arbitrary way.
void _randomize(sgpem::SchedulableList& status)
{
status.swap(9, 10);
@ -140,21 +145,35 @@ public:
status.swap(9, 4);
status.swap(4, 5);
status.swap(7, 1);
for (unsigned int i = 0; i <= status.size(); i++)
for (unsigned int i = 0; i < status.size(); i++)
{
// FIXME: These methods aren't implemented!!
//status.get_item_at(i).give_cpu_time(1);
//status.get_item_at(i).set_last_scheduled(_history_length);
//status.get_item_at(i).set_state(1<<(i%4));
status.get_item_at(i)->give_cpu_time(i%2);
status.get_item_at(i)->set_last_scheduled(_history_length%30);
status.get_item_at(i)->set_state(i%2 ? SchedulableStatus::state_running : SchedulableStatus::state_ready);
}
return;
}
// truncates the history by one instant
void _truncate()
{
if (_history_length > -1)
{
if (_get_simulation_status_at[_history_length] != NULL)
{
delete _get_simulation_status_at[_history_length];
_get_simulation_status_at[_history_length] = NULL;
}
if (_get_scheduled_at[_history_length] != NULL)
{
delete _get_scheduled_at[_history_length];
_get_scheduled_at[_history_length] = NULL;
}
_history_length = _history_length - 1;
}
History::get_instance().truncate_at(_history_length);
return;
}
@ -169,6 +188,7 @@ main(int argc, char** argv)
std::string command("ERERERT"); // the sequence of commands to test
command = argv[1];
// sets up the test data
Process p1("P1", 1,5,1);
@ -233,8 +253,8 @@ main(int argc, char** argv)
initial.add_at_bottom(ss18);
HistoryTester HT(initial);
HT.test("ERERERERTTTETRERERETETTTTTTTTTTTTTT");
HT.test(command);
cout << std::endl << "end of test\n";
exit(0);
}

View File

@ -24,20 +24,14 @@
#include <glibmm/module.h> // ??
#include <cassert>
#include <string>
#include "config.h"
#include "gettext.h"
#include "glibmm/ustring.h"
#include <vector>
#include <iostream>
#include "backend/process.hh"
#include "backend/slice.hh"
#include "backend/observed_subject.hh"
#include "backend/schedulable_list.hh"
#include "backend/schedulable_status.hh"
@ -190,12 +184,12 @@ namespace sgpem
class History : public ObservedSubject
{
public:
// what the hell are these smart pointers?
memory::smart_ptr<sgpem::SchedulableStatus> get_scheduled_at(int time) const;
memory::smart_ptr<sgpem::SchedulableStatus> get_scheduled_at(int time) const {}
memory::smart_ptr<sgpem::SchedulableList> get_simulation_status_at(int time) const;
int get_current_time() const;
int get_current_time() const {return _total_time_elapsed;}
void enqueue_slice(const sgpem::SchedulableList& status);
void truncate_at(int instant);
void truncate_at(int instant) {}
static History& get_instance();
private:
History(int); //private constructor. The parameter is discarded