aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/unit++/unit++.cc
diff options
context:
space:
mode:
authorLaurent Richard <[email protected]>2004-10-07 11:02:31 +0000
committerLaurent Richard <[email protected]>2004-10-07 11:02:31 +0000
commit27fb7a5b96462dc22fff821789ad382804579b28 (patch)
tree90eff8fc95db9e9b1a32da52dc993da6a2cf2f77 /tests/lib/unit++/unit++.cc
parentAdded FLAG_PASSED message flag to indicate a forwarded message (used in maild... (diff)
downloadvmime-27fb7a5b96462dc22fff821789ad382804579b28.tar.gz
vmime-27fb7a5b96462dc22fff821789ad382804579b28.zip
New unit test system: Unit++.
Added test for header::getAllByName/Type
Diffstat (limited to 'tests/lib/unit++/unit++.cc')
-rw-r--r--tests/lib/unit++/unit++.cc93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/lib/unit++/unit++.cc b/tests/lib/unit++/unit++.cc
new file mode 100644
index 00000000..c7c13372
--- /dev/null
+++ b/tests/lib/unit++/unit++.cc
@@ -0,0 +1,93 @@
+// Copyright (C) 2001 Claus Dr�by
+// Terms of use are in the file COPYING
+#include <algorithm>
+#include <functional>
+#include "unit++.h"
+
+using namespace unitpp;
+using namespace std;
+
+#ifndef GUI
+gui_hook::gui_hook() { }
+#endif
+void test::visit(visitor* v)
+{
+ v->visit(*this);
+}
+testcase::testcase(test* t)
+: cnt(new size_t(1)), tst(t)
+{
+}
+testcase::testcase(const testcase& t)
+: cnt(t.cnt), tst(t.tst)
+{
+ (*cnt)++;
+}
+void testcase::dec_cnt()
+{
+ if (--(*cnt) == 0) {
+ delete cnt;
+ delete tst;
+ }
+}
+testcase::~testcase()
+{
+ dec_cnt();
+}
+testcase& testcase::operator=(const testcase& t)
+{
+ ++*(t.cnt);
+ dec_cnt();
+ cnt = t.cnt;
+ tst = t.tst;
+ return *this;
+}
+suite& suite::main()
+{
+ static suite instance("top");
+ return instance;
+}
+test* suite::get_child(const string& id)
+{
+ vector<string>::iterator p = std::find(ids.begin(), ids.end(), id);
+ if (p != ids.end())
+ return &(static_cast<test&>(tests[p - ids.begin()]));
+ return 0;
+}
+vector<string> unitpp::vectorize(const string& str, char c)
+{
+ vector<string> res;
+ string::const_iterator s, p;
+ for (s = str.begin(); s != str.end(); ) {
+ p = find(s, str.end(), c);
+ res.push_back(string(s, p));
+ s = (p == str.end()) ? p : p + 1;
+ }
+ return res;
+}
+test* suite::find(const string& id)
+{
+ vector<string> ss(vectorize(id, '.'));
+ test* tp = this;
+ for (vector<string>::iterator p = ss.begin(); p != ss.end(); ++p)
+ if (!(tp = tp->get_child(*p)))
+ break;
+ return tp;
+}
+void suite::add(const string& id, const testcase& t)
+{
+ ids.push_back(id);
+ tests.push_back(t);
+}
+void suite::visit(visitor* v)
+{
+ v->visit(*this);
+ for_each(tests.begin(), tests.end(),
+ bind2nd(mem_fun_ref(&testcase::visit), v));
+ v->visit(*this, 0);
+}
+
+void unitpp::assertion_error::out(ostream& os) const
+{
+ os << msg << string(" [assertion failed]");
+}