Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/micromock/inc/micromock.h

raw
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 #ifndef MICROMOCK_H
5 #define MICROMOCK_H
6
7 #pragma once
8
9 #include "mock.h"
10 #include "globalmock.h"
11 #include "threadsafeglobalmock.h"
12 #include "mockmethodcallbase.h"
13 #include "mockmethodcall.h"
14 #include "mockcallrecorder.h"
15 #include "mockcallargument.h"
16 #include "mockvalue.h"
17 #include "mockvaluebase.h"
18 #include "mockresultvalue.h"
19 #include "strictunorderedcallcomparer.h"
20 #include "strictorderedcallcomparer.h"
21 #include "nicecallcomparer.h"
22 #include "micromockexception.h"
23 #include "micromocktestmutex.h"
24 #include "micromockenumtostring.h"
25
26 // Defines for ignored arguments
27 #define IGNORED_PTR_ARG (NULL)
28 #define IGNORED_NUM_ARG (17)
29 #ifndef _MSC_VER
30 #define IGNORE (0)
31 #endif
32
33 #define TYPED_MOCK_CLASS(className, mockType) \
34 class className : public CStrictUnorderedCallComparer< mockType<className> >
35
36 #define MICROMOCK_POINTER_TYPE_EQUAL(T) \
37 template<> \
38 static bool operator==<T*>(_In_ const CMockValue<T*>& lhs, \
39 _In_ const CMockValue<T*>& rhs) \
40 { \
41 bool result = false; \
42 if (lhs.GetValue() == rhs.GetValue()) \
43 { \
44 result = true; \
45 } else \
46 if ((NULL != lhs.GetValue()) && \
47 (NULL != rhs.GetValue()) && \
48 (*lhs.GetValue() == *rhs.GetValue())) \
49 { \
50 result = true; \
51 } \
52 return result; \
53 }
54
55 // A strict expected call implies that all arguments are checked
56 #define STRICT_EXPECTED_CALL(ClassName, ...) \
57 MU_C2(ClassName.Expected_, __VA_ARGS__)
58
59 // By using the below macro, none of the arguments are checked by default
60 // To specify checking the argument values, use the ValidateArgument
61 // expected call modifier method
62 #define EXPECTED_CALL(ClassName, ...) \
63 STRICT_EXPECTED_CALL(ClassName, __VA_ARGS__) \
64 .IgnoreAllArguments()
65
66 // When called only specifies actions for the specific call instance
67 // he actions specified this way are not included in the comparison
68 // of expected and actual calls
69 #define WHEN_CALLED(ClassName, ...) \
70 EXPECTED_CALL(ClassName, __VA_ARGS__) \
71 .OnlySpecifiesActions()
72
73 // This is the strict version of WHEN_CALLED
74 #define WHEN_CALLED_STRICT(ClassName, ...) \
75 STRICT_EXPECTED_CALL(ClassName, __VA_ARGS__) \
76 .OnlySpecifiesActions()
77
78 #define RECORD_ACTUAL_MOCK_CALL(mockMethodCall, fail) \
79 RecordActualCall(mockMethodCall, fail)
80
81 #define RECORD_EXPECTED_MOCK_CALL(mockMethodCall) \
82 RecordExpectedCall(mockMethodCall)
83
84 #define REMATCH_ACTUAL_MOCK_CALL(mockMethodCall) \
85 MatchActualCall(mockMethodCall)
86
87 #define RECORD_ACTUAL_STATIC_MOCK_CALL(mockMethodCall, fail) \
88 GetSingleton()->RecordActualCall(mockMethodCall, fail)
89
90 #define RECORD_EXPECTED_STATIC_MOCK_CALL(mockMethodCall)\
91 GetSingleton()->RecordExpectedCall(mockMethodCall)
92
93 #define REMATCH_ACTUAL_STATIC_MOCK_CALL(mockMethodCall) \
94 GetSingleton()->MatchActualCall(mockMethodCall)
95
96 #define STATIC_MOCK_LOCK(name) \
97 void MockLock_##name() \
98 { \
99 GetSingleton()->Lock(); \
100 }
101
102 #define STATIC_MOCK_UNLOCK() \
103 GetSingleton()->Unlock()
104
105 #define MOCK_METHOD_END(resultType, value) \
106 return (NULL != result) ? dynamic_cast<CMockValue<resultType>*>(result)->GetValue() : (value); \
107 }
108
109 #define MOCK_VOID_METHOD_END() \
110 result = result; \
111 }
112
113 // Added to only for cpp unittests. Shall be removed once cpp unittest are deprecated
114 #define DEFINE_MICROMOCK_ENUM_TO_STRING(type, ...) MICROMOCK_ENUM_TO_STRING(type, MU_FOR_EACH_1(MU_DEFINE_ENUMERATION_CONSTANT_AS_WIDESTRING, __VA_ARGS__));
115
116 #include "micromockcallmacros.h"
117
118 #endif // MICROMOCK_H