aboutsummaryrefslogtreecommitdiffstats
path: root/unittest.cpp
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2014-04-15 03:02:48 +0900
committeripknHama <ipknhama@gmail.com>2014-04-15 03:02:48 +0900
commitb69a40c15b1f947acdb7f8dcfdd25a4fc3685339 (patch)
treeeacde7671fd5913192c5ac99853ac554b3988eac /unittest.cpp
parent86346f211fc5ae49767656883bbf9483e11da46e (diff)
downloadcrow-b69a40c15b1f947acdb7f8dcfdd25a4fc3685339.tar.gz
crow-b69a40c15b1f947acdb7f8dcfdd25a4fc3685339.zip
preparing unittest, assert on handler with void return type
Diffstat (limited to 'unittest.cpp')
-rw-r--r--unittest.cpp62
1 files changed, 58 insertions, 4 deletions
diff --git a/unittest.cpp b/unittest.cpp
index eaf4466..5bdd911 100644
--- a/unittest.cpp
+++ b/unittest.cpp
@@ -1,10 +1,64 @@
#include <iostream>
+#include <vector>
+#include "routing.h"
using namespace std;
+using namespace flask;
+
+struct Test { Test(); virtual void test() = 0; };
+vector<Test*> tests;
+Test::Test() { tests.push_back(this); }
+
+bool failed__ = false;
+void fail() { failed__ = true; }
+
+#define TEST(x) struct test##x:public Test{void test();}x##_; \
+ void test##x::test()
+
+TEST(Rule)
+{
+ Rule r("/http/");
+ r.name("abc");
+ try
+ {
+ r.validate();
+ fail();
+ }
+ catch(runtime_error& e)
+ {
+ }
+
+ int x = 0;
+
+ r([&x]{x = 1;return "";});
+ r.validate();
+ if (x!=0)
+ fail();
+ r.handle(request(), routing_params());
+ if (x == 0)
+ fail();
+
+}
+
+int testmain()
+{
+ bool failed = false;
+ for(auto t:tests)
+ {
+ failed__ = false;
+ t->test();
+ if (failed__)
+ {
+ cerr << "F";
+ failed = true;
+ }
+ else
+ cerr << ".";
+ }
+ cerr<<endl;
+ return failed ? -1 : 0;
+}
int main()
{
- //cout << strtol("+123999999999999999999", NULL, 10) <<endl;
- //cout <<errno <<endl;
- cout << strtol("+9223372036854775807", NULL, 10) <<endl;
- cout <<errno <<endl;
+ return testmain();
}