mirror of
https://github.com/CrowCpp/Crow.git
synced 2024-06-07 21:10:44 +00:00
update makefile, add more test
This commit is contained in:
parent
f8ee6d4dad
commit
dc50332033
8
Makefile
8
Makefile
@ -1,5 +1,5 @@
|
|||||||
all: covtest example
|
all: covtest example
|
||||||
example: example.cpp flask.h http_server.h http_connection.h parser.h http_response.h routing.h common.h
|
example: example.cpp flask.h http_server.h http_connection.h parser.h http_response.h routing.h common.h utility.h
|
||||||
g++ -Wall -g -O2 -std=c++11 -o example example.cpp http-parser/http_parser.c -pthread -lboost_system -lboost_thread -I http-parser/
|
g++ -Wall -g -O2 -std=c++11 -o example example.cpp http-parser/http_parser.c -pthread -lboost_system -lboost_thread -I http-parser/
|
||||||
|
|
||||||
test: covtest
|
test: covtest
|
||||||
@ -11,11 +11,11 @@ runtest: example
|
|||||||
pkill example
|
pkill example
|
||||||
|
|
||||||
unittest: unittest.cpp routing.h
|
unittest: unittest.cpp routing.h
|
||||||
g++ -Wall -g -O2 -std=c++11 -o unittest unittest.cpp
|
g++ -Wall -g -std=c++11 -o unittest unittest.cpp
|
||||||
./unittest
|
./unittest
|
||||||
|
|
||||||
covtest: unittest.cpp routing.h
|
covtest: unittest.cpp routing.h utility.h flask.h http_server.h http_connection.h parser.h http_response.h common.h
|
||||||
g++ -Wall -g -O2 -std=c++11 --coverage -o covtest unittest.cpp -fkeep-inline-functions -fno-default-inline -fno-inline-small-functions
|
g++ -Wall -g -std=c++11 -fno-default-inline -fno-inline-small-functions --coverage -o covtest unittest.cpp http-parser/http_parser.c -pthread -lboost_system -lboost_thread -I http-parser/
|
||||||
./covtest
|
./covtest
|
||||||
gcov -r unittest.cpp
|
gcov -r unittest.cpp
|
||||||
|
|
||||||
|
20
unittest.cpp
20
unittest.cpp
@ -2,6 +2,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "routing.h"
|
#include "routing.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
#include "flask.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace flask;
|
using namespace flask;
|
||||||
|
|
||||||
@ -60,6 +61,9 @@ TEST(Rule)
|
|||||||
|
|
||||||
TEST(ParameterTagging)
|
TEST(ParameterTagging)
|
||||||
{
|
{
|
||||||
|
static_assert(black_magic::is_valid("<int><int><int>"), "valid url");
|
||||||
|
static_assert(!black_magic::is_valid("<int><int<<int>"), "invalid url");
|
||||||
|
static_assert(!black_magic::is_valid("nt>"), "invalid url");
|
||||||
ASSERT_EQUAL(1, black_magic::get_parameter_tag("<int>"));
|
ASSERT_EQUAL(1, black_magic::get_parameter_tag("<int>"));
|
||||||
ASSERT_EQUAL(2, black_magic::get_parameter_tag("<uint>"));
|
ASSERT_EQUAL(2, black_magic::get_parameter_tag("<uint>"));
|
||||||
ASSERT_EQUAL(3, black_magic::get_parameter_tag("<float>"));
|
ASSERT_EQUAL(3, black_magic::get_parameter_tag("<float>"));
|
||||||
@ -72,13 +76,25 @@ TEST(ParameterTagging)
|
|||||||
ASSERT_EQUAL(6*6+6*3+2, black_magic::get_parameter_tag("<uint><double><int>"));
|
ASSERT_EQUAL(6*6+6*3+2, black_magic::get_parameter_tag("<uint><double><int>"));
|
||||||
|
|
||||||
// url definition parsed in compile time, build into *one number*, and given to template argument
|
// url definition parsed in compile time, build into *one number*, and given to template argument
|
||||||
static_assert(is_same<black_magic::S<uint64_t, double, int64_t>, black_magic::arguments<6*6+6*3+2>::type>::value, "tag to type container");
|
static_assert(std::is_same<black_magic::S<uint64_t, double, int64_t>, black_magic::arguments<6*6+6*3+2>::type>::value, "tag to type container");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(response)
|
TEST(simple_response_routing_params)
|
||||||
{
|
{
|
||||||
ASSERT_EQUAL(100, response(100).code);
|
ASSERT_EQUAL(100, response(100).code);
|
||||||
ASSERT_EQUAL(200, response("Hello there").code);
|
ASSERT_EQUAL(200, response("Hello there").code);
|
||||||
|
|
||||||
|
routing_params rp;
|
||||||
|
rp.int_params.push_back(1);
|
||||||
|
rp.int_params.push_back(5);
|
||||||
|
rp.uint_params.push_back(2);
|
||||||
|
rp.double_params.push_back(3);
|
||||||
|
rp.string_params.push_back("hello");
|
||||||
|
ASSERT_EQUAL(1, rp.get<int64_t>(0));
|
||||||
|
ASSERT_EQUAL(5, rp.get<int64_t>(1));
|
||||||
|
ASSERT_EQUAL(2, rp.get<uint64_t>(0));
|
||||||
|
ASSERT_EQUAL(3, rp.get<double>(0));
|
||||||
|
ASSERT_EQUAL("hello", rp.get<string>(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
int testmain()
|
int testmain()
|
||||||
|
@ -34,6 +34,9 @@ namespace flask
|
|||||||
return begin_;
|
return begin_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr const char* begin() const { return begin_; }
|
||||||
|
constexpr const char* end() const { return begin_ + size_; }
|
||||||
|
|
||||||
constexpr unsigned size() const {
|
constexpr unsigned size() const {
|
||||||
return size_;
|
return size_;
|
||||||
}
|
}
|
||||||
@ -59,11 +62,6 @@ namespace flask
|
|||||||
is_valid(s, i+1, f);
|
is_valid(s, i+1, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr int count(const_str s, unsigned i=0)
|
|
||||||
{
|
|
||||||
return i == s.size() ? 0 : s[i] == '<' ? 1+count(s,i+1) : count(s,i+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool is_equ_n(const_str a, unsigned ai, const_str b, unsigned bi, unsigned n)
|
constexpr bool is_equ_n(const_str a, unsigned ai, const_str b, unsigned bi, unsigned n)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user