OTest2
A C++ testing framework
dsl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Ondrej Starek
3  *
4  * This file is part of OTest2.
5  *
6  * OTest2 is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License,
9  * or (at your option) any later version.
10  *
11  * OTest2 is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OTest2__INCLUDE_OTEST2_DSL_H_
21 #define OTest2__INCLUDE_OTEST2_DSL_H_
22 
23 #ifndef OTEST2_PARSER_ACTIVE
24 
25 /* -- test structure description */
26 #define OT2_START_UP()
27 #define OT2_TEAR_DOWN()
28 #define OT2_SUITE(name_) namespace name_ { using namespace ::OTest2::Assertions; using namespace ::OTest2::Controls; } namespace name_
29 #define OT2_CASE(name_) namespace name_ { using namespace ::OTest2::Assertions; using namespace ::OTest2::Controls; } namespace name_
30 #define OT2_SCENARIO()
31 #define OT2_STATE()
32 #define OT2_SIMPLE() void AnonymousState() OT2_SCENARIO()
33 
34 /* -- asserted try/catch block */
35 #define testTry try
36 #define testCatch(exc_type_, name_) catch(typename ::OTest2::TypePack<exc_type_>::Type name_)
37 
38 /* -- user data variables */
39 #define OT2_USER_DATA()
40 #define OT2_USER_DATA_KEY(key_)
41 
42 /* -- tags */
43 #define OT2_TAGS(tags_)
44 
45 #else /* -- OTEST2_PARSER_ACTIVE */
46 
47 #define OT2_START_UP() __attribute__((annotate("otest2::startUp")))
48 #define OT2_TEAR_DOWN() __attribute__((annotate("otest2::tearDown")))
49 #define OT2_SUITE(name_) namespace name_ { using namespace ::OTest2::Assertions; using namespace ::OTest2::Controls; } namespace name_ __attribute__((annotate("otest2::suite")))
50 #define OT2_CASE(name_) namespace name_ { using namespace ::OTest2::Assertions; using namespace ::OTest2::Controls; } namespace name_ __attribute__((annotate("otest2::case")))
51 #define OT2_SCENARIO() __attribute__((annotate("otest2::scenario")))
52 #define OT2_STATE() __attribute__((annotate("otest2::state")))
53 #define OT2_SIMPLE() void AnonymousState() OT2_SCENARIO()
54 
55 #define testTry try
56 #define testCatch(exc_type_, name_) catch(typename ::OTest2::TypePack<exc_type_>::Type __attribute__((annotate("otest2::catch"))) name_ )
57 
58 #define OT2_USER_DATA() __attribute__((annotate("otest2::userData()")))
59 #define OT2_USER_DATA_KEY(key_) __attribute__((annotate("otest2::userData(" key_ ")")))
60 
61 #define OT2_TAGS(tags_) __attribute__((annotate("otest2::tags(" tags_ ")")))
62 
63 #endif /* -- OTEST2_PARSER_ACTIVE */
64 
65 #define OT2_SECTION(name_) if(::OTest2::Controls::Private::sectionName(#name_))
66 
67 /* -- compact DSL syntax */
68 #define TEST_START_UP() void startUp() OT2_START_UP()
69 #define TEST_TEAR_DOWN() void tearDown() OT2_TEAR_DOWN()
70 #define TEST_SUITE(name_) OT2_SUITE(name_)
71 #define TEST_CASE(name_) OT2_CASE(name_)
72 #define TEST_SCENARIO(name_) void name_() OT2_SCENARIO()
73 #define TEST_STATE(name_) void name_() OT2_STATE()
74 #define TEST_SIMPLE() OT2_SIMPLE()
75 #define TEST_SECTION(name_) OT2_SECTION(name_)
76 
77 #endif /* -- OTest2__INCLUDE_OTEST2_DSL_H_ */