Classes | Macros
DesignByContract.h File Reference
#include <ECObjects/ECObjects.h>

Go to the source code of this file.


struct  AssertDisabler
 This class is utilzed by the macros defined in this header file. No calling code should typically ever need to use this class directly. More...


#define DesignByContract_H_
#define DISABLE_ASSERTS   AssertDisabler assertDisabler;
 Utilize this macro to disable asserts that may occur within a codeblock. More...

Macro Definition Documentation

#define DesignByContract_H_
#define DISABLE_ASSERTS   AssertDisabler assertDisabler;

Utilize this macro to disable asserts that may occur within a codeblock.

The intent is that this macro will only ever be used by ATPs when testing failure scenarios. No delivered code should ever utilize this macro. This macro can only be used once within a codeblock and will disable any assert that may occur within the context of that codeblock. Usage within Nested codeblocks and method calls are valid. Let's assume the following method exists in a library

StatusInt SetHour (int hour)
PRECONDITION (0 <= hour && hour <= 23, ERROR);
m_hour = hour;
return SUCCESS;

Aside from logging and returning the specified ERROR, the PRECONDITION macro will assert in debug builds when argument <= 0. Now let's assume you wanted to write a test case that validated this expected failure condition. You would encounter problems in a debug build because the assertion dialog would display and interrupt a test that was designed to target this failure. You can DISABLE_ASSERTS in the context of executing this method from your test in order to prevent such scenario from occuring.

void TestFailureAndSuccessScenarioInAFunctionThatWillAssert
EXPECT_EQ (ERROR, ExpectArgumentGreaterThenZero (-1));
EXPECT_EQ (SUCCESS, ExpectArgumentGreaterThenZero (-1));

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.