2014-04-14 15:31:51 +00:00
|
|
|
#include <iostream>
|
2014-04-14 18:02:48 +00:00
|
|
|
#include <vector>
|
|
|
|
#include "routing.h"
|
2014-04-14 15:31:51 +00:00
|
|
|
using namespace std;
|
2014-04-14 18:02:48 +00:00
|
|
|
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;
|
|
|
|
}
|
2014-04-02 16:38:08 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2014-04-14 18:02:48 +00:00
|
|
|
return testmain();
|
2014-04-02 16:38:08 +00:00
|
|
|
}
|