asserts.h
1 //------------------------------------------------------------------------------
2 // asserts.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2024 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef DOOMSEEKER_TESTS_ASSERTS_H
24 #define DOOMSEEKER_TESTS_ASSERTS_H
25 
26 // TODO 3533 -- replace with Qt Test
27 
28 #define _T_STR2(x) #x
29 #define _T_STR(x) _T_STR2(x)
30 
31 #define _TLINE __FILE__ ":" _T_STR(__LINE__) ":"
32 
33 #define T_ASSERT_DATETIME_EQUAL(expected, actual) { \
34  auto _expected = (expected); \
35  auto _actual = (actual); \
36  if (!(_expected == _actual)) \
37  { \
38  testLog << QString(_TLINE "expected: %1, got %2") \
39  .arg(_expected.toString(Qt::TextDate)).arg(_actual.toString(Qt::TextDate)); \
40  return false; \
41  }}
42 
43 #define T_ASSERT_EQUAL(expected, actual) { \
44  auto _expected = (expected); \
45  auto _actual = (actual); \
46  if (!(_expected == _actual)) \
47  { \
48  testLog << QString(_TLINE "expected: %1, got %2").arg(_expected).arg(_actual); \
49  return false; \
50  }}
51 
52 #define T_ASSERT_FALSE(actual) { \
53  auto _actual = (actual); \
54  if (_actual) \
55  { \
56  testLog << QString(_TLINE "expected: false, got %2").arg(_actual); \
57  return false; \
58  }}
59 
60 #define T_ASSERT_ISEMPTY(actual) { \
61  auto _isEmpty = (actual).isEmpty(); \
62  if (!_isEmpty) \
63  { \
64  testLog << QString(_TLINE "`" #actual "` expected to be empty"); \
65  return false; \
66  }}
67 
68 #define T_ASSERT_SIZE(expected, actual) { \
69  auto _expected = (expected); \
70  auto _actual = (actual).size(); \
71  if (!(_expected == _actual)) \
72  { \
73  testLog << QString(_TLINE "`" #expected " == " #actual ".size()`" \
74  " expected size: %1, got: %2").arg(_expected).arg(_actual); \
75  return false; \
76  }}
77 
78 #endif