mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 03:26:01 +00:00
WebSocket refactoring and tests:
websocket:
* Move echo server to test/
* Fix warnings
* Fix maskgen being uncopyable
* Simplify utf8_checker special member declarations
* Fix stream move assignable when owning the next layer
* Add javadocs for stream special members
* Add stream unit tests
* Move throwing member definitions to the .ipp file
* Use get_lowest_layer in stream declaration
* Perform type checks at each call site instead of constructor
* Demote close_code to a non-class enum:
Otherwise, application specific close codes
cannot be assigned without using static_cast.
core:
* Add streambuf_readstream special members tests
* Add move assignment operator to streambuf_readstream
* Add detail/get_lowest_layer trait
* Add static_string tests
* Move static_string from websocket to core
This commit is contained in:
191
test/static_string.cpp
Normal file
191
test/static_string.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
// Test that header file is self-contained.
|
||||
#include <beast/static_string.hpp>
|
||||
|
||||
#include <beast/detail/unit_test/suite.hpp>
|
||||
|
||||
namespace beast {
|
||||
namespace websocket {
|
||||
|
||||
class static_string_test : public beast::detail::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void testMembers()
|
||||
{
|
||||
using str1 = static_string<1>;
|
||||
using str2 = static_string<2>;
|
||||
{
|
||||
str1 s1;
|
||||
expect(s1 == "");
|
||||
expect(s1.empty());
|
||||
expect(s1.size() == 0);
|
||||
expect(s1.max_size() == 1);
|
||||
expect(s1.capacity() == 1);
|
||||
expect(s1.begin() == s1.end());
|
||||
expect(s1.cbegin() == s1.cend());
|
||||
expect(s1.rbegin() == s1.rend());
|
||||
expect(s1.crbegin() == s1.crend());
|
||||
try
|
||||
{
|
||||
expect(s1.at(0) == 0);
|
||||
fail();
|
||||
}
|
||||
catch(std::exception const&)
|
||||
{
|
||||
pass();
|
||||
}
|
||||
expect(s1.data()[0] == 0);
|
||||
expect(*s1.c_str() == 0);
|
||||
expect(std::distance(s1.begin(), s1.end()) == 0);
|
||||
expect(std::distance(s1.cbegin(), s1.cend()) == 0);
|
||||
expect(std::distance(s1.rbegin(), s1.rend()) == 0);
|
||||
expect(std::distance(s1.crbegin(), s1.crend()) == 0);
|
||||
expect(s1.compare(s1) == 0);
|
||||
expect(s1.to_string() == std::string{});
|
||||
}
|
||||
{
|
||||
str1 const s1;
|
||||
expect(s1 == "");
|
||||
expect(s1.empty());
|
||||
expect(s1.size() == 0);
|
||||
expect(s1.max_size() == 1);
|
||||
expect(s1.capacity() == 1);
|
||||
expect(s1.begin() == s1.end());
|
||||
expect(s1.cbegin() == s1.cend());
|
||||
expect(s1.rbegin() == s1.rend());
|
||||
expect(s1.crbegin() == s1.crend());
|
||||
try
|
||||
{
|
||||
expect(s1.at(0) == 0);
|
||||
fail();
|
||||
}
|
||||
catch(std::exception const&)
|
||||
{
|
||||
pass();
|
||||
}
|
||||
expect(s1.data()[0] == 0);
|
||||
expect(*s1.c_str() == 0);
|
||||
expect(std::distance(s1.begin(), s1.end()) == 0);
|
||||
expect(std::distance(s1.cbegin(), s1.cend()) == 0);
|
||||
expect(std::distance(s1.rbegin(), s1.rend()) == 0);
|
||||
expect(std::distance(s1.crbegin(), s1.crend()) == 0);
|
||||
expect(s1.compare(s1) == 0);
|
||||
expect(s1.to_string() == std::string{});
|
||||
}
|
||||
{
|
||||
str1 s1;
|
||||
str1 s2("x");
|
||||
expect(s2 == "x");
|
||||
expect(s2[0] == 'x');
|
||||
expect(s2.at(0) == 'x');
|
||||
expect(s2.front() == 'x');
|
||||
expect(s2.back() == 'x');
|
||||
str1 const s3(s2);
|
||||
expect(s3 == "x");
|
||||
expect(s3[0] == 'x');
|
||||
expect(s3.at(0) == 'x');
|
||||
expect(s3.front() == 'x');
|
||||
expect(s3.back() == 'x');
|
||||
s2 = "y";
|
||||
expect(s2 == "y");
|
||||
s1 = s2;
|
||||
expect(s1 == "y");
|
||||
s1.clear();
|
||||
expect(s1.empty());
|
||||
expect(s1.size() == 0);
|
||||
}
|
||||
{
|
||||
str2 s1("x");
|
||||
str1 s2(s1);
|
||||
expect(s2 == "x");
|
||||
str1 s3;
|
||||
s3 = s2;
|
||||
expect(s3 == "x");
|
||||
s1 = "xy";
|
||||
expect(s1.size() == 2);
|
||||
expect(s1[0] == 'x');
|
||||
expect(s1[1] == 'y');
|
||||
expect(s1.at(0) == 'x');
|
||||
expect(s1.at(1) == 'y');
|
||||
expect(s1.front() == 'x');
|
||||
expect(s1.back() == 'y');
|
||||
auto const s4 = s1;
|
||||
expect(s4[0] == 'x');
|
||||
expect(s4[1] == 'y');
|
||||
expect(s4.at(0) == 'x');
|
||||
expect(s4.at(1) == 'y');
|
||||
expect(s4.front() == 'x');
|
||||
expect(s4.back() == 'y');
|
||||
try
|
||||
{
|
||||
s3 = s1;
|
||||
fail();
|
||||
}
|
||||
catch(std::exception const&)
|
||||
{
|
||||
pass();
|
||||
}
|
||||
try
|
||||
{
|
||||
str1 s5(s1);
|
||||
fail();
|
||||
}
|
||||
catch(std::exception const&)
|
||||
{
|
||||
pass();
|
||||
}
|
||||
}
|
||||
{
|
||||
str2 s1("x");
|
||||
str2 s2("x");
|
||||
expect(s1 == s2);
|
||||
expect(s1 <= s2);
|
||||
expect(s1 >= s2);
|
||||
expect(! (s1 < s2));
|
||||
expect(! (s1 > s2));
|
||||
expect(! (s1 != s2));
|
||||
}
|
||||
{
|
||||
str1 s1("x");
|
||||
str2 s2("x");
|
||||
expect(s1 == s2);
|
||||
expect(s1 <= s2);
|
||||
expect(s1 >= s2);
|
||||
expect(! (s1 < s2));
|
||||
expect(! (s1 > s2));
|
||||
expect(! (s1 != s2));
|
||||
}
|
||||
{
|
||||
str2 s("x");
|
||||
expect(s == "x");
|
||||
expect(s <= "x");
|
||||
expect(s >= "x");
|
||||
expect(! (s < "x"));
|
||||
expect(! (s > "x"));
|
||||
expect(! (s != "x"));
|
||||
expect("x" == s);
|
||||
expect("x" <= s);
|
||||
expect("x" >= s);
|
||||
expect(! ("x" < s));
|
||||
expect(! ("x" > s));
|
||||
expect(! ("x" != s));
|
||||
}
|
||||
pass();
|
||||
}
|
||||
|
||||
void run() override
|
||||
{
|
||||
testMembers();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(static_string,websocket,beast);
|
||||
|
||||
} // websocket
|
||||
} // beast
|
||||
Reference in New Issue
Block a user