summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordufourj2006-04-17 08:18:37 +0000
committerdufourj2006-04-17 08:18:37 +0000
commit16302ab0ce9263a31e36b93648959575e8c5c02b (patch)
tree31cb4a869ba7741468139d17c27ccc5ae3e32a88
parente5996fa7074b11bce48b125756051d09de438533 (diff)
Tester :
- interfa├žage avec interpreter. TODO: - gestion du contr├┤le-c.
-rw-r--r--i/marvin/src/tester/Makefile.defs2
-rw-r--r--i/marvin/src/tester/test_tester.cc36
-rw-r--r--i/marvin/src/tester/tester.cc54
-rw-r--r--i/marvin/src/tester/tester.hh20
4 files changed, 69 insertions, 43 deletions
diff --git a/i/marvin/src/tester/Makefile.defs b/i/marvin/src/tester/Makefile.defs
index ec5bd6a..eeff4ab 100644
--- a/i/marvin/src/tester/Makefile.defs
+++ b/i/marvin/src/tester/Makefile.defs
@@ -1,5 +1,5 @@
PROGRAMS += test_tester
-tester_OBJECTS = tester.o $(config_OBJECTS) $(interpreter_OBJECTS)
+tester_OBJECTS = tester.o $(config_OBJECTS) $(interpreter_OBJECTS) $(log_OBJECTS)
test_tester_OBJECTS = test_tester.o $(tester_OBJECTS)
diff --git a/i/marvin/src/tester/test_tester.cc b/i/marvin/src/tester/test_tester.cc
index 8db2a31..b89b25f 100644
--- a/i/marvin/src/tester/test_tester.cc
+++ b/i/marvin/src/tester/test_tester.cc
@@ -24,48 +24,40 @@
// }}}
#include "tester.hh"
-class TestTester
+class TestTester : public Tester
{
- Tester t;
public:
// Constructor
TestTester (int argc, char ** argv)
- : t (argc, argv) { }
- bool funcA (const Interpreter::Args &a)
+ : Tester (argc, argv) { }
+ void funcA (const Interpreter::Args &a)
{
std::cout << " a " << a << std::endl;
- return true;
}
- bool funcB (void)
+ void funcB (void)
{
std::cout << " b ( )" << std::endl;
- return true;
}
- bool funcC (int i)
+ void funcC (int i)
{
std::cout << " c ( " << i << " )" << std::endl;
- return true;
}
- bool funcD (const std::string &s)
+ void funcD (const std::string &s)
{
std::cout << " d ( " << s << " )" << std::endl;
- return true;
}
- bool funcE (int i, const std::string &s, double d)
+ void funcE (int i, const std::string &s, double d)
{
std::cout << " e ( " << i << ' ' << s << ' ' << d << " )" << std::endl;
- return true;
}
- int main (void)
+ void preRun (void)
{
// Add functions.
- t.add ("a", Interpreter::memFunc (*this, &TestTester::funcA));
- t.add ("b", Interpreter::memFunc (*this, &TestTester::funcB));
- t.add ("c", Interpreter::memFunc (*this, &TestTester::funcC));
- t.add ("d", Interpreter::memFunc (*this, &TestTester::funcD));
- t.add ("e", Interpreter::memFunc (*this, &TestTester::funcE));
- t.run ();
- return 0;
+ add ("a", Interpreter::memFunc (*this, &TestTester::funcA));
+ add ("b", Interpreter::memFunc (*this, &TestTester::funcB));
+ add ("c", Interpreter::memFunc (*this, &TestTester::funcC));
+ add ("d", Interpreter::memFunc (*this, &TestTester::funcD));
+ add ("e", Interpreter::memFunc (*this, &TestTester::funcE));
}
};
@@ -75,7 +67,7 @@ main (int argc, char **argv)
try
{
TestTester tt (argc, argv);
- return tt.main ();
+ tt.run ();
}
catch (const std::exception &e)
{
diff --git a/i/marvin/src/tester/tester.cc b/i/marvin/src/tester/tester.cc
index 2ded27f..58e62c8 100644
--- a/i/marvin/src/tester/tester.cc
+++ b/i/marvin/src/tester/tester.cc
@@ -27,8 +27,7 @@
#include <unistd.h> // getopt
#include <exception> // std::exception
#include <cstdlib> // std::exit
-#include <fstream> // std::ifstream
-#include <sstream> // std::stringstream
+#include <sstream> // std::ostringstream
/// Constructor.
Tester::Tester (int argc, char **argv)
@@ -40,14 +39,15 @@ Tester::Tester (int argc, char **argv)
/// Getopt command line.
/// Supported arguemnts :
-/// - -c "commands list"
+/// - -c 'commands list'
/// - -f <file>
+/// - -h : help
void
Tester::getOpt (int argc, char **argv)
{
- char *optstring = "c:f:";
+ char *optstring = "hc:f:";
int option;
- std::ifstream file;
+ std::string strTmp;
// Check number of args
if (argc < 2)
@@ -65,19 +65,17 @@ Tester::getOpt (int argc, char **argv)
switch (option)
{
case 'c':
- commands_.append (optarg);
+ // Check commands
+ strTmp = optarg;
+ listOpts_.push_back (Opt(false, strTmp));
break;
case 'f':
- file.open (optarg);
- if (file.is_open ())
- {
- std::stringstream buffer_tmp;
- buffer_tmp << file.rdbuf();
- commands_.append (buffer_tmp.str ());
- file.close ();
- }
- else
- throw std::runtime_error ("File not found : " + std::string (optarg));
+ strTmp = optarg;
+ listOpts_.push_back (Opt(true, strTmp));
+ break;
+ case 'h':
+ usage ();
+ std::exit (0);
break;
case '?':
default:
@@ -106,10 +104,30 @@ Tester::add (const std::string &s, Interpreter::Func *f)
interpreter_.add (s, f);
}
+/// Run commands.
void
Tester::run (void)
{
- // TODO called interpreter with the commands_, in check mode then in run
- // mode.
+ // Pre-run
+ preRun ();
+ // Run
+ ListOpts::const_iterator it;
+ // Check all, dry run
+ for (it = listOpts_.begin (); it != listOpts_.end (); it++)
+ {
+ if (it->first)
+ interpreter_.interpretFile (it->second, true);
+ else
+ interpreter_.interpretString (it->second, true);
+ }
+ // Run !
+ for (it = listOpts_.begin (); it != listOpts_.end (); it++)
+ {
+ if (it->first)
+ interpreter_.interpretFile (it->second, false);
+ else
+ interpreter_.interpretString (it->second, false);
+ }
+ postRun ();
}
diff --git a/i/marvin/src/tester/tester.hh b/i/marvin/src/tester/tester.hh
index c476125..5f4e68c 100644
--- a/i/marvin/src/tester/tester.hh
+++ b/i/marvin/src/tester/tester.hh
@@ -26,8 +26,10 @@
// }}}
#include "config/config.hh"
#include "interpreter/interpreter.hh"
+#include "log/data_circular_buffer_factory.hh"
#include <string>
+#include <list>
class Tester
{
@@ -38,8 +40,11 @@ class Tester
Interpreter interpreter_;
/// Program name.
std::string program_;
- /// Commands to parse.
- std::string commands_;
+ /// Internal typedef.
+ typedef std::pair<bool /*file ?*/, std::string> Opt;
+ typedef std::list<Opt> ListOpts;
+ /// Options list.
+ ListOpts listOpts_;
/// Getopt command line.
void getOpt (int argc, char **argv);
/// Print usage to stdout.
@@ -47,10 +52,21 @@ class Tester
public:
/// Constructor.
Tester (int argc, char ** argv);
+ /// Destructor.
+ virtual ~Tester (void) { }
/// Add a test function, Tester owns f.
void add (const std::string &s, Interpreter::Func *f);
/// Run commands.
+ /// Call preRun, check command, run them, call postRun.
void run (void);
+ /// Executed before checking/running commands.
+ virtual void preRun (void) { }
+ /// Executed after running commands.
+ virtual void postRun (void) { }
+ private:
+ /// DataCircularBufferFactory for beeing destruct at the end of the program.
+ /// It must stay at the end of the program !
+ DataCircularBufferFactory dbc;
};
#endif // tester_hh