| 1 | // SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "wtmpparse.h" |
| 6 | |
| 7 | #include <stub.h> |
| 8 | |
| 9 | #include <QDebug> |
| 10 | |
| 11 | #include <gtest/gtest.h> |
| 12 | #include <string.h> |
| 13 | |
| 14 | TEST(wtmpparse_wtmp_open_UT, wtmpparse_wtmp_open_UT) |
| 15 | { |
| 16 | int result = wtmp_open(QString(WTMP_FILE).toLatin1().data()); |
| 17 | EXPECT_NE(result, -1); |
| 18 | } |
| 19 | |
| 20 | TEST(wtmpparse_wtmp_next_UT, wtmp_open_back_UT) |
| 21 | { |
| 22 | char fileName[]="test_test"; |
| 23 | int result = wtmp_open_back(fileName); |
| 24 | EXPECT_EQ(result, -1); |
| 25 | } |
| 26 | |
| 27 | TEST(wtmpparse_wtmp_next_UT, seek_end_UT) |
| 28 | { |
| 29 | int result = seek_end(); |
| 30 | EXPECT_EQ(result, 0); |
| 31 | } |
| 32 | |
| 33 | TEST(wtmpparse_wtmp_next_UT, wtmp_reload_back_UT) |
| 34 | { |
| 35 | int result = wtmp_reload_back(); |
| 36 | EXPECT_NE(result, 0); |
| 37 | } |
| 38 | |
| 39 | TEST(wtmpparse_wtmp_next_UT, wtmp_back_UT) |
| 40 | { |
| 41 | struct utmp *test = wtmp_back(); |
| 42 | EXPECT_EQ(test, nullptr); |
| 43 | } |
| 44 | |
| 45 | TEST(wtmpparse_wtmp_next_UT, show_end_time_UT) |
| 46 | { |
| 47 | // const char *endTime= show_end_time(233); |
| 48 | // EXPECT_NE(strlen(endTime), 0)<<"check the status after show_end_time(233)"; |
| 49 | |
| 50 | } |
| 51 | |
| 52 | TEST(wtmpparse_wtmp_next_UT, show_start_time_UT) |
| 53 | { |
| 54 | // const char * startTime= show_start_time(233); |
| 55 | // EXPECT_NE(strlen(startTime), 0)<<"check the status after show_start_time(233)"; |
| 56 | } |
| 57 | |
| 58 | TEST(wtmpparse_wtmp_next_UT, wtmpparse_wtmp_next_UT_001) |
| 59 | { |
| 60 | utmp *tmp=wtmp_next(); |
| 61 | EXPECT_EQ(fdWtmp, -1)<<"check the status after wtmp_next()"; |
| 62 | EXPECT_EQ(tmp, nullptr)<<"check the status after wtmp_next()"; |
| 63 | } |
| 64 | |
| 65 | TEST(wtmpparse_wtmp_close_UT, wtmpparse_wtmp_close_UT_001) |
| 66 | { |
| 67 | int result = wtmp_open(QString(WTMP_FILE).toLatin1().data()); |
| 68 | EXPECT_NE(result, -1); |
| 69 | wtmp_close(); |
| 70 | } |
| 71 | |
| 72 | TEST(wtmpparse_wtmp_close_UT, wtmpparse_wtmp_close_UT_002) |
| 73 | { |
| 74 | wtmp_close(); |
| 75 | EXPECT_EQ(fdWtmp, -1)<<"check the status after wtmp_close()"; |
| 76 | } |
| 77 | |
| 78 | TEST(wtmpparse_st_list_init_UT, wtmpparse_st_list_init_UT_001) |
| 79 | { |
| 80 | utmp_list *utmListPtr = st_list_init(); |
| 81 | EXPECT_EQ(utmListPtr->value.ut_type, 0)<<"check the status after st_list_init()"; |
| 82 | free(utmListPtr); |
| 83 | } |
| 84 | |
| 85 | TEST(wtmpparse_st_utmp_init_UT, wtmpparse_st_utmp_init_UT_001) |
| 86 | { |
| 87 | utmp *utmptr = st_utmp_init(); |
| 88 | EXPECT_EQ(utmptr->ut_type, 0)<<"check the status after st_utmp_init()"; |
| 89 | free(utmptr); |
| 90 | } |
| 91 | |
| 92 | TEST(wtmpparse_list_insert_UT, wtmpparse_list_insert_UT_001) |
| 93 | { |
| 94 | QList<utmp *> plist; |
| 95 | utmp *info = static_cast<utmp*>(malloc(sizeof(struct utmp))); |
| 96 | list_insert(plist, info); |
| 97 | EXPECT_EQ(plist.size(), 1); |
| 98 | free(info); |
| 99 | } |
| 100 | |
| 101 | TEST(wtmpparse_list_delete_UT, wtmpparse_list_delete_UT) |
| 102 | { |
| 103 | utmp_list *list = st_list_init(); |
| 104 | utmp info; |
| 105 | list->value = info; |
| 106 | utmp_list *list2 = st_list_init(); |
| 107 | |
| 108 | list2->value = info; |
| 109 | list->next = list2; |
| 110 | list= list_delete(list); |
| 111 | EXPECT_EQ(list, list2)<<"check the status after list_delete()"; |
| 112 | free(list2); |
| 113 | } |
| 114 | |
| 115 | TEST(wtmpparse_list_get_ele_and_del_UT, wtmpparse_list_get_ele_and_del_UT) |
| 116 | { |
| 117 | QList<utmp> list; |
| 118 | utmp info1; |
| 119 | strcpy(info1.ut_line, "test1"); |
| 120 | list.append(info1); |
| 121 | utmp info2; |
| 122 | strcpy(info2.ut_line, "test2"); |
| 123 | list.append(info2); |
| 124 | int result = -1; |
| 125 | |
| 126 | utmp info3 = list_get_ele_and_del(list, "test1", result); |
| 127 | qDebug() << "info3.ut_line" << info3.ut_line; |
| 128 | EXPECT_EQ(result, 0); |
| 129 | EXPECT_EQ(QString(info3.ut_line) == QString("test1"), true); |
| 130 | EXPECT_EQ(list.size(), 1); |
| 131 | } |
| 132 | |
| 133 | TEST(wtmpparse_show_base_info_UT, wtmpparse_show_base_info_UT) |
| 134 | { |
| 135 | utmp info1; |
| 136 | strcpy(info1.ut_line, "test"); |
| 137 | show_base_info(&info1); |
| 138 | EXPECT_NE(&info1, nullptr)<<"check the status after show_base_info()"; |
| 139 | } |