Install also the benchmark (Yocto)
[profile/ivi/persistence-client-library.git] / test / persCheck.h
1 /******************************************************************************
2  * Project         Persistency
3  * (c) copyright   2014
4  * Company         XS Embedded GmbH
5  *****************************************************************************/
6 /******************************************************************************
7  * This Source Code Form is subject to the terms of the
8  * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed
9  * with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 ******************************************************************************/
11  /**
12  * @file           persCheck.h
13  * @ingroup        Persistence client library test
14  * @author         awehrle
15  * @brief          Test of persistence client library
16  * @see
17  */
18
19 #ifndef PERSCHECK_H_
20 #define PERSCHECK_H_
21
22 #include "pers_test_base.h"
23 #include <check.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 enum X_TEST_REPORTS{
30    X_TEST_REPORTED_RESULT
31 };
32
33 int _optTestsReported;
34 char _optTestID[256];
35
36 #define X_TEST_INIT() do { \
37    _optTestID[0] = '\0'; \
38    } while(0)
39
40 #define ___FILE___ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
41
42 #define REPORT_WARNINGS(){ \
43    if(0==(_optTestsReported & (1 << X_TEST_REPORTED_RESULT))) \
44       X_TEST_REPORT_RESULT(PASSED); \
45 }
46
47 /**
48  * @brief: Report name of test. This has to be reported first.
49  * MANDATORY
50  */
51 #define X_TEST_REPORT_TEST_NAME(...) do { \
52    char buf[sizeof(_optTestID)]; \
53    snprintf(buf,sizeof(buf), __VA_ARGS__); \
54    snprintf (_optTestID, sizeof(_optTestID),"%s::%s", ___FILE___, buf); \
55    X_TEST_REPORT_TEST_ID(_optTestID); \
56    X_TEST_REPORT_TEST_NAME_ID(_optTestID, __VA_ARGS__); \
57    } while(0)
58
59 /**
60  * @brief: Path to root of source code directory under test
61  * MANDATORY
62  */
63 #define X_TEST_REPORT_PATH(...) do { \
64    X_TEST_REPORT_PATH_ID( _optTestID, __VA_ARGS__ ); \
65    } while(0)
66
67 /**
68  * @brief: Name of subcomponent under test, leave empty or set value NONE if not suitable for a COMPONENT test
69  * MANDATORY
70  */
71 #define X_TEST_REPORT_COMP_NAME(...) do { \
72    X_TEST_REPORT_COMP_NAME_ID( _optTestID, __VA_ARGS__ ); \
73    } while(0)
74
75 /**
76  * @brief: Name of class or file under test, leave empty or set value NONE for a COMPONENT test
77  * MANDATORY
78  */
79 #define X_TEST_REPORT_FILE_NAME(...) do { \
80    X_TEST_REPORT_FILE_NAME_ID( _optTestID, __VA_ARGS__ ); \
81    } while(0)
82
83 /**
84  * @brief: If information exists: Reference to a requirement, feature or bug ID. Else leave empty or set value NONE
85  * MANDATORY
86  */
87 #define X_TEST_REPORT_REFERENCE(...) do { \
88    X_TEST_REPORT_REFERENCE_ID( _optTestID, __VA_ARGS__ ); \
89    } while(0)
90
91 /**
92  * @brief: A short description of test case.
93  * Do not leave empty, can also be a internal department Test ID like CORE-OS-BOOT-0001
94  * MANDATORY
95  */
96 #define X_TEST_REPORT_DESCRIPTION(...) do { \
97    X_TEST_REPORT_DESCRIPTION_ID( _optTestID, __VA_ARGS__ ); \
98    } while(0)
99
100 /**
101  * @brief: Reports weather this is a UNIT or a COMPONENT test
102  * MANDATORY
103  */
104 #define X_TEST_REPORT_KIND(kind) do { \
105    X_TEST_REPORT_KIND_ID( _optTestID, kind ); \
106    } while(0)
107
108 /**
109  * @brief: valid values: PASSED, FAILED or NONE. PASSED if test result is ok, FAILED if test result is not as expected, NONE if no test exists for whole file or class
110  * MANDATORY
111  */
112 #define X_TEST_REPORT_RESULT(result) do { \
113    X_TEST_REPORT_RESULT_ID( _optTestID, result); \
114    _optTestsReported |= 1 << X_TEST_REPORTED_RESULT; \
115    } while(0)
116
117 /**
118  * @brief: Additional information, if test "just" checks common information flow inside structure (GOOD test case) or if structure is tested with invalid or border values(BORDER)
119  * OPTIONAL
120  */
121 #define X_TEST_REPORT_TYPE(type) do { \
122    X_TEST_REPORT_TYPE_ID( _optTestID, type ); \
123    } while(0)
124
125 #undef START_TEST
126 /* Start a unit test with START_TEST(unit_name), end with END_TEST
127    One must use braces within a START_/END_ pair to declare new variables
128 */
129 #define START_TEST(__testname)\
130 static void __testname (int _i CK_ATTRIBUTE_UNUSED)\
131 {\
132    X_TEST_INIT(); \
133    X_TEST_REPORT_TEST_NAME(""# __testname); \
134    tcase_fn_start (""# __testname, __FILE__, __LINE__);
135
136 #define x_fail_unless(exp, ...){\
137    int result = exp; \
138    if(!result){ \
139       X_TEST_REPORT_RESULT(FAILED); \
140    } \
141    fail_unless(exp, ##__VA_ARGS__); \
142 } while(0)
143
144 #define x_fail_if(exp, ...) {\
145    int result = exp; \
146    if(result){ \
147       X_TEST_REPORT_RESULT(FAILED); \
148    } \
149    fail_if(exp, ##__VA_ARGS__); \
150 } while(0)
151
152 /* Always fail */
153 #define x_fail(...) {\
154    X_TEST_REPORT_RESULT(FAILED); \
155    fail(__VA_ARGS__); \
156 } while(0)
157
158 #undef END_TEST
159 /* End a unit test */
160 #define END_TEST {\
161    REPORT_WARNINGS(); \
162    _optTestsReported = 0; }\
163 }
164
165 #ifdef __cplusplus
166 }
167 #endif
168
169 #endif /* PERSCHECK_H_ */