comparison tests/libcommon/util/main.cpp @ 46:b0593a3e2ca8

Server: use Boost.Asio and add basic authentication support
author David Demelier <markand@malikania.fr>
date Sun, 04 Dec 2016 21:26:18 +0100
parents f30c84b4b9ed
children 858621081b95
comparison
equal deleted inserted replaced
45:719b5457ea92 46:b0593a3e2ca8
54 { 54 {
55 BOOST_REQUIRE_EQUAL(10, util::clamp(20, 0, 10)); 55 BOOST_REQUIRE_EQUAL(10, util::clamp(20, 0, 10));
56 } 56 }
57 57
58 BOOST_AUTO_TEST_SUITE_END() 58 BOOST_AUTO_TEST_SUITE_END()
59
60 /*
61 * util::netsplit
62 * ------------------------------------------------------------------
63 */
64
65 BOOST_AUTO_TEST_SUITE(netsplit)
66
67 BOOST_AUTO_TEST_CASE(simple)
68 {
69 std::string input = "hello world\r\n\r\n";
70 std::vector<std::string> messages = util::netsplit(input);
71
72 BOOST_REQUIRE_EQUAL(1U, messages.size());
73 BOOST_REQUIRE_EQUAL("hello world", messages[0]);
74 BOOST_REQUIRE(input.empty());
75 }
76
77 BOOST_AUTO_TEST_CASE(two)
78 {
79 std::string input = "hello world\r\n\r\nhow are you?\r\n\r\n";
80 std::vector<std::string> messages = util::netsplit(input);
81
82 BOOST_REQUIRE_EQUAL(2U, messages.size());
83 BOOST_REQUIRE_EQUAL("hello world", messages[0]);
84 BOOST_REQUIRE_EQUAL("how are you?", messages[1]);
85 BOOST_REQUIRE(input.empty());
86 }
87
88 BOOST_AUTO_TEST_CASE(imcomplete)
89 {
90 std::string input = "hello world\r\n";
91 std::vector<std::string> messages = util::netsplit(input);
92
93 BOOST_REQUIRE_EQUAL(0U, messages.size());
94 BOOST_REQUIRE_EQUAL("hello world\r\n", input);
95 }
96
97 BOOST_AUTO_TEST_CASE(empty)
98 {
99 std::string input = "hello world\r\n\r\n\r\n\r\nhow are you?\r\n\r\n";
100 std::vector<std::string> messages = util::netsplit(input);
101
102 BOOST_REQUIRE_EQUAL(3U, messages.size());
103 BOOST_REQUIRE_EQUAL("hello world", messages[0]);
104 BOOST_REQUIRE(messages[1].empty());
105 BOOST_REQUIRE_EQUAL("how are you?", messages[2]);
106 BOOST_REQUIRE(input.empty());
107 }
108
109 BOOST_AUTO_TEST_SUITE_END()