Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ApplicationCore
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ChimeraTK Mirror
ApplicationCore
Commits
40cb7fde
Commit
40cb7fde
authored
5 years ago
by
Jan H. K. Timm
Browse files
Options
Downloads
Patches
Plain Diff
ExceptionDummy
add bool thereHaveBeenExceptions write test for taht testExceptionsDummyDevice.cc
parent
a61bfdbf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/executables_src/testExceptionDummyDevice.cc
+55
-0
55 additions, 0 deletions
tests/executables_src/testExceptionDummyDevice.cc
tests/include/ExceptionDevice.h
+8
-1
8 additions, 1 deletion
tests/include/ExceptionDevice.h
with
63 additions
and
1 deletion
tests/executables_src/testExceptionDummyDevice.cc
0 → 100644
+
55
−
0
View file @
40cb7fde
#define BOOST_TEST_MODULE testExceptionsDummy
#include
"ExceptionDevice.h"
#include
<ChimeraTK/BackendFactory.h>
#include
<ChimeraTK/Device.h>
#include
<boost/test/included/unit_test.hpp>
using
namespace
boost
::
unit_test_framework
;
namespace
ctk
=
ChimeraTK
;
auto
exceptionDummy
=
boost
::
dynamic_pointer_cast
<
ExceptionDummy
>
(
ctk
::
BackendFactory
::
getInstance
().
createBackend
(
"(ExceptionDummy:1?map=test3.map)"
));
ctk
::
Device
device
;
BOOST_AUTO_TEST_CASE
(
testExceptionsDummyDevice
)
{
// test general function
BOOST_CHECK
(
!
device
.
isFunctional
());
device
.
open
(
"(ExceptionDummy:1?map=test3.map)"
);
BOOST_CHECK
(
device
.
isFunctional
());
// test throwExceptionRead
exceptionDummy
->
throwExceptionRead
=
true
;
BOOST_CHECK
(
!
device
.
isFunctional
());
BOOST_CHECK_THROW
(
device
.
read
<
int32_t
>
(
"/Integers/signed32"
),
ChimeraTK
::
runtime_error
);
BOOST_CHECK
(
!
device
.
isFunctional
());
BOOST_CHECK_THROW
(
device
.
open
(
"(ExceptionDummy:1?map=test3.map)"
),
ChimeraTK
::
runtime_error
);
BOOST_CHECK
(
!
device
.
isFunctional
());
exceptionDummy
->
throwExceptionRead
=
false
;
BOOST_CHECK
(
!
device
.
isFunctional
());
device
.
open
(
"(ExceptionDummy:1?map=test3.map)"
);
BOOST_CHECK
(
device
.
isFunctional
());
// test throwExceptionWrite
exceptionDummy
->
throwExceptionWrite
=
true
;
BOOST_CHECK
(
!
device
.
isFunctional
());
BOOST_CHECK_THROW
(
device
.
write
<
int32_t
>
(
"/Integers/signed32"
,
0
),
ChimeraTK
::
runtime_error
);
BOOST_CHECK
(
!
device
.
isFunctional
());
BOOST_CHECK_THROW
(
device
.
open
(
"(ExceptionDummy:1?map=test3.map)"
),
ChimeraTK
::
runtime_error
);
BOOST_CHECK
(
!
device
.
isFunctional
());
exceptionDummy
->
throwExceptionWrite
=
false
;
BOOST_CHECK
(
!
device
.
isFunctional
());
device
.
open
(
"(ExceptionDummy:1?map=test3.map)"
);
BOOST_CHECK
(
device
.
isFunctional
());
// test throwExceptionOpen
exceptionDummy
->
throwExceptionOpen
=
true
;
BOOST_CHECK
(
!
device
.
isFunctional
());
BOOST_CHECK_THROW
(
device
.
open
(
"(ExceptionDummy:1?map=test3.map)"
),
ChimeraTK
::
runtime_error
);
BOOST_CHECK
(
!
device
.
isFunctional
());
exceptionDummy
->
throwExceptionOpen
=
false
;
device
.
open
(
"(ExceptionDummy:1?map=test3.map)"
);
BOOST_CHECK
(
device
.
isFunctional
());
}
This diff is collapsed.
Click to expand it.
tests/include/ExceptionDevice.h
+
8
−
1
View file @
40cb7fde
...
...
@@ -8,22 +8,28 @@ class ExceptionDummy : public ChimeraTK::DummyBackend {
bool
throwExceptionOpen
{
false
};
bool
throwExceptionRead
{
false
};
bool
throwExceptionWrite
{
false
};
bool
thereHaveBeenExceptions
{
false
};
static
boost
::
shared_ptr
<
DeviceBackend
>
createInstance
(
std
::
string
,
std
::
map
<
std
::
string
,
std
::
string
>
parameters
)
{
return
boost
::
shared_ptr
<
DeviceBackend
>
(
new
ExceptionDummy
(
parameters
[
"map"
]));
}
void
open
()
override
{
if
(
throwExceptionOpen
)
{
thereHaveBeenExceptions
=
true
;
throw
(
ChimeraTK
::
runtime_error
(
"DummyException: This is a test"
));
}
ChimeraTK
::
DummyBackend
::
open
();
if
(
throwExceptionRead
||
throwExceptionWrite
)
{
thereHaveBeenExceptions
=
true
;
throw
(
ChimeraTK
::
runtime_error
(
"DummyException: open throws because of device error when already open."
));
}
thereHaveBeenExceptions
=
false
;
}
void
read
(
uint8_t
bar
,
uint32_t
address
,
int32_t
*
data
,
size_t
sizeInBytes
)
override
{
if
(
throwExceptionRead
)
{
thereHaveBeenExceptions
=
true
;
throw
(
ChimeraTK
::
runtime_error
(
"DummyException: read throws by request"
));
}
ChimeraTK
::
DummyBackend
::
read
(
bar
,
address
,
data
,
sizeInBytes
);
...
...
@@ -31,13 +37,14 @@ class ExceptionDummy : public ChimeraTK::DummyBackend {
void
write
(
uint8_t
bar
,
uint32_t
address
,
int32_t
const
*
data
,
size_t
sizeInBytes
)
override
{
if
(
throwExceptionWrite
)
{
thereHaveBeenExceptions
=
true
;
throw
(
ChimeraTK
::
runtime_error
(
"DummyException: write throws by request"
));
}
ChimeraTK
::
DummyBackend
::
write
(
bar
,
address
,
data
,
sizeInBytes
);
}
bool
isFunctional
()
const
override
{
return
(
_opened
&&
!
throwExceptionOpen
&&
!
throwExceptionRead
&&
!
throwExceptionWrite
);
return
(
_opened
&&
!
throwExceptionOpen
&&
!
throwExceptionRead
&&
!
throwExceptionWrite
&&
!
thereHaveBeenExceptions
);
}
class
BackendRegisterer
{
...
...
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