From 60c986d2c38ee40f851cbbda58ed7abfbe168c5e Mon Sep 17 00:00:00 2001 From: LI Daobing Date: Thu, 23 May 2024 22:42:14 -0700 Subject: [PATCH] add more test --- src/iptux/UiModels.cpp | 2 -- src/iptux/UiModelsTest.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/iptux/UiModels.cpp b/src/iptux/UiModels.cpp index 34c0045d..aa8d6c67 100644 --- a/src/iptux/UiModels.cpp +++ b/src/iptux/UiModels.cpp @@ -667,8 +667,6 @@ static void InsertHeaderToBuffer(GtkTextBuffer* buffer, } } -#define OCCUPY_OBJECT 0x01 - /** * 插入图片到TextBuffer. * @param buffer text-buffer diff --git a/src/iptux/UiModelsTest.cpp b/src/iptux/UiModelsTest.cpp index d70fa2c1..f9684560 100644 --- a/src/iptux/UiModelsTest.cpp +++ b/src/iptux/UiModelsTest.cpp @@ -1,5 +1,6 @@ #include "gtest/gtest.h" +#include "iptux-utils/TestHelper.h" #include #include @@ -76,3 +77,38 @@ TEST(GroupInfo, GetHintAsMarkup) { "\nSignature:\nhello"); } + +static string igtk_text_get_all_text(GtkTextBuffer* buffer) { + GtkTextIter start, end; + gtk_text_buffer_get_start_iter(buffer, &start); + gtk_text_buffer_get_end_iter(buffer, &end); + char* s = gtk_text_buffer_get_slice(buffer, &start, &end, true); + string ret(s); + g_free(s); + return ret; +} + +TEST(GroupInfo, addMsgPara) { + PalInfo pal("127.0.0.1", 2425); + pal.setVersion("1_iptux"); + pal.setName("palname"); + PalInfo me("127.0.0.2", 2425); + PPalInfo cpal = make_shared(pal); + CPPalInfo cme = make_shared(me); + GroupInfo gi(cpal, cme, nullptr); + gi.buffer = gtk_text_buffer_new(nullptr); + + MsgPara msg(cpal); + msg.dtlist.push_back(ChipData("helloworld")); + + gi.addMsgPara(msg); + ASSERT_EQ(igtk_text_get_all_text(gi.buffer).substr(10), + " palname:\nhelloworld\n"); + + msg = MsgPara(cpal); + msg.dtlist.push_back( + ChipData(MessageContentType::PICTURE, testDataPath("iptux.png"))); + gi.addMsgPara(msg); + ASSERT_EQ(igtk_text_get_all_text(gi.buffer).substr(10), + " palname:\nhelloworld\n\xEF\xBF\xBC"); +}