Skip to content

Commit

Permalink
add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
lidaobing committed May 24, 2024
1 parent 312583c commit 60c986d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/iptux/UiModels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,6 @@ static void InsertHeaderToBuffer(GtkTextBuffer* buffer,
}
}

#define OCCUPY_OBJECT 0x01

/**
* 插入图片到TextBuffer.
* @param buffer text-buffer
Expand Down
36 changes: 36 additions & 0 deletions src/iptux/UiModelsTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "gtest/gtest.h"

#include "iptux-utils/TestHelper.h"
#include <memory>
#include <vector>

Expand Down Expand Up @@ -76,3 +77,38 @@ TEST(GroupInfo, GetHintAsMarkup) {
"\nSignature:\n<span foreground=\"#00FF00\" font_style=\"italic\" "
"size=\"smaller\">hello</span>");
}

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<PalInfo>(pal);
CPPalInfo cme = make_shared<PalInfo>(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");
}

0 comments on commit 60c986d

Please sign in to comment.