From 67629d2ddcc7010b5484e4b412b9d46dd76c330c Mon Sep 17 00:00:00 2001 From: dufourj Date: Fri, 24 Mar 2006 14:22:49 +0000 Subject: Tester : - rajout du chargement des commandes depuis un fichier (-f) ; - correction d'un try mal placé. --- i/marvin/src/tester/test_tester.cc | 2 +- i/marvin/src/tester/tester.cc | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/i/marvin/src/tester/test_tester.cc b/i/marvin/src/tester/test_tester.cc index 3075552..8db2a31 100644 --- a/i/marvin/src/tester/test_tester.cc +++ b/i/marvin/src/tester/test_tester.cc @@ -72,9 +72,9 @@ class TestTester int main (int argc, char **argv) { - TestTester tt (argc, argv); try { + TestTester tt (argc, argv); return tt.main (); } catch (const std::exception &e) diff --git a/i/marvin/src/tester/tester.cc b/i/marvin/src/tester/tester.cc index 5b93fd8..2ded27f 100644 --- a/i/marvin/src/tester/tester.cc +++ b/i/marvin/src/tester/tester.cc @@ -27,6 +27,8 @@ #include // getopt #include // std::exception #include // std::exit +#include // std::ifstream +#include // std::stringstream /// Constructor. Tester::Tester (int argc, char **argv) @@ -39,11 +41,13 @@ Tester::Tester (int argc, char **argv) /// Getopt command line. /// Supported arguemnts : /// - -c "commands list" +/// - -f void Tester::getOpt (int argc, char **argv) { - char *optstring = "c:"; + char *optstring = "c:f:"; int option; + std::ifstream file; // Check number of args if (argc < 2) @@ -63,6 +67,18 @@ Tester::getOpt (int argc, char **argv) case 'c': commands_.append (optarg); 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)); + break; case '?': default: usage (); @@ -76,8 +92,10 @@ Tester::getOpt (int argc, char **argv) void Tester::usage (void) const { - std::cout << "Usage: " << program_ << " [-c ]" << - std::endl; + std::cout << "Usage: " << program_ + << " [-c ]" + << " [-f ]" + << std::endl; } -- cgit v1.2.3