forked from cpputest/cpputest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMockSupport_c.cpp
904 lines (789 loc) · 28.5 KB
/
MockSupport_c.cpp
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
/*
* Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the <organization> nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "CppUTest/CppUTestConfig.h"
#include "CppUTest/Utest.h"
#include "CppUTest/UtestMacros.h"
#include "CppUTest/PlatformSpecificFunctions_c.h"
#include "CppUTestExt/MockSupport.h"
#include "CppUTestExt/MockSupport_c.h"
typedef void (*cpputest_cpp_function_pointer)(); /* Cl2000 requires cast to C++ function */
class MockFailureReporterTestTerminatorForInCOnlyCode : public TestTerminatorWithoutExceptions
{
public:
MockFailureReporterTestTerminatorForInCOnlyCode(bool crashOnFailure) : crashOnFailure_(crashOnFailure)
{
}
virtual void exitCurrentTest() const _override
{
if (crashOnFailure_)
UT_CRASH();
TestTerminatorWithoutExceptions::exitCurrentTest();
} // LCOV_EXCL_LINE
// LCOV_EXCL_START
virtual ~MockFailureReporterTestTerminatorForInCOnlyCode()
{
}
// LCOV_EXCL_STOP
private:
bool crashOnFailure_;
};
class MockFailureReporterForInCOnlyCode : public MockFailureReporter
{
public:
void failTest(const MockFailure& failure) _override
{
if (!getTestToFail()->hasFailed())
getTestToFail()->failWith(failure, MockFailureReporterTestTerminatorForInCOnlyCode(crashOnFailure_));
} // LCOV_EXCL_LINE
};
static MockSupport* currentMockSupport = NULL;
static MockExpectedCall* expectedCall = NULL;
static MockActualCall* actualCall = NULL;
static MockFailureReporterForInCOnlyCode failureReporterForC;
class MockCFunctionComparatorNode : public MockNamedValueComparator
{
public:
MockCFunctionComparatorNode(MockCFunctionComparatorNode* next, MockTypeEqualFunction_c equal, MockTypeValueToStringFunction_c toString)
: next_(next), equal_(equal), toString_(toString) {}
virtual ~MockCFunctionComparatorNode() {}
virtual bool isEqual(const void* object1, const void* object2) _override
{
return equal_(object1, object2) != 0;
}
virtual SimpleString valueToString(const void* object) _override
{
return SimpleString(toString_(object));
}
MockCFunctionComparatorNode* next_;
MockTypeEqualFunction_c equal_;
MockTypeValueToStringFunction_c toString_;
};
static MockCFunctionComparatorNode* comparatorList_ = NULL;
class MockCFunctionCopierNode : public MockNamedValueCopier
{
public:
MockCFunctionCopierNode(MockCFunctionCopierNode* next, MockTypeCopyFunction_c copier)
: next_(next), copier_(copier) {}
virtual ~MockCFunctionCopierNode() {}
virtual void copy(void* dst, const void* src) _override
{
copier_(dst, src);
}
MockCFunctionCopierNode* next_;
MockTypeCopyFunction_c copier_;
};
static MockCFunctionCopierNode* copierList_ = NULL;
extern "C" {
void strictOrder_c();
MockExpectedCall_c* expectOneCall_c(const char* name);
void expectNoCall_c(const char* name);
MockExpectedCall_c* expectNCalls_c(const unsigned int number, const char* name);
MockActualCall_c* actualCall_c(const char* name);
void disable_c();
void enable_c();
void ignoreOtherCalls_c();
void setBoolData_c(const char* name, int value);
void setIntData_c(const char* name, int value);
void setUnsignedIntData_c(const char* name, unsigned int value);
void setDoubleData_c(const char* name, double value);
void setStringData_c(const char* name, const char* value);
void setPointerData_c(const char* name, void* value);
void setConstPointerData_c(const char* name, const void* value);
void setFunctionPointerData_c(const char* name, void (*value)());
void setDataObject_c(const char* name, const char* type, void* value);
MockValue_c getData_c(const char* name);
int hasReturnValue_c();
void checkExpectations_c();
int expectedCallsLeft_c();
void clear_c();
void crashOnFailure_c(unsigned shouldCrash);
MockExpectedCall_c* withBoolParameters_c(const char* name, int value);
MockExpectedCall_c* withIntParameters_c(const char* name, int value);
MockExpectedCall_c* withUnsignedIntParameters_c(const char* name, unsigned int value);
MockExpectedCall_c* withLongIntParameters_c(const char* name, long int value);
MockExpectedCall_c* withUnsignedLongIntParameters_c(const char* name, unsigned long int value);
MockExpectedCall_c* withDoubleParameters_c(const char* name, double value);
MockExpectedCall_c* withStringParameters_c(const char* name, const char* value);
MockExpectedCall_c* withPointerParameters_c(const char* name, void* value);
MockExpectedCall_c* withConstPointerParameters_c(const char* name, const void* value);
MockExpectedCall_c* withFunctionPointerParameters_c(const char* name, void (*value)());
MockExpectedCall_c* withMemoryBufferParameters_c(const char* name, const unsigned char* value, size_t size);
MockExpectedCall_c* withParameterOfType_c(const char* type, const char* name, const void* value);
MockExpectedCall_c* withOutputParameterReturning_c(const char* name, const void* value, size_t size);
MockExpectedCall_c* withOutputParameterOfTypeReturning_c(const char* type, const char* name, const void* value);
MockExpectedCall_c* ignoreOtherParameters_c();
MockExpectedCall_c* andReturnBoolValue_c(int value);
MockExpectedCall_c* andReturnIntValue_c(int value);
MockExpectedCall_c* andReturnUnsignedIntValue_c(unsigned int value);
MockExpectedCall_c* andReturnLongIntValue_c(long int value);
MockExpectedCall_c* andReturnUnsignedLongIntValue_c(unsigned long int value);
MockExpectedCall_c* andReturnDoubleValue_c(double value);
MockExpectedCall_c* andReturnStringValue_c(const char* value);
MockExpectedCall_c* andReturnPointerValue_c(void* value);
MockExpectedCall_c* andReturnConstPointerValue_c(const void* value);
MockExpectedCall_c* andReturnFunctionPointerValue_c(void (*value)());
MockActualCall_c* withActualBoolParameters_c(const char* name, int value);
MockActualCall_c* withActualIntParameters_c(const char* name, int value);
MockActualCall_c* withActualUnsignedIntParameters_c(const char* name, unsigned int value);
MockActualCall_c* withActualLongIntParameters_c(const char* name, long int value);
MockActualCall_c* withActualUnsignedLongIntParameters_c(const char* name, unsigned long int value);
MockActualCall_c* withActualDoubleParameters_c(const char* name, double value);
MockActualCall_c* withActualStringParameters_c(const char* name, const char* value);
MockActualCall_c* withActualPointerParameters_c(const char* name, void* value);
MockActualCall_c* withActualConstPointerParameters_c(const char* name, const void* value);
MockActualCall_c* withActualFunctionPointerParameters_c(const char* name, void (*value)());
MockActualCall_c* withActualMemoryBufferParameters_c(const char* name, const unsigned char* value, size_t size);
MockActualCall_c* withActualParameterOfType_c(const char* type, const char* name, const void* value);
MockActualCall_c* withActualOutputParameter_c(const char* name, void* value);
MockActualCall_c* withActualOutputParameterOfType_c(const char* type, const char* name, void* value);
MockValue_c returnValue_c();
int boolReturnValue_c();
int returnBoolValueOrDefault_c(int defaultValue);
int intReturnValue_c();
int returnIntValueOrDefault_c(int defaultValue);
unsigned int unsignedIntReturnValue_c();
unsigned int returnUnsignedIntValueOrDefault_c(unsigned int defaultValue);
long int longIntReturnValue_c();
long int returnLongIntValueOrDefault_c(long int defaultValue);
unsigned long int unsignedLongIntReturnValue_c();
unsigned long int returnUnsignedLongIntValueOrDefault_c(unsigned long int defaultValue);
const char* stringReturnValue_c();
const char* returnStringValueOrDefault_c(const char * defaultValue);
double doubleReturnValue_c();
double returnDoubleValueOrDefault_c(double defaultValue);
void* pointerReturnValue_c();
void* returnPointerValueOrDefault_c(void * defaultValue);
const void* constPointerReturnValue_c();
const void* returnConstPointerValueOrDefault_c(const void * defaultValue);
void (*functionPointerReturnValue_c())();
void (*returnFunctionPointerValueOrDefault_c(void(*defaultValue)()))();
static void installComparator_c (const char* typeName, MockTypeEqualFunction_c isEqual, MockTypeValueToStringFunction_c valueToString)
{
comparatorList_ = new MockCFunctionComparatorNode(comparatorList_, isEqual, valueToString);
currentMockSupport->installComparator(typeName, *comparatorList_);
}
static void installCopier_c (const char* typeName, MockTypeCopyFunction_c copier)
{
copierList_ = new MockCFunctionCopierNode(copierList_, copier);
currentMockSupport->installCopier(typeName, *copierList_);
}
static void removeAllComparatorsAndCopiers_c()
{
while (comparatorList_) {
MockCFunctionComparatorNode *next = comparatorList_->next_;
delete comparatorList_;
comparatorList_ = next;
}
while (copierList_) {
MockCFunctionCopierNode *next = copierList_->next_;
delete copierList_;
copierList_ = next;
}
currentMockSupport->removeAllComparatorsAndCopiers();
}
static MockExpectedCall_c gExpectedCall = {
withBoolParameters_c,
withIntParameters_c,
withUnsignedIntParameters_c,
withLongIntParameters_c,
withUnsignedLongIntParameters_c,
withDoubleParameters_c,
withStringParameters_c,
withPointerParameters_c,
withConstPointerParameters_c,
withFunctionPointerParameters_c,
withMemoryBufferParameters_c,
withParameterOfType_c,
withOutputParameterReturning_c,
withOutputParameterOfTypeReturning_c,
ignoreOtherParameters_c,
andReturnBoolValue_c,
andReturnUnsignedIntValue_c,
andReturnIntValue_c,
andReturnLongIntValue_c,
andReturnUnsignedLongIntValue_c,
andReturnDoubleValue_c,
andReturnStringValue_c,
andReturnPointerValue_c,
andReturnConstPointerValue_c,
andReturnFunctionPointerValue_c,
};
static MockActualCall_c gActualCall = {
withActualBoolParameters_c,
withActualIntParameters_c,
withActualUnsignedIntParameters_c,
withActualLongIntParameters_c,
withActualUnsignedLongIntParameters_c,
withActualDoubleParameters_c,
withActualStringParameters_c,
withActualPointerParameters_c,
withActualConstPointerParameters_c,
withActualFunctionPointerParameters_c,
withActualMemoryBufferParameters_c,
withActualParameterOfType_c,
withActualOutputParameter_c,
withActualOutputParameterOfType_c,
hasReturnValue_c,
returnValue_c,
boolReturnValue_c,
returnBoolValueOrDefault_c,
intReturnValue_c,
returnIntValueOrDefault_c,
unsignedIntReturnValue_c,
returnUnsignedIntValueOrDefault_c,
longIntReturnValue_c,
returnLongIntValueOrDefault_c,
unsignedLongIntReturnValue_c,
returnUnsignedLongIntValueOrDefault_c,
stringReturnValue_c,
returnStringValueOrDefault_c,
doubleReturnValue_c,
returnDoubleValueOrDefault_c,
pointerReturnValue_c,
returnPointerValueOrDefault_c,
constPointerReturnValue_c,
returnConstPointerValueOrDefault_c,
functionPointerReturnValue_c,
returnFunctionPointerValueOrDefault_c
};
static MockSupport_c gMockSupport = {
strictOrder_c,
expectOneCall_c,
expectNoCall_c,
expectNCalls_c,
actualCall_c,
hasReturnValue_c,
returnValue_c,
boolReturnValue_c,
returnBoolValueOrDefault_c,
intReturnValue_c,
returnIntValueOrDefault_c,
unsignedIntReturnValue_c,
returnUnsignedIntValueOrDefault_c,
longIntReturnValue_c,
returnLongIntValueOrDefault_c,
unsignedLongIntReturnValue_c,
returnUnsignedLongIntValueOrDefault_c,
stringReturnValue_c,
returnStringValueOrDefault_c,
doubleReturnValue_c,
returnDoubleValueOrDefault_c,
pointerReturnValue_c,
returnPointerValueOrDefault_c,
constPointerReturnValue_c,
returnConstPointerValueOrDefault_c,
functionPointerReturnValue_c,
returnFunctionPointerValueOrDefault_c,
setBoolData_c,
setIntData_c,
setUnsignedIntData_c,
setStringData_c,
setDoubleData_c,
setPointerData_c,
setConstPointerData_c,
setFunctionPointerData_c,
setDataObject_c,
getData_c,
disable_c,
enable_c,
ignoreOtherCalls_c,
checkExpectations_c,
expectedCallsLeft_c,
clear_c,
crashOnFailure_c,
installComparator_c,
installCopier_c,
removeAllComparatorsAndCopiers_c
};
MockExpectedCall_c* withBoolParameters_c(const char* name, int value)
{
expectedCall = &expectedCall->withParameter(name, (value != 0));
return &gExpectedCall;
}
MockExpectedCall_c* withIntParameters_c(const char* name, int value)
{
expectedCall = &expectedCall->withParameter(name, value);
return &gExpectedCall;
}
MockExpectedCall_c* withUnsignedIntParameters_c(const char* name, unsigned int value)
{
expectedCall = &expectedCall->withParameter(name, value);
return &gExpectedCall;
}
MockExpectedCall_c* withLongIntParameters_c(const char* name, long int value)
{
expectedCall = &expectedCall->withParameter(name, value);
return &gExpectedCall;
}
MockExpectedCall_c* withUnsignedLongIntParameters_c(const char* name, unsigned long int value)
{
expectedCall = &expectedCall->withParameter(name, value);
return &gExpectedCall;
}
MockExpectedCall_c* withDoubleParameters_c(const char* name, double value)
{
expectedCall = &expectedCall->withParameter(name, value);
return &gExpectedCall;
}
MockExpectedCall_c* withStringParameters_c(const char* name, const char* value)
{
expectedCall = &expectedCall->withParameter(name, value);
return &gExpectedCall;
}
MockExpectedCall_c* withPointerParameters_c(const char* name, void* value)
{
expectedCall = &expectedCall->withParameter(name, value);
return &gExpectedCall;
}
MockExpectedCall_c* withConstPointerParameters_c(const char* name, const void* value)
{
expectedCall = &expectedCall->withParameter(name, value);
return &gExpectedCall;
}
MockExpectedCall_c* withFunctionPointerParameters_c(const char* name, void (*value)())
{
expectedCall = &expectedCall->withParameter(name, (cpputest_cpp_function_pointer)value);
return &gExpectedCall;
}
MockExpectedCall_c* withMemoryBufferParameters_c(const char* name, const unsigned char* value, size_t size)
{
expectedCall = &expectedCall->withParameter(name, value, size);
return &gExpectedCall;
}
MockExpectedCall_c* withParameterOfType_c(const char* type, const char* name, const void* value)
{
expectedCall = &expectedCall->withParameterOfType(type, name, value);
return &gExpectedCall;
}
MockExpectedCall_c* withOutputParameterReturning_c(const char* name, const void* value, size_t size)
{
expectedCall = &expectedCall->withOutputParameterReturning(name, value, size);
return &gExpectedCall;
}
MockExpectedCall_c* withOutputParameterOfTypeReturning_c(const char* type, const char* name, const void* value)
{
expectedCall = &expectedCall->withOutputParameterOfTypeReturning(type, name, value);
return &gExpectedCall;
}
MockExpectedCall_c* ignoreOtherParameters_c()
{
expectedCall = &expectedCall->ignoreOtherParameters();
return &gExpectedCall;
}
MockExpectedCall_c* andReturnBoolValue_c(int value)
{
expectedCall = &expectedCall->andReturnValue(value != 0);
return &gExpectedCall;
}
MockExpectedCall_c* andReturnUnsignedIntValue_c(unsigned int value)
{
expectedCall = &expectedCall->andReturnValue(value);
return &gExpectedCall;
}
MockExpectedCall_c* andReturnIntValue_c(int value)
{
expectedCall = &expectedCall->andReturnValue(value);
return &gExpectedCall;
}
MockExpectedCall_c* andReturnLongIntValue_c(long int value)
{
expectedCall = &expectedCall->andReturnValue(value);
return &gExpectedCall;
}
MockExpectedCall_c* andReturnUnsignedLongIntValue_c(unsigned long int value)
{
expectedCall = &expectedCall->andReturnValue(value);
return &gExpectedCall;
}
MockExpectedCall_c* andReturnDoubleValue_c(double value)
{
expectedCall = &expectedCall->andReturnValue(value);
return &gExpectedCall;
}
MockExpectedCall_c* andReturnStringValue_c(const char* value)
{
expectedCall = &expectedCall->andReturnValue(value);
return &gExpectedCall;
}
MockExpectedCall_c* andReturnPointerValue_c(void* value)
{
expectedCall = &expectedCall->andReturnValue(value);
return &gExpectedCall;
}
MockExpectedCall_c* andReturnConstPointerValue_c(const void* value)
{
expectedCall = &expectedCall->andReturnValue(value);
return &gExpectedCall;
}
MockExpectedCall_c* andReturnFunctionPointerValue_c(void (*value)())
{
expectedCall = &expectedCall->andReturnValue((cpputest_cpp_function_pointer)value);
return &gExpectedCall;
}
static MockValue_c getMockValueCFromNamedValue(const MockNamedValue& namedValue)
{
MockValue_c returnValue;
if (SimpleString::StrCmp(namedValue.getType().asCharString(), "bool") == 0) {
returnValue.type = MOCKVALUETYPE_BOOL;
returnValue.value.boolValue = namedValue.getBoolValue() ? 1 : 0;
}
else if (SimpleString::StrCmp(namedValue.getType().asCharString(), "int") == 0) {
returnValue.type = MOCKVALUETYPE_INTEGER;
returnValue.value.intValue = namedValue.getIntValue();
}
else if (SimpleString::StrCmp(namedValue.getType().asCharString(), "unsigned int") == 0) {
returnValue.type = MOCKVALUETYPE_UNSIGNED_INTEGER;
returnValue.value.unsignedIntValue = namedValue.getUnsignedIntValue();
}
else if (SimpleString::StrCmp(namedValue.getType().asCharString(), "long int") == 0) {
returnValue.type = MOCKVALUETYPE_LONG_INTEGER;
returnValue.value.longIntValue = namedValue.getLongIntValue();
}
else if (SimpleString::StrCmp(namedValue.getType().asCharString(), "unsigned long int") == 0) {
returnValue.type = MOCKVALUETYPE_UNSIGNED_LONG_INTEGER;
returnValue.value.unsignedLongIntValue = namedValue.getUnsignedLongIntValue();
}
else if (SimpleString::StrCmp(namedValue.getType().asCharString(), "double") == 0) {
returnValue.type = MOCKVALUETYPE_DOUBLE;
returnValue.value.doubleValue = namedValue.getDoubleValue();
}
else if (SimpleString::StrCmp(namedValue.getType().asCharString(), "const char*") == 0) {
returnValue.type = MOCKVALUETYPE_STRING;
returnValue.value.stringValue = namedValue.getStringValue();
}
else if (SimpleString::StrCmp(namedValue.getType().asCharString(), "void*") == 0) {
returnValue.type = MOCKVALUETYPE_POINTER;
returnValue.value.pointerValue = namedValue.getPointerValue();
}
else if (SimpleString::StrCmp(namedValue.getType().asCharString(), "const void*") == 0) {
returnValue.type = MOCKVALUETYPE_CONST_POINTER;
returnValue.value.constPointerValue = namedValue.getConstPointerValue();
}
else if (SimpleString::StrCmp(namedValue.getType().asCharString(), "void (*)()") == 0) {
returnValue.type = MOCKVALUETYPE_FUNCTIONPOINTER;
returnValue.value.functionPointerValue = (void (*)()) namedValue.getFunctionPointerValue();
}
else if (SimpleString::StrCmp(namedValue.getType().asCharString(), "const unsigned char*") == 0) {
returnValue.type = MOCKVALUETYPE_MEMORYBUFFER;
returnValue.value.memoryBufferValue = namedValue.getMemoryBuffer();
}
else {
returnValue.type = MOCKVALUETYPE_OBJECT;
returnValue.value.objectValue = namedValue.getObjectPointer();
}
return returnValue;
}
void strictOrder_c()
{
currentMockSupport->strictOrder();
}
MockExpectedCall_c* expectOneCall_c(const char* name)
{
expectedCall = ¤tMockSupport->expectOneCall(name);
return &gExpectedCall;
}
void expectNoCall_c(const char* name)
{
currentMockSupport->expectNoCall(name);
}
MockExpectedCall_c* expectNCalls_c(const unsigned int number, const char* name)
{
expectedCall = ¤tMockSupport->expectNCalls(number, name);
return &gExpectedCall;
}
MockActualCall_c* actualCall_c(const char* name)
{
actualCall = ¤tMockSupport->actualCall(name);
return &gActualCall;
}
MockActualCall_c* withActualBoolParameters_c(const char* name, int value)
{
actualCall = &actualCall->withParameter(name, (value != 0));
return &gActualCall;
}
MockActualCall_c* withActualIntParameters_c(const char* name, int value)
{
actualCall = &actualCall->withParameter(name, value);
return &gActualCall;
}
MockActualCall_c* withActualUnsignedIntParameters_c(const char* name, unsigned int value)
{
actualCall = &actualCall->withParameter(name, value);
return &gActualCall;
}
MockActualCall_c* withActualLongIntParameters_c(const char* name, long int value)
{
actualCall = &actualCall->withParameter(name, value);
return &gActualCall;
}
MockActualCall_c* withActualUnsignedLongIntParameters_c(const char* name, unsigned long int value)
{
actualCall = &actualCall->withParameter(name, value);
return &gActualCall;
}
MockActualCall_c* withActualDoubleParameters_c(const char* name, double value)
{
actualCall = &actualCall->withParameter(name, value);
return &gActualCall;
}
MockActualCall_c* withActualStringParameters_c(const char* name, const char* value)
{
actualCall = &actualCall->withParameter(name, value);
return &gActualCall;
}
MockActualCall_c* withActualPointerParameters_c(const char* name, void* value)
{
actualCall = &actualCall->withParameter(name, value);
return &gActualCall;
}
MockActualCall_c* withActualConstPointerParameters_c(const char* name, const void* value)
{
actualCall = &actualCall->withParameter(name, value);
return &gActualCall;
}
MockActualCall_c* withActualFunctionPointerParameters_c(const char* name, void (*value)())
{
actualCall = &actualCall->withParameter(name, (cpputest_cpp_function_pointer) value);
return &gActualCall;
}
MockActualCall_c* withActualMemoryBufferParameters_c(const char* name, const unsigned char* value, size_t size)
{
actualCall = &actualCall->withParameter(name, value, size);
return &gActualCall;
}
MockActualCall_c* withActualParameterOfType_c(const char* type, const char* name, const void* value)
{
actualCall = &actualCall->withParameterOfType(type, name, value);
return &gActualCall;
}
MockActualCall_c* withActualOutputParameter_c(const char* name, void* value)
{
actualCall = &actualCall->withOutputParameter(name, value);
return &gActualCall;
}
MockActualCall_c* withActualOutputParameterOfType_c(const char* type, const char* name, void* value)
{
actualCall = &actualCall->withOutputParameterOfType(type, name, value);
return &gActualCall;
}
MockValue_c returnValue_c()
{
return getMockValueCFromNamedValue(actualCall->returnValue());
}
int boolReturnValue_c()
{
return actualCall->returnBoolValue() ? 1 : 0;
}
int returnBoolValueOrDefault_c(int defaultValue)
{
if (!hasReturnValue_c()) {
return defaultValue;
}
return boolReturnValue_c();
}
int intReturnValue_c()
{
return actualCall->returnIntValue();
}
int returnIntValueOrDefault_c(int defaultValue)
{
if (!hasReturnValue_c()) {
return defaultValue;
}
return intReturnValue_c();
}
unsigned int unsignedIntReturnValue_c()
{
return actualCall->returnUnsignedIntValue();
}
unsigned int returnUnsignedIntValueOrDefault_c(unsigned int defaultValue)
{
if (!hasReturnValue_c()) {
return defaultValue;
}
return unsignedIntReturnValue_c();
}
long int longIntReturnValue_c()
{
return actualCall->returnLongIntValue();
}
long int returnLongIntValueOrDefault_c(long int defaultValue)
{
if (!hasReturnValue_c()) {
return defaultValue;
}
return longIntReturnValue_c();
}
unsigned long int unsignedLongIntReturnValue_c()
{
return actualCall->returnUnsignedLongIntValue();
}
unsigned long int returnUnsignedLongIntValueOrDefault_c(unsigned long int defaultValue)
{
if (!hasReturnValue_c()) {
return defaultValue;
}
return unsignedLongIntReturnValue_c();
}
const char* stringReturnValue_c()
{
return actualCall->returnStringValue();
}
const char* returnStringValueOrDefault_c(const char * defaultValue)
{
if (!hasReturnValue_c()) {
return defaultValue;
}
return stringReturnValue_c();
}
double doubleReturnValue_c()
{
return actualCall->returnDoubleValue();
}
double returnDoubleValueOrDefault_c(double defaultValue)
{
if (!hasReturnValue_c()) {
return defaultValue;
}
return doubleReturnValue_c();
}
void* pointerReturnValue_c()
{
return actualCall->returnPointerValue();
}
void* returnPointerValueOrDefault_c(void * defaultValue)
{
if (!hasReturnValue_c()) {
return defaultValue;
}
return pointerReturnValue_c();
}
const void* constPointerReturnValue_c()
{
return actualCall->returnConstPointerValue();
}
const void* returnConstPointerValueOrDefault_c(const void * defaultValue)
{
if (!hasReturnValue_c()) {
return defaultValue;
}
return constPointerReturnValue_c();
}
void (*functionPointerReturnValue_c())()
{
return (void (*)()) actualCall->returnFunctionPointerValue();
}
void (*returnFunctionPointerValueOrDefault_c(void (*defaultValue)()))()
{
if (!hasReturnValue_c()) {
return defaultValue;
}
return functionPointerReturnValue_c();
}
void disable_c()
{
currentMockSupport->disable();
}
void enable_c()
{
currentMockSupport->enable();
}
void ignoreOtherCalls_c()
{
currentMockSupport->ignoreOtherCalls();
}
void setBoolData_c(const char* name, int value)
{
currentMockSupport->setData(name, (value != 0));
}
void setIntData_c(const char* name, int value)
{
currentMockSupport->setData(name, value);
}
void setUnsignedIntData_c(const char* name, unsigned int value)
{
currentMockSupport->setData(name, value);
}
void setDoubleData_c(const char* name, double value)
{
currentMockSupport->setData(name, value);
}
void setStringData_c(const char* name, const char* value)
{
currentMockSupport->setData(name, value);
}
void setPointerData_c(const char* name, void* value)
{
currentMockSupport->setData(name, value);
}
void setConstPointerData_c(const char* name, const void* value)
{
currentMockSupport->setData(name, value);
}
void setFunctionPointerData_c(const char* name, void (*value)())
{
currentMockSupport->setData(name, (cpputest_cpp_function_pointer) value);
}
void setDataObject_c(const char* name, const char* type, void* value)
{
currentMockSupport->setDataObject(name, type, value);
}
MockValue_c getData_c(const char* name)
{
return getMockValueCFromNamedValue(currentMockSupport->getData(name));
}
int hasReturnValue_c()
{
return currentMockSupport->hasReturnValue();
}
void checkExpectations_c()
{
currentMockSupport->checkExpectations();
}
int expectedCallsLeft_c()
{
return currentMockSupport->expectedCallsLeft();
}
void clear_c()
{
currentMockSupport->clear();
}
void crashOnFailure_c(unsigned shouldCrash)
{
currentMockSupport->crashOnFailure(0 != shouldCrash);
}
MockSupport_c* mock_c()
{
currentMockSupport = &mock("", &failureReporterForC);
return &gMockSupport;
}
MockSupport_c* mock_scope_c(const char* scope)
{
currentMockSupport = &mock(scope, &failureReporterForC);
return &gMockSupport;
}
}