Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
9002d826
Commit
9002d826
authored
7 years ago
by
Pospelov, Gennady
Browse files
Options
Downloads
Patches
Plain Diff
Minor cleanup in unit tests.
parent
a943bf6d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Tests/UnitTests/GUI/TestSessionItem.h
+8
-123
8 additions, 123 deletions
Tests/UnitTests/GUI/TestSessionItem.h
Tests/UnitTests/GUI/TestSessionModel.h
+5
-5
5 additions, 5 deletions
Tests/UnitTests/GUI/TestSessionModel.h
with
13 additions
and
128 deletions
Tests/UnitTests/GUI/TestSessionItem.h
+
8
−
123
View file @
9002d826
...
...
@@ -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
_t
ypes
)
TEST_F
(
TestSessionItem
,
model
T
ypes
)
{
const
QString
model1
=
"modeltype 1"
;
const
QString
model2
=
"modeltype 2"
;
...
...
This diff is collapsed.
Click to expand it.
Tests/UnitTests/GUI/TestSessionModel.h
+
5
−
5
View file @
9002d826
...
...
@@ -46,7 +46,7 @@ TEST_F(TestSessionModel, setData)
EXPECT_EQ
(
spy
.
count
(),
1
);
}
TEST_F
(
TestSessionModel
,
test_
SampleModel
_Create
Copy
)
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
_Create
PartialCopy
)
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
_Create
Copy
)
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
_Create
PartialCopy
)
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_copyParameterized
Item
)
TEST_F
(
TestSessionModel
,
copy
Item
)
{
std
::
unique_ptr
<
MaterialModel
>
P_materialModel
(
new
MaterialModel
());
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment