aboutsummaryrefslogtreecommitdiff
path: root/tests/main.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-01-27 16:23:26 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-19 00:14:44 +0200
commit61c3ec1e6e8f26f6d1efc271794e791ecde8f1e2 (patch)
treeaaa7d7c88f20b5972cf85514ea5c5990ea1a6a9c /tests/main.cpp
parenta089da2e943ee4e0237a370b9372f232970c22b3 (diff)
Use rich text for messages
Diffstat (limited to 'tests/main.cpp')
-rw-r--r--tests/main.cpp36
1 files changed, 2 insertions, 34 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index 0fd291c..24cc74f 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -1,5 +1,5 @@
#include "../include/DynamicImage.hpp"
-#include <dchat/IncomingMessage.hpp>
+#include "../include/ChatMessage.hpp"
#include <stdio.h>
#include <vector>
#include <string.h>
@@ -20,38 +20,6 @@ static void requireEqualValues(int a, int b, const char *file, int line)
}
#define REQUIRE_EQUAL(a, b) do { requireEqualValues((a), (b), __FILE__, __LINE__); } while(0)
-static void applyRichText(Gtk::TextView *textView, const Glib::ustring &text)
-{
- auto buffer = textView->get_buffer();
- buffer->set_text("");
- Gtk::TextIter iter = buffer->get_iter_at_offset(0);
-
- dchat::parseIncomingMessage(text.data(), text.bytes(), [textView, &text, &iter, &buffer](dchat::IncomingMessagePart messagePart)
- {
- switch(messagePart.type)
- {
- case dchat::IncomingMessagePart::Type::TEXT:
- {
- iter = buffer->insert(iter, text.data() + messagePart.textRange.start, text.data() + messagePart.textRange.end);
- break;
- }
- case dchat::IncomingMessagePart::Type::EMOJI:
- {
- auto anchor = Gtk::TextChildAnchor::create();
- iter = buffer->insert_child_anchor(iter, anchor);
- auto image = Gtk::manage(new dchat::DynamicImage());
- image->url = text.substr(messagePart.textRange.start, messagePart.textRange.length());
- image->set_size_request(35, 35);
- textView->add_child_at_anchor(*image, anchor);
- break;
- }
- default:
- assert(false);
- break;
- }
- });
-}
-
static int testVisual(int argc, char **argv)
{
auto app = Gtk::Application::create(argc, argv, "dec05eba.dchat", Gio::APPLICATION_NON_UNIQUE);
@@ -67,7 +35,7 @@ static int testVisual(int argc, char **argv)
auto textView = Gtk::manage(new Gtk::TextView());
textView->set_size_request(640, 480);
textView->set_wrap_mode(Gtk::WRAP_WORD_CHAR);
- applyRichText(textView, "Hello world [emoji](https://discordemoji.com/assets/emoji/PeepoHide.png)[emoji](https://discordemoji.com/assets/emoji/PeepoHide.png)");
+ dchat::applyRichText(textView, "Hello world [emoji](https://discordemoji.com/assets/emoji/PeepoHide.png)[emoji](https://discordemoji.com/assets/emoji/PeepoHide.png)");
grid->attach(*textView, 0, 0, 1, 1);
window.show_all();