mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Squashed 'src/cpp/websocketpp/' content from commit 1ec36a4
git-subtree-dir: src/cpp/websocketpp git-subtree-split: 1ec36a47468a23f01754fa3a086874e13a4d52d9
This commit is contained in:
29
test/basic/Makefile
Normal file
29
test/basic/Makefile
Normal file
@@ -0,0 +1,29 @@
|
||||
BOOST_LIB_PATH ?= /usr/local/lib
|
||||
BOOST_INCLUDE_PATH ?= /usr/local/include
|
||||
|
||||
CFLAGS = -O2 -I$(BOOST_INCLUDE_PATH)
|
||||
LDFLAGS = -L$(BOOST_LIB_PATH)
|
||||
|
||||
CXX ?= c++
|
||||
SHARED ?= "1"
|
||||
|
||||
ifeq ($(SHARED), 1)
|
||||
LDFLAGS := $(LDFLAGS) -lboost_system -lboost_date_time -lboost_regex -lboost_unit_test_framework -lwebsocketpp
|
||||
else
|
||||
LDFLAGS := $(LDFLAGS) $(BOOST_LIB_PATH)/libboost_system.a $(BOOST_LIB_PATH)/libboost_date_time.a $(BOOST_LIB_PATH)/libboost_regex.a $(BOOST_LIB_PATH)/libboost_unit_test_framework.a ../../libwebsocketpp.a
|
||||
endif
|
||||
|
||||
tests: hybi_util.cpp
|
||||
$(CXX) $(CFLAGS) $^ -o $@ $(LDFLAGS)
|
||||
|
||||
perf: uri_perf.cpp
|
||||
$(CXX) $(CFLAGS) $^ -o $@ $(LDFLAGS)
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CFLAGS) -o $@ $^
|
||||
|
||||
# cleanup by removing generated files
|
||||
#
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f *.o tests
|
||||
98
test/basic/hybi_util.cpp
Normal file
98
test/basic/hybi_util.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the WebSocket++ Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE hybi_util
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../../src/processors/hybi_util.hpp"
|
||||
#include "../../src/network_utilities.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_CASE( circshift_0 ) {
|
||||
if (sizeof(size_t) == 8) {
|
||||
size_t test = 0x0123456789abcdef;
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,0);
|
||||
|
||||
BOOST_CHECK( test == 0x0123456789abcdef);
|
||||
} else {
|
||||
size_t test = 0x01234567;
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,0);
|
||||
|
||||
BOOST_CHECK( test == 0x01234567);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( circshift_1 ) {
|
||||
if (sizeof(size_t) == 8) {
|
||||
size_t test = 0x0123456789abcdef;
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,1);
|
||||
|
||||
BOOST_CHECK( test == 0xef0123456789abcd);
|
||||
} else {
|
||||
size_t test = 0x01234567;
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,1);
|
||||
|
||||
BOOST_CHECK( test == 0x67012345);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( circshift_2 ) {
|
||||
if (sizeof(size_t) == 8) {
|
||||
size_t test = 0x0123456789abcdef;
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,2);
|
||||
|
||||
BOOST_CHECK( test == 0xcdef0123456789ab);
|
||||
} else {
|
||||
size_t test = 0x01234567;
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,2);
|
||||
|
||||
BOOST_CHECK( test == 0x45670123);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( circshift_3 ) {
|
||||
if (sizeof(size_t) == 8) {
|
||||
size_t test = 0x0123456789abcdef;
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,3);
|
||||
|
||||
BOOST_CHECK( test == 0xabcdef0123456789);
|
||||
} else {
|
||||
size_t test = 0x01234567;
|
||||
|
||||
test = websocketpp::processor::hybi_util::circshift_prepared_key(test,3);
|
||||
|
||||
BOOST_CHECK( test == 0x23456701);
|
||||
}
|
||||
}
|
||||
40
test/basic/logging.cpp
Normal file
40
test/basic/logging.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the WebSocket++ Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../src/logger/logger.hpp"
|
||||
|
||||
int main () {
|
||||
websocketpp::log::logger<websocketpp::log::elevel::value> log;
|
||||
|
||||
log.set_levels(websocketpp::log::elevel::DEVEL,websocketpp::log::elevel::ERROR);
|
||||
log.at(websocketpp::log::elevel::DEVEL) << "devel: " << 5 << websocketpp::log::endl;
|
||||
log.at(websocketpp::log::elevel::INFO) << "info: " << 5 << websocketpp::log::endl;
|
||||
log.at(websocketpp::log::elevel::WARN) << "warn: " << 5 << websocketpp::log::endl;
|
||||
log.at(websocketpp::log::elevel::ERROR) << "error: " << 5 << websocketpp::log::endl;
|
||||
log.at(websocketpp::log::elevel::FATAL) << "fatal: " << 5 << websocketpp::log::endl;
|
||||
|
||||
}
|
||||
312
test/basic/parsing.cpp
Normal file
312
test/basic/parsing.cpp
Normal file
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the WebSocket++ Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE uri
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../../src/uri.hpp"
|
||||
|
||||
// Test a regular valid ws URI
|
||||
BOOST_AUTO_TEST_CASE( uri_valid ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("ws://localhost:9000/chat");
|
||||
|
||||
BOOST_CHECK( uri.get_secure() == false );
|
||||
BOOST_CHECK( uri.get_host() == "localhost");
|
||||
BOOST_CHECK( uri.get_port() == 9000 );
|
||||
BOOST_CHECK( uri.get_resource() == "/chat" );
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false);
|
||||
}
|
||||
|
||||
// Test a regular valid ws URI
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_no_port_unsecure ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("ws://localhost/chat");
|
||||
|
||||
BOOST_CHECK( uri.get_secure() == false );
|
||||
BOOST_CHECK( uri.get_host() == "localhost");
|
||||
BOOST_CHECK( uri.get_port() == 80 );
|
||||
BOOST_CHECK( uri.get_resource() == "/chat" );
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Valid URI with no port (secure)
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_no_port_secure ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://localhost/chat");
|
||||
|
||||
BOOST_CHECK( uri.get_secure() == true );
|
||||
BOOST_CHECK( uri.get_host() == "localhost");
|
||||
BOOST_CHECK( uri.get_port() == 443 );
|
||||
BOOST_CHECK( uri.get_resource() == "/chat" );
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false);
|
||||
}
|
||||
|
||||
// Valid URI with no resource
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_no_resource ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://localhost:9000");
|
||||
|
||||
BOOST_CHECK( uri.get_secure() == true );
|
||||
BOOST_CHECK( uri.get_host() == "localhost");
|
||||
BOOST_CHECK( uri.get_port() == 9000 );
|
||||
BOOST_CHECK( uri.get_resource() == "/" );
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false);
|
||||
}
|
||||
|
||||
// Valid URI IPv6 Literal
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_ipv6_literal ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://[::1]:9000/chat");
|
||||
|
||||
BOOST_CHECK( uri.get_secure() == true );
|
||||
BOOST_CHECK( uri.get_host() == "::1");
|
||||
BOOST_CHECK( uri.get_port() == 9000 );
|
||||
BOOST_CHECK( uri.get_resource() == "/chat" );
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Valid URI with more complicated host
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_2 ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://thor-websocket.zaphoyd.net:88/");
|
||||
|
||||
BOOST_CHECK( uri.get_secure() == true );
|
||||
BOOST_CHECK( uri.get_host() == "thor-websocket.zaphoyd.net");
|
||||
BOOST_CHECK( uri.get_port() == 88 );
|
||||
BOOST_CHECK( uri.get_resource() == "/" );
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false);
|
||||
}
|
||||
|
||||
|
||||
// Invalid URI (port too long)
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_long_port ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://localhost:900000/chat");
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == true);
|
||||
}
|
||||
|
||||
// Invalid URI (http method)
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_http ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("http://localhost:9000/chat");
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == true);
|
||||
}
|
||||
|
||||
// Valid URI IPv4 literal
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_ipv4_literal ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://127.0.0.1:9000/chat");
|
||||
|
||||
BOOST_CHECK( uri.get_secure() == true );
|
||||
BOOST_CHECK( uri.get_host() == "127.0.0.1");
|
||||
BOOST_CHECK( uri.get_port() == 9000 );
|
||||
BOOST_CHECK( uri.get_resource() == "/chat" );
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false);
|
||||
}
|
||||
|
||||
// Valid URI complicated resource path
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_3 ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://localhost:9000/chat/foo/bar");
|
||||
|
||||
BOOST_CHECK( uri.get_secure() == true );
|
||||
BOOST_CHECK( uri.get_host() == "localhost");
|
||||
BOOST_CHECK( uri.get_port() == 9000 );
|
||||
BOOST_CHECK( uri.get_resource() == "/chat/foo/bar" );
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false);
|
||||
}
|
||||
|
||||
// Invalid URI broken method separator
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_method_separator ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss:/localhost:9000/chat");
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == true);
|
||||
}
|
||||
|
||||
// Invalid URI port > 65535
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_gt_16_bit_port ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss:/localhost:70000/chat");
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == true);
|
||||
}
|
||||
|
||||
// Invalid URI includes uri fragment
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_fragment ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss:/localhost:70000/chat#foo");
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == true);
|
||||
}
|
||||
|
||||
// Invalid URI with no brackets around IPv6 literal
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_bad_v6_literal_1 ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://::1/chat");
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == true);
|
||||
}
|
||||
|
||||
// Invalid URI with port and no brackets around IPv6 literal
|
||||
BOOST_AUTO_TEST_CASE( uri_invalid_bad_v6_literal_2 ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://::1:2009/chat");
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == true);
|
||||
}
|
||||
|
||||
// Valid URI complicated resource path with query
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_4 ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://localhost:9000/chat/foo/bar?foo=bar");
|
||||
|
||||
BOOST_CHECK( uri.get_secure() == true );
|
||||
BOOST_CHECK( uri.get_host() == "localhost");
|
||||
BOOST_CHECK( uri.get_port() == 9000 );
|
||||
BOOST_CHECK( uri.get_resource() == "/chat/foo/bar?foo=bar" );
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false);
|
||||
}
|
||||
|
||||
// Valid URI with a mapped v4 ipv6 literal
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_v4_mapped ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://[0000:0000:0000:0000:0000:0000:192.168.1.1]:9000/");
|
||||
|
||||
BOOST_CHECK( uri.get_secure() == true );
|
||||
BOOST_CHECK( uri.get_host() == "0000:0000:0000:0000:0000:0000:192.168.1.1");
|
||||
BOOST_CHECK( uri.get_port() == 9000 );
|
||||
BOOST_CHECK( uri.get_resource() == "/" );
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false);
|
||||
}
|
||||
|
||||
// Valid URI with a v6 address with mixed case
|
||||
BOOST_AUTO_TEST_CASE( uri_valid_v6_mixed_case ) {
|
||||
bool exception = false;
|
||||
try {
|
||||
websocketpp::uri uri("wss://[::10aB]:9000/");
|
||||
|
||||
BOOST_CHECK( uri.get_secure() == true );
|
||||
BOOST_CHECK( uri.get_host() == "::10aB");
|
||||
BOOST_CHECK( uri.get_port() == 9000 );
|
||||
BOOST_CHECK( uri.get_resource() == "/" );
|
||||
} catch (websocketpp::uri_exception& e) {
|
||||
exception = true;
|
||||
}
|
||||
|
||||
BOOST_CHECK( exception == false);
|
||||
}
|
||||
|
||||
// TODO: tests for the other two constructors
|
||||
51
test/basic/uri_perf.cpp
Normal file
51
test/basic/uri_perf.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the WebSocket++ Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
#include <boost/date_time.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../../src/uri.hpp"
|
||||
|
||||
int main() {
|
||||
boost::posix_time::ptime start = boost::posix_time::microsec_clock::local_time();
|
||||
|
||||
long m = 100000;
|
||||
long n = 3;
|
||||
|
||||
for (long i = 0; i < m; i++) {
|
||||
websocketpp::uri uri1("wss://thor-websocket.zaphoyd.net:9002/foo/bar/baz?a=b&c=d");
|
||||
websocketpp::uri uri2("ws://[::1]");
|
||||
websocketpp::uri uri3("ws://localhost:9000/chat");
|
||||
}
|
||||
boost::posix_time::ptime end = boost::posix_time::microsec_clock::local_time();
|
||||
boost::posix_time::time_period period(start,end);
|
||||
int ms = period.length().total_milliseconds();
|
||||
|
||||
std::cout << "Created " << m*n << " URIs in " << ms << "ms" << " (" << (m*n)/(ms/1000.0) << "/s)" << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user