Fresco/Fresco-Test/syunit-c++/src Breakpoint.cc,1.2,1.3 ResultsMap.cc,1.2,1.3 TestCase.cc,1.2,1.3 TestCmd.cc,1.2,1.3
Nathaniel Smith <[email protected]> Tue, 20 May 2003 04:06:30 -0500
| Newsgroups | gmane.comp.video.fresco.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvs/fresco/Fresco/Fresco-Test/syunit-c++/src
In directory purcel:/tmp/cvs-serv3366/src
Modified Files:
Breakpoint.cc ResultsMap.cc TestCase.cc TestCmd.cc
Log Message:
Old formatting changes that I forgot to check in.
Index: Breakpoint.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Fresco-Test/syunit-c++/src/Breakpoint.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Breakpoint.cc 19 Feb 2003 20:40:16 -0000 1.2
+++ Breakpoint.cc 20 May 2003 09:06:27 -0000 1.3
@@ -2,19 +2,19 @@
extern "C"
{
-
- void
- SyUnit_fail_breakpoint()
- {
- SyUnit_problem_breakpoint();
- }
-
- void
- SyUnit_error_breakpoint()
- {
- SyUnit_problem_breakpoint();
- }
-
- void
- SyUnit_problem_breakpoint() {}
+
+ void
+ SyUnit_fail_breakpoint()
+ {
+ SyUnit_problem_breakpoint();
+ }
+
+ void
+ SyUnit_error_breakpoint()
+ {
+ SyUnit_problem_breakpoint();
+ }
+
+ void
+ SyUnit_problem_breakpoint() {}
}
Index: ResultsMap.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Fresco-Test/syunit-c++/src/ResultsMap.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ResultsMap.cc 19 Feb 2003 20:40:16 -0000 1.2
+++ ResultsMap.cc 20 May 2003 09:06:27 -0000 1.3
@@ -2,82 +2,82 @@
namespace SyUnit
{
-
-const std::string ResultsMap::continuation_indent(" ");
-const std::string ResultsMap::blank_line_quote(".");
-
-void
-ResultsMap::clear()
-{
- my_keys.clear();
- my_map.clear();
-}
-std::string&
-ResultsMap::operator [] (const std::string& key)
-{
- // Is this really the best way to check whether a map already
- // contains an entry for a given key?
- if (!my_map.count(key))
+ const std::string ResultsMap::continuation_indent(" ");
+ const std::string ResultsMap::blank_line_quote(".");
+
+ void
+ ResultsMap::clear()
{
- my_keys.push_back(std::string(key));
+ my_keys.clear();
+ my_map.clear();
}
- return my_map[key];
-}
-
-bool
-ResultsMap::operator == (const ResultsMap& other) const
-{
- return my_map == other.my_map;
-}
-
-ResultsMap &
-ResultsMap::operator = (const ResultsMap& other)
-{
- my_keys = other.my_keys;
- my_map = other.my_map;
-}
-
-// This might be a bit inefficient, since we print one character at a
-// time, but the effect is probably negligible (and the code is
-// cleaner and probably faster than my first try that didn't do
-// that...)
-std::ostream&
-operator << (std::ostream& os, ResultsMap rm)
-{
- std::list<std::string>::const_iterator i;
- for (i = rm.my_keys.begin(); i != rm.my_keys.end(); i++)
+
+ std::string&
+ ResultsMap::operator [] (const std::string& key)
{
- // "<key>: "
- os << *i << ": ";
-
- // "<desc>"
- std::string& desc = rm[*i];
-
- bool seen_chars_this_line = true;
- std::string::iterator j = desc.begin();
- while (j != desc.end())
- {
- if (*j == '\n')
+ // Is this really the best way to check whether a map already
+ // contains an entry for a given key?
+ if (!my_map.count(key))
{
- if (!seen_chars_this_line) os << rm.blank_line_quote;
- seen_chars_this_line = false;
- os << *j;
- j++;
- if (j != desc.end()) os << rm.continuation_indent;
+ my_keys.push_back(std::string(key));
}
- else
+ return my_map[key];
+ }
+
+ bool
+ ResultsMap::operator == (const ResultsMap& other) const
+ {
+ return my_map == other.my_map;
+ }
+
+ ResultsMap &
+ ResultsMap::operator = (const ResultsMap& other)
+ {
+ my_keys = other.my_keys;
+ my_map = other.my_map;
+ }
+
+ // This might be a bit inefficient, since we print one character at a
+ // time, but the effect is probably negligible (and the code is
+ // cleaner and probably faster than my first try that didn't do
+ // that...)
+ std::ostream&
+ operator << (std::ostream& os, ResultsMap rm)
+ {
+ std::list<std::string>::const_iterator i;
+ for (i = rm.my_keys.begin(); i != rm.my_keys.end(); i++)
{
- seen_chars_this_line = true;
- os << *j;
- j++;
+ // "<key>: "
+ os << *i << ": ";
+
+ // "<desc>"
+ std::string& desc = rm[*i];
+
+ bool seen_chars_this_line = true;
+ std::string::iterator j = desc.begin();
+ while (j != desc.end())
+ {
+ if (*j == '\n')
+ {
+ if (!seen_chars_this_line) os << rm.blank_line_quote;
+ seen_chars_this_line = false;
+ os << *j;
+ j++;
+ if (j != desc.end()) os << rm.continuation_indent;
+ }
+ else
+ {
+ seen_chars_this_line = true;
+ os << *j;
+ j++;
+ }
+ }
+ // Add a final \n if necessary
+ if (seen_chars_this_line) os << '\n';
}
- }
- // Add a final \n if necessary
- if (seen_chars_this_line) os << '\n';
- }
+
+ return os;
+ }
- return os;
-}
-
}
Index: TestCase.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Fresco-Test/syunit-c++/src/TestCase.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- TestCase.cc 19 Feb 2003 20:40:16 -0000 1.2
+++ TestCase.cc 20 May 2003 09:06:27 -0000 1.3
@@ -6,67 +6,67 @@
namespace SyUnit
{
-
-void
-TestCase::fail(const std::string msg)
-{
- SyUnit_fail_breakpoint();
- result["Result"] = "FAIL";
- result["Cause"] = msg;
- throw TestFailure();
-}
-
-void
-TestCase::error(const std::string msg)
-{
- SyUnit_error_breakpoint();
- result["Result"] = "ERROR";
- result["Cause"] = msg;
- throw TestError();
-}
-
-void
-TestCase::assert_true(bool cond,
- const std::string msg)
-{
- if (!cond) fail(msg);
-}
-
-void
-TestCase::assert_false(bool cond,
- const std::string msg)
-{
- if (cond) fail(msg);
-}
-
-void
-TestCase::assert_equals_delta(double x, double y, double epsilon,
- const std::string msg)
-{
- if (! (-epsilon < x-y && epsilon > x-y) )
+
+ void
+ TestCase::fail(const std::string msg)
{
- if (msg != "") fail(msg);
- else
- {
- std::stringstream my_msg;
- my_msg << "assert_equals_delta failed: "
- << x << " - " << y << " = " << x - y
- << "; epsilon was " << epsilon << ".";
- fail(my_msg.str());
- }
+ SyUnit_fail_breakpoint();
+ result["Result"] = "FAIL";
+ result["Cause"] = msg;
+ throw TestFailure();
}
-}
-
-void
-TestCase::assert_equals(float, float, const std::string)
-{
- error("Called assert_equals with two float arguments.");
-}
-
-void
-TestCase::assert_equals(double, double, const std::string)
-{
- error("Called assert_equals with two double arguments.");
-}
-
+
+ void
+ TestCase::error(const std::string msg)
+ {
+ SyUnit_error_breakpoint();
+ result["Result"] = "ERROR";
+ result["Cause"] = msg;
+ throw TestError();
+ }
+
+ void
+ TestCase::assert_true(bool cond,
+ const std::string msg)
+ {
+ if (!cond) fail(msg);
+ }
+
+ void
+ TestCase::assert_false(bool cond,
+ const std::string msg)
+ {
+ if (cond) fail(msg);
+ }
+
+ void
+ TestCase::assert_equals_delta(double x, double y, double epsilon,
+ const std::string msg)
+ {
+ if (! (-epsilon < x-y && epsilon > x-y) )
+ {
+ if (msg != "") fail(msg);
+ else
+ {
+ std::stringstream my_msg;
+ my_msg << "assert_equals_delta failed: "
+ << x << " - " << y << " = " << x - y
+ << "; epsilon was " << epsilon << ".";
+ fail(my_msg.str());
+ }
+ }
+ }
+
+ void
+ TestCase::assert_equals(float, float, const std::string)
+ {
+ error("Called assert_equals with two float arguments.");
+ }
+
+ void
+ TestCase::assert_equals(double, double, const std::string)
+ {
+ error("Called assert_equals with two double arguments.");
+ }
+
}
Index: TestCmd.cc
===================================================================
RCS file: /cvs/fresco/Fresco/Fresco-Test/syunit-c++/src/TestCmd.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- TestCmd.cc 19 Feb 2003 20:40:16 -0000 1.2
+++ TestCmd.cc 20 May 2003 09:06:27 -0000 1.3
@@ -6,117 +6,117 @@
namespace SyUnit
{
-
-TestCmd::TestCmd(char argc, char** argv)
- : my_exec_name(argv[0]),
- my_action(INVALID),
- my_test_name(),
- my_tests()
-{
- if (argc == 1)
- {
- usage();
- exit(1);
- }
- if (!strcmp(argv[1], "run"))
- {
- my_action = RUN;
- if (argc == 2) my_test_name = "all";
- else if (argc == 3) my_test_name = argv[2];
- else
- {
- std::cerr << "Too many arguments to \"run\".\n";
- usage();
- exit(1);
- }
- }
- else if (!strcmp(argv[1], "list"))
- {
- my_action = LIST;
- if (argc > 2)
- {
- std::cerr << "Too many arguments to \"list\".\n";
- usage();
- exit(1);
- }
- }
- else
- {
- std::cerr << "Unknown command \"" << argv[1] << "\"\n";
- usage();
- exit(1);
- }
-}
-
-TestCmd::~TestCmd()
-{
- std::map<const std::string, TestCaseWrapper*>::iterator i;
- for (i = my_tests.begin(); i != my_tests.end(); i++)
- {
- delete(i->second);
- }
-}
-
-// This takes ownership of the passed in TestCaseWrapper
-void
-TestCmd::add(TestCaseWrapper* test)
-{
- if (!my_tests.count(test->name()))
+
+ TestCmd::TestCmd(char argc, char** argv)
+ : my_exec_name(argv[0]),
+ my_action(INVALID),
+ my_test_name(),
+ my_tests()
{
- my_tests[test->name()] = test;
+ if (argc == 1)
+ {
+ usage();
+ exit(1);
+ }
+ if (!strcmp(argv[1], "run"))
+ {
+ my_action = RUN;
+ if (argc == 2) my_test_name = "all";
+ else if (argc == 3) my_test_name = argv[2];
+ else
+ {
+ std::cerr << "Too many arguments to \"run\".\n";
+ usage();
+ exit(1);
+ }
+ }
+ else if (!strcmp(argv[1], "list"))
+ {
+ my_action = LIST;
+ if (argc > 2)
+ {
+ std::cerr << "Too many arguments to \"list\".\n";
+ usage();
+ exit(1);
+ }
+ }
+ else
+ {
+ std::cerr << "Unknown command \"" << argv[1] << "\"\n";
+ usage();
+ exit(1);
+ }
}
- else
+
+ TestCmd::~TestCmd()
{
- std::cerr << "Multiple tests registered under name "
- << test->name() << std::endl;
- exit(1);
+ std::map<const std::string, TestCaseWrapper*>::iterator i;
+ for (i = my_tests.begin(); i != my_tests.end(); i++)
+ {
+ delete(i->second);
+ }
}
-}
-int
-TestCmd::run()
-{
- std::map<const std::string, TestCaseWrapper*>::iterator i;
- if (my_action == LIST)
+ // This takes ownership of the passed in TestCaseWrapper
+ void
+ TestCmd::add(TestCaseWrapper* test)
{
- for (i = my_tests.begin(); i != my_tests.end(); i++)
- {
- std::cout << i->first << std::endl;
- }
+ if (!my_tests.count(test->name()))
+ {
+ my_tests[test->name()] = test;
+ }
+ else
+ {
+ std::cerr << "Multiple tests registered under name "
+ << test->name() << std::endl;
+ exit(1);
+ }
}
- else if (my_action == RUN)
+
+ int
+ TestCmd::run()
{
- if (my_test_name == "all")
- {
- bool first_time = true;
- for (i = my_tests.begin(); i != my_tests.end(); i++)
+ std::map<const std::string, TestCaseWrapper*>::iterator i;
+ if (my_action == LIST)
{
- if (first_time) first_time = false;
- else std::cout << "\n";
- std::cout << i->second->run();
+ for (i = my_tests.begin(); i != my_tests.end(); i++)
+ {
+ std::cout << i->first << std::endl;
+ }
}
- }
- else
- {
- std::cout << my_tests[my_test_name]->run();
- }
-
+ else if (my_action == RUN)
+ {
+ if (my_test_name == "all")
+ {
+ bool first_time = true;
+ for (i = my_tests.begin(); i != my_tests.end(); i++)
+ {
+ if (first_time) first_time = false;
+ else std::cout << "\n";
+ std::cout << i->second->run();
+ }
+ }
+ else
+ {
+ std::cout << my_tests[my_test_name]->run();
+ }
+
+ }
+ else
+ {
+ std::cerr << "Can't happen: invalid action in run()\n";
+ exit(1);
+ }
+ return 0;
}
- else
+
+ void
+ TestCmd::usage()
{
- std::cerr << "Can't happen: invalid action in run()\n";
- exit(1);
+ std::cerr << "Usage:" << std::endl
+ << " " << my_exec_name << " list" << std::endl
+ << " " << my_exec_name << " run <test name>" << std::endl
+ << " " << my_exec_name << " run [all]" << std::endl;
}
- return 0;
-}
-
-void
-TestCmd::usage()
-{
- std::cerr << "Usage:" << std::endl
- << " " << my_exec_name << " list" << std::endl
- << " " << my_exec_name << " run <test name>" << std::endl
- << " " << my_exec_name << " run [all]" << std::endl;
-}
-
+
}