forked from ivogeorg/msl-clang-003
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmocka.h
2079 lines (1940 loc) · 64.4 KB
/
cmocka.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CMOCKA_H_
#define CMOCKA_H_
#ifdef _WIN32
# ifdef _MSC_VER
#define __func__ __FUNCTION__
# ifndef inline
#define inline __inline
# endif /* inline */
# if _MSC_VER < 1500
# ifdef __cplusplus
extern "C" {
# endif /* __cplusplus */
int __stdcall IsDebuggerPresent();
# ifdef __cplusplus
} /* extern "C" */
# endif /* __cplusplus */
# endif /* _MSC_VER < 1500 */
# endif /* _MSC_VER */
#endif /* _WIN32 */
/**
* @defgroup cmocka The CMocka API
*
* These headers or their equivalents should be included prior to including
* this header file.
* @code
* #include <stdarg.h>
* #include <stddef.h>
* #include <setjmp.h>
* @endcode
*
* This allows test applications to use custom definitions of C standard
* library functions and types.
*
* @{
*/
/* If __WORDSIZE is not set, try to figure it out and default to 32 bit. */
#ifndef __WORDSIZE
# if defined(__x86_64__) && !defined(__ILP32__)
# define __WORDSIZE 64
# else
# define __WORDSIZE 32
# endif
#endif
#ifdef DOXYGEN
/**
* Largest integral type. This type should be large enough to hold any
* pointer or integer supported by the compiler.
*/
typedef uintmax_t LargestIntegralType;
#else /* DOXGEN */
#ifndef LargestIntegralType
# if __WORDSIZE == 64
# define LargestIntegralType unsigned long int
# else
# define LargestIntegralType unsigned long long int
# endif
#endif /* LargestIntegralType */
#endif /* DOXYGEN */
/* Printf format used to display LargestIntegralType. */
#ifndef LargestIntegralTypePrintfFormat
# ifdef _WIN32
# define LargestIntegralTypePrintfFormat "0x%I64x"
# else
# if __WORDSIZE == 64
# define LargestIntegralTypePrintfFormat "%#lx"
# else
# define LargestIntegralTypePrintfFormat "%#llx"
# endif
# endif /* _WIN32 */
#endif /* LargestIntegralTypePrintfFormat */
/* Perform an unsigned cast to LargestIntegralType. */
#define cast_to_largest_integral_type(value) \
((LargestIntegralType)(value))
/* Smallest integral type capable of holding a pointer. */
#if !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
# if defined(_WIN32)
/* WIN32 is an ILP32 platform */
typedef unsigned int uintptr_t;
# elif defined(_WIN64)
typedef unsigned long int uintptr_t
# else /* _WIN32 */
/* ILP32 and LP64 platforms */
# ifdef __WORDSIZE /* glibc */
# if __WORDSIZE == 64
typedef unsigned long int uintptr_t;
# else
typedef unsigned int uintptr_t;
# endif /* __WORDSIZE == 64 */
# else /* __WORDSIZE */
# if defined(_LP64) || defined(_I32LPx)
typedef unsigned long int uintptr_t;
# else
typedef unsigned int uintptr_t;
# endif
# endif /* __WORDSIZE */
# endif /* _WIN32 */
# define _UINTPTR_T
# define _UINTPTR_T_DEFINED
#endif /* !defined(_UINTPTR_T) || !defined(_UINTPTR_T_DEFINED) */
/* Perform an unsigned cast to uintptr_t. */
#define cast_to_pointer_integral_type(value) \
((uintptr_t)((size_t)(value)))
/* Perform a cast of a pointer to LargestIntegralType */
#define cast_ptr_to_largest_integral_type(value) \
cast_to_largest_integral_type(cast_to_pointer_integral_type(value))
/* GCC have printf type attribute check. */
#ifdef __GNUC__
#define CMOCKA_PRINTF_ATTRIBUTE(a,b) \
__attribute__ ((__format__ (__printf__, a, b)))
#else
#define CMOCKA_PRINTF_ATTRIBUTE(a,b)
#endif /* __GNUC__ */
#if defined(__GNUC__)
#define CMOCKA_DEPRECATED __attribute__ ((deprecated))
#elif defined(_MSC_VER)
#define CMOCKA_DEPRECATED __declspec(deprecated)
#else
#define CMOCKA_DEPRECATED
#endif
/**
* @defgroup cmocka_mock Mock Objects
* @ingroup cmocka
*
* Mock objects mock objects are simulated objects that mimic the behavior of
* real objects. Instead of calling the real objects, the tested object calls a
* mock object that merely asserts that the correct methods were called, with
* the expected parameters, in the correct order.
*
* <ul>
* <li><strong>will_return(function, value)</strong> - The will_return() macro
* pushes a value onto a stack of mock values. This macro is intended to be
* used by the unit test itself, while programming the behaviour of the mocked
* object.</li>
*
* <li><strong>mock()</strong> - the mock macro pops a value from a stack of
* test values. The user of the mock() macro is the mocked object that uses it
* to learn how it should behave.</li>
* </ul>
*
* Because the will_return() and mock() are intended to be used in pairs, the
* cmocka library would fail the test if there are more values pushed onto the
* stack using will_return() than consumed with mock() and vice-versa.
*
* The following unit test stub illustrates how would a unit test instruct the
* mock object to return a particular value:
*
* @code
* will_return(chef_cook, "hotdog");
* will_return(chef_cook, 0);
* @endcode
*
* Now the mock object can check if the parameter it received is the parameter
* which is expected by the test driver. This can be done the following way:
*
* @code
* int chef_cook(const char *order, char **dish_out)
* {
* check_expected(order);
* }
* @endcode
*
* For a complete example please at a look
* <a href="http://git.cryptomilk.org/projects/cmocka.git/tree/example/chef_wrap/waiter_test_wrap.c">here</a>.
*
* @{
*/
#ifdef DOXYGEN
/**
* @brief Retrieve a return value of the current function.
*
* @return The value which was stored to return by this function.
*
* @see will_return()
*/
LargestIntegralType mock(void);
#else
#define mock() _mock(__func__, __FILE__, __LINE__)
#endif
#ifdef DOXYGEN
/**
* @brief Retrieve a typed return value of the current function.
*
* The value would be casted to type internally to avoid having the
* caller to do the cast manually.
*
* @param[in] #type The expected type of the return value
*
* @return The value which was stored to return by this function.
*
* @code
* int param;
*
* param = mock_type(int);
* @endcode
*
* @see will_return()
* @see mock()
* @see mock_ptr_type()
*/
#type mock_type(#type);
#else
#define mock_type(type) ((type) mock())
#endif
#ifdef DOXYGEN
/**
* @brief Retrieve a typed return value of the current function.
*
* The value would be casted to type internally to avoid having the
* caller to do the cast manually but also casted to uintptr_t to make
* sure the result has a valid size to be used as a pointer.
*
* @param[in] #type The expected type of the return value
*
* @return The value which was stored to return by this function.
*
* @code
* char *param;
*
* param = mock_ptr_type(char *);
* @endcode
*
* @see will_return()
* @see mock()
* @see mock_type()
*/
type mock_ptr_type(#type);
#else
#define mock_ptr_type(type) ((type) (uintptr_t) mock())
#endif
#ifdef DOXYGEN
/**
* @brief Store a value to be returned by mock() later.
*
* @param[in] #function The function which should return the given value.
*
* @param[in] value The value to be returned by mock().
*
* @code
* int return_integer(void)
* {
* return (int)mock();
* }
*
* static void test_integer_return(void **state)
* {
* will_return(return_integer, 42);
*
* assert_int_equal(my_function_calling_return_integer(), 42);
* }
* @endcode
*
* @see mock()
* @see will_return_count()
*/
void will_return(#function, LargestIntegralType value);
#else
#define will_return(function, value) \
_will_return(#function, __FILE__, __LINE__, \
cast_to_largest_integral_type(value), 1)
#endif
#ifdef DOXYGEN
/**
* @brief Store a value to be returned by mock() later.
*
* @param[in] #function The function which should return the given value.
*
* @param[in] value The value to be returned by mock().
*
* @param[in] count The parameter returns the number of times the value should
* be returned by mock(). If count is set to -1 the value will
* always be returned.
*
* @see mock()
*/
void will_return_count(#function, LargestIntegralType value, int count);
#else
#define will_return_count(function, value, count) \
_will_return(#function, __FILE__, __LINE__, \
cast_to_largest_integral_type(value), count)
#endif
#ifdef DOXYGEN
/**
* @brief Store a value that will be always returned by mock().
*
* @param[in] #function The function which should return the given value.
*
* @param[in] #value The value to be returned by mock().
*
* This is equivalent to:
* @code
* will_return_count(function, value, -1);
* @endcode
*
* @see will_return_count()
* @see mock()
*/
void will_return_always(#function, LargestIntegralType value);
#else
#define will_return_always(function, value) \
will_return_count(function, (value), -1)
#endif
/** @} */
/**
* @defgroup cmocka_param Checking Parameters
* @ingroup cmocka
*
* Functionality to store expected values for mock function parameters.
*
* In addition to storing the return values of mock functions, cmocka provides
* functionality to store expected values for mock function parameters using
* the expect_*() functions provided. A mock function parameter can then be
* validated using the check_expected() macro.
*
* Successive calls to expect_*() macros for a parameter queues values to check
* the specified parameter. check_expected() checks a function parameter
* against the next value queued using expect_*(), if the parameter check fails
* a test failure is signalled. In addition if check_expected() is called and
* no more parameter values are queued a test failure occurs.
*
* The following test stub illustrates how to do this. First is the the function
* we call in the test driver:
*
* @code
* static void test_driver(void **state)
* {
* expect_string(chef_cook, order, "hotdog");
* }
* @endcode
*
* Now the chef_cook function can check if the parameter we got passed is the
* parameter which is expected by the test driver. This can be done the
* following way:
*
* @code
* int chef_cook(const char *order, char **dish_out)
* {
* check_expected(order);
* }
* @endcode
*
* For a complete example please at a look at
* <a href="http://git.cryptomilk.org/projects/cmocka.git/tree/example/chef_wrap/waiter_test_wrap.c">here</a>
*
* @{
*/
/*
* Add a custom parameter checking function. If the event parameter is NULL
* the event structure is allocated internally by this function. If event
* parameter is provided it must be allocated on the heap and doesn't need to
* be deallocated by the caller.
*/
#ifdef DOXYGEN
/**
* @brief Add a custom parameter checking function.
*
* If the event parameter is NULL the event structure is allocated internally
* by this function. If the parameter is provided it must be allocated on the
* heap and doesn't need to be deallocated by the caller.
*
* @param[in] #function The function to add a custom parameter checking
* function for.
*
* @param[in] #parameter The parameters passed to the function.
*
* @param[in] #check_function The check function to call.
*
* @param[in] check_data The data to pass to the check function.
*/
void expect_check(#function, #parameter, #check_function, const void *check_data);
#else
#define expect_check(function, parameter, check_function, check_data) \
_expect_check(#function, #parameter, __FILE__, __LINE__, check_function, \
cast_to_largest_integral_type(check_data), NULL, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is part of the provided
* array.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] value_array[] The array to check for the value.
*
* @see check_expected().
*/
void expect_in_set(#function, #parameter, LargestIntegralType value_array[]);
#else
#define expect_in_set(function, parameter, value_array) \
expect_in_set_count(function, parameter, value_array, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is part of the provided
* array.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] value_array[] The array to check for the value.
*
* @param[in] count The count parameter returns the number of times the value
* should be returned by check_expected(). If count is set
* to -1 the value will always be returned.
*
* @see check_expected().
*/
void expect_in_set_count(#function, #parameter, LargestIntegralType value_array[], size_t count);
#else
#define expect_in_set_count(function, parameter, value_array, count) \
_expect_in_set(#function, #parameter, __FILE__, __LINE__, value_array, \
sizeof(value_array) / sizeof((value_array)[0]), count)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is not part of the
* provided array.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] value_array[] The array to check for the value.
*
* @see check_expected().
*/
void expect_not_in_set(#function, #parameter, LargestIntegralType value_array[]);
#else
#define expect_not_in_set(function, parameter, value_array) \
expect_not_in_set_count(function, parameter, value_array, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is not part of the
* provided array.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] value_array[] The array to check for the value.
*
* @param[in] count The count parameter returns the number of times the value
* should be returned by check_expected(). If count is set
* to -1 the value will always be returned.
*
* @see check_expected().
*/
void expect_not_in_set_count(#function, #parameter, LargestIntegralType value_array[], size_t count);
#else
#define expect_not_in_set_count(function, parameter, value_array, count) \
_expect_not_in_set( \
#function, #parameter, __FILE__, __LINE__, value_array, \
sizeof(value_array) / sizeof((value_array)[0]), count)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check a parameter is inside a numerical range.
* The check would succeed if minimum <= value <= maximum.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] minimum The lower boundary of the interval to check against.
*
* @param[in] maximum The upper boundary of the interval to check against.
*
* @see check_expected().
*/
void expect_in_range(#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum);
#else
#define expect_in_range(function, parameter, minimum, maximum) \
expect_in_range_count(function, parameter, minimum, maximum, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check a parameter is inside a
* numerical range. The check would succeed if minimum <= value <= maximum.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] minimum The lower boundary of the interval to check against.
*
* @param[in] maximum The upper boundary of the interval to check against.
*
* @param[in] count The count parameter returns the number of times the value
* should be returned by check_expected(). If count is set
* to -1 the value will always be returned.
*
* @see check_expected().
*/
void expect_in_range_count(#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum, size_t count);
#else
#define expect_in_range_count(function, parameter, minimum, maximum, count) \
_expect_in_range(#function, #parameter, __FILE__, __LINE__, minimum, \
maximum, count)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check a parameter is outside a numerical range.
* The check would succeed if minimum > value > maximum.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] minimum The lower boundary of the interval to check against.
*
* @param[in] maximum The upper boundary of the interval to check against.
*
* @see check_expected().
*/
void expect_not_in_range(#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum);
#else
#define expect_not_in_range(function, parameter, minimum, maximum) \
expect_not_in_range_count(function, parameter, minimum, maximum, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check a parameter is outside a
* numerical range. The check would succeed if minimum > value > maximum.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] minimum The lower boundary of the interval to check against.
*
* @param[in] maximum The upper boundary of the interval to check against.
*
* @param[in] count The count parameter returns the number of times the value
* should be returned by check_expected(). If count is set
* to -1 the value will always be returned.
*
* @see check_expected().
*/
void expect_not_in_range_count(#function, #parameter, LargestIntegralType minimum, LargestIntegralType maximum, size_t count);
#else
#define expect_not_in_range_count(function, parameter, minimum, maximum, \
count) \
_expect_not_in_range(#function, #parameter, __FILE__, __LINE__, \
minimum, maximum, count)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if a parameter is the given value.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] value The value to check.
*
* @see check_expected().
*/
void expect_value(#function, #parameter, LargestIntegralType value);
#else
#define expect_value(function, parameter, value) \
expect_value_count(function, parameter, value, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check if a parameter is the given value.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] value The value to check.
*
* @param[in] count The count parameter returns the number of times the value
* should be returned by check_expected(). If count is set
* to -1 the value will always be returned.
*
* @see check_expected().
*/
void expect_value_count(#function, #parameter, LargestIntegralType value, size_t count);
#else
#define expect_value_count(function, parameter, value, count) \
_expect_value(#function, #parameter, __FILE__, __LINE__, \
cast_to_largest_integral_type(value), count)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if a parameter isn't the given value.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] value The value to check.
*
* @see check_expected().
*/
void expect_not_value(#function, #parameter, LargestIntegralType value);
#else
#define expect_not_value(function, parameter, value) \
expect_not_value_count(function, parameter, value, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check if a parameter isn't the given value.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] value The value to check.
*
* @param[in] count The count parameter returns the number of times the value
* should be returned by check_expected(). If count is set
* to -1 the value will always be returned.
*
* @see check_expected().
*/
void expect_not_value_count(#function, #parameter, LargestIntegralType value, size_t count);
#else
#define expect_not_value_count(function, parameter, value, count) \
_expect_not_value(#function, #parameter, __FILE__, __LINE__, \
cast_to_largest_integral_type(value), count)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is equal to the
* provided string.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] string The string value to compare.
*
* @see check_expected().
*/
void expect_string(#function, #parameter, const char *string);
#else
#define expect_string(function, parameter, string) \
expect_string_count(function, parameter, string, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value is equal to the
* provided string.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] string The string value to compare.
*
* @param[in] count The count parameter returns the number of times the value
* should be returned by check_expected(). If count is set
* to -1 the value will always be returned.
*
* @see check_expected().
*/
void expect_string_count(#function, #parameter, const char *string, size_t count);
#else
#define expect_string_count(function, parameter, string, count) \
_expect_string(#function, #parameter, __FILE__, __LINE__, \
(const char*)(string), count)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value isn't equal to the
* provided string.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] string The string value to compare.
*
* @see check_expected().
*/
void expect_not_string(#function, #parameter, const char *string);
#else
#define expect_not_string(function, parameter, string) \
expect_not_string_count(function, parameter, string, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter value isn't equal to the
* provided string.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] string The string value to compare.
*
* @param[in] count The count parameter returns the number of times the value
* should be returned by check_expected(). If count is set
* to -1 the value will always be returned.
*
* @see check_expected().
*/
void expect_not_string_count(#function, #parameter, const char *string, size_t count);
#else
#define expect_not_string_count(function, parameter, string, count) \
_expect_not_string(#function, #parameter, __FILE__, __LINE__, \
(const char*)(string), count)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter does match an area of memory.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] memory The memory to compare.
*
* @param[in] size The size of the memory to compare.
*
* @see check_expected().
*/
void expect_memory(#function, #parameter, void *memory, size_t size);
#else
#define expect_memory(function, parameter, memory, size) \
expect_memory_count(function, parameter, memory, size, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check if the parameter does match an area
* of memory.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] memory The memory to compare.
*
* @param[in] size The size of the memory to compare.
*
* @param[in] count The count parameter returns the number of times the value
* should be returned by check_expected(). If count is set
* to -1 the value will always be returned.
*
* @see check_expected().
*/
void expect_memory_count(#function, #parameter, void *memory, size_t size, size_t count);
#else
#define expect_memory_count(function, parameter, memory, size, count) \
_expect_memory(#function, #parameter, __FILE__, __LINE__, \
(const void*)(memory), size, count)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if the parameter doesn't match an area of
* memory.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] memory The memory to compare.
*
* @param[in] size The size of the memory to compare.
*
* @see check_expected().
*/
void expect_not_memory(#function, #parameter, void *memory, size_t size);
#else
#define expect_not_memory(function, parameter, memory, size) \
expect_not_memory_count(function, parameter, memory, size, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check if the parameter doesn't match an
* area of memory.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] memory The memory to compare.
*
* @param[in] size The size of the memory to compare.
*
* @param[in] count The count parameter returns the number of times the value
* should be returned by check_expected(). If count is set
* to -1 the value will always be returned.
*
* @see check_expected().
*/
void expect_not_memory_count(#function, #parameter, void *memory, size_t size, size_t count);
#else
#define expect_not_memory_count(function, parameter, memory, size, count) \
_expect_not_memory(#function, #parameter, __FILE__, __LINE__, \
(const void*)(memory), size, count)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to check if a parameter (of any value) has been passed.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @see check_expected().
*/
void expect_any(#function, #parameter);
#else
#define expect_any(function, parameter) \
expect_any_count(function, parameter, 1)
#endif
#ifdef DOXYGEN
/**
* @brief Add an event to repeatedly check if a parameter (of any value) has
* been passed.
*
* The event is triggered by calling check_expected() in the mocked function.
*
* @param[in] #function The function to add the check for.
*
* @param[in] #parameter The name of the parameter passed to the function.
*
* @param[in] count The count parameter returns the number of times the value
* should be returned by check_expected(). If count is set
* to -1 the value will always be returned.
*
* @see check_expected().
*/
void expect_any_count(#function, #parameter, size_t count);
#else
#define expect_any_count(function, parameter, count) \
_expect_any(#function, #parameter, __FILE__, __LINE__, count)
#endif
#ifdef DOXYGEN
/**
* @brief Determine whether a function parameter is correct.
*
* This ensures the next value queued by one of the expect_*() macros matches
* the specified variable.
*
* This function needs to be called in the mock object.
*
* @param[in] #parameter The parameter to check.
*/
void check_expected(#parameter);
#else
#define check_expected(parameter) \
_check_expected(__func__, #parameter, __FILE__, __LINE__, \
cast_to_largest_integral_type(parameter))
#endif
#ifdef DOXYGEN
/**
* @brief Determine whether a function parameter is correct.
*
* This ensures the next value queued by one of the expect_*() macros matches
* the specified variable.
*
* This function needs to be called in the mock object.
*
* @param[in] #parameter The pointer to check.
*/
void check_expected_ptr(#parameter);
#else
#define check_expected_ptr(parameter) \
_check_expected(__func__, #parameter, __FILE__, __LINE__, \
cast_ptr_to_largest_integral_type(parameter))
#endif
/** @} */
/**
* @defgroup cmocka_asserts Assert Macros
* @ingroup cmocka
*
* This is a set of useful assert macros like the standard C libary's
* assert(3) macro.
*
* On an assertion failure a cmocka assert macro will write the failure to the
* standard error stream and signal a test failure. Due to limitations of the C
* language the general C standard library assert() and cmocka's assert_true()
* and assert_false() macros can only display the expression that caused the
* assert failure. cmocka's type specific assert macros, assert_{type}_equal()
* and assert_{type}_not_equal(), display the data that caused the assertion
* failure which increases data visibility aiding debugging of failing test
* cases.
*
* @{
*/