• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thetic / mutiny / 24091888441

07 Apr 2026 04:15PM UTC coverage: 98.638% (-0.3%) from 98.944%
24091888441

Pull #46

github

web-flow
Merge 27d6dcf7c into 6bef603bd
Pull Request #46: Replace typed mock virtuals with template NVI

168 of 169 new or added lines in 8 files covered. (99.41%)

17 existing lines in 2 files now uncovered.

5504 of 5580 relevant lines covered (98.64%)

3462.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.31
/src/mock/mock.c.cpp
1
#include "mutiny/mock.h"
2

3
#include "mutiny/mock/Failure.hpp"
4
#include "mutiny/mock/NamedValueComparator.hpp"
5
#include "mutiny/mock/NamedValueCopier.hpp"
6

7
#include "mutiny/test/Shell.hpp"
8

9
#include "mutiny/mock.hpp"
10

11
namespace {
12

13
class MockFailureReporterTestTerminatorForInCOnlyCode
14
  : public mu::tiny::test::Terminator
15
{
16
public:
17
  MockFailureReporterTestTerminatorForInCOnlyCode(bool crash_on_failure)
7✔
18
    : crash_on_failure_(crash_on_failure)
7✔
19
  {
20
  }
7✔
21

22
  void exit_current_test() const override
7✔
23
  {
24
    if (crash_on_failure_)
7✔
25
      mu::tiny::test::Shell::crash();
1✔
26

27
    mu::tiny::test::Shell::get_current_test_terminator_without_exceptions()
7✔
28
        .exit_current_test();
7✔
29
  }
×
30
  ~MockFailureReporterTestTerminatorForInCOnlyCode() override = default;
×
31

32
private:
33
  bool crash_on_failure_;
34
};
35

36
class MockFailureReporterForInCOnlyCode : public mu::tiny::mock::FailureReporter
37
{
38
public:
39
  void fail_test(mu::tiny::mock::Failure failure) override
7✔
40
  {
41
    if (!get_test_to_fail()->has_failed()) {
7✔
42
      get_test_to_fail()->add_failure(failure);
7✔
43
      {
44
        auto freed(static_cast<mu::tiny::mock::Failure&&>(failure));
7✔
45
      }
7✔
46
      exit_test();
7✔
47
    }
48
  }
×
49

50
  void exit_test() override
7✔
51
  {
52
    MockFailureReporterTestTerminatorForInCOnlyCode(crash_on_failure_)
7✔
53
        .exit_current_test();
7✔
54
  }
×
55
};
56

57
mu::tiny::mock::Support* current_mock_support = nullptr;
58
mu::tiny::mock::ExpectedCall* expected_call = nullptr;
59
mu::tiny::mock::ActualCall* current_actual_call = nullptr;
60
MockFailureReporterForInCOnlyCode failure_reporter_for_c;
61

62
class MockCFunctionComparatorNode : public mu::tiny::mock::NamedValueComparator
63
{
64
public:
65
  MockCFunctionComparatorNode(
3✔
66
      MockCFunctionComparatorNode* nx,
67
      MutinyMockTypeEqualFunction eq,
68
      MutinyMockTypeValueToStringFunction ts
69
  )
70
    : next(nx)
6✔
71
    , equal(eq)
3✔
72
    , to_string(ts)
3✔
73
  {
74
  }
3✔
75
  ~MockCFunctionComparatorNode() override = default;
6✔
76

77
  bool is_equal(const void* object1, const void* object2) override
3✔
78
  {
79
    return equal(object1, object2) != 0;
3✔
80
  }
81
  mu::tiny::String value_to_string(const void* object) override
3✔
82
  {
83
    return mu::tiny::String(to_string(object));
3✔
84
  }
85

86
  MockCFunctionComparatorNode* next;
87
  MutinyMockTypeEqualFunction equal;
88
  MutinyMockTypeValueToStringFunction to_string;
89
};
90

91
MockCFunctionComparatorNode* comparator_list = nullptr;
92

93
class MockCFunctionCopierNode : public mu::tiny::mock::NamedValueCopier
94
{
95
public:
96
  MockCFunctionCopierNode(
2✔
97
      MockCFunctionCopierNode* nx,
98
      MutinyMockTypeCopyFunction cp
99
  )
100
    : next(nx)
4✔
101
    , copier(cp)
2✔
102
  {
103
  }
2✔
104
  ~MockCFunctionCopierNode() override = default;
4✔
105

106
  void copy(void* dst, const void* src) override { copier(dst, src); }
2✔
107

108
  MockCFunctionCopierNode* next;
109
  MutinyMockTypeCopyFunction copier;
110
};
111

112
MockCFunctionCopierNode* copier_list = nullptr;
113

114
void install_comparator(
3✔
115
    const char* type_name,
116
    MutinyMockTypeEqualFunction is_equal,
117
    MutinyMockTypeValueToStringFunction value_to_string
118
)
119
{
120
  comparator_list = new MockCFunctionComparatorNode(
6✔
121
      comparator_list, is_equal, value_to_string
122
  );
3✔
123
  current_mock_support->install_comparator(type_name, *comparator_list);
3✔
124
}
3✔
125

126
void install_copier(const char* type_name, MutinyMockTypeCopyFunction copier)
2✔
127
{
128
  copier_list = new MockCFunctionCopierNode(copier_list, copier);
2✔
129
  current_mock_support->install_copier(type_name, *copier_list);
2✔
130
}
2✔
131

132
void remove_all_comparators_and_copiers()
5✔
133
{
134
  while (comparator_list) {
8✔
135
    MockCFunctionComparatorNode* next = comparator_list->next;
3✔
136
    delete comparator_list;
3✔
137
    comparator_list = next;
3✔
138
  }
139
  while (copier_list) {
7✔
140
    MockCFunctionCopierNode* next = copier_list->next;
2✔
141
    delete copier_list;
2✔
142
    copier_list = next;
2✔
143
  }
144
  current_mock_support->remove_all_comparators_and_copiers();
5✔
145
}
5✔
146

147
struct MutinyMockExpectedCall* expect_one_call(const char* name);
148
void expect_no_call(const char* name);
149
struct MutinyMockExpectedCall* expect_n_calls(
150
    const unsigned int number,
151
    const char* name
152
);
153

154
struct MutinyMockActualCall* actual_call(const char* name);
155
void disable();
156
void enable();
157
void ignore_other_calls();
158
void set_bool_data(const char* name, int value);
159
void set_int_data(const char* name, int value);
160
void set_unsigned_int_data(const char* name, unsigned int value);
161
void set_long_int_data(const char* name, long int value);
162
void set_unsigned_long_int_data(const char* name, unsigned long int value);
163
void set_double_data(const char* name, double value);
164
void set_string_data(const char* name, const char* value);
165
void set_pointer_data(const char* name, void* value);
166
void set_const_pointer_data(const char* name, const void* value);
167
void set_function_pointer_data(const char* name, void (*value)());
168
void set_data_object(const char* name, const char* type, void* value);
169
void set_data_const_object(
170
    const char* name,
171
    const char* type,
172
    const void* value
173
);
174
struct MutinyMockValue get_data(const char* name);
175
int has_return_value();
176

177
void check_expectations();
178
int expected_calls_left();
179
void clear();
180
void crash_on_failure(unsigned should_crash);
181

182
struct MutinyMockExpectedCall* with_bool_parameters(
183
    const char* name,
184
    int value
185
);
186
struct MutinyMockExpectedCall* with_int_parameters(const char* name, int value);
187
struct MutinyMockExpectedCall* with_unsigned_int_parameters(
188
    const char* name,
189
    unsigned int value
190
);
191
struct MutinyMockExpectedCall* with_long_int_parameters(
192
    const char* name,
193
    long int value
194
);
195
struct MutinyMockExpectedCall* with_unsigned_long_int_parameters(
196
    const char* name,
197
    unsigned long int value
198
);
199
struct MutinyMockExpectedCall* with_long_long_int_parameters(
200
    const char* name,
201
    long long value
202
);
203
struct MutinyMockExpectedCall* with_unsigned_long_long_int_parameters(
204
    const char* name,
205
    unsigned long long value
206
);
207
struct MutinyMockExpectedCall* with_double_parameters(
208
    const char* name,
209
    double value
210
);
211
struct MutinyMockExpectedCall* with_double_parameters_and_tolerance(
212
    const char* name,
213
    double value,
214
    double tolerance
215
);
216
struct MutinyMockExpectedCall* with_string_parameters(
217
    const char* name,
218
    const char* value
219
);
220
struct MutinyMockExpectedCall* with_pointer_parameters(
221
    const char* name,
222
    void* value
223
);
224
struct MutinyMockExpectedCall* with_const_pointer_parameters(
225
    const char* name,
226
    const void* value
227
);
228
struct MutinyMockExpectedCall* with_function_pointer_parameters(
229
    const char* name,
230
    void (*value)()
231
);
232
struct MutinyMockExpectedCall* with_memory_buffer_parameters(
233
    const char* name,
234
    const unsigned char* value,
235
    size_t size
236
);
237
struct MutinyMockExpectedCall* with_parameter_of_type(
238
    const char* type,
239
    const char* name,
240
    const void* value
241
);
242
struct MutinyMockExpectedCall* with_output_parameter_returning(
243
    const char* name,
244
    const void* value,
245
    size_t size
246
);
247
struct MutinyMockExpectedCall* with_output_parameter_of_type_returning(
248
    const char* type,
249
    const char* name,
250
    const void* value
251
);
252
struct MutinyMockExpectedCall* with_unmodified_output_parameter(
253
    const char* name
254
);
255
struct MutinyMockExpectedCall* ignore_other_parameters();
256
struct MutinyMockExpectedCall* and_return_bool_value(int value);
257
struct MutinyMockExpectedCall* and_return_int_value(int value);
258
struct MutinyMockExpectedCall* and_return_unsigned_int_value(
259
    unsigned int value
260
);
261
struct MutinyMockExpectedCall* and_return_long_int_value(long int value);
262
struct MutinyMockExpectedCall* and_return_unsigned_long_int_value(
263
    unsigned long int value
264
);
265
struct MutinyMockExpectedCall* and_return_long_long_int_value(long long value);
266
struct MutinyMockExpectedCall* and_return_unsigned_long_long_int_value(
267
    unsigned long long value
268
);
269
struct MutinyMockExpectedCall* and_return_double_value(double value);
270
struct MutinyMockExpectedCall* and_return_string_value(const char* value);
271
struct MutinyMockExpectedCall* and_return_pointer_value(void* value);
272
struct MutinyMockExpectedCall* and_return_const_pointer_value(
273
    const void* value
274
);
275
struct MutinyMockExpectedCall* and_return_function_pointer_value(
276
    void (*value)()
277
);
278

279
struct MutinyMockActualCall* with_actual_bool_parameters(
280
    const char* name,
281
    int value
282
);
283
struct MutinyMockActualCall* with_actual_int_parameters(
284
    const char* name,
285
    int value
286
);
287
struct MutinyMockActualCall* with_actual_unsigned_int_parameters(
288
    const char* name,
289
    unsigned int value
290
);
291
struct MutinyMockActualCall* with_actual_long_int_parameters(
292
    const char* name,
293
    long int value
294
);
295
struct MutinyMockActualCall* with_actual_unsigned_long_int_parameters(
296
    const char* name,
297
    unsigned long int value
298
);
299
struct MutinyMockActualCall* with_actual_long_long_int_parameters(
300
    const char* name,
301
    long long value
302
);
303
struct MutinyMockActualCall* with_actual_unsigned_long_long_int_parameters(
304
    const char* name,
305
    unsigned long long value
306
);
307
struct MutinyMockActualCall* with_actual_double_parameters(
308
    const char* name,
309
    double value
310
);
311
struct MutinyMockActualCall* with_actual_string_parameters(
312
    const char* name,
313
    const char* value
314
);
315
struct MutinyMockActualCall* with_actual_pointer_parameters(
316
    const char* name,
317
    void* value
318
);
319
struct MutinyMockActualCall* with_actual_const_pointer_parameters(
320
    const char* name,
321
    const void* value
322
);
323
struct MutinyMockActualCall* with_actual_function_pointer_parameters(
324
    const char* name,
325
    void (*value)()
326
);
327
struct MutinyMockActualCall* with_actual_memory_buffer_parameters(
328
    const char* name,
329
    const unsigned char* value,
330
    size_t size
331
);
332
struct MutinyMockActualCall* with_actual_parameter_of_type(
333
    const char* type,
334
    const char* name,
335
    const void* value
336
);
337
struct MutinyMockActualCall* with_actual_output_parameter(
338
    const char* name,
339
    void* value
340
);
341
struct MutinyMockActualCall* with_actual_output_parameter_of_type(
342
    const char* type,
343
    const char* name,
344
    void* value
345
);
346
struct MutinyMockValue return_value();
347
int bool_return_value();
348
int return_bool_value_or_default(int default_value);
349
int int_return_value();
350
int return_int_value_or_default(int default_value);
351
unsigned int unsigned_int_return_value();
352
unsigned int return_unsigned_int_value_or_default(unsigned int default_value);
353
long int long_int_return_value();
354
long int return_long_int_value_or_default(long int default_value);
355
unsigned long int unsigned_long_int_return_value();
356
unsigned long int return_unsigned_long_int_value_or_default(
357
    unsigned long int default_value
358
);
359
long long long_long_int_return_value();
360
long long return_long_long_int_value_or_default(long long default_value);
361
unsigned long long unsigned_long_long_int_return_value();
362
unsigned long long return_unsigned_long_long_int_value_or_default(
363
    unsigned long long default_value
364
);
365
const char* string_return_value();
366
const char* return_string_value_or_default(const char* default_value);
367
double double_return_value();
368
double return_double_value_or_default(double default_value);
369
void* pointer_return_value();
370
void* return_pointer_value_or_default(void* default_value);
371
const void* const_pointer_return_value();
372
const void* return_const_pointer_value_or_default(const void* default_value);
373
void (*function_pointer_return_value())();
374
void (*return_function_pointer_value_or_default(void (*default_value)()))();
375
struct MutinyMockExpectedCall g_expected_call = {
376
  with_bool_parameters,
377
  with_int_parameters,
378
  with_unsigned_int_parameters,
379
  with_long_int_parameters,
380
  with_unsigned_long_int_parameters,
381
  with_long_long_int_parameters,
382
  with_unsigned_long_long_int_parameters,
383
  with_double_parameters,
384
  with_double_parameters_and_tolerance,
385
  with_string_parameters,
386
  with_pointer_parameters,
387
  with_const_pointer_parameters,
388
  with_function_pointer_parameters,
389
  with_memory_buffer_parameters,
390
  with_parameter_of_type,
391
  with_output_parameter_returning,
392
  with_output_parameter_of_type_returning,
393
  with_unmodified_output_parameter,
394
  ignore_other_parameters,
395
  and_return_bool_value,
396
  and_return_unsigned_int_value,
397
  and_return_int_value,
398
  and_return_long_int_value,
399
  and_return_unsigned_long_int_value,
400
  and_return_long_long_int_value,
401
  and_return_unsigned_long_long_int_value,
402
  and_return_double_value,
403
  and_return_string_value,
404
  and_return_pointer_value,
405
  and_return_const_pointer_value,
406
  and_return_function_pointer_value,
407
};
408

409
struct MutinyMockActualCall g_actual_call = {
410
  with_actual_bool_parameters,
411
  with_actual_int_parameters,
412
  with_actual_unsigned_int_parameters,
413
  with_actual_long_int_parameters,
414
  with_actual_unsigned_long_int_parameters,
415
  with_actual_long_long_int_parameters,
416
  with_actual_unsigned_long_long_int_parameters,
417
  with_actual_double_parameters,
418
  with_actual_string_parameters,
419
  with_actual_pointer_parameters,
420
  with_actual_const_pointer_parameters,
421
  with_actual_function_pointer_parameters,
422
  with_actual_memory_buffer_parameters,
423
  with_actual_parameter_of_type,
424
  with_actual_output_parameter,
425
  with_actual_output_parameter_of_type,
426
  has_return_value,
427
  return_value,
428
  bool_return_value,
429
  return_bool_value_or_default,
430
  int_return_value,
431
  return_int_value_or_default,
432
  unsigned_int_return_value,
433
  return_unsigned_int_value_or_default,
434
  long_int_return_value,
435
  return_long_int_value_or_default,
436
  unsigned_long_int_return_value,
437
  return_unsigned_long_int_value_or_default,
438
  long_long_int_return_value,
439
  return_long_long_int_value_or_default,
440
  unsigned_long_long_int_return_value,
441
  return_unsigned_long_long_int_value_or_default,
442
  string_return_value,
443
  return_string_value_or_default,
444
  double_return_value,
445
  return_double_value_or_default,
446
  pointer_return_value,
447
  return_pointer_value_or_default,
448
  const_pointer_return_value,
449
  return_const_pointer_value_or_default,
450
  function_pointer_return_value,
451
  return_function_pointer_value_or_default
452
};
453

454
struct MutinyMockExpectedCall* with_bool_parameters(const char* name, int value)
3✔
455
{
456
  expected_call = &expected_call->with_parameter(name, (value != 0));
3✔
457
  return &g_expected_call;
3✔
458
}
459

460
struct MutinyMockExpectedCall* with_int_parameters(const char* name, int value)
4✔
461
{
462
  expected_call = &expected_call->with_parameter(name, value);
4✔
463
  return &g_expected_call;
4✔
464
}
465

466
struct MutinyMockExpectedCall* with_unsigned_int_parameters(
2✔
467
    const char* name,
468
    unsigned int value
469
)
470
{
471
  expected_call = &expected_call->with_parameter(name, value);
2✔
472
  return &g_expected_call;
2✔
473
}
474

475
struct MutinyMockExpectedCall* with_long_int_parameters(
2✔
476
    const char* name,
477
    long int value
478
)
479
{
480
  expected_call = &expected_call->with_parameter(name, value);
2✔
481
  return &g_expected_call;
2✔
482
}
483

484
struct MutinyMockExpectedCall* with_unsigned_long_int_parameters(
2✔
485
    const char* name,
486
    unsigned long int value
487
)
488
{
489
  expected_call = &expected_call->with_parameter(name, value);
2✔
490
  return &g_expected_call;
2✔
491
}
492

493
struct MutinyMockExpectedCall* with_long_long_int_parameters(
2✔
494
    const char* name,
495
    long long value
496
)
497
{
498
  expected_call = &expected_call->with_parameter(name, value);
2✔
499
  return &g_expected_call;
2✔
500
}
501

502
struct MutinyMockExpectedCall* with_unsigned_long_long_int_parameters(
2✔
503
    const char* name,
504
    unsigned long long value
505
)
506
{
507
  expected_call = &expected_call->with_parameter(name, value);
2✔
508
  return &g_expected_call;
2✔
509
}
510

511
struct MutinyMockExpectedCall* with_double_parameters(
3✔
512
    const char* name,
513
    double value
514
)
515
{
516
  expected_call = &expected_call->with_parameter(name, value);
3✔
517
  return &g_expected_call;
3✔
518
}
519

520
struct MutinyMockExpectedCall* with_double_parameters_and_tolerance(
2✔
521
    const char* name,
522
    double value,
523
    double tolerance
524
)
525
{
526
  expected_call = &expected_call->with_parameter(name, value, tolerance);
2✔
527
  return &g_expected_call;
2✔
528
}
529

530
struct MutinyMockExpectedCall* with_string_parameters(
3✔
531
    const char* name,
532
    const char* value
533
)
534
{
535
  expected_call = &expected_call->with_parameter(name, value);
3✔
536
  return &g_expected_call;
3✔
537
}
538

539
struct MutinyMockExpectedCall* with_pointer_parameters(
3✔
540
    const char* name,
541
    void* value
542
)
543
{
544
  expected_call = &expected_call->with_parameter(name, value);
3✔
545
  return &g_expected_call;
3✔
546
}
547

548
struct MutinyMockExpectedCall* with_const_pointer_parameters(
2✔
549
    const char* name,
550
    const void* value
551
)
552
{
553
  expected_call = &expected_call->with_parameter(name, value);
2✔
554
  return &g_expected_call;
2✔
555
}
556

557
struct MutinyMockExpectedCall* with_function_pointer_parameters(
3✔
558
    const char* name,
559
    void (*value)()
560
)
561
{
562
  expected_call = &expected_call->with_parameter(name, value);
3✔
563
  return &g_expected_call;
3✔
564
}
565

566
struct MutinyMockExpectedCall* with_memory_buffer_parameters(
3✔
567
    const char* name,
568
    const unsigned char* value,
569
    size_t size
570
)
571
{
572
  expected_call = &expected_call->with_parameter(name, value, size);
3✔
573
  return &g_expected_call;
3✔
574
}
575

576
struct MutinyMockExpectedCall* with_parameter_of_type(
4✔
577
    const char* type,
578
    const char* name,
579
    const void* value
580
)
581
{
582
  expected_call = &expected_call->with_parameter_of_type(type, name, value);
4✔
583
  return &g_expected_call;
4✔
584
}
585

586
struct MutinyMockExpectedCall* with_output_parameter_returning(
3✔
587
    const char* name,
588
    const void* value,
589
    size_t size
590
)
591
{
592
  expected_call =
3✔
593
      &expected_call->with_output_parameter_returning(name, value, size);
3✔
594
  return &g_expected_call;
3✔
595
}
596

597
struct MutinyMockExpectedCall* with_output_parameter_of_type_returning(
3✔
598
    const char* type,
599
    const char* name,
600
    const void* value
601
)
602
{
603
  expected_call = &expected_call->with_output_parameter_of_type_returning(
3✔
604
      type, name, value
605
  );
606
  return &g_expected_call;
3✔
607
}
608

609
struct MutinyMockExpectedCall* with_unmodified_output_parameter(
1✔
610
    const char* name
611
)
612
{
613
  expected_call = &expected_call->with_unmodified_output_parameter(name);
1✔
614
  return &g_expected_call;
1✔
615
}
616

617
struct MutinyMockExpectedCall* ignore_other_parameters()
2✔
618
{
619
  expected_call = &expected_call->ignore_other_parameters();
2✔
620
  return &g_expected_call;
2✔
621
}
622

623
struct MutinyMockExpectedCall* and_return_bool_value(int value)
3✔
624
{
625
  expected_call = &expected_call->and_return_value(value != 0);
3✔
626
  return &g_expected_call;
3✔
627
}
628

629
struct MutinyMockExpectedCall* and_return_unsigned_int_value(unsigned int value)
3✔
630
{
631
  expected_call = &expected_call->and_return_value(value);
3✔
632
  return &g_expected_call;
3✔
633
}
634

635
struct MutinyMockExpectedCall* and_return_int_value(int value)
4✔
636
{
637
  expected_call = &expected_call->and_return_value(value);
4✔
638
  return &g_expected_call;
4✔
639
}
640

641
struct MutinyMockExpectedCall* and_return_long_int_value(long int value)
3✔
642
{
643
  expected_call = &expected_call->and_return_value(value);
3✔
644
  return &g_expected_call;
3✔
645
}
646

647
struct MutinyMockExpectedCall* and_return_unsigned_long_int_value(
3✔
648
    unsigned long int value
649
)
650
{
651
  expected_call = &expected_call->and_return_value(value);
3✔
652
  return &g_expected_call;
3✔
653
}
654

655
struct MutinyMockExpectedCall* and_return_long_long_int_value(long long value)
3✔
656
{
657
  expected_call = &expected_call->and_return_value(value);
3✔
658
  return &g_expected_call;
3✔
659
}
660

661
struct MutinyMockExpectedCall* and_return_unsigned_long_long_int_value(
3✔
662
    unsigned long long value
663
)
664
{
665
  expected_call = &expected_call->and_return_value(value);
3✔
666
  return &g_expected_call;
3✔
667
}
668

669
struct MutinyMockExpectedCall* and_return_double_value(double value)
3✔
670
{
671
  expected_call = &expected_call->and_return_value(value);
3✔
672
  return &g_expected_call;
3✔
673
}
674

675
struct MutinyMockExpectedCall* and_return_string_value(const char* value)
3✔
676
{
677
  expected_call = &expected_call->and_return_value(value);
3✔
678
  return &g_expected_call;
3✔
679
}
680

681
struct MutinyMockExpectedCall* and_return_pointer_value(void* value)
3✔
682
{
683
  expected_call = &expected_call->and_return_value(value);
3✔
684
  return &g_expected_call;
3✔
685
}
686

687
struct MutinyMockExpectedCall* and_return_const_pointer_value(const void* value)
3✔
688
{
689
  expected_call = &expected_call->and_return_value(value);
3✔
690
  return &g_expected_call;
3✔
691
}
692

693
struct MutinyMockExpectedCall* and_return_function_pointer_value(
3✔
694
    void (*value)()
695
)
696
{
697
  expected_call = &expected_call->and_return_value(value);
3✔
698
  return &g_expected_call;
3✔
699
}
700

701
struct MutinyMockValue get_mock_value_c_from_named_value(
36✔
702
    const mu::tiny::mock::NamedValue& named_value
703
)
704
{
705
  using mu::tiny::strcmp;
706
  struct MutinyMockValue return_value;
707
  if (strcmp(named_value.get_type().c_str(), "bool") == 0) {
36✔
708
    return_value.type = mutiny_type_bool;
3✔
709
    return_value.value.bool_value = named_value.get_bool_value() ? 1 : 0;
3✔
710
  } else if (strcmp(named_value.get_type().c_str(), "int") == 0) {
33✔
711
    return_value.type = mutiny_type_integer;
2✔
712
    return_value.value.int_value = named_value.get_int_value();
2✔
713
  } else if (strcmp(named_value.get_type().c_str(), "unsigned int") == 0) {
31✔
UNCOV
714
    return_value.type = mutiny_type_unsigned_integer;
×
UNCOV
715
    return_value.value.unsigned_int_value =
×
NEW
UNCOV
716
        named_value.get_unsigned_int_value();
×
717
  } else if (strcmp(named_value.get_type().c_str(), "long int") == 0) {
31✔
718
    return_value.type = mutiny_type_long_integer;
1✔
719
    return_value.value.long_int_value = named_value.get_long_int_value();
1✔
720
  } else if (strcmp(named_value.get_type().c_str(), "unsigned long int") == 0) {
30✔
721
    return_value.type = mutiny_type_unsigned_long_integer;
1✔
722
    return_value.value.unsigned_long_int_value =
1✔
723
        named_value.get_unsigned_long_int_value();
1✔
724
  } else if (strcmp(named_value.get_type().c_str(), "long long int") == 0) {
29✔
725
    return_value.type = mutiny_type_long_long_integer;
4✔
726
    return_value.value.long_long_int_value =
4✔
727
        named_value.get_long_long_int_value();
4✔
728
  } else if (
25✔
729
      strcmp(named_value.get_type().c_str(), "unsigned long long int") == 0
25✔
730
  ) {
731
    return_value.type = mutiny_type_unsigned_long_long_integer;
3✔
732
    return_value.value.unsigned_long_long_int_value =
3✔
733
        named_value.get_unsigned_long_long_int_value();
3✔
734
  } else if (strcmp(named_value.get_type().c_str(), "double") == 0) {
22✔
735
    return_value.type = mutiny_type_double;
3✔
736
    return_value.value.double_value = named_value.get_double_value();
3✔
737
  } else if (strcmp(named_value.get_type().c_str(), "const char*") == 0) {
19✔
738
    return_value.type = mutiny_type_string;
3✔
739
    return_value.value.string_value = named_value.get_string_value();
3✔
740
  } else if (strcmp(named_value.get_type().c_str(), "void*") == 0) {
16✔
741
    return_value.type = mutiny_type_pointer;
4✔
742
    return_value.value.pointer_value = named_value.get_pointer_value();
4✔
743
  } else if (strcmp(named_value.get_type().c_str(), "const void*") == 0) {
12✔
744
    return_value.type = mutiny_type_const_pointer;
2✔
745
    return_value.value.const_pointer_value =
2✔
746
        named_value.get_const_pointer_value();
2✔
747
  } else if (strcmp(named_value.get_type().c_str(), "void (*)()") == 0) {
10✔
748
    return_value.type = mutiny_type_functionpointer;
3✔
749
    return_value.value.function_pointer_value =
3✔
750
        named_value.get_function_pointer_value();
3✔
751
  } else if (
7✔
752
      strcmp(named_value.get_type().c_str(), "const unsigned char*") == 0
7✔
753
  ) {
754
    return_value.type = mutiny_type_memorybuffer;
2✔
755
    return_value.value.memory_buffer_value = named_value.get_memory_buffer();
2✔
756
  } else if (named_value.is_const_object()) {
5✔
757
    return_value.type = mutiny_type_const_object;
2✔
758
    return_value.value.const_object_value =
2✔
759
        named_value.get_const_object_pointer();
2✔
760
  } else {
761
    return_value.type = mutiny_type_object;
3✔
762
    return_value.value.object_value = named_value.get_object_pointer();
3✔
763
  }
764
  return return_value;
36✔
765
}
766

767
void strict_order()
2✔
768
{
769
  current_mock_support->strict_order();
2✔
770
}
2✔
771

772
struct MutinyMockExpectedCall* expect_one_call(const char* name)
86✔
773
{
774
  expected_call = &current_mock_support->expect_one_call(name);
86✔
775
  return &g_expected_call;
86✔
776
}
777

778
void expect_no_call(const char* name)
2✔
779
{
780
  current_mock_support->expect_no_call(name);
2✔
781
}
2✔
782

783
struct MutinyMockExpectedCall* expect_n_calls(
2✔
784
    const unsigned int number,
785
    const char* name
786
)
787
{
788
  expected_call = &current_mock_support->expect_n_calls(number, name);
2✔
789
  return &g_expected_call;
2✔
790
}
791

792
struct MutinyMockActualCall* actual_call(const char* name)
97✔
793
{
794
  current_actual_call = &current_mock_support->actual_call(name);
97✔
795
  return &g_actual_call;
92✔
796
}
797

798
struct MutinyMockActualCall* with_actual_bool_parameters(
3✔
799
    const char* name,
800
    int value
801
)
802
{
803
  current_actual_call =
3✔
804
      &current_actual_call->with_parameter(name, (value != 0));
3✔
805
  return &g_actual_call;
3✔
806
}
807

808
struct MutinyMockActualCall* with_actual_int_parameters(
4✔
809
    const char* name,
810
    int value
811
)
812
{
813
  current_actual_call = &current_actual_call->with_parameter(name, value);
4✔
814
  return &g_actual_call;
4✔
815
}
816

817
struct MutinyMockActualCall* with_actual_unsigned_int_parameters(
2✔
818
    const char* name,
819
    unsigned int value
820
)
821
{
822
  current_actual_call = &current_actual_call->with_parameter(name, value);
2✔
823
  return &g_actual_call;
2✔
824
}
825

826
struct MutinyMockActualCall* with_actual_long_int_parameters(
2✔
827
    const char* name,
828
    long int value
829
)
830
{
831
  current_actual_call = &current_actual_call->with_parameter(name, value);
2✔
832
  return &g_actual_call;
2✔
833
}
834

835
struct MutinyMockActualCall* with_actual_unsigned_long_int_parameters(
2✔
836
    const char* name,
837
    unsigned long int value
838
)
839
{
840
  current_actual_call = &current_actual_call->with_parameter(name, value);
2✔
841
  return &g_actual_call;
2✔
842
}
843

844
struct MutinyMockActualCall* with_actual_long_long_int_parameters(
2✔
845
    const char* name,
846
    long long value
847
)
848
{
849
  current_actual_call = &current_actual_call->with_parameter(name, value);
2✔
850
  return &g_actual_call;
2✔
851
}
852

853
struct MutinyMockActualCall* with_actual_unsigned_long_long_int_parameters(
2✔
854
    const char* name,
855
    unsigned long long value
856
)
857
{
858
  current_actual_call = &current_actual_call->with_parameter(name, value);
2✔
859
  return &g_actual_call;
2✔
860
}
861

862
struct MutinyMockActualCall* with_actual_double_parameters(
6✔
863
    const char* name,
864
    double value
865
)
866
{
867
  current_actual_call = &current_actual_call->with_parameter(name, value);
6✔
868
  return &g_actual_call;
6✔
869
}
870

871
struct MutinyMockActualCall* with_actual_string_parameters(
3✔
872
    const char* name,
873
    const char* value
874
)
875
{
876
  current_actual_call = &current_actual_call->with_parameter(name, value);
3✔
877
  return &g_actual_call;
3✔
878
}
879

880
struct MutinyMockActualCall* with_actual_pointer_parameters(
3✔
881
    const char* name,
882
    void* value
883
)
884
{
885
  current_actual_call = &current_actual_call->with_parameter(name, value);
3✔
886
  return &g_actual_call;
3✔
887
}
888

889
struct MutinyMockActualCall* with_actual_const_pointer_parameters(
2✔
890
    const char* name,
891
    const void* value
892
)
893
{
894
  current_actual_call = &current_actual_call->with_parameter(name, value);
2✔
895
  return &g_actual_call;
2✔
896
}
897

898
struct MutinyMockActualCall* with_actual_function_pointer_parameters(
3✔
899
    const char* name,
900
    void (*value)()
901
)
902
{
903
  current_actual_call = &current_actual_call->with_parameter(name, value);
3✔
904
  return &g_actual_call;
3✔
905
}
906

907
struct MutinyMockActualCall* with_actual_memory_buffer_parameters(
3✔
908
    const char* name,
909
    const unsigned char* value,
910
    size_t size
911
)
912
{
913
  current_actual_call = &current_actual_call->with_parameter(name, value, size);
3✔
914
  return &g_actual_call;
2✔
915
}
916

917
struct MutinyMockActualCall* with_actual_parameter_of_type(
4✔
918
    const char* type,
919
    const char* name,
920
    const void* value
921
)
922
{
923
  current_actual_call =
3✔
924
      &current_actual_call->with_parameter_of_type(type, name, value);
4✔
925
  return &g_actual_call;
3✔
926
}
927

928
struct MutinyMockActualCall* with_actual_output_parameter(
4✔
929
    const char* name,
930
    void* value
931
)
932
{
933
  current_actual_call =
4✔
934
      &current_actual_call->with_output_parameter(name, value);
4✔
935
  return &g_actual_call;
4✔
936
}
937

938
struct MutinyMockActualCall* with_actual_output_parameter_of_type(
3✔
939
    const char* type,
940
    const char* name,
941
    void* value
942
)
943
{
944
  current_actual_call =
3✔
945
      &current_actual_call->with_output_parameter_of_type(type, name, value);
3✔
946
  return &g_actual_call;
3✔
947
}
948

949
struct MutinyMockValue return_value()
13✔
950
{
951
  return get_mock_value_c_from_named_value(current_actual_call->return_value());
13✔
952
}
953

954
int bool_return_value()
6✔
955
{
956
  return current_actual_call->return_value_as<bool>() ? 1 : 0;
6✔
957
}
958

959
int return_bool_value_or_default(int default_value)
5✔
960
{
961
  if (!has_return_value()) {
5✔
962
    return default_value;
3✔
963
  }
964
  return bool_return_value();
2✔
965
}
966

967
int int_return_value()
6✔
968
{
969
  return current_actual_call->return_value_as<int>();
6✔
970
}
971

972
int return_int_value_or_default(int default_value)
5✔
973
{
974
  if (!has_return_value()) {
5✔
975
    return default_value;
3✔
976
  }
977
  return int_return_value();
2✔
978
}
979

980
unsigned int unsigned_int_return_value()
6✔
981
{
982
  return current_actual_call->return_value_as<unsigned int>();
6✔
983
}
984

985
unsigned int return_unsigned_int_value_or_default(unsigned int default_value)
5✔
986
{
987
  if (!has_return_value()) {
5✔
988
    return default_value;
3✔
989
  }
990
  return unsigned_int_return_value();
2✔
991
}
992

993
long int long_int_return_value()
6✔
994
{
995
  return current_actual_call->return_value_as<long int>();
6✔
996
}
997

998
long int return_long_int_value_or_default(long int default_value)
5✔
999
{
1000
  if (!has_return_value()) {
5✔
1001
    return default_value;
3✔
1002
  }
1003
  return long_int_return_value();
2✔
1004
}
1005

1006
unsigned long int unsigned_long_int_return_value()
6✔
1007
{
1008
  return current_actual_call->return_value_as<unsigned long int>();
6✔
1009
}
1010

1011
unsigned long int return_unsigned_long_int_value_or_default(
5✔
1012
    unsigned long int default_value
1013
)
1014
{
1015
  if (!has_return_value()) {
5✔
1016
    return default_value;
3✔
1017
  }
1018
  return unsigned_long_int_return_value();
2✔
1019
}
1020

1021
long long long_long_int_return_value()
6✔
1022
{
1023
  return current_actual_call->return_value_as<long long>();
6✔
1024
}
1025

1026
long long return_long_long_int_value_or_default(long long default_value)
5✔
1027
{
1028
  if (!has_return_value()) {
5✔
1029
    return default_value;
3✔
1030
  }
1031
  return long_long_int_return_value();
2✔
1032
}
1033

1034
unsigned long long unsigned_long_long_int_return_value()
6✔
1035
{
1036
  return current_actual_call->return_value_as<unsigned long long>();
6✔
1037
}
1038

1039
unsigned long long return_unsigned_long_long_int_value_or_default(
5✔
1040
    unsigned long long default_value
1041
)
1042
{
1043
  if (!has_return_value()) {
5✔
1044
    return default_value;
3✔
1045
  }
1046
  return unsigned_long_long_int_return_value();
2✔
1047
}
1048

1049
const char* string_return_value()
6✔
1050
{
1051
  return current_actual_call->return_value_as<const char*>();
6✔
1052
}
1053

1054
const char* return_string_value_or_default(const char* default_value)
5✔
1055
{
1056
  if (!has_return_value()) {
5✔
1057
    return default_value;
3✔
1058
  }
1059
  return string_return_value();
2✔
1060
}
1061

1062
double double_return_value()
6✔
1063
{
1064
  return current_actual_call->return_value_as<double>();
6✔
1065
}
1066

1067
double return_double_value_or_default(double default_value)
5✔
1068
{
1069
  if (!has_return_value()) {
5✔
1070
    return default_value;
3✔
1071
  }
1072
  return double_return_value();
2✔
1073
}
1074

1075
void* pointer_return_value()
6✔
1076
{
1077
  return current_actual_call->return_value_as<void*>();
6✔
1078
}
1079

1080
void* return_pointer_value_or_default(void* default_value)
5✔
1081
{
1082
  if (!has_return_value()) {
5✔
1083
    return default_value;
3✔
1084
  }
1085
  return pointer_return_value();
2✔
1086
}
1087

1088
const void* const_pointer_return_value()
6✔
1089
{
1090
  return current_actual_call->return_value_as<const void*>();
6✔
1091
}
1092

1093
const void* return_const_pointer_value_or_default(const void* default_value)
5✔
1094
{
1095
  if (!has_return_value()) {
5✔
1096
    return default_value;
3✔
1097
  }
1098
  return const_pointer_return_value();
2✔
1099
}
1100

1101
void (*function_pointer_return_value())()
6✔
1102
{
1103
  return current_actual_call
1104
      ->return_value_as<mu::tiny::mock::ActualCall::FunctionPointerReturnValue>();
6✔
1105
}
1106

1107
void (*return_function_pointer_value_or_default(void (*default_value)()))()
5✔
1108
{
1109
  if (!has_return_value()) {
5✔
1110
    return default_value;
3✔
1111
  }
1112
  return function_pointer_return_value();
2✔
1113
}
1114

1115
void disable()
2✔
1116
{
1117
  current_mock_support->disable();
2✔
1118
}
2✔
1119

1120
void enable()
2✔
1121
{
1122
  current_mock_support->enable();
2✔
1123
}
2✔
1124

1125
void ignore_other_calls()
1✔
1126
{
1127
  current_mock_support->ignore_other_calls();
1✔
1128
}
1✔
1129

1130
void set_bool_data(const char* name, int value)
2✔
1131
{
1132
  current_mock_support->set_data(name, (value != 0));
2✔
1133
}
2✔
1134

1135
void set_int_data(const char* name, int value)
3✔
1136
{
1137
  current_mock_support->set_data(name, value);
3✔
1138
}
3✔
1139

1140
void set_unsigned_int_data(const char* name, unsigned int value)
1✔
1141
{
1142
  current_mock_support->set_data(name, value);
1✔
1143
}
1✔
1144

1145
void set_long_int_data(const char* name, long int value)
1✔
1146
{
1147
  current_mock_support->set_data(name, value);
1✔
1148
}
1✔
1149

1150
void set_unsigned_long_int_data(const char* name, unsigned long int value)
1✔
1151
{
1152
  current_mock_support->set_data(name, value);
1✔
1153
}
1✔
1154

1155
void set_double_data(const char* name, double value)
3✔
1156
{
1157
  current_mock_support->set_data(name, value);
3✔
1158
}
3✔
1159

1160
void set_string_data(const char* name, const char* value)
3✔
1161
{
1162
  current_mock_support->set_data(name, value);
3✔
1163
}
3✔
1164

1165
void set_pointer_data(const char* name, void* value)
3✔
1166
{
1167
  current_mock_support->set_data(name, value);
3✔
1168
}
3✔
1169

1170
void set_const_pointer_data(const char* name, const void* value)
3✔
1171
{
1172
  current_mock_support->set_data(name, value);
3✔
1173
}
3✔
1174

1175
void set_function_pointer_data(const char* name, void (*value)())
3✔
1176
{
1177
  current_mock_support->set_data(name, value);
3✔
1178
}
3✔
1179

1180
void set_data_object(const char* name, const char* type, void* value)
3✔
1181
{
1182
  current_mock_support->set_data_object(name, type, value);
3✔
1183
}
3✔
1184

1185
void set_data_const_object(
1✔
1186
    const char* name,
1187
    const char* type,
1188
    const void* value
1189
)
1190
{
1191
  current_mock_support->set_data_const_object(name, type, value);
1✔
1192
}
1✔
1193

1194
struct MutinyMockValue get_data(const char* name)
23✔
1195
{
1196
  return get_mock_value_c_from_named_value(
23✔
1197
      current_mock_support->get_data(name)
46✔
1198
  );
46✔
1199
}
1200

1201
int has_return_value()
66✔
1202
{
1203
  return current_mock_support->has_return_value();
66✔
1204
}
1205

1206
void check_expectations()
14✔
1207
{
1208
  current_mock_support->check_expectations();
14✔
1209
}
14✔
1210

1211
int expected_calls_left()
4✔
1212
{
1213
  return current_mock_support->expected_calls_left();
4✔
1214
}
1215

1216
void clear()
82✔
1217
{
1218
  current_mock_support->clear();
82✔
1219
}
82✔
1220

1221
void crash_on_failure(unsigned should_crash)
3✔
1222
{
1223
  current_mock_support->crash_on_failure(0 != should_crash);
3✔
1224
}
3✔
1225

1226
struct MutinyMockSupport g_mock_support = {
1227
  strict_order,
1228
  expect_one_call,
1229
  expect_no_call,
1230
  expect_n_calls,
1231
  actual_call,
1232
  has_return_value,
1233
  return_value,
1234
  bool_return_value,
1235
  return_bool_value_or_default,
1236
  int_return_value,
1237
  return_int_value_or_default,
1238
  unsigned_int_return_value,
1239
  return_unsigned_int_value_or_default,
1240
  long_int_return_value,
1241
  return_long_int_value_or_default,
1242
  unsigned_long_int_return_value,
1243
  return_unsigned_long_int_value_or_default,
1244
  long_long_int_return_value,
1245
  return_long_long_int_value_or_default,
1246
  unsigned_long_long_int_return_value,
1247
  return_unsigned_long_long_int_value_or_default,
1248
  string_return_value,
1249
  return_string_value_or_default,
1250
  double_return_value,
1251
  return_double_value_or_default,
1252
  pointer_return_value,
1253
  return_pointer_value_or_default,
1254
  const_pointer_return_value,
1255
  return_const_pointer_value_or_default,
1256
  function_pointer_return_value,
1257
  return_function_pointer_value_or_default,
1258
  set_bool_data,
1259
  set_int_data,
1260
  set_unsigned_int_data,
1261
  set_long_int_data,
1262
  set_unsigned_long_int_data,
1263
  set_string_data,
1264
  set_double_data,
1265
  set_pointer_data,
1266
  set_const_pointer_data,
1267
  set_function_pointer_data,
1268
  set_data_object,
1269
  set_data_const_object,
1270
  get_data,
1271
  disable,
1272
  enable,
1273
  ignore_other_calls,
1274
  check_expectations,
1275
  expected_calls_left,
1276
  clear,
1277
  crash_on_failure,
1278
  install_comparator,
1279
  install_copier,
1280
  remove_all_comparators_and_copiers
1281
};
1282
} // namespace
1283

1284
struct MutinyMockSupport* mutiny_mock()
425✔
1285
{
1286
  current_mock_support = &mu::tiny::mock::mock("", &failure_reporter_for_c);
425✔
1287
  return &g_mock_support;
425✔
1288
}
1289

1290
struct MutinyMockSupport* mutiny_mock_scope(const char* scope)
8✔
1291
{
1292
  current_mock_support = &mu::tiny::mock::mock(scope, &failure_reporter_for_c);
8✔
1293
  return &g_mock_support;
8✔
1294
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc