summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Morozenkov <omorozenkov@gmail.com>2015-12-06 23:39:14 +0300
committerOleg Morozenkov <omorozenkov@gmail.com>2015-12-06 23:39:14 +0300
commite89d523a7ac895f9bb724f3fa504f49c978aa4df (patch)
tree6506007a111068c218eb63d329a56e31519c7379
parent6fd3160feba7dc1228221ff4c8626cad48406d06 (diff)
Some fixes. Closes #9, #10
-rw-r--r--README.md1
-rw-r--r--include/tgbot/Api.h38
-rw-r--r--include/tgbot/TgTypeParser.h5
-rw-r--r--include/tgbot/net/HttpParser.h1
-rw-r--r--include/tgbot/net/HttpServer.h2
-rw-r--r--include/tgbot/types/Chat.h22
-rw-r--r--include/tgbot/types/GenericChat.h49
-rw-r--r--include/tgbot/types/GroupChat.h50
-rw-r--r--include/tgbot/types/Message.h7
-rw-r--r--include/tgbot/types/User.h9
-rw-r--r--src/TgTypeParser.cpp64
-rw-r--r--test/tgbot/net/HttpParser.cpp12
-rw-r--r--test/tgbot/tools/StringTools.cpp4
-rw-r--r--test/utils.h9
14 files changed, 80 insertions, 193 deletions
diff --git a/README.md b/README.md
index a09a64e..1569ea4 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,7 @@
[![Join the chat at https://gitter.im/reo7sp/tgbot-cpp](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/reo7sp/tgbot-cpp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
&nbsp;
[![Flattr this](https://button.flattr.com/flattr-badge-large.png "Flattr this")](https://flattr.com/submit/auto?user_id=Reo_SP&url=https%3A%2F%2Fgithub.com%2Freo7sp%2Ftgbot-cpp)
+[![Donate using Yandex.Money](https://i.imgur.com/8Fi2DnS.png)](https://money.yandex.ru/to/410011554060830)
C++ library for Telegram bot API.
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index 0d32252..0f3c097 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -59,7 +59,7 @@ public:
/**
* Use this method to send text messages.
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param chatId Unique identifier for the target chat.
* @param text Text of the message to be sent.
* @param disableWebPagePreview Optional. Disables link previews for links in this message.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
@@ -70,7 +70,7 @@ public:
/**
* Use this method to forward messages of any kind.
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param chatId Unique identifier for the target chat.
* @param fromChatId Unique identifier for the chat where the original message was sent — User or GroupChat id.
* @param messageId Unique message identifier.
* @return On success, the sent message is returned.
@@ -79,7 +79,7 @@ public:
/**
* Use this method to send photos.
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param chatId Unique identifier for the target chat.
* @param photo Photo to send.
* @param caption Optional. Photo caption.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
@@ -90,8 +90,8 @@ public:
/**
* Use this method to send photos.
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
- * @param photoId Id of the photo that is already on the Telegram servers.
+ * @param chatId Unique identifier for the target chat.
+ * @param photo Photo to send. Id of the photo that is already on the Telegram servers.
* @param caption Optional. Photo caption.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
* @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
@@ -101,7 +101,7 @@ public:
/**
* Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document).
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param chatId Unique identifier for the target chat.
* @param audio Audio to send.
* @param duration Duration of sent audio in seconds.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
@@ -112,8 +112,8 @@ public:
/**
* Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Document).
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
- * @param audioId Id of the audio that is already on the Telegram servers.
+ * @param chatId Unique identifier for the target chat.
+ * @param audio Id of the audio that is already on the Telegram servers.
* @param duration Duration of sent audio in seconds.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
* @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
@@ -123,7 +123,7 @@ public:
/**
* Use this method to send general files.
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param chatId Unique identifier for the target chat.
* @param document Document to send.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
* @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
@@ -133,8 +133,8 @@ public:
/**
* Use this method to send general files.
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
- * @param documentId Id of the document that is already on the Telegram servers.
+ * @param chatId Unique identifier for the target chat.
+ * @param document Id of the document that is already on the Telegram servers.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
* @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
* @return On success, the sent message is returned.
@@ -143,7 +143,7 @@ public:
/**
* Use this method to send .webp stickers.
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param chatId Unique identifier for the target chat.
* @param sticker Sticker to send.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
* @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
@@ -153,8 +153,8 @@ public:
/**
* Use this method to send .webp stickers.
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
- * @param stickerId Id of the sticker that is already on the Telegram servers.
+ * @param chatId Unique identifier for the target chat.
+ * @param sticker Id of the sticker that is already on the Telegram servers.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
* @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
* @return On success, the sent message is returned.
@@ -163,7 +163,7 @@ public:
/**
* Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param chatId Unique identifier for the target chat.
* @param video Video to send.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
* @param replyMarkup Optional. Additional interface options. An object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
@@ -173,8 +173,8 @@ public:
/**
* Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
- * @param videoId Id of the video that is already on the Telegram servers.
+ * @param chatId Unique identifier for the target chat.
+ * @param video Id of the video that is already on the Telegram servers.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
* @param replyMarkup Optional. Additional interface options. A object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user.
* @return On success, the sent message is returned.
@@ -183,7 +183,7 @@ public:
/**
* Use this method to send point on the map.
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param chatId Unique identifier for the target chat.
* @param latitude Latitude of location.
* @param longitude Longitude of location.
* @param replyToMessageId Optional. If the message is a reply, ID of the original message.
@@ -196,7 +196,7 @@ public:
* Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).
* Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot.
* We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
- * @param chatId Unique identifier for the message recipient — User or GroupChat id.
+ * @param chatId Unique identifier for the target chat.
* @param action Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for location data.
*/
void sendChatAction(int32_t chatId, const std::string& action) const;
diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h
index 2da9685..670e35e 100644
--- a/include/tgbot/TgTypeParser.h
+++ b/include/tgbot/TgTypeParser.h
@@ -30,7 +30,6 @@
#include "tgbot/types/User.h"
#include "tgbot/types/Chat.h"
-#include "tgbot/types/GroupChat.h"
#include "tgbot/types/Message.h"
#include "tgbot/types/PhotoSize.h"
#include "tgbot/types/Audio.h"
@@ -63,8 +62,6 @@ public:
std::string parseChat(const Chat::Ptr& object) const;
User::Ptr parseJsonAndGetUser(const boost::property_tree::ptree& data) const;
std::string parseUser(const User::Ptr& object) const;
- GroupChat::Ptr parseJsonAndGetGroupChat(const boost::property_tree::ptree& data) const;
- std::string parseGroupChat(const GroupChat::Ptr& object) const;
Message::Ptr parseJsonAndGetMessage(const boost::property_tree::ptree& data) const;
std::string parseMessage(const Message::Ptr& object) const;
PhotoSize::Ptr parseJsonAndGetPhotoSize(const boost::property_tree::ptree& data) const;
@@ -91,8 +88,6 @@ public:
std::string parseReplyKeyboardHide(const ReplyKeyboardHide::Ptr& object) const;
ForceReply::Ptr parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const;
std::string parseForceReply(const ForceReply::Ptr& object) const;
- GenericChat::Ptr parseJsonAndGetGenericChat(const boost::property_tree::ptree& data) const;
- std::string parseGenericChat(const GenericChat::Ptr& object) const;
GenericReply::Ptr parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const;
std::string parseGenericReply(const GenericReply::Ptr& object) const;
diff --git a/include/tgbot/net/HttpParser.h b/include/tgbot/net/HttpParser.h
index 83068fb..ec4c077 100644
--- a/include/tgbot/net/HttpParser.h
+++ b/include/tgbot/net/HttpParser.h
@@ -25,6 +25,7 @@
#include <string>
#include <map>
+#include <vector>
#include "tgbot/net/Url.h"
#include "tgbot/net/HttpReqArg.h"
diff --git a/include/tgbot/net/HttpServer.h b/include/tgbot/net/HttpServer.h
index 888c0a8..164bd2b 100644
--- a/include/tgbot/net/HttpServer.h
+++ b/include/tgbot/net/HttpServer.h
@@ -80,7 +80,7 @@ protected:
data.reserve(10240);
socket->async_receive(data, [this]() {
std::map<std::string, std::string> headers;
- std::string body = HttpParser::parseResponse(data, headers);
+ std::string body = HttpParser::getInstance().parseResponse(data, headers);
socket->async_send(_handler(body, headers));
});
}
diff --git a/include/tgbot/types/Chat.h b/include/tgbot/types/Chat.h
index d05155c..9a109e7 100644
--- a/include/tgbot/types/Chat.h
+++ b/include/tgbot/types/Chat.h
@@ -26,25 +26,33 @@
#include <string>
#include <memory>
-#include "tgbot/types/GenericChat.h"
-
namespace TgBot {
/**
* This object represents a Telegram Chat
* @ingroup types
*/
-class Chat : public GenericChat {
+class Chat {
public:
typedef std::shared_ptr<Chat> Ptr;
/**
- * Type of chat : can be either
- * "private", "group", "supergroup,
- * or "channel"
+ * Enum of possible types of a chat.
+ */
+ enum class Type {
+ Private, Group, Supergroup, Channel
+ };
+
+ /**
+ * Unique identifier for this chat, not exceeding 1e13 by absolute value
+ */
+ int64_t id;
+
+ /**
+ * Type of chat: can be either "private", "group", "supergroup, or "channel".
*/
- std::string type;
+ Type type;
/**
* Optional. Title for channels and group chat
diff --git a/include/tgbot/types/GenericChat.h b/include/tgbot/types/GenericChat.h
deleted file mode 100644
index 2d91281..0000000
--- a/include/tgbot/types/GenericChat.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2015 Oleg Morozenkov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#ifndef TGBOT_CPP_GENERICCHAT_H
-#define TGBOT_CPP_GENERICCHAT_H
-
-#include <memory>
-
-namespace TgBot {
-
-/**
- * This abstract class is base of everything to which you can send a message.
- * @ingroup types
- */
-class GenericChat {
-
-public:
- typedef std::shared_ptr<GenericChat> Ptr;
-
- virtual ~GenericChat() { }
-
- /**
- * Unique identifier for this user, bot or group chat
- */
- int32_t id;
-};
-
-}
-
-#endif //TGBOT_CPP_GENERICCHAT_H
diff --git a/include/tgbot/types/GroupChat.h b/include/tgbot/types/GroupChat.h
deleted file mode 100644
index fedb7f0..0000000
--- a/include/tgbot/types/GroupChat.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2015 Oleg Morozenkov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#ifndef TGBOT_CPP_GROUPCHAT_H
-#define TGBOT_CPP_GROUPCHAT_H
-
-#include <string>
-#include <memory>
-
-#include "tgbot/types/GenericChat.h"
-
-namespace TgBot {
-
-/**
- * This object represents a group chat.
- * @ingroup types
- */
-class GroupChat : public GenericChat {
-
-public:
- typedef std::shared_ptr<GroupChat> Ptr;
-
- /**
- * Group name.
- */
- std::string title;
-};
-
-}
-
-#endif //TGBOT_CPP_GROUPCHAT_H
diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h
index 4185052..daedf03 100644
--- a/include/tgbot/types/Message.h
+++ b/include/tgbot/types/Message.h
@@ -29,7 +29,6 @@
#include "tgbot/types/Chat.h"
#include "tgbot/types/User.h"
-#include "tgbot/types/GenericChat.h"
#include "tgbot/types/Message.h"
#include "tgbot/types/Audio.h"
#include "tgbot/types/Document.h"
@@ -56,7 +55,7 @@ public:
int32_t messageId;
/**
- * Sender.
+ * Optional. Sender, can be empty for messages sent to channels.
*/
User::Ptr from;
@@ -66,9 +65,9 @@ public:
int32_t date;
/**
- * Chat.
+ * Conversation the message belongs to.
*/
- Chat::Ptr chat;
+ Chat::Ptr chat;
/**
* Optional. For forwarded messages, sender of the original message.
diff --git a/include/tgbot/types/User.h b/include/tgbot/types/User.h
index 99c7d12..420d355 100644
--- a/include/tgbot/types/User.h
+++ b/include/tgbot/types/User.h
@@ -26,20 +26,23 @@
#include <string>
#include <memory>
-#include "tgbot/types/GenericChat.h"
-
namespace TgBot {
/**
* This object represents a Telegram user or bot.
* @ingroup types
*/
-class User : public GenericChat {
+class User {
public:
typedef std::shared_ptr<User> Ptr;
/**
+ * Unique identifier for this user or bot.
+ */
+ int32_t id;
+
+ /**
* User‘s or bot’s first name.
*/
std::string firstName;
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index df80ca7..d84e2a1 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -35,7 +35,16 @@ TgTypeParser& TgTypeParser::getInstance() {
Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const {
Chat::Ptr result(new Chat);
result->id = data.get<int32_t>("id");
- result->type = data.get<string>("type");
+ string type = data.get<string>("type");
+ if (type == "private") {
+ result->type = Chat::Type::Private;
+ } else if (type == "group") {
+ result->type = Chat::Type::Group;
+ } else if (type == "supergroup") {
+ result->type = Chat::Type::Supergroup;
+ } else if (type == "channel") {
+ result->type = Chat::Type::Channel;
+ }
result->title = data.get("title", "");
result->username = data.get("username", "");
result->firstName = data.get<string>("first_name");
@@ -51,7 +60,15 @@ string TgTypeParser::parseChat(const Chat::Ptr& object) const {
string result;
result += '{';
appendToJson(result, "id", object->id);
- appendToJson(result, "type", object->type);
+ if (object->type == Chat::Type::Private) {
+ appendToJson(result, "type", "private");
+ } else if (object->type == Chat::Type::Group) {
+ appendToJson(result, "type", "group");
+ } else if (object->type == Chat::Type::Supergroup) {
+ appendToJson(result, "type", "supergroup");
+ } else if (object->type == Chat::Type::Channel) {
+ appendToJson(result, "type", "channel");
+ }
appendToJson(result, "title", object->title);
appendToJson(result, "username", object->username);
appendToJson(result, "first_name", object->firstName);
@@ -85,32 +102,12 @@ string TgTypeParser::parseUser(const User::Ptr& object) const {
return result;
}
-GroupChat::Ptr TgTypeParser::parseJsonAndGetGroupChat(const ptree& data) const {
- GroupChat::Ptr result(new GroupChat);
- result->id = data.get<int32_t>("id");
- result->title = data.get<string>("title");
- return result;
-}
-
-string TgTypeParser::parseGroupChat(const GroupChat::Ptr& object) const {
- if (!object) {
- return "";
- }
- string result;
- result += '{';
- appendToJson(result, "id", object->id);
- appendToJson(result, "title", object->title);
- result.erase(result.length() - 1);
- result += '}';
- return result;
-}
-
Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const {
Message::Ptr result(new Message);
result->messageId = data.get<int32_t>("message_id");
- result->from = parseJsonAndGetUser(data.find("from")->second);
+ result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from");
result->date = data.get<int32_t>("date");
- result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat");
+ result->chat = parseJsonAndGetChat(data.find("chat")->second);
result->forwardFrom = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "forward_from");
result->forwardDate = data.get("forward_date", 0);
result->replyToMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message");
@@ -459,25 +456,6 @@ std::string TgTypeParser::parseForceReply(const ForceReply::Ptr& object) const {
return result;
}
-GenericChat::Ptr TgTypeParser::parseJsonAndGetGenericChat(const ptree& data) const {
- if (data.find("first_name") == data.not_found()) {
- return static_pointer_cast<GenericChat>(parseJsonAndGetGroupChat(data));
- } else {
- return static_pointer_cast<GenericChat>(parseJsonAndGetUser(data));
- }
-}
-
-string TgTypeParser::parseGenericChat(const GenericChat::Ptr& object) const {
- if (!object) {
- return "";
- }
- if (dynamic_pointer_cast<User>(object) == nullptr) {
- return parseGroupChat(static_pointer_cast<GroupChat>(object));
- } else {
- return parseUser(static_pointer_cast<User>(object));
- }
-}
-
GenericReply::Ptr TgTypeParser::parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const {
if (data.find("force_reply") != data.not_found()) {
return static_pointer_cast<GenericReply>(parseJsonAndGetForceReply(data));
diff --git a/test/tgbot/net/HttpParser.cpp b/test/tgbot/net/HttpParser.cpp
index 362a13f..236eb90 100644
--- a/test/tgbot/net/HttpParser.cpp
+++ b/test/tgbot/net/HttpParser.cpp
@@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(generateRequest) {
"Content-Length: 49\r\n"
"\r\n"
"email=test%40example.com&text=Hello%2c%20world%21";
- BOOST_CHECK_MESSAGE(t == e, diff(t, e));
+ BOOST_CHECK_MESSAGE(t == e, diffS(t, e));
}
BOOST_AUTO_TEST_CASE(generateMultipartFormData) {
@@ -59,14 +59,14 @@ BOOST_AUTO_TEST_CASE(generateMultipartFormData) {
"Content-Type: text/plain\r\n"
"\r\n"
"Hello, world!\r\n";
- BOOST_CHECK_MESSAGE(t == e, diff(t, e));
+ 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";
- BOOST_CHECK_MESSAGE(t == e, diff(t, e));
+ BOOST_CHECK_MESSAGE(t == e, diffS(t, e));
}
BOOST_AUTO_TEST_CASE(generateResponse) {
@@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(generateResponse) {
"Content-Length: 8\r\n"
"\r\n"
"testdata";
- BOOST_CHECK_MESSAGE(t == e, diff(t, e));
+ BOOST_CHECK_MESSAGE(t == e, diffS(t, e));
}
BOOST_AUTO_TEST_CASE(parseRequest) {
@@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(parseRequest) {
};
string e = "testdata";
- BOOST_CHECK_MESSAGE(t == e, diff(t, e));
+ BOOST_CHECK_MESSAGE(t == e, diffS(t, e));
BOOST_CHECK_MESSAGE(tHeaders == eHeaders, diff(tHeaders, eHeaders, [](const pair<const string, string>& item) -> string {
return item.first + '=' + item.second;
}));
@@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(parseResponse) {
};
string e = "testdata";
- BOOST_CHECK_MESSAGE(t == e, diff(t, e));
+ BOOST_CHECK_MESSAGE(t == e, diffS(t, e));
BOOST_CHECK_MESSAGE(tHeaders == eHeaders, diff(tHeaders, eHeaders, [](const pair<const string, string>& item) -> string {
return item.first + '=' + item.second;
}));
diff --git a/test/tgbot/tools/StringTools.cpp b/test/tgbot/tools/StringTools.cpp
index 11f85af..86eb147 100644
--- a/test/tgbot/tools/StringTools.cpp
+++ b/test/tgbot/tools/StringTools.cpp
@@ -51,13 +51,13 @@ BOOST_AUTO_TEST_CASE(split) {
BOOST_AUTO_TEST_CASE(urlEncode) {
string t = StringTools::urlEncode("`1234567890-qwertyuiop[]\\asdfghjkl;'zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:ZXCVBNM<>? ");
string e = "%601234567890-qwertyuiop%5b%5d%5casdfghjkl%3b%27zxcvbnm%2c.%2f~%21%40%23%24%25%5e%26%2a%28%29_%2bQWERTYUIOP%7b%7d%7cASDFGHJKL%3aZXCVBNM%3c%3e%3f%20";
- BOOST_CHECK_MESSAGE(t == e, diff(t, e));
+ BOOST_CHECK_MESSAGE(t == e, diffS(t, e));
}
BOOST_AUTO_TEST_CASE(urlDecode) {
string t = StringTools::urlDecode("%601234567890-qwertyuiop%5b%5d%5casdfghjkl%3b%27zxcvbnm%2c.%2f~%21%40%23%24%25%5e%26%2a%28%29_%2bQWERTYUIOP%7b%7d%7cASDFGHJKL%3aZXCVBNM%3c%3e%3f%20");
string e = "`1234567890-qwertyuiop[]\\asdfghjkl;'zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:ZXCVBNM<>? ";
- BOOST_CHECK_MESSAGE(t == e, diff(t, e));
+ BOOST_CHECK_MESSAGE(t == e, diffS(t, e));
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/utils.h b/test/utils.h
index 31f9e25..abd2f07 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -29,7 +29,7 @@
#include <boost/lexical_cast.hpp>
-std::string diff(const std::string& test, const std::string& expected) {
+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);
@@ -45,9 +45,10 @@ std::string diff(const std::string& test, const std::string& expected) {
v2.push_back(s2);
}
} while (r1 || r2);
- diff(v1, v2, [](const std::string& item) -> std::string {
- return std::string(item);
- });
+ return "";
+ //return diff(v1, v2, [](const std::string& item) {
+ //return item;
+ //});
}
template<typename T>