150 lines
4.4 KiB
C++
150 lines
4.4 KiB
C++
//
|
|
// Created by dongl on 23-5-4.
|
|
//
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
#include "works/db/po/PoJson.h"
|
|
#include "works/db/UserFriendsDB.h"
|
|
#include "works/db/UserDB.h"
|
|
#include "smtp/send_email.h"
|
|
#include "storage/Storage.h"
|
|
#include "IMDataPacket.h"
|
|
#include "template/MsgTemplate.h"
|
|
|
|
int main(int argc, char **argv) {
|
|
testing::InitGoogleTest(&argc, argv);
|
|
return RUN_ALL_TESTS();
|
|
}
|
|
|
|
TEST(JSON, MYSQL_TYPE_JSON) {
|
|
auto i = new PoJsonFriends();
|
|
std::string str = i->append(2725096176, 1, 100344, 1)->
|
|
append(783556037, 1, 1024255, 2)->to_string();
|
|
|
|
printf("%s", str.c_str());
|
|
}
|
|
|
|
|
|
TEST(add_friends, add_friends__Test) {
|
|
auto i = UserFriendsDB();
|
|
i.add_friends(2725096176, 783556037);
|
|
i.add_friends(2725096176, 2725096176);
|
|
i.add_friends(783556037, 783556037);
|
|
i.add_friends(783556037, 2725096176);
|
|
}
|
|
|
|
|
|
|
|
TEST(select_friends, select_friends_Test) {
|
|
auto i = UserFriendsDB();
|
|
i.select_friends_info(2725096176, 783556037);
|
|
}
|
|
|
|
TEST(select_friends_all, select_friends_Test) {
|
|
auto i = UserFriendsDB();
|
|
auto doc = i.select_friends_all_json(2725096176);
|
|
if (doc.has_value())
|
|
for (auto member = doc.value().MemberBegin(); member != doc.value().MemberEnd(); ++member) {
|
|
auto belong_grouping = member->value.GetObject().FindMember("belong_grouping");
|
|
auto add_time = member->value.GetObject().FindMember("add_time");
|
|
auto add_source = member->value.GetObject().FindMember("add_source");
|
|
printf("%s - %s:%d, %s:%d, %s:%d ", member->name.GetString(),
|
|
belong_grouping->name.GetString(), belong_grouping->value.GetInt(),
|
|
add_time->name.GetString(), add_time->value.GetInt(),
|
|
add_source->name.GetString(), add_source->value.GetInt());
|
|
}
|
|
}
|
|
|
|
TEST(fetch_account, fetch_account__Test) {
|
|
auto i = new UserDB();
|
|
if (i->fetch_account().has_value())
|
|
printf("%zu", i->fetch_account());
|
|
else
|
|
printf("号码池空");
|
|
}
|
|
|
|
TEST(bind_account_email, bind_account__Test) {
|
|
auto i = new UserDB();
|
|
printf("%d", i->bind_email(2725096176, "dongl@tholen.cn"));
|
|
}
|
|
|
|
TEST(bind_account_phone, bind_account__Test) {
|
|
auto i = new UserDB();
|
|
printf("%d", i->bind_phone(2725096176, "18900000000"));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// "smtp.163.com",
|
|
// "bxhuu1o1vvyviiij6w@163.com",
|
|
// "IWXVJLUPMVFCFOBX",
|
|
// "2725096176@qq.com",
|
|
// "这是你的IM验证码",
|
|
|
|
//"<center>\n"
|
|
// "<h2 style=\"background-color: #CCFFCC\"> 验证码: XP02EE </h2>\n"
|
|
//"</center>"
|
|
|
|
|
|
TEST(email_send, email_send__Test) {
|
|
send_email_def("2725096176@qq.com", "AAKXT4");
|
|
}
|
|
|
|
TEST(fecth_frinds, fecth_frinds_Test) {
|
|
auto i = UserFriendsDB();
|
|
auto document = i.select_friends_all_json(783556037);
|
|
|
|
if (document.has_value())
|
|
for (auto mem = document->MemberBegin(); mem != document->MemberEnd(); ++mem) {
|
|
printf("%s", mem->name.GetString());
|
|
}
|
|
}
|
|
|
|
TEST(select_friends_fdb, fecth_frinds_Test) {
|
|
auto i = UserFriendsDB();
|
|
auto user = i.select_user(2725096176);
|
|
printf("user.value().client_info; %s\n", user.value().client_info.c_str());
|
|
printf("user.value().client_info; %lu\n", user.value().account);
|
|
}
|
|
|
|
|
|
TEST(selsct_is_friend, fecth_frinds_Test) {
|
|
auto i = UserFriendsDB();
|
|
auto user = i.select_friend(2725096176, 783556037);
|
|
auto kk = i.select_add_type(1111111);
|
|
|
|
printf("1111111, %c\n", kk);
|
|
|
|
printf("2725096176, %b\n", user);
|
|
}
|
|
|
|
TEST (MP_IM_PUSH_MSG, MP_IM_PUSH_MSG_TEST) {
|
|
auto temp = new IMDataPacket(mp::MP_TYPE::MP_IM_PUSH_MSG, // 推消息数据包头
|
|
mp::MP_SUB_TYPE::MP_IM_TEXT, // 数据包体 消息类型
|
|
mp::MP_SUB_TYPE::MP_SESSION_FRIEND, // 数据包体 会话类型
|
|
1,
|
|
time(nullptr),
|
|
783556037,
|
|
"hello test msg!"
|
|
);
|
|
|
|
std::cout << temp->packet() << std::endl;
|
|
|
|
MSG::Storage* storage = new MSG::Storage("im_session", "chat");
|
|
|
|
StorageMsg* msg = new StorageMsg();
|
|
msg->msg_type = mp::MP_SUB_TYPE::MP_IM_TEXT;
|
|
msg->session_type = mp::MP_SUB_TYPE::MP_SESSION_FRIEND;
|
|
msg->message_id = 1;
|
|
msg->time = time(nullptr);
|
|
msg->account = 783556037;
|
|
msg->im_msg_data = "hello test msg!";
|
|
storage->push(msg);
|
|
|
|
sleep(10);
|
|
} |