Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdf3c16c

Browse files
committed
Initial migration from Boost.Test to googletest
Squashed from a few (local) commits: * Migrate message_transform_test and utils_thread_pool tests to googletest * Simplify message testing, breaking it down to basics (construction, equality) * Add googletest to YCM config * Add the googletest dependency to CMakeLists.txt * Add googlemock and googletest submodules properly. * Add submodules for gtest and gmock
1 parent80ca426 commitdf3c16c

File tree

10 files changed

+139
-210
lines changed

10 files changed

+139
-210
lines changed

‎.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "deps/googletest"]
2+
path=deps/googletest
3+
url=https://github.com/google/googletest.git
4+
[submodule "deps/googlemock"]
5+
path=deps/googlemock
6+
url=https://github.com/google/googlemock.git

‎.ycm_extra_conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1',
3131
'-I',
3232
os.environ['BOOST_ROOT'],
33+
# add dependency to googletest and googlemock
34+
'-I','deps/googletest/googletest/include',
35+
'-I','deps/googletest/googlemock/include',
36+
3337
# Always enable debugging for the project when building for semantic
3438
# completion.
3539
'-DBOOST_NETWORK_DEBUG',

‎CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ if (Boost_FOUND)
9595
enable_testing()
9696
add_subdirectory(libs/network/src)
9797
if (CPP-NETLIB_BUILD_TESTS)
98+
add_subdirectory(deps/googletest)
9899
add_subdirectory(libs/network/test)
99100
endif (CPP-NETLIB_BUILD_TESTS)
100101
if (CPP-NETLIB_BUILD_EXPERIMENTS)

‎boost/network/message.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ struct basic_message {
101101
friendstructdetail::directive_base<Tag>;
102102
friendstructdetail::wrapper_base<Tag, basic_message<Tag> >;
103103

104+
// Define an equality operator that's only available via ADL.
105+
friendbooloperator==(basic_messageconst& l, basic_messageconst& r) {
106+
return l.headers_ == r.headers_ && l.source_ == r.source_ &&
107+
l.destination_ == r.destination_ && l.body_ == r.body_;
108+
}
109+
110+
// Define an inequality operator that's only available via ADL in terms of
111+
// equality defined above.
112+
friendbooloperator!=(basic_messageconst& l, basic_messageconst& r) {
113+
return !(l == r);
114+
}
115+
104116
mutable headers_container_type headers_;
105117
mutable string_type body_;
106118
mutable string_type source_;

‎deps/googlemock

Submodulegooglemock added atf7d03d2

‎deps/googletest

Submodulegoogletest added atddb8012

‎libs/network/test/CMakeLists.txt

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# Copyright (c) Dean Michael Berris 2010.
1+
# Copyright (c) Dean Michael Berris 2010.
2+
# Copyright 2015 Google, Inc.
23
# Distributed under the Boost Software License, Version 1.0.
3-
#(See accompanying file LICENSE_1_0.txt or copy at
4-
#http://www.boost.org/LICENSE_1_0.txt)
4+
# (See accompanying file LICENSE_1_0.txt or copy at
5+
# http://www.boost.org/LICENSE_1_0.txt)
56

6-
include_directories(${CPP-NETLIB_SOURCE_DIR})
7+
include_directories(${CPP-NETLIB_SOURCE_DIR}${gtest_SOURCE_DIR}/include)
78

89
add_subdirectory(uri)
910
add_subdirectory(http)
@@ -17,26 +18,28 @@ if (Boost_FOUND)
1718
# utils_base64_test -- turn on when ready.
1819
)
1920
foreach (test${TESTS})
20-
if (${CMAKE_CXX_COMPILER_ID}MATCHESGNU)
21-
set_source_files_properties(${test}.cpp
22-
PROPERTIESCOMPILE_FLAGS"-Wall")
23-
endif()
24-
add_executable(cpp-netlib-${test}${test}.cpp)
25-
add_dependencies(cpp-netlib-${test}cppnetlib-uri)
26-
target_link_libraries(cpp-netlib-${test}${Boost_LIBRARIES}${CMAKE_THREAD_LIBS_INIT}cppnetlib-uri)
27-
if (OPENSSL_FOUND)
28-
target_link_libraries(cpp-netlib-${test}${OPENSSL_LIBRARIES})
29-
endif()
30-
if (${CMAKE_CXX_COMPILER_ID}MATCHESGNUAND${CMAKE_SYSTEM_NAME}MATCHES"Windows")
31-
target_link_libraries(cpp-netlib-${test}ws2_32wsock32)
32-
endif()
33-
if (${CMAKE_SYSTEM_NAME}MATCHES"Linux")
34-
target_link_libraries(cpp-netlib-${test}rt)
35-
endif()
36-
set_target_properties(cpp-netlib-${test}
37-
PROPERTIESRUNTIME_OUTPUT_DIRECTORY${CPP-NETLIB_BINARY_DIR}/tests)
38-
add_test(cpp-netlib-${test}
39-
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test})
21+
if (${CMAKE_CXX_COMPILER_ID}MATCHESGNU)
22+
set_source_files_properties(${test}.cpp
23+
PROPERTIESCOMPILE_FLAGS"-Wall")
24+
endif()
25+
add_executable(cpp-netlib-${test}${test}.cpp)
26+
add_dependencies(cpp-netlib-${test}cppnetlib-uri)
27+
target_link_libraries(cpp-netlib-${test}
28+
${Boost_THREAD_LIBRARY}${Boost_SYSTEM_LIBRARY}
29+
${CMAKE_THREAD_LIBS_INIT}cppnetlib-urigtest_main)
30+
if (OPENSSL_FOUND)
31+
target_link_libraries(cpp-netlib-${test}${OPENSSL_LIBRARIES})
32+
endif()
33+
if (${CMAKE_CXX_COMPILER_ID}MATCHESGNUAND${CMAKE_SYSTEM_NAME}MATCHES"Windows")
34+
target_link_libraries(cpp-netlib-${test}ws2_32wsock32)
35+
endif()
36+
if (${CMAKE_SYSTEM_NAME}MATCHES"Linux")
37+
target_link_libraries(cpp-netlib-${test}rt)
38+
endif()
39+
set_target_properties(cpp-netlib-${test}
40+
PROPERTIESRUNTIME_OUTPUT_DIRECTORY${CPP-NETLIB_BINARY_DIR}/tests)
41+
add_test(cpp-netlib-${test}
42+
${CPP-NETLIB_BINARY_DIR}/tests/cpp-netlib-${test})
4043
endforeach (test)
4144

4245
# Also copy the server directory to the root of the build directory.

‎libs/network/test/message_test.cpp

Lines changed: 46 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,65 @@
11

2-
// Copyright Dean Michael Berris 2007.
2+
// Copyright Dean Michael Berris 2007.
3+
// Copyright 2015 Google, Inc.
34
// Distributed under the Boost Software License, Version 1.0.
4-
//(See accompanying file LICENSE_1_0.txt or copy at
5-
//http://www.boost.org/LICENSE_1_0.txt)
5+
// (See accompanying file LICENSE_1_0.txt or copy at
6+
// http://www.boost.org/LICENSE_1_0.txt)
67

7-
#defineBOOST_TEST_MODULE message test
8-
#include<boost/config/warning_disable.hpp>
9-
#include<boost/test/unit_test.hpp>
10-
#include<boost/network.hpp>
8+
// Migrated from using Boost.Test to using googletest instead.
9+
#include<gtest/gtest.h>
1110
#include<algorithm>
12-
#include<boost/mpl/list.hpp>
11+
#include<boost/network/include/message.hpp>
12+
#include<boost/network/message/directives.hpp>
1313

14-
usingnamespaceboost::network;
14+
namespace{
1515

16-
typedef boost::mpl::list<http::tags::http_default_8bit_tcp_resolve,
17-
http::tags::http_default_8bit_udp_resolve,
18-
http::tags::http_keepalive_8bit_tcp_resolve,
19-
http::tags::http_keepalive_8bit_udp_resolve,
20-
tags::default_string, tags::default_wstring> tag_types;
16+
namespacehttp= boost::network::http;
17+
namespacenetwork= boost::network;
2118

22-
structstring_header_name {
23-
static std::string string;
19+
template<classT>
20+
classMessageTest : public ::testing::Test {
2421
};
2522

26-
std::string string_header_name::string ="Header";
27-
28-
structwstring_header_name {
29-
static std::wstring string;
30-
};
31-
32-
std::wstring wstring_header_name::string =L"Header";
33-
34-
structstring_header_value {
35-
static std::string string;
36-
};
37-
38-
std::string string_header_value::string ="Value";
39-
40-
structwstring_header_value {
41-
static std::wstring string;
42-
};
43-
44-
std::wstring wstring_header_value::string =L"Value";
45-
46-
template<classTag>
47-
structheader_name : string_header_name {};
48-
49-
template<>
50-
structheader_name<tags::default_wstring> : wstring_header_name {};
51-
52-
template<classTag>
53-
structheader_value : string_header_value {};
54-
55-
template<>
56-
structheader_value<tags::default_wstring> : wstring_header_value {};
57-
58-
structstring_body_data {
59-
static std::string string;
60-
};
61-
62-
std::string string_body_data::string =
63-
"The quick brown fox jumps over the lazy dog.";
64-
65-
structwstring_body_data {
66-
static std::wstring string;
67-
};
68-
69-
std::wstring wstring_body_data::string =
70-
L"The quick brown fox jumps over the lazy dog.";
71-
72-
template<classTag>
73-
structbody_data : string_body_data {};
74-
75-
template<>
76-
structbody_data<tags::default_wstring> : wstring_body_data {};
77-
78-
structstring_source_data {
79-
static std::string string;
80-
};
81-
82-
std::string string_source_data::string ="Source";
83-
84-
structwstring_source_data {
85-
static std::wstring string;
86-
};
87-
88-
std::wstring wstring_source_data::string =L"Source";
89-
90-
template<classTag>
91-
structsource_data : string_source_data {};
92-
93-
template<>
94-
structsource_data<tags::default_wstring> : wstring_body_data {};
95-
96-
structstring_destination_data {
97-
static std::string string;
98-
};
99-
100-
std::string string_destination_data::string ="Destination";
101-
102-
structwstring_destination_data {
103-
static std::wstring string;
104-
};
105-
106-
std::wstring wstring_destination_data::string =L"Destination";
107-
108-
template<classTag>
109-
structdestination_data : string_destination_data {};
110-
111-
template<>
112-
structdestination_data<tags::default_wstring> : wstring_destination_data {};
23+
using TagTypes = ::testing::Types<http::tags::http_default_8bit_tcp_resolve,
24+
http::tags::http_default_8bit_udp_resolve,
25+
http::tags::http_keepalive_8bit_tcp_resolve,
26+
http::tags::http_keepalive_8bit_udp_resolve,
27+
network::tags::default_string>;
28+
TYPED_TEST_CASE(MessageTest, TagTypes);
29+
30+
TYPED_TEST(MessageTest, Constructors){
31+
network::basic_message<TypeParam> message;// default construction
32+
auto copy = message;// copy construction
33+
ASSERT_TRUE(copy == message);
34+
}
11335

114-
/**
115-
* Defines a set of template functions that can be used to test
116-
* generic code.
117-
*/
36+
TYPED_TEST(MessageTest, Equality) {
37+
// Create an original message.
38+
network::basic_message<TypeParam> message;
39+
message <<network::source("source") <<network::destination("destination")
40+
<<network::header("key","value") <<network::body("body");
11841

119-
BOOST_AUTO_TEST_CASE_TEMPLATE(copy_constructor_test, T, tag_types) {
120-
basic_message<T> instance;
121-
instance <<header(header_name<T>::string, header_value<T>::string);
122-
basic_message<T>copy(instance);
123-
BOOST_CHECK_EQUAL(headers(copy).count(header_name<T>::string),
124-
static_cast<std::size_t>(1));
125-
typename headers_range<basic_message<T> >::type range =
126-
headers(copy)[header_name<T>::string];
127-
BOOST_CHECK(boost::begin(range) !=boost::end(range));
128-
}
42+
// Create the identical message.
43+
network::basic_message<TypeParam> other;
44+
other <<network::source("source") <<network::destination("destination")
45+
<<network::header("key","value") <<network::body("body");
12946

130-
BOOST_AUTO_TEST_CASE_TEMPLATE(swap_test, T, tag_types) {
131-
basic_message<T> instance;
132-
instance <<header(header_name<T>::string, header_value<T>::string);
133-
basic_message<T> other;
134-
swap(instance, other);
135-
BOOST_CHECK_EQUAL(headers(instance).count(header_name<T>::string),
136-
static_cast<std::size_t>(0));
137-
BOOST_CHECK_EQUAL(headers(other).count(header_name<T>::string),
138-
static_cast<std::size_t>(1));
47+
ASSERT_TRUE(message == other);
13948
}
14049

141-
BOOST_AUTO_TEST_CASE_TEMPLATE(headers_directive_test, T, tag_types) {
142-
basic_message<T> instance;
143-
instance <<header(header_name<T>::string, header_value<T>::string);
144-
BOOST_CHECK_EQUAL(headers(instance).count(header_name<T>::string),
145-
static_cast<std::size_t>(1));
146-
typename headers_range<basic_message<T> >::type range =
147-
headers(instance)[header_name<T>::string];
148-
BOOST_CHECK(boost::begin(range) !=boost::end(range));
149-
}
50+
TYPED_TEST(MessageTest, Inequality) {
51+
// Create an original message.
52+
network::basic_message<TypeParam> message;
53+
message <<network::source("source") <<network::destination("destination")
54+
<<network::header("key","value") <<network::body("body");
15055

151-
BOOST_AUTO_TEST_CASE_TEMPLATE(body_directive_test, T, tag_types) {
152-
basic_message<T> instance;
153-
instance << ::boost::network::body(body_data<T>::string);
154-
typename string<T>::type body_string =body(instance);
155-
BOOST_CHECK(body_string == body_data<T>::string);
156-
}
56+
// Create a different message.
57+
network::basic_message<TypeParam> other;
58+
other <<network::source("source") <<network::destination("destination")
59+
<<network::header("key","value") <<network::body("different body!");
15760

158-
BOOST_AUTO_TEST_CASE_TEMPLATE(source_directive_test, T, tag_types) {
159-
basic_message<T> instance;
160-
instance << ::boost::network::source(source_data<T>::string);
161-
typename string<T>::type source_string =source(instance);
162-
BOOST_CHECK(source_string == source_data<T>::string);
61+
ASSERT_FALSE(message == other);
16362
}
16463

165-
BOOST_AUTO_TEST_CASE_TEMPLATE(destination_directive_test, T, tag_types) {
166-
basic_message<T> instance;
167-
instance <<destination(destination_data<T>::string);
168-
BOOST_CHECK(destination(instance) == destination_data<T>::string);
169-
}
64+
}// namespace
17065

171-
BOOST_AUTO_TEST_CASE_TEMPLATE(remove_header_directive_test, T, tag_types) {
172-
basic_message<T> instance;
173-
instance <<header(header_name<T>::string, header_value<T>::string)
174-
<<remove_header(header_name<T>::string);
175-
typename headers_range<basic_message<T> >::type range =headers(instance);
176-
BOOST_CHECK(boost::begin(range) ==boost::end(range));
177-
}
Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11

2-
// Copyright Dean Michael Berris 2007.
2+
// Copyright Dean Michael Berris 2007.
3+
// Copyright 2015, Google, Inc.
34
// Distributed under the Boost Software License, Version 1.0.
4-
//(See accompanying file LICENSE_1_0.txt or copy at
5-
//http://www.boost.org/LICENSE_1_0.txt)
5+
// (See accompanying file LICENSE_1_0.txt or copy at
6+
// http://www.boost.org/LICENSE_1_0.txt)
67

7-
#defineBOOST_TEST_MODULE message test
8-
#include<boost/config/warning_disable.hpp>
9-
#include<boost/test/unit_test.hpp>
10-
#include<boost/network/include/message.hpp>
8+
#include<gtest/gtest.h>
119
#include<algorithm>
10+
#include<boost/network/include/message.hpp>
1211

13-
BOOST_AUTO_TEST_CASE(message_transform_toupper) {
12+
TEST(MessageTransformTest, TransformToUpper) {
1413
usingnamespaceboost::network;
1514

1615
message msg;
1716
msg <<source("me");
18-
BOOST_CHECK_EQUAL(source(msg),"me");
17+
ASSERT_EQ("me",source(msg));
1918
msg <<transform(to_upper_, source_);
20-
BOOST_CHECK_EQUAL(source(msg),"ME");
19+
ASSERT_EQ("ME",source(msg));
2120
msg <<destination("you");
22-
BOOST_CHECK_EQUAL(destination(msg),"you");
21+
ASSERT_EQ("you",destination(msg));
2322
msg <<transform(to_upper_, destination_);
24-
BOOST_CHECK_EQUAL(destination(msg),"YOU");
23+
ASSERT_EQ("YOU",destination(msg));
2524
}
2625

27-
BOOST_AUTO_TEST_CASE(message_transform_tolower) {
26+
TEST(MessageTransformTest, TransformToLower) {
2827
usingnamespaceboost::network;
2928

3029
message msg;
3130
msg <<source("ME");
32-
BOOST_CHECK_EQUAL(source(msg),"ME");
31+
ASSERT_EQ("ME",source(msg));
3332
msg <<transform(to_lower_, source_);
34-
BOOST_CHECK_EQUAL(source(msg),"me");
33+
ASSERT_EQ("me",source(msg));
3534
msg <<destination("YOU");
36-
BOOST_CHECK_EQUAL(destination(msg),"YOU");
35+
ASSERT_EQ("YOU",destination(msg));
3736
msg <<transform(to_lower_, destination_);
38-
BOOST_CHECK_EQUAL(destination(msg),"you");
37+
ASSERT_EQ("you",destination(msg));
3938
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp