From e70380e003ae28822a6b903193c9a699cc02c405 Mon Sep 17 00:00:00 2001 From: ipknHama Date: Thu, 7 Aug 2014 04:46:28 +0900 Subject: cmake update, added template test --- examples/CMakeLists.txt | 11 ++++++----- examples/example_test.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 examples/example_test.py (limited to 'examples') diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7313adf..24150f0 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,16 +4,17 @@ project (crow_examples) add_executable(example example.cpp) target_link_libraries(example crow) target_link_libraries(example ${Boost_LIBRARIES} ) -set_target_properties(example PROPERTIES COMPILE_FLAGS "-Wall -std=c++1y") +add_custom_command(OUTPUT example_test.py + COMMAND ${CMAKE_COMMAND} -E + copy ${PROJECT_SOURCE_DIR}/example_test.py ${CMAKE_CURRENT_BINARY_DIR}/example_test.py + DEPENDS ${PROJECT_SOURCE_DIR}/example_test.py + ) +add_custom_target(example_copy ALL DEPENDS example_test.py) add_executable(example_chat example_chat.cpp) target_link_libraries(example_chat crow) target_link_libraries(example_chat ${Boost_LIBRARIES} ) -set_target_properties(example_chat PROPERTIES COMPILE_FLAGS "-Wall -std=c++1y") -message(${CMAKE_CURRENT_BINARY_DIR}) -message(${PROJECT_SOURCE_DIR}) add_custom_command(OUTPUT example_chat.html - #TARGET example_chat COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/example_chat.html ${CMAKE_CURRENT_BINARY_DIR}/example_chat.html DEPENDS ${PROJECT_SOURCE_DIR}/example_chat.html diff --git a/examples/example_test.py b/examples/example_test.py new file mode 100644 index 0000000..e2bf651 --- /dev/null +++ b/examples/example_test.py @@ -0,0 +1,28 @@ +import urllib +assert "Hello World!" == urllib.urlopen('http://localhost:18080').read() +assert "About Crow example." == urllib.urlopen('http://localhost:18080/about').read() +assert 404 == urllib.urlopen('http://localhost:18080/list').getcode() +assert "3 bottles of beer!" == urllib.urlopen('http://localhost:18080/hello/3').read() +assert "100 bottles of beer!" == urllib.urlopen('http://localhost:18080/hello/100').read() +assert 400 == urllib.urlopen('http://localhost:18080/hello/500').getcode() +assert "3" == urllib.urlopen('http://localhost:18080/add_json', data='{"a":1,"b":2}').read() +assert "3" == urllib.urlopen('http://localhost:18080/add/1/2').read() + +# test persistent connection +import socket +import time +s = socket.socket() +s.connect(('localhost', 18080)) +for i in xrange(10): + s.send('''GET / HTTP/1.1 +Host: localhost\r\n\r\n'''); + assert 'Hello World!' in s.recv(1024) + +# test timeout +s = socket.socket() +s.connect(('localhost', 18080)) +print 'ERROR REQUEST' +s.send('''GET / HTTP/1.1 +hHhHHefhwjkefhklwejfklwejf +''') +print s.recv(1024) -- cgit v1.2.3-54-g00ecf