Skip to content

Commit b5141a2

Browse files
committed
New YT_IN_SEQUENCE to repeat expectations
1 parent 1445ae9 commit b5141a2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

example/sensor_test.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,15 @@ YT_TEST (printer, printer_success)
102102
// `start_printing` to be called with the file name we passed to the SUT function
103103
YT_MUST_CALL_IN_ORDER (start_printing, YT_V (DUMMY_FILE_NAME));
104104

105-
// * '_' means don't care argument. That is we just expect 'is_printing_complete' to be
106-
// called, but do not care about what argument was passed to it.
107-
YT_MUST_CALL_ANY_ORDER_ATLEAST_TIMES (stop_after_iteration, is_printing_complete, _);
108-
YT_MUST_CALL_ANY_ORDER_ATLEAST_TIMES (stop_after_iteration, printer_report_progress, _);
105+
// YT_IN_SEQUENCE repeats the expectations placed within it the given number of times. It is
106+
// used to put expectations on a loop which iterates some number of times.
107+
YT_IN_SEQUENCE (stop_after_iteration)
108+
{
109+
// * '_' means don't care argument. That is we just expect 'is_printing_complete' to be
110+
// called, but do not care about what argument was passed to it.
111+
YT_MUST_CALL_IN_ORDER (is_printing_complete, _);
112+
YT_MUST_CALL_IN_ORDER (printer_report_progress, _);
113+
}
109114

110115
YT_MUST_CALL_IN_ORDER (set_status, YT_V (STATUS_FINISHED));
111116

yukti.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ static void YT__free_testRecord (YT__TestRecord* trecord)
429429
// Compilation will fail since the these macros will expand to invalid C code.
430430
#define YT__ERROR_MESSAGE Invalid when YUKTI_TEST_NO_MUST_CALL is defined
431431

432+
#define YT_IN_SEQUENCE(n) YT__ERROR_MESSAGE
432433
#define YT_MUST_CALL_IN_ORDER(...) YT__ERROR_MESSAGE
433434
#define YT_MUST_CALL_IN_ORDER_ATLEAST_TIMES(...) YT__ERROR_MESSAGE
434435
#define YT_MUST_CALL_ANY_ORDER(...) YT__ERROR_MESSAGE
@@ -438,6 +439,8 @@ static void YT__free_testRecord (YT__TestRecord* trecord)
438439
#define YT__teardown() (void)0
439440
#define YT__ec_init() (void)0
440441
#else
442+
#define YT_IN_SEQUENCE(n) for (unsigned i = 0; i < (n); i++)
443+
441444
#define YT_MUST_NEVER_CALL(f, ...) \
442445
do { \
443446
YT__current_testrecord->total_exp_count++; \
@@ -996,6 +999,7 @@ static int YT__equal_mem (const void* a, const void* b, unsigned long size, int*
996999
#define DECLARE_FUNC_VOID YT_DECLARE_FUNC_VOID
9971000
#define DECLARE_FUNC YT_DECLARE_FUNC
9981001
#define RESET_MOCK YT__RESET_MOCK
1002+
#define IN_SEQUENCE YT_IN_SEQUENCE
9991003
#define MUST_CALL_IN_ORDER YT_MUST_CALL_IN_ORDER
10001004
#define MUST_CALL_IN_ORDER_ATLEAST_TIMES YT_MUST_CALL_IN_ORDER_ATLEAST_TIMES
10011005
#define MUST_CALL_ANY_ORDER YT_MUST_CALL_ANY_ORDER

0 commit comments

Comments
 (0)