-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14e6fff
commit 3d1ecdb
Showing
7 changed files
with
113 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Spy signal call without having a main loop | ||
#include <QSignalSpy> | ||
#include <QDateTime> | ||
#include <QDebug> | ||
|
||
// gtest framework | ||
#include <gtest/gtest.h> | ||
|
||
// Our test classes | ||
#include <SharedFooList.hpp> | ||
|
||
// First basic test fixture that have only one QObject | ||
class SharedObjectListTest : public ::testing::Test | ||
{ | ||
protected: | ||
void SetUp() override | ||
{ | ||
} | ||
|
||
void TearDown() override | ||
{ | ||
} | ||
|
||
SharedFooList _list; | ||
}; | ||
|
||
TEST_F(SharedObjectListTest, Append) | ||
{ | ||
QSignalSpy spyAboutToInsert(&_list, &Olm::SharedObjectListBase::itemAboutToBeInserted); | ||
QSignalSpy spyInsert(&_list, &Olm::SharedObjectListBase::itemInserted); | ||
ASSERT_EQ(_list.size(), 0); | ||
|
||
auto foo1 = QSharedPointer<Foo>(new Foo()); | ||
_list.append(foo1); | ||
|
||
ASSERT_EQ(_list.size(), 1); | ||
ASSERT_EQ(spyAboutToInsert.count(), 1); | ||
ASSERT_EQ(spyInsert.count(), 1); | ||
|
||
auto foo2 = QSharedPointer<Foo>(new Foo()); | ||
_list.append(foo2); | ||
_list.append(foo1); | ||
|
||
ASSERT_EQ(_list.size(), 3); | ||
ASSERT_EQ(spyAboutToInsert.count(), 3); | ||
ASSERT_EQ(spyInsert.count(), 3); | ||
|
||
ASSERT_TRUE(_list.at(0) == foo1); | ||
ASSERT_TRUE(_list.at(1) == foo2); | ||
ASSERT_TRUE(_list.at(2) == foo1); | ||
|
||
_list.clear(); | ||
} | ||
|
||
TEST_F(SharedObjectListTest, AppendFuzz) | ||
{ | ||
auto initTime = QDateTime::currentMSecsSinceEpoch(); | ||
for(int i = 0; i < 10000; ++i) | ||
_list.append(QSharedPointer<Foo>(new Foo())); | ||
auto appendTime = QDateTime::currentMSecsSinceEpoch(); | ||
ASSERT_EQ(_list.size(), 10000); | ||
_list.clear(); | ||
auto clearTime = QDateTime::currentMSecsSinceEpoch(); | ||
|
||
qDebug("Append 10000 Shared QObject Time : %llu ms. Clear time : %llu ms", (appendTime - initTime), (clearTime - appendTime)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef __FOO_LIST_HPP__ | ||
#define __FOO_LIST_HPP__ | ||
|
||
#include <ObjectListModel.hpp> | ||
#include <Foo.hpp> | ||
|
||
class FooList : public Olm::ObjectList<Foo> | ||
{ | ||
Q_OBJECT | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef __SHARED_FOO_LIST_HPP__ | ||
#define __SHARED_FOO_LIST_HPP__ | ||
|
||
#include <ObjectListModel.hpp> | ||
#include <Foo.hpp> | ||
|
||
class SharedFooList : public Olm::SharedObjectList<Foo> | ||
{ | ||
Q_OBJECT | ||
}; | ||
|
||
#endif |