1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

chore(cleanup): Minor cleanup to contact management test

* Fix compile error on macOS by marking GroupWidget::widgetIsVisible as
override
* Mark mock functions override for consistency
* Change QWARN to QVERIFY since logs will be missed in CI
* Uncomment add of offline and online friends in testSortByActivity
* Add out-of-line method definition to anchor vtable
This commit is contained in:
Anthony Bilinski 2022-02-10 01:16:02 -08:00
parent 0a9e121811
commit a1ebf297d3
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
2 changed files with 33 additions and 25 deletions

View File

@ -47,7 +47,7 @@ public:
bool isGroup() const final; bool isGroup() const final;
QString getNameItem() const final; QString getNameItem() const final;
bool isOnline() const final; bool isOnline() const final;
bool widgetIsVisible() const; bool widgetIsVisible() const final;
QDateTime getLastActivity() const final; QDateTime getLastActivity() const final;
QWidget* getWidget() final; QWidget* getWidget() final;
void setWidgetVisible(bool visible) final; void setWidgetVisible(bool visible) final;

View File

@ -35,16 +35,18 @@ public:
lastActivity(lastAct), lastActivity(lastAct),
online(onlineRes) {} online(onlineRes) {}
bool isFriend() const { return true; } ~MockFriend();
bool isGroup() const { return false; }
bool isOnline() const { return online; }
bool widgetIsVisible() const { return visible; }
QString getNameItem() const { return name; } bool isFriend() const override { return true; }
QDateTime getLastActivity() const { return lastActivity; } bool isGroup() const override { return false; }
QWidget* getWidget() { return nullptr; } bool isOnline() const override { return online; }
bool widgetIsVisible() const override { return visible; }
void setWidgetVisible(bool v) { visible = v; } QString getNameItem() const override { return name; }
QDateTime getLastActivity() const override { return lastActivity; }
QWidget* getWidget() override { return nullptr; }
void setWidgetVisible(bool v) override { visible = v; }
private: private:
QString name; QString name;
@ -54,6 +56,8 @@ private:
}; };
MockFriend::~MockFriend() = default;
class MockGroup : public IFriendListItem class MockGroup : public IFriendListItem
{ {
public: public:
@ -63,22 +67,26 @@ public:
MockGroup(const QString& nameStr) MockGroup(const QString& nameStr)
:name(nameStr) {} :name(nameStr) {}
bool isFriend() const { return false; } ~MockGroup();
bool isGroup() const { return true; }
bool isOnline() const { return true; }
bool widgetIsVisible() const { return visible; }
QString getNameItem() const { return name; } bool isFriend() const override { return false; }
QDateTime getLastActivity() const { return QDateTime::currentDateTime(); } bool isGroup() const override { return true; }
QWidget* getWidget() { return nullptr; } bool isOnline() const override { return true; }
bool widgetIsVisible() const override { return visible; }
void setWidgetVisible(bool v) { visible = v; } QString getNameItem() const override { return name; }
QDateTime getLastActivity() const override { return QDateTime::currentDateTime(); }
QWidget* getWidget() override { return nullptr; }
void setWidgetVisible(bool v) override { visible = v; }
private: private:
QString name; QString name;
bool visible = true; bool visible = true;
}; };
MockGroup::~MockGroup() = default;
class FriendItemsBuilder class FriendItemsBuilder
{ {
public: public:
@ -242,7 +250,7 @@ private:
void checkDifferentNames() { void checkDifferentNames() {
for (auto name : sortedByNameOnlineFriends) { for (auto name : sortedByNameOnlineFriends) {
if (sortedByNameOfflineFriends.contains(name, Qt::CaseInsensitive)) { if (sortedByNameOfflineFriends.contains(name, Qt::CaseInsensitive)) {
QWARN("Names in sortedByNameOnlineFriends and sortedByNameOfflineFriends " QFAIL("Names in sortedByNameOnlineFriends and sortedByNameOfflineFriends "
"should be different"); "should be different");
break; break;
} }
@ -344,10 +352,10 @@ void TestFriendListManager::testSortByName()
void TestFriendListManager::testSortByActivity() void TestFriendListManager::testSortByActivity()
{ {
FriendItemsBuilder listBuilder; FriendItemsBuilder listBuilder;
auto unsortedVec = listBuilder./*addOfflineFriends() auto unsortedVec = listBuilder.addOfflineFriends()
->addOnlineFriends()->*/addGroups()->buildUnsorted(); ->addOnlineFriends()->addGroups()->buildUnsorted();
auto sortedVec = listBuilder./*addOfflineFriends() auto sortedVec = listBuilder.addOfflineFriends()
->addOnlineFriends()->*/addGroups()->buildSortedByActivity(); ->addOnlineFriends()->addGroups()->buildSortedByActivity();
std::unique_ptr<FriendListManager> manager = createManagerWithItems(unsortedVec); std::unique_ptr<FriendListManager> manager = createManagerWithItems(unsortedVec);
manager->sortByActivity(); manager->sortByActivity();