Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mirrors
SuperElastix
Commits
951d2a00
Commit
951d2a00
authored
Dec 07, 2015
by
Floris Berendsen
Browse files
ENH: extra tests, conflicting interface
parent
f5fb31c3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Modules/Core/ComponentInterface/include/GDOptimizer4thPartyComponent.h
View file @
951d2a00
...
...
@@ -12,7 +12,7 @@ namespace elx
class
GDOptimizer4thPartyComponent
:
public
Implements
<
Accepting
<
MetricValueInterface
>
,
Providing
<
OptimizerUpdateInterface
>
Providing
<
OptimizerUpdateInterface
,
ConflictinUpdateInterface
>
>
{
...
...
@@ -24,6 +24,10 @@ namespace elx
//virtual int ConnectFrom(const char *, ComponentBase*);
int
Set
(
MetricValueInterface
*
);
int
Update
();
//template <class ConflictinUpdateInterface> virtual int Update() { return 5; };
// "error" : member function templates cannot be virtual
int
Update
(
ConflictinUpdateInterface
*
)
{
return
5
;
};
};
}
//end namespace elx
...
...
Modules/Core/ComponentInterface/include/Interfaces.h
View file @
951d2a00
...
...
@@ -23,6 +23,17 @@ public:
virtual
int
Update
()
=
0
;
};
class
ConflictinUpdateInterface
{
public:
// "error" : member function templates cannot be virtual
// template <class ConflictinUpdateInterface> virtual int Update() = 0;
//TODO http://en.cppreference.com/w/cpp/language/member_template
//TODO solution: http://stackoverflow.com/questions/2004820/inherit-interfaces-which-share-a-method-name
//TODO better?: http://stackoverflow.com/questions/18398409/c-inherit-from-multiple-base-classes-with-the-same-virtual-function-name
virtual
int
Update
(
ConflictinUpdateInterface
*
)
=
0
;
};
// Define the accepting interfaces as templated by the providing interface
template
<
class
InterfaceT
>
...
...
Testing/Unit/elxComponentInterfaceTest.cxx
View file @
951d2a00
...
...
@@ -87,7 +87,7 @@ TEST_F( InterfaceTest, ConnectByName )
EXPECT_NO_THROW
(
IFstatus
=
optimizer3p
->
ConnectFrom
(
"MetricDerivativeInterface"
,
metric4p
));
EXPECT_EQ
(
IFstatus
,
interfaceStatus
::
noprovider
);
EXPECT_NO_THROW
(
IFstatus
=
optimizer4p
->
ConnectFrom
(
"MetricDerivativeInterface"
,
metric3p
));
EXPECT_EQ
(
IFstatus
,
interfaceStatus
::
noaccepter
);
...
...
@@ -96,21 +96,44 @@ TEST_F( InterfaceTest, ConnectByName )
TEST_F
(
InterfaceTest
,
ConnectAll
)
{
int
connectionCount
=
0
;
int
returnval
;
OptimizerUpdateInterface
*
updateIF
;
EXPECT_NO_THROW
(
connectionCount
=
optimizer3p
->
ConnectFrom
(
metric3p
));
EXPECT_EQ
(
connectionCount
,
2
);
// both MetricValueInterface and MetricDerivativeInterface are connected
//optimizer3p should have a OptimizerUpdateInterface
updateIF
=
dynamic_cast
<
OptimizerUpdateInterface
*>
(
optimizer3p
);
ASSERT_NE
(
updateIF
,
nullptr
);
EXPECT_NO_THROW
(
returnval
=
updateIF
->
Update
());
// Update can only be called if metric and optimizer are connected
EXPECT_NO_THROW
(
connectionCount
=
optimizer3p
->
ConnectFrom
(
metric4p
));
EXPECT_EQ
(
connectionCount
,
1
);
// only MetricValueInterface is connected
//metric4p does not have MetricDerivativeInterface, so optimizer3p cannot run
EXPECT_NO_THROW
(
connectionCount
=
optimizer4p
->
ConnectFrom
(
metric3p
));
EXPECT_EQ
(
connectionCount
,
1
);
// only MetricValueInterface is connected
updateIF
=
dynamic_cast
<
OptimizerUpdateInterface
*>
(
optimizer4p
);
ASSERT_NE
(
updateIF
,
nullptr
);
EXPECT_NO_THROW
(
returnval
=
updateIF
->
Update
());
EXPECT_NO_THROW
(
connectionCount
=
optimizer4p
->
ConnectFrom
(
metric4p
));
EXPECT_EQ
(
connectionCount
,
1
);
// only MetricValueInterface is connected
updateIF
=
dynamic_cast
<
OptimizerUpdateInterface
*>
(
optimizer4p
);
ASSERT_NE
(
updateIF
,
nullptr
);
EXPECT_NO_THROW
(
returnval
=
updateIF
->
Update
());
EXPECT_NO_THROW
(
connectionCount
=
metric4p
->
ConnectFrom
(
optimizer4p
));
EXPECT_EQ
(
connectionCount
,
0
);
// cannot connect in this direction
ConflictinUpdateInterface
*
update2IF
=
dynamic_cast
<
ConflictinUpdateInterface
*>
(
optimizer4p
);
ASSERT_NE
(
update2IF
,
nullptr
);
EXPECT_NO_THROW
(
returnval
=
update2IF
->
Update
(
update2IF
));
}
}
// namespace elx
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment