Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Simox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Leander Singer
Simox
Commits
957214a6
Commit
957214a6
authored
5 years ago
by
Rainer Kartmann
Browse files
Options
Downloads
Patches
Plain Diff
Add comments
parent
838bc724
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
VirtualRobot/VirtualRobotChecks.h
+29
-1
29 additions, 1 deletion
VirtualRobot/VirtualRobotChecks.h
VirtualRobot/tests/VirtualRobotChecksTest.cpp
+0
-2
0 additions, 2 deletions
VirtualRobot/tests/VirtualRobotChecksTest.cpp
with
29 additions
and
3 deletions
VirtualRobot/VirtualRobotChecks.h
+
29
−
1
View file @
957214a6
...
...
@@ -4,12 +4,33 @@
#include
"VirtualRobotException.h"
/**
* The macros VR_CHECK_*() defined in this file can be used as "soft"
* assertions. That is, they can be used to check some condition and, if this
* condition fails, throw an exception (of type `VirtualRobotCheckException`).
* Thrown exceptions give information about where they were thrown and what
* condition failed.
*
* All macros are defined in two versions, one taking a "hint", explaining
* what is checked, and one taking no hint.
*
* Hints hould be formulated "positively", i.e. what condition is tested and
* what must be true, not what went wrong otherwise. For example:
*
* @code
* VR_CHECK_EQUAL_HINT(vector.size(), 3, "Vector must have exactly 3 elements.");
* VR_CHECK_HINT(pointer, "Pointer must not be null.");
*
* *not:* VR_CHECK_HINT(pointer, "Pointer is null.");
* @endcode
*
*/
namespace
VirtualRobot
{
/**
* @brief Exception class thrown by VR_CHECK_* macros
("soft" assertions)
.
* @brief Exception class thrown by VR_CHECK_* macros.
*/
class
VIRTUAL_ROBOT_IMPORT_EXPORT
VirtualRobotCheckException
:
public
VirtualRobotException
...
...
@@ -116,10 +137,17 @@ namespace VirtualRobot
#define VR_CHECK_POSITIVE_HINT(value, hint) VR_CHECK_GREATER_HINT(value, 0, hint)
/**
* Check whether `value` is in the range [0, size), i.e. whether it would be
* a valid index into an array of size `size`.
*/
#define VR_CHECK_FITS_SIZE(value, size) \
VR_CHECK_NONNEGATIVE(value); \
VR_CHECK_LESS(value, size)
/**
* @see VR_CHECK_FITS_SIZE()
*/
#define VR_CHECK_FITS_SIZE_HINT(value, size, hint) \
VR_CHECK_NONNEGATIVE_HINT(value, hint); \
VR_CHECK_LESS_HINT(value, size, hint)
...
...
This diff is collapsed.
Click to expand it.
VirtualRobot/tests/VirtualRobotChecksTest.cpp
+
0
−
2
View file @
957214a6
...
...
@@ -66,8 +66,6 @@ BOOST_AUTO_TEST_CASE(test_VR_CHECK_EQUAL)
BOOST_CHECK_THROW
(
VR_CHECK_EQUAL
(
0
,
1
),
VirtualRobotCheckException
);
BOOST_CHECK_THROW
(
VR_CHECK_EQUAL
(
z
,
10
),
VirtualRobotCheckException
);
BOOST_CHECK_THROW
(
VR_CHECK_EQUAL
(
a
,
b
),
VirtualRobotCheckException
);
VR_CHECK_EQUAL
(
0
,
1
);
}
...
...
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