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
093c6b16
Commit
093c6b16
authored
3 years ago
by
Matthias Puchner
Browse files
Options
Downloads
Patches
Plain Diff
adapt unit tests
parent
829132a6
No related branches found
No related tags found
1 merge request
!570
remove SessionModel/Item from SampleModel and all related items
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tests/Unit/GUI/TestSessionXML.cpp
+71
-63
71 additions, 63 deletions
Tests/Unit/GUI/TestSessionXML.cpp
with
71 additions
and
63 deletions
Tests/Unit/GUI/TestSessionXML.cpp
+
71
−
63
View file @
093c6b16
#include
"GUI/Model/Group/PropertyItem.h"
#include
"GUI/Model/Group/PropertyItem.h"
#include
"GUI/Model/Instrument/BackgroundItems.h"
#include
"GUI/Model/Instrument/InstrumentItems.h"
#include
"GUI/Model/Instrument/InstrumentModel.h"
#include
"GUI/Model/Job/JobModel.h"
#include
"GUI/Model/Sample/FormFactorItems.h"
#include
"GUI/Model/Sample/FormFactorItems.h"
#include
"GUI/Model/Sample/LayerItem.h"
#include
"GUI/Model/Sample/LayerItem.h"
#include
"GUI/Model/Sample/MultiLayerItem.h"
#include
"GUI/Model/Sample/MultiLayerItem.h"
#include
"GUI/Model/Sample/ParticleItem.h"
#include
"GUI/Model/Sample/ParticleItem.h"
#include
"GUI/Model/Sample/ParticleLayoutItem.h"
#include
"GUI/Model/Sample/SampleModel.h"
#include
"GUI/Model/Session/Serializer.h"
#include
"GUI/Model/Session/SessionModel.h"
#include
"GUI/Model/Session/SessionModel.h"
#include
"Tests/GTestWrapper/google_test.h"
#include
"Tests/GTestWrapper/google_test.h"
#include
<QXmlStreamReader>
#include
<QXmlStreamReader>
...
@@ -25,6 +32,26 @@ void itemFromXML(QString buffer, SessionItem* item)
...
@@ -25,6 +32,26 @@ void itemFromXML(QString buffer, SessionItem* item)
GUI
::
Session
::
XML
::
readItems
(
&
reader
,
item
);
GUI
::
Session
::
XML
::
readItems
(
&
reader
,
item
);
}
}
template
<
typename
ItemType
>
QByteArray
serialize
(
ItemType
&
t
)
{
QByteArray
a
;
QXmlStreamWriter
w
(
&
a
);
w
.
writeStartElement
(
"start"
);
Serializer
s
(
&
w
);
t
.
serialize
(
s
);
w
.
writeEndElement
();
return
a
;
}
template
<
typename
ItemType
>
void
deserialize
(
ItemType
&
t
,
const
QByteArray
&
a
)
{
QXmlStreamReader
r
(
a
);
Serializer
sr
(
&
r
);
r
.
readNextStartElement
();
ASSERT_EQ
(
r
.
name
().
toString
(),
"start"
);
t
.
serialize
(
sr
);
}
}
// namespace
}
// namespace
class
TestSessionXML
:
public
::
testing
::
Test
{
class
TestSessionXML
:
public
::
testing
::
Test
{
...
@@ -56,52 +83,37 @@ TEST_F(TestSessionXML, sessionItem)
...
@@ -56,52 +83,37 @@ TEST_F(TestSessionXML, sessionItem)
//! Testing to/from xml: FullSphereItem
//! Testing to/from xml: FullSphereItem
TEST_F
(
TestSessionXML
,
FullSphere
Item
)
TEST_F
(
TestSessionXML
,
Instrument
Item
)
{
{
// source model, to xml
// source model, to xml
Session
Model
source
(
"TestModel"
)
;
Instrument
Model
source
;
auto
*
sphere
=
source
.
insertItem
<
FullSphere
Item
>
();
auto
*
instrument
=
source
.
insertItem
<
SpecularInstrument
Item
>
();
SessionItem
*
radius
=
sphere
->
radius
Item
();
SessionItem
*
backgroundItem
=
instrument
->
background
Item
();
QString
buffer
=
itemToXML
(
source
.
rootItem
());
QString
buffer
=
itemToXML
(
source
.
rootItem
());
// target model, from xml
// target model, from xml
Session
Model
target
(
"TestModel"
)
;
Instrument
Model
target
;
itemFromXML
(
buffer
,
target
.
rootItem
());
itemFromXML
(
buffer
,
target
.
rootItem
());
// checking top items in source and target models
// checking top items in source and target models
SessionItem
*
t_item
=
target
.
topItem
();
SessionItem
*
t_item
=
target
.
topItem
();
EXPECT_TRUE
(
t_item
->
hasModelType
<
FullSphereItem
>
());
EXPECT_TRUE
(
t_item
->
hasModelType
<
SpecularInstrumentItem
>
());
auto
*
t_sphere
=
dynamic_cast
<
FullSphereItem
*>
(
t_item
);
auto
*
t_sphere
=
dynamic_cast
<
SpecularInstrumentItem
*>
(
t_item
);
SessionItem
*
t_radius
=
t_sphere
->
radiusItem
();
SessionItem
*
t_radius
=
t_sphere
->
backgroundItem
();
EXPECT_EQ
(
sphere
->
parent
()
->
tagFromItem
(
sphere
),
t_sphere
->
parent
()
->
tagFromItem
(
t_sphere
));
EXPECT_EQ
(
instrument
->
parent
()
->
tagFromItem
(
instrument
),
EXPECT_EQ
(
sphere
->
displayName
(),
t_sphere
->
displayName
());
t_sphere
->
parent
()
->
tagFromItem
(
t_sphere
));
EXPECT_EQ
(
sphere
->
modelType
(),
t_sphere
->
modelType
());
EXPECT_EQ
(
instrument
->
displayName
(),
t_sphere
->
displayName
());
EXPECT_EQ
(
sphere
->
numberOfChildren
(),
t_sphere
->
numberOfChildren
());
EXPECT_EQ
(
instrument
->
modelType
(),
t_sphere
->
modelType
());
EXPECT_EQ
(
sphere
->
radius
(),
t_sphere
->
radius
());
EXPECT_EQ
(
instrument
->
numberOfChildren
(),
t_sphere
->
numberOfChildren
());
EXPECT_EQ
(
instrument
->
analyzerEfficiency
(),
t_sphere
->
analyzerEfficiency
());
EXPECT_EQ
(
radius
->
parent
()
->
tagFromItem
(
sphere
),
t_radius
->
parent
()
->
tagFromItem
(
t_sphere
));
EXPECT_EQ
(
radius
->
displayName
(),
t_radius
->
displayName
());
EXPECT_EQ
(
backgroundItem
->
parent
()
->
tagFromItem
(
instrument
),
EXPECT_EQ
(
radius
->
modelType
(),
t_radius
->
modelType
());
t_radius
->
parent
()
->
tagFromItem
(
t_sphere
));
EXPECT_EQ
(
radius
->
numberOfChildren
(),
t_radius
->
numberOfChildren
());
EXPECT_EQ
(
backgroundItem
->
displayName
(),
t_radius
->
displayName
());
EXPECT_EQ
(
radius
->
value
().
toDouble
(),
t_radius
->
value
().
toDouble
());
EXPECT_EQ
(
backgroundItem
->
modelType
(),
t_radius
->
modelType
());
EXPECT_EQ
(
backgroundItem
->
numberOfChildren
(),
t_radius
->
numberOfChildren
());
// final XML comparison
EXPECT_EQ
(
backgroundItem
->
value
().
toDouble
(),
t_radius
->
value
().
toDouble
());
EXPECT_EQ
(
buffer
,
itemToXML
(
target
.
rootItem
()));
}
TEST_F
(
TestSessionXML
,
twoFullSphereItems
)
{
// source model, to xml
SessionModel
source
(
"TestModel"
);
auto
*
sphere1
=
source
.
insertItem
<
FullSphereItem
>
();
sphere1
->
setRadius
(
1.0
);
auto
*
sphere2
=
source
.
insertItem
<
FullSphereItem
>
();
sphere2
->
setRadius
(
2.0
);
QString
buffer
=
itemToXML
(
source
.
rootItem
());
SessionModel
target
(
"TestModel"
);
itemFromXML
(
buffer
,
target
.
rootItem
());
// final XML comparison
// final XML comparison
EXPECT_EQ
(
buffer
,
itemToXML
(
target
.
rootItem
()));
EXPECT_EQ
(
buffer
,
itemToXML
(
target
.
rootItem
()));
...
@@ -109,54 +121,50 @@ TEST_F(TestSessionXML, twoFullSphereItems)
...
@@ -109,54 +121,50 @@ TEST_F(TestSessionXML, twoFullSphereItems)
TEST_F
(
TestSessionXML
,
emptyMultiLayer
)
TEST_F
(
TestSessionXML
,
emptyMultiLayer
)
{
{
SessionModel
source
(
"TestModel"
);
MultiLayerItem
source
;
source
.
insertItem
<
MultiLayerItem
>
();
const
auto
a1
=
serialize
(
source
);
QString
buffer
=
itemToXML
(
source
.
rootItem
());
SessionModel
target
(
"TestModel"
)
;
MultiLayerItem
target
;
itemFromXML
(
buffer
,
target
.
rootItem
()
);
deserialize
(
target
,
a1
);
// final XML comparison
// final XML comparison
EXPECT_EQ
(
buffer
,
itemToXML
(
target
.
rootItem
()));
const
auto
a2
=
serialize
(
target
);
EXPECT_EQ
(
a1
,
a2
);
}
}
TEST_F
(
TestSessionXML
,
Layer
)
TEST_F
(
TestSessionXML
,
Layer
)
{
{
SessionModel
source
(
"TestModel"
);
LayerItem
source
;
source
.
insertItem
<
LayerItem
>
();
const
auto
a1
=
serialize
(
source
);
QString
buffer
=
itemToXML
(
source
.
rootItem
());
SessionModel
target
(
"TestModel"
)
;
LayerItem
target
;
itemFromXML
(
buffer
,
target
.
rootItem
()
);
deserialize
(
target
,
a1
);
// final XML comparison
// final XML comparison
EXPECT_EQ
(
buffer
,
itemToXML
(
target
.
rootItem
()
));
EXPECT_EQ
(
a1
,
serialize
(
target
));
}
}
TEST_F
(
TestSessionXML
,
Particle
)
TEST_F
(
TestSessionXML
,
Particle
)
{
{
SessionModel
source
(
"TestModel"
);
ParticleItem
source
;
source
.
insertItem
<
ParticleItem
>
();
const
auto
a1
=
serialize
(
source
);
QString
buffer
=
itemToXML
(
source
.
rootItem
());
SessionModel
target
(
"TestModel"
)
;
ParticleItem
target
;
itemFromXML
(
buffer
,
target
.
rootItem
()
);
deserialize
(
target
,
a1
);
// final XML comparison
// final XML comparison
EXPECT_EQ
(
buffer
,
itemToXML
(
target
.
rootItem
()
));
EXPECT_EQ
(
a1
,
serialize
(
target
));
}
}
TEST_F
(
TestSessionXML
,
ParticleWithFF
)
TEST_F
(
TestSessionXML
,
ParticleWithFF
)
{
{
SessionModel
source
(
"TestModel"
);
ParticleItem
source
;
auto
*
particle
=
source
.
insertItem
<
ParticleItem
>
();
source
.
setFormFactorType
<
AnisoPyramidItem
>
();
const
auto
a1
=
serialize
(
source
);
particle
->
setFormFactorType
<
AnisoPyramidItem
>
();
ParticleItem
target
;
QString
buffer
=
itemToXML
(
source
.
rootItem
());
deserialize
(
target
,
a1
);
SessionModel
target
(
"TestModel"
);
itemFromXML
(
buffer
,
target
.
rootItem
());
// final XML comparison
// final XML comparison
EXPECT_EQ
(
buffer
,
itemToXML
(
target
.
rootItem
()
));
EXPECT_EQ
(
a1
,
serialize
(
target
));
}
}
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