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

thetic / mutiny / 24573089316

17 Apr 2026 03:28PM UTC coverage: 97.192% (-1.4%) from 98.629%
24573089316

Pull #59

github

web-flow
Merge 7426fcdfb into e0583988c
Pull Request #59: Disunity

1 of 3 new or added lines in 2 files covered. (33.33%)

74 existing lines in 7 files now uncovered.

4984 of 5128 relevant lines covered (97.19%)

3235.13 hits per line

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

98.6
/src/mock/ExpectedCallsList.cpp
1
#include "mutiny/mock/ExpectedCallsList.hpp"
2

3
#include "mutiny/mock/CheckedExpectedCall.hpp"
4

5
namespace mu {
6
namespace tiny {
7
namespace mock {
8

9
ExpectedCallsList::~ExpectedCallsList()
499✔
10
{
11
  while (head_) {
609✔
12
    MockExpectedCallsListNode* next = head_->next;
110✔
13
    delete head_;
110✔
14
    head_ = next;
110✔
15
  }
16
}
499✔
17

18
bool ExpectedCallsList::has_calls_out_of_order() const
393✔
19
{
20
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
778✔
21
    if (p->expected_call->is_out_of_order())
389✔
22
      return true;
4✔
23
  return false;
389✔
24
}
25

26
bool ExpectedCallsList::empty() const
644✔
27
{
28
  return head_ == nullptr;
644✔
29
}
30

31
unsigned int ExpectedCallsList::amount_of_actual_calls_fulfilled_for(
17✔
32
    const String& name
33
) const
34
{
35
  unsigned int count = 0;
17✔
36
  for (MockExpectedCallsListNode* p = head_; p; p = p->next) {
18✔
37
    if (p->expected_call->relates_to(name)) {
1✔
38
      count += p->expected_call->get_actual_calls_fulfilled();
1✔
39
    }
40
  }
41
  return count;
17✔
42
}
43

44
bool ExpectedCallsList::has_finalized_matching_expectations() const
40✔
45
{
46
  for (MockExpectedCallsListNode* p = head_; p; p = p->next) {
91✔
47
    if (p->expected_call->is_matching_actual_call_and_finalized()) {
51✔
UNCOV
48
      return true;
×
49
    }
50
  }
51
  return false;
40✔
52
}
53

54
bool ExpectedCallsList::has_unfulfilled_expectations() const
370✔
55
{
56
  for (MockExpectedCallsListNode* p = head_; p; p = p->next) {
731✔
57
    if (!p->expected_call->is_fulfilled()) {
380✔
58
      return true;
19✔
59
    }
60
  }
61
  return false;
351✔
62
}
63

64
bool ExpectedCallsList::has_expectation_with_name(const String& name) const
16✔
65
{
66
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
23✔
67
    if (p->expected_call->relates_to(name))
12✔
68
      return true;
5✔
69
  return false;
11✔
70
}
71

72
void ExpectedCallsList::add_expected_call(CheckedExpectedCall* call)
897✔
73
{
74
  auto* new_call = new MockExpectedCallsListNode(call);
897✔
75

76
  if (head_ == nullptr)
897✔
77
    head_ = new_call;
734✔
78
  else {
79
    MockExpectedCallsListNode* last_call = head_;
163✔
80
    while (last_call->next)
344✔
81
      last_call = last_call->next;
181✔
82
    last_call->next = new_call;
163✔
83
  }
84
}
897✔
85

86
void ExpectedCallsList::add_potentially_matching_expectations(
390✔
87
    const ExpectedCallsList& list
88
)
89
{
90
  for (MockExpectedCallsListNode* p = list.head_; p; p = p->next)
1,079✔
91
    if (p->expected_call->can_match_actual_calls())
689✔
92
      add_expected_call(p->expected_call);
432✔
93
}
390✔
94

95
void ExpectedCallsList::add_expectations_related_to(
44✔
96
    const String& name,
97
    const ExpectedCallsList& list
98
)
99
{
100
  for (MockExpectedCallsListNode* p = list.head_; p; p = p->next)
90✔
101
    if (p->expected_call->relates_to(name))
46✔
102
      add_expected_call(p->expected_call);
46✔
103
}
44✔
104

105
void ExpectedCallsList::add_expectations(const ExpectedCallsList& list)
26✔
106
{
107
  for (MockExpectedCallsListNode* p = list.head_; p; p = p->next)
61✔
108
    add_expected_call(p->expected_call);
35✔
109
}
26✔
110

111
void ExpectedCallsList::only_keep_expectations_related_to(const String& name)
390✔
112
{
113
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
822✔
114
    if (!p->expected_call->relates_to(name))
432✔
115
      p->expected_call = nullptr;
18✔
116

117
  prune_empty_node_from_list();
390✔
118
}
390✔
119

120
void ExpectedCallsList::only_keep_out_of_order_expectations()
4✔
121
{
122
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
15✔
123
    if (!p->expected_call->is_out_of_order())
11✔
124
      p->expected_call = nullptr;
3✔
125
  prune_empty_node_from_list();
4✔
126
}
4✔
127

128
void ExpectedCallsList::only_keep_unmatching_expectations()
235✔
129
{
130
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
509✔
131
    if (p->expected_call->is_matching_actual_call_and_finalized()) {
274✔
132
      p->expected_call->reset_actual_call_matching_state();
1✔
133
      p->expected_call = nullptr;
1✔
134
    }
135

136
  prune_empty_node_from_list();
235✔
137
}
235✔
138

139
void ExpectedCallsList::only_keep_expectations_with_input_parameter_name(
14✔
140
    const String& name
141
)
142
{
143
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
29✔
144
    if (!p->expected_call->has_input_parameter_with_name(name))
15✔
145
      p->expected_call = nullptr;
4✔
146
  prune_empty_node_from_list();
14✔
147
}
14✔
148

149
void ExpectedCallsList::only_keep_expectations_with_output_parameter_name(
3✔
150
    const String& name
151
)
152
{
153
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
6✔
154
    if (!p->expected_call->has_output_parameter_with_name(name))
3✔
155
      p->expected_call = nullptr;
2✔
156
  prune_empty_node_from_list();
3✔
157
}
3✔
158

159
void ExpectedCallsList::only_keep_expectations_with_input_parameter(
188✔
160
    const NamedValue& parameter
161
)
162
{
163
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
408✔
164
    if (!p->expected_call->has_input_parameter(parameter))
220✔
165
      p->expected_call = nullptr;
25✔
166
  prune_empty_node_from_list();
188✔
167
}
188✔
168

169
void ExpectedCallsList::only_keep_expectations_with_output_parameter(
47✔
170
    const NamedValue& parameter
171
)
172
{
173
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
100✔
174
    if (!p->expected_call->has_output_parameter(parameter))
53✔
175
      p->expected_call = nullptr;
3✔
176
  prune_empty_node_from_list();
47✔
177
}
47✔
178

179
void ExpectedCallsList::only_keep_expectations_on_object(const void* object_ptr)
2✔
180
{
181
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
4✔
182
    if (!p->expected_call->relates_to_object(object_ptr))
2✔
183
      p->expected_call = nullptr;
1✔
184
  prune_empty_node_from_list();
2✔
185
}
2✔
186

187
CheckedExpectedCall* ExpectedCallsList::
592✔
188
    remove_first_finalized_matching_expectation()
189
{
190
  for (MockExpectedCallsListNode* p = head_; p; p = p->next) {
922✔
191
    if (p->expected_call->is_matching_actual_call_and_finalized()) {
645✔
192
      CheckedExpectedCall* matching_call = p->expected_call;
315✔
193
      p->expected_call = nullptr;
315✔
194
      prune_empty_node_from_list();
315✔
195
      return matching_call;
315✔
196
    }
197
  }
198
  return nullptr;
277✔
199
}
200

201
CheckedExpectedCall* ExpectedCallsList::get_first_matching_expectation()
277✔
202
{
203
  for (MockExpectedCallsListNode* p = head_; p; p = p->next) {
535✔
204
    if (p->expected_call->is_matching_actual_call()) {
311✔
205
      return p->expected_call;
53✔
206
    }
207
  }
208
  return nullptr;
224✔
209
}
210

211
CheckedExpectedCall* ExpectedCallsList::remove_first_matching_expectation()
40✔
212
{
213
  for (MockExpectedCallsListNode* p = head_; p; p = p->next) {
49✔
214
    if (p->expected_call->is_matching_actual_call()) {
40✔
215
      CheckedExpectedCall* matching_call = p->expected_call;
31✔
216
      p->expected_call = nullptr;
31✔
217
      prune_empty_node_from_list();
31✔
218
      return matching_call;
31✔
219
    }
220
  }
221
  return nullptr;
9✔
222
}
223

224
void ExpectedCallsList::prune_empty_node_from_list()
1,229✔
225
{
226
  MockExpectedCallsListNode* current = head_;
1,229✔
227
  MockExpectedCallsListNode* previous = nullptr;
1,229✔
228
  MockExpectedCallsListNode* to_be_deleted = nullptr;
1,229✔
229

230
  while (current) {
2,612✔
231
    if (current->expected_call == nullptr) {
1,383✔
232
      to_be_deleted = current;
403✔
233
      if (previous == nullptr)
403✔
234
        head_ = current = current->next;
385✔
235
      else
236
        current = previous->next = current->next;
18✔
237
      delete to_be_deleted;
403✔
238
    } else {
239
      previous = current;
980✔
240
      current = current->next;
980✔
241
    }
242
  }
243
}
1,229✔
244

245
void ExpectedCallsList::delete_all_expectations_and_clear_list()
429✔
246
{
247
  while (head_) {
813✔
248
    MockExpectedCallsListNode* next = head_->next;
384✔
249
    delete head_->expected_call;
384✔
250
    delete head_;
384✔
251
    head_ = next;
384✔
252
  }
253
}
429✔
254

255
void ExpectedCallsList::reset_actual_call_matching_state()
350✔
256
{
257
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
378✔
258
    p->expected_call->reset_actual_call_matching_state();
28✔
259
}
350✔
260

261
void ExpectedCallsList::was_passed_to_object()
1✔
262
{
263
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
2✔
264
    p->expected_call->was_passed_to_object();
1✔
265
}
1✔
266

267
void ExpectedCallsList::parameter_was_passed(const String& parameter_name)
174✔
268
{
269
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
369✔
270
    p->expected_call->input_parameter_was_passed(parameter_name);
195✔
271
}
174✔
272

273
void ExpectedCallsList::output_parameter_was_passed(
44✔
274
    const String& parameter_name
275
)
276
{
277
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
94✔
278
    p->expected_call->output_parameter_was_passed(parameter_name);
50✔
279
}
44✔
280

281
namespace {
282
String string_or_none_text_when_empty(
126✔
283
    const String& input_string,
284
    const String& line_prefix
285
)
286
{
287
  String str = input_string;
126✔
288
  if (str == "") {
126✔
289
    str += line_prefix;
74✔
290
    str += "<none>";
74✔
291
  }
292
  return str;
126✔
293
}
×
294

295
String append_string_on_a_new_line(
66✔
296
    const String& input_string,
297
    const String& line_prefix,
298
    const String& string_to_append
299
)
300
{
301
  String str = input_string;
66✔
302
  if (str != "")
66✔
303
    str += "\n";
14✔
304
  str += line_prefix;
66✔
305
  str += string_to_append;
66✔
306
  return str;
66✔
307
}
×
308
} // namespace
309

310
String ExpectedCallsList::unfulfilled_calls_to_string(
59✔
311
    const String& line_prefix
312
) const
313
{
314
  String str;
59✔
315
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
109✔
316
    if (!p->expected_call->is_fulfilled())
50✔
317
      str = append_string_on_a_new_line(
80✔
318
          str, line_prefix, p->expected_call->call_to_string()
80✔
319
      );
40✔
320
  return string_or_none_text_when_empty(str, line_prefix);
118✔
321
}
59✔
322

323
String ExpectedCallsList::fulfilled_calls_to_string(
59✔
324
    const String& line_prefix
325
) const
326
{
327
  String str;
59✔
328

329
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
109✔
330
    if (p->expected_call->is_fulfilled())
50✔
331
      str = append_string_on_a_new_line(
20✔
332
          str, line_prefix, p->expected_call->call_to_string()
20✔
333
      );
10✔
334

335
  return string_or_none_text_when_empty(str, line_prefix);
118✔
336
}
59✔
337

338
String ExpectedCallsList::calls_with_missing_parameters_to_string(
8✔
339
    const String& line_prefix,
340
    const String& missing_parameters_prefix
341
) const
342
{
343
  String str;
8✔
344
  for (MockExpectedCallsListNode* p = head_; p; p = p->next) {
16✔
345
    str = append_string_on_a_new_line(
16✔
346
        str, line_prefix, p->expected_call->call_to_string()
16✔
347
    );
8✔
348
    str = append_string_on_a_new_line(
16✔
349
        str,
350
        line_prefix + missing_parameters_prefix,
16✔
351
        p->expected_call->missing_parameters_to_string()
16✔
352
    );
8✔
353
  }
354

355
  return string_or_none_text_when_empty(str, line_prefix);
16✔
356
}
8✔
357

358
bool ExpectedCallsList::
9✔
359
    has_unmatching_expectations_because_of_missing_parameters() const
360
{
361
  for (MockExpectedCallsListNode* p = head_; p; p = p->next)
10✔
362
    if (!p->expected_call->are_parameters_matching_actual_call())
9✔
363
      return true;
8✔
364
  return false;
1✔
365
}
366

367
} // namespace mock
368
} // namespace tiny
369
} // namespace mu
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