fixed adding file problem
[c11concurrency-benchmarks.git] / gdax-orderbook-hpp / demo / dependencies / websocketpp-0.7.0 / test / logger / basic.cpp
1 /*
2  * Copyright (c) 2014, Peter Thorson. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above copyright
9  *       notice, this list of conditions and the following disclaimer in the
10  *       documentation and/or other materials provided with the distribution.
11  *     * Neither the name of the WebSocket++ Project nor the
12  *       names of its contributors may be used to endorse or promote products
13  *       derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 //#define BOOST_TEST_DYN_LINK
28 #define BOOST_TEST_MODULE basic_log
29 #include <boost/test/unit_test.hpp>
30
31 #include <string>
32
33 #include <websocketpp/logger/basic.hpp>
34 #include <websocketpp/concurrency/none.hpp>
35 #include <websocketpp/concurrency/basic.hpp>
36
37 typedef websocketpp::log::basic<websocketpp::concurrency::basic,websocketpp::log::alevel> basic_access_log_type;
38
39 BOOST_AUTO_TEST_CASE( is_token_char ) {
40     typedef websocketpp::log::basic<websocketpp::concurrency::none,websocketpp::log::elevel> error_log;
41
42     error_log elog;
43
44     BOOST_CHECK( elog.static_test(websocketpp::log::elevel::info ) == true );
45     BOOST_CHECK( elog.static_test(websocketpp::log::elevel::warn ) == true );
46     BOOST_CHECK( elog.static_test(websocketpp::log::elevel::rerror ) == true );
47     BOOST_CHECK( elog.static_test(websocketpp::log::elevel::fatal ) == true );
48
49     elog.set_channels(websocketpp::log::elevel::info);
50
51     elog.write(websocketpp::log::elevel::info,"Information");
52     elog.write(websocketpp::log::elevel::warn,"A warning");
53     elog.write(websocketpp::log::elevel::rerror,"A error");
54     elog.write(websocketpp::log::elevel::fatal,"A critical error");
55 }
56
57 BOOST_AUTO_TEST_CASE( access_clear ) {
58     typedef websocketpp::log::basic<websocketpp::concurrency::none,websocketpp::log::alevel> access_log;
59
60     std::stringstream out;
61     access_log logger(0xffffffff,&out);
62
63     // clear all channels
64     logger.clear_channels(0xffffffff);
65
66     // writes shouldn't happen
67     logger.write(websocketpp::log::alevel::devel,"devel");
68     //std::cout << "|" << out.str() << "|" << std::endl;
69     BOOST_CHECK( out.str().size() == 0 );
70 }
71
72 BOOST_AUTO_TEST_CASE( basic_concurrency ) {
73     typedef websocketpp::log::basic<websocketpp::concurrency::basic,websocketpp::log::alevel> access_log;
74
75     std::stringstream out;
76     access_log logger(0xffffffff,&out);
77
78     logger.set_channels(0xffffffff);
79
80     logger.write(websocketpp::log::alevel::devel,"devel");
81     //std::cout << "|" << out.str() << "|" << std::endl;
82     BOOST_CHECK( out.str().size() > 0 );
83 }
84
85
86 BOOST_AUTO_TEST_CASE( copy_constructor ) {
87     std::stringstream out;
88
89     basic_access_log_type logger1(0xffffffff,&out);
90     basic_access_log_type logger2(logger1);
91
92     logger2.set_channels(0xffffffff);
93     logger2.write(websocketpp::log::alevel::devel,"devel");
94     BOOST_CHECK( out.str().size() > 0 );
95 }
96
97 #ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
98 BOOST_AUTO_TEST_CASE( move_constructor ) {
99     std::stringstream out;
100
101     basic_access_log_type logger1(0xffffffff,&out);
102     basic_access_log_type logger2(std::move(logger1));
103
104     logger2.set_channels(0xffffffff);
105     logger2.write(websocketpp::log::alevel::devel,"devel");
106     BOOST_CHECK( out.str().size() > 0 );
107 }
108
109 // Emplace requires move assignment, which logger doesn't support right now
110 // due to const members. This is pretty irritating and will probably result in
111 // the const members being removed. For now though this test will fail to
112 // compile
113 /*BOOST_AUTO_TEST_CASE( emplace ) {
114     std::stringstream out1;
115     std::stringstream out2;
116
117     std::vector<basic_access_log_type> v;
118
119     v.emplace_back(websocketpp::log::level(0xffffffff),&out1);
120     v.emplace_back(websocketpp::log::level(0xffffffff),&out2);
121
122     v[0].set_channels(0xffffffff);
123     v[1].set_channels(0xffffffff);
124     v[0].write(websocketpp::log::alevel::devel,"devel");
125     v[1].write(websocketpp::log::alevel::devel,"devel");
126     BOOST_CHECK( out1.str().size() > 0 );
127     BOOST_CHECK( out2.str().size() > 0 );
128 }*/
129 #endif // #ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
130
131 // As long as there are const member variables these can't exist
132 // These remain commented as they are useful for testing the deleted operators
133 /*BOOST_AUTO_TEST_CASE( copy_assign ) {
134     basic_access_log_type logger1;
135     basic_access_log_type logger2;
136
137     logger2 = logger1;
138 }
139
140 BOOST_AUTO_TEST_CASE( move_assign ) {
141     basic_access_log_type logger1;
142     basic_access_log_type logger2;
143
144     logger2 = std::move(logger1);
145 }*/