summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/tgbot/net/HttpParser.cpp9
-rw-r--r--test/tgbot/tools/StringTools.cpp10
-rw-r--r--test/utils.h45
3 files changed, 35 insertions, 29 deletions
diff --git a/test/tgbot/net/HttpParser.cpp b/test/tgbot/net/HttpParser.cpp
index 236eb90..9272736 100644
--- a/test/tgbot/net/HttpParser.cpp
+++ b/test/tgbot/net/HttpParser.cpp
@@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(generateRequest) {
"Content-Type: application/x-www-form-urlencoded\r\n"
"Content-Length: 49\r\n"
"\r\n"
- "email=test%40example.com&text=Hello%2c%20world%21";
+ "email=test%40example.com&text=Hello%2C%20world%21";
BOOST_CHECK_MESSAGE(t == e, diffS(t, e));
}
@@ -55,17 +55,18 @@ BOOST_AUTO_TEST_CASE(generateMultipartFormData) {
"\r\n"
"test@example.com\r\n"
"--" + boundary + "\r\n"
- "Content-Disposition: form-data; name=\"text\"\r\n"
+ "Content-Disposition: form-data; name=\"text\"; filename=\"\"\r\n"
"Content-Type: text/plain\r\n"
"\r\n"
- "Hello, world!\r\n";
+ "Hello, world!\r\n"
+ "--" + boundary + "--\r\n";
BOOST_CHECK_MESSAGE(t == e, diffS(t, e));
}
BOOST_AUTO_TEST_CASE(generateWwwFormUrlencoded) {
vector<HttpReqArg> args = { HttpReqArg("email", "test@example.com"), HttpReqArg("text", "Hello, world!") };
string t = HttpParser::getInstance().generateWwwFormUrlencoded(args);
- string e = "email=test%40example.com&text=Hello%2c%20world%21";
+ string e = "email=test%40example.com&text=Hello%2C%20world%21";
BOOST_CHECK_MESSAGE(t == e, diffS(t, e));
}
diff --git a/test/tgbot/tools/StringTools.cpp b/test/tgbot/tools/StringTools.cpp
index 453919c..81e469a 100644
--- a/test/tgbot/tools/StringTools.cpp
+++ b/test/tgbot/tools/StringTools.cpp
@@ -36,12 +36,18 @@ BOOST_AUTO_TEST_SUITE(tStringTools)
BOOST_AUTO_TEST_CASE(startsWith) {
BOOST_CHECK(StringTools::startsWith("abc123", "abc"));
- BOOST_CHECK(StringTools::startsWith("abc", "abc123"));
+ BOOST_CHECK(!StringTools::startsWith("abc123", "aac"));
+ BOOST_CHECK(!StringTools::startsWith("abc123", "Xabc"));
+ BOOST_CHECK(!StringTools::startsWith("abc123", "abcX"));
+ BOOST_CHECK(!StringTools::startsWith("abc", "abc123"));
}
BOOST_AUTO_TEST_CASE(endsWith) {
BOOST_CHECK(StringTools::endsWith("abc123", "123"));
- BOOST_CHECK(StringTools::endsWith("123", "abc123"));
+ BOOST_CHECK(!StringTools::endsWith("abc123", "113"));
+ BOOST_CHECK(!StringTools::endsWith("abc123", "X123"));
+ BOOST_CHECK(!StringTools::endsWith("abc123", "123X"));
+ BOOST_CHECK(!StringTools::endsWith("123", "abc123"));
}
BOOST_AUTO_TEST_CASE(split) {
diff --git a/test/utils.h b/test/utils.h
index abd2f07..93f64ff 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -29,30 +29,8 @@
#include <boost/lexical_cast.hpp>
-std::string diffS(const std::string& test, const std::string& expected) {
- std::vector<std::string> v1, v2;
- std::istringstream ss1(test);
- std::istringstream ss2(expected);
- std::string s1, s2;
- bool r1, r2;
- do {
- r1 = std::getline(ss1, s1) ? true : false;
- r2 = std::getline(ss2, s2) ? true : false;
- if (r1) {
- v1.push_back(s1);
- }
- if (r2) {
- v2.push_back(s2);
- }
- } while (r1 || r2);
- return "";
- //return diff(v1, v2, [](const std::string& item) {
- //return item;
- //});
-}
-
template<typename T>
-std::string diff(const T& test, const T& expected, std::string (*toStringFunc)(const typename T::value_type&)) {
+inline std::string diff(const T& test, const T& expected, std::string (*toStringFunc)(const typename T::value_type&)) {
std::string result;
result += "\n*** BEGIN *** Count: t=";
result += boost::lexical_cast<std::string>(test.size());
@@ -102,4 +80,25 @@ std::string diff(const T& test, const T& expected, std::string (*toStringFunc)(c
return result;
}
+inline std::string diffS(const std::string& test, const std::string& expected) {
+ std::vector<std::string> v1, v2;
+ std::istringstream ss1(test);
+ std::istringstream ss2(expected);
+ std::string s1, s2;
+ bool r1, r2;
+ do {
+ r1 = std::getline(ss1, s1) ? true : false;
+ r2 = std::getline(ss2, s2) ? true : false;
+ if (r1) {
+ v1.push_back(s1);
+ }
+ if (r2) {
+ v2.push_back(s2);
+ }
+ } while (r1 || r2);
+ return diff(v1, v2, [](const std::string& item) {
+ return item;
+ });
+}
+
#endif //TGBOT_UTILS_H