mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-22 11:35:49 +00:00
Don't include unit test sources in code coverage (RIPD-1132):
Most files containing unit test code are moved to src/test. JTx and the test client code are not yet moved.
This commit is contained in:
103
src/test/basics/StringUtilities_test.cpp
Normal file
103
src/test/basics/StringUtilities_test.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/basics/Slice.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/basics/ToString.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class StringUtilities_test : public beast::unit_test::suite
|
||||
{
|
||||
public:
|
||||
void testUnHexSuccess (std::string const& strIn, std::string const& strExpected)
|
||||
{
|
||||
auto rv = strUnHex (strIn);
|
||||
BEAST_EXPECT(rv.second);
|
||||
BEAST_EXPECT(makeSlice(rv.first) == makeSlice(strExpected));
|
||||
}
|
||||
|
||||
void testUnHexFailure (std::string const& strIn)
|
||||
{
|
||||
auto rv = strUnHex (strIn);
|
||||
BEAST_EXPECT(! rv.second);
|
||||
BEAST_EXPECT(rv.first.empty());
|
||||
}
|
||||
|
||||
void testUnHex ()
|
||||
{
|
||||
testcase ("strUnHex");
|
||||
|
||||
testUnHexSuccess ("526970706c6544", "RippleD");
|
||||
testUnHexSuccess ("A", "\n");
|
||||
testUnHexSuccess ("0A", "\n");
|
||||
testUnHexSuccess ("D0A", "\r\n");
|
||||
testUnHexSuccess ("0D0A", "\r\n");
|
||||
testUnHexSuccess ("200D0A", " \r\n");
|
||||
testUnHexSuccess ("282A2B2C2D2E2F29", "(*+,-./)");
|
||||
|
||||
// Check for things which contain some or only invalid characters
|
||||
testUnHexFailure ("123X");
|
||||
testUnHexFailure ("V");
|
||||
testUnHexFailure ("XRP");
|
||||
}
|
||||
|
||||
void testParseUrl ()
|
||||
{
|
||||
testcase ("parseUrl");
|
||||
|
||||
std::string strScheme;
|
||||
std::string strDomain;
|
||||
int iPort;
|
||||
std::string strPath;
|
||||
|
||||
BEAST_EXPECT (parseUrl ("lower://domain", strScheme, strDomain, iPort, strPath));
|
||||
BEAST_EXPECT(strScheme == "lower");
|
||||
BEAST_EXPECT(strDomain == "domain");
|
||||
BEAST_EXPECT(iPort == -1);
|
||||
BEAST_EXPECT(strPath == "");
|
||||
BEAST_EXPECT(parseUrl ("UPPER://domain:234/", strScheme, strDomain, iPort, strPath));
|
||||
BEAST_EXPECT(strScheme == "upper");
|
||||
BEAST_EXPECT(iPort == 234);
|
||||
BEAST_EXPECT(strPath == "/");
|
||||
BEAST_EXPECT(parseUrl ("Mixed://domain/path", strScheme, strDomain, iPort, strPath));
|
||||
BEAST_EXPECT(strScheme == "mixed");
|
||||
BEAST_EXPECT(strPath == "/path");
|
||||
}
|
||||
|
||||
void testToString ()
|
||||
{
|
||||
testcase ("toString");
|
||||
auto result = to_string("hello");
|
||||
BEAST_EXPECT(result == "hello");
|
||||
}
|
||||
|
||||
void run ()
|
||||
{
|
||||
testParseUrl ();
|
||||
testUnHex ();
|
||||
testToString ();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(StringUtilities, ripple_basics, ripple);
|
||||
|
||||
} // ripple
|
||||
Reference in New Issue
Block a user