Skip to content
Snippets Groups Projects
Commit 9002d826 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Minor cleanup in unit tests.

parent a943bf6d
No related branches found
No related tags found
No related merge requests found
......@@ -6,23 +6,7 @@
class TestSessionItem : public ::testing::Test
{
public:
// TODO refactor whole unit test together with SessionTagInfo refactoring
~TestSessionItem();
void verify_get_item(SessionItem* item, const QString& tag, QVector<SessionItem*> list)
{
if (list.size() > 0)
EXPECT_TRUE(item->getItem(tag) == list[0]);
else
EXPECT_TRUE(item->getItem(tag) == nullptr);
auto items = item->getItems(tag);
EXPECT_TRUE(items.size() == list.size());
EXPECT_TRUE(items == list);
EXPECT_TRUE(item->getItem(tag, -1) == nullptr);
EXPECT_TRUE(item->getItem(tag, list.size()) == nullptr);
for (int i = 0; i < list.size(); i++) {
EXPECT_TRUE(item->getItem(tag, i) == list[i]);
}
}
};
TestSessionItem::~TestSessionItem() = default;
......@@ -150,7 +134,7 @@ TEST_F(TestSessionItem, tagWithLimits)
EXPECT_TRUE(item->registerTag(tag1, 0, maxItems));
QVector<SessionItem*> expected;
for (int i=0; i<maxItems; ++i) {
for (int i = 0; i < maxItems; ++i) {
auto child = new SessionItem(modelType);
expected.push_back(child);
EXPECT_TRUE(item->insertItem(-1, child, tag1));
......@@ -174,14 +158,14 @@ TEST_F(TestSessionItem, tagsAndModelTypes)
// adding two types of items under different tags
QVector<SessionItem*> expected1;
for (int i=0; i<maxItems1; ++i) {
for (int i = 0; i < maxItems1; ++i) {
auto child = new SessionItem(modelType1);
expected1.push_back(child);
EXPECT_TRUE(item->insertItem(-1, child, tag1));
}
QVector<SessionItem*> expected2;
for (int i=0; i<maxItems2; ++i) {
for (int i = 0; i < maxItems2; ++i) {
auto child = new SessionItem(modelType2);
expected2.push_back(child);
EXPECT_TRUE(item->insertItem(-1, child, tag2));
......@@ -212,14 +196,14 @@ TEST_F(TestSessionItem, takeRow)
// adding two types of items under different tags
QVector<SessionItem*> expected1;
for (int i=0; i<maxItems1; ++i) {
for (int i = 0; i < maxItems1; ++i) {
auto child = new SessionItem(modelType1);
expected1.push_back(child);
EXPECT_TRUE(item->insertItem(-1, child, tag1));
}
QVector<SessionItem*> expected2;
for (int i=0; i<maxItems2; ++i) {
for (int i = 0; i < maxItems2; ++i) {
auto child = new SessionItem(modelType2);
expected2.push_back(child);
EXPECT_TRUE(item->insertItem(-1, child, tag2));
......@@ -230,7 +214,7 @@ TEST_F(TestSessionItem, takeRow)
EXPECT_TRUE(taken1->parent() == nullptr);
delete taken1;
auto taken2 = item->takeRow(maxItems1-1); // one item less already
auto taken2 = item->takeRow(maxItems1 - 1); // one item less already
EXPECT_EQ(taken2, expected2.at(0));
delete taken2;
......@@ -241,106 +225,7 @@ TEST_F(TestSessionItem, takeRow)
EXPECT_EQ(item->getItems(tag2), expected2);
}
TEST_F(TestSessionItem, test_tags)
{
// const QString modeltype = "This is the model type";
// const QString tag1 = "TAG1";
// const QString tag2 = "TAG2";
// const QString tag3 = "TAG3";
// const QString tag4 = "TAG4";
// std::unique_ptr<SessionItem> item(new SessionItem(modeltype));
// // before using a tag, it must be registered
// EXPECT_TRUE(item->registerTag(tag1));
// // register twice returns false
// EXPECT_TRUE(item->registerTag(tag1) == false);
// // register empty string returns false
// EXPECT_TRUE(item->registerTag("") == false);
// // now we insert one element at the beginning
// SessionItem* child = new SessionItem(modeltype);
// EXPECT_TRUE(item->insertItem(0, child, tag1));
// // insertion out of range is forbidden
// EXPECT_TRUE(item->insertItem(-1, child, tag1) == false);
// EXPECT_TRUE(item->insertItem(2, child, tag1) == false);
// // double insertion is forbidden
// EXPECT_TRUE(item->insertItem(0, child, tag1) == false);
// // we try to access tagged items
// QVector<SessionItem*> expected = {child};
// verify_get_item(item.get(), tag1, expected);
// // nullptr is not allowed
// EXPECT_TRUE(item->insertItem(1, nullptr, tag1) == false);
// verify_get_item(item.get(), tag1, expected);
// // LIMITS
// // register tag with limit 0 - 1
// EXPECT_TRUE(item->registerTag(tag2, 0, 1));
// SessionItem* child2 = new SessionItem(modeltype);
// EXPECT_TRUE(item->insertItem(0, child2, tag2));
// expected = {child2};
// verify_get_item(item.get(), tag2, expected);
// EXPECT_TRUE(item->insertItem(1, child2, tag2) == false);
// // register tag with limit 0 - 3 (using item 2 - 5)
// EXPECT_TRUE(item->registerTag(tag3, 0, 4));
// // add four items
// QVector<SessionItem*> expected_tag3;
// for (int i = 0; i < 4; i++) {
// auto child = new SessionItem(modeltype);
// expected_tag3.push_back(child);
// EXPECT_TRUE(item->insertItem(i, child, tag3));
// }
// verify_get_item(item.get(), tag3, expected_tag3);
// // the fifth should fail
// child = new SessionItem(modeltype);
// EXPECT_TRUE(item->insertItem(0, child, tag3) == false);
// delete child;
// // items should be unchanged
// verify_get_item(item.get(), tag3, expected_tag3);
// // register tag with limit 4 - 4 add items to fill up limit
// EXPECT_TRUE(item->registerTag(tag4, 4, 4));
// // add four items
// QVector<SessionItem*> expected_tag4;
// for (int i = 0; i < 4; i++) {
// auto child = new SessionItem(modeltype);
// expected_tag4.push_back(child);
// EXPECT_TRUE(item->insertItem(i, child, tag4));
// }
// verify_get_item(item.get(), tag4, expected_tag4);
// child = new SessionItem(modeltype);
// EXPECT_TRUE(item->insertItem(0, child, tag4) == false);
// delete child;
// // REMOVAL
// // tag4 can not be removed
// SessionItem* last = item->takeItem(3, tag4);
// EXPECT_TRUE(last == nullptr);
// verify_get_item(item.get(), tag4, expected_tag4);
// // remove all from tag3, checking access of tag4
// for (int i = 3; i >= 0; i--) {
// last = item->takeItem(i, tag3);
// EXPECT_TRUE(last == expected_tag3[i]);
// delete last;
// }
// verify_get_item(item.get(), tag4, expected_tag4);
}
TEST_F(TestSessionItem, test_data_roles)
TEST_F(TestSessionItem, dataRoles)
{
std::unique_ptr<SessionItem> item(new SessionItem("Some model type"));
item->setData(Qt::DisplayRole, 1234);
......@@ -356,7 +241,7 @@ TEST_F(TestSessionItem, test_data_roles)
}
}
TEST_F(TestSessionItem, test_model_types)
TEST_F(TestSessionItem, modelTypes)
{
const QString model1 = "modeltype 1";
const QString model2 = "modeltype 2";
......
......@@ -46,7 +46,7 @@ TEST_F(TestSessionModel, setData)
EXPECT_EQ(spy.count(), 1);
}
TEST_F(TestSessionModel, test_SampleModel_CreateCopy)
TEST_F(TestSessionModel, SampleModelCopy)
{
std::unique_ptr<MaterialModel> P_materialModel(new MaterialModel());
......@@ -69,7 +69,7 @@ TEST_F(TestSessionModel, test_SampleModel_CreateCopy)
EXPECT_EQ(buffer1, buffer2);
}
TEST_F(TestSessionModel, test_SampleModel_CreatePartialCopy)
TEST_F(TestSessionModel, SampleModelPartialCopy)
{
std::unique_ptr<MaterialModel> P_materialModel(new MaterialModel());
......@@ -88,7 +88,7 @@ TEST_F(TestSessionModel, test_SampleModel_CreatePartialCopy)
EXPECT_EQ(result->modelType(), multilayer1->modelType());
}
TEST_F(TestSessionModel, test_InstrumentModel_CreateCopy)
TEST_F(TestSessionModel, InstrumentModelCopy)
{
InstrumentModel model1;
SessionItem* instrument1 = model1.insertNewItem(Constants::InstrumentType);
......@@ -109,7 +109,7 @@ TEST_F(TestSessionModel, test_InstrumentModel_CreateCopy)
EXPECT_EQ(buffer1, buffer2);
}
TEST_F(TestSessionModel, test_InstrumentModel_CreatePartialCopy)
TEST_F(TestSessionModel, InstrumentModelPartialCopy)
{
InstrumentModel model1;
SessionItem* instrument1 = model1.insertNewItem(Constants::InstrumentType);
......@@ -126,7 +126,7 @@ TEST_F(TestSessionModel, test_InstrumentModel_CreatePartialCopy)
//! Test if SessionItem can be copied from one model to another. Particularly, we test
//! here if a MultiLayerItem can be copied from SampleModel to the JobItem of JobModel
TEST_F(TestSessionModel, test_copyParameterizedItem)
TEST_F(TestSessionModel, copyItem)
{
std::unique_ptr<MaterialModel> P_materialModel(new MaterialModel());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment