File indexing completed on 2025-05-11 08:24:35
0001 #include <rtems/test.h>
0002
0003 static int initial_value = 3;
0004
0005 static int counter;
0006
0007 static void
0008 setup(void *ctx)
0009 {
0010 int *c;
0011
0012 T_log(T_QUIET, "setup begin");
0013 T_eq_ptr(ctx, &initial_value);
0014 T_eq_ptr(ctx, T_fixture_context());
0015 c = ctx;
0016 counter = *c;
0017 T_set_fixture_context(&counter);
0018 T_eq_ptr(&counter, T_fixture_context());
0019 T_log(T_QUIET, "setup end");
0020 }
0021
0022 static void
0023 stop(void *ctx)
0024 {
0025 int *c;
0026
0027 T_log(T_QUIET, "stop begin");
0028 T_eq_ptr(ctx, &counter);
0029 c = ctx;
0030 ++(*c);
0031 T_log(T_QUIET, "stop end");
0032 }
0033
0034 static void
0035 teardown(void *ctx)
0036 {
0037 int *c;
0038
0039 T_log(T_QUIET, "teardown begin");
0040 T_eq_ptr(ctx, &counter);
0041 c = ctx;
0042 T_eq_int(*c, 4);
0043 T_log(T_QUIET, "teardown end");
0044 }
0045
0046 static size_t
0047 scope(void *ctx, char *buf, size_t n)
0048 {
0049
0050 return T_str_copy(buf, "/More", n);
0051 }
0052
0053 static const T_fixture fixture = {
0054 .setup = setup,
0055 .stop = stop,
0056 .teardown = teardown,
0057 .scope = scope,
0058 .initial_context = &initial_value
0059 };
0060
0061 static int initial_value_2 = 7;
0062
0063 static int counter_2;
0064
0065 static void
0066 setup_2(void *ctx)
0067 {
0068 int *c;
0069
0070 T_log(T_QUIET, "setup 2 begin");
0071 T_eq_ptr(ctx, &initial_value_2);
0072 T_eq_ptr(ctx, T_fixture_context());
0073 c = ctx;
0074 counter_2 = *c;
0075 T_set_fixture_context(&counter_2);
0076 T_eq_ptr(&counter_2, T_fixture_context());
0077 T_log(T_QUIET, "setup 2 end");
0078 }
0079
0080 static void
0081 stop_2(void *ctx)
0082 {
0083 int *c;
0084
0085 T_log(T_QUIET, "stop 2 begin");
0086 T_eq_ptr(ctx, &counter_2);
0087 c = ctx;
0088 ++(*c);
0089 T_log(T_QUIET, "stop 2 end");
0090 }
0091
0092 static void
0093 teardown_2(void *ctx)
0094 {
0095 int *c;
0096
0097 T_log(T_QUIET, "teardown 2 begin");
0098 T_eq_ptr(ctx, &counter_2);
0099 c = ctx;
0100 T_eq_int(*c, 8);
0101 T_log(T_QUIET, "teardown 2 end");
0102 }
0103
0104 static size_t
0105 scope_2(void *ctx, char *buf, size_t n)
0106 {
0107
0108 return T_str_copy(buf, "/AndMore", n);
0109 }
0110
0111 static const T_fixture fixture_2 = {
0112 .setup = setup_2,
0113 .stop = stop_2,
0114 .teardown = teardown_2,
0115 .scope = scope_2,
0116 .initial_context = &initial_value_2
0117 };
0118
0119 static T_fixture_node node;
0120
0121 T_TEST_CASE_FIXTURE(fixture, &fixture)
0122 {
0123 void *ctx;
0124
0125 T_assert_true(true, "all right");
0126 ctx = T_push_fixture(&node, &fixture_2);
0127 T_eq_ptr(ctx, &initial_value_2);
0128 ++counter_2;
0129 T_pop_fixture();
0130 ctx = T_push_fixture(&node, &fixture_2);
0131 T_eq_ptr(ctx, &initial_value_2);
0132 T_assert_true(false, "test fails and we stop the test case");
0133 T_log(T_QUIET, "not reached");
0134 }
0135
0136 #include "t-self-test.h"
0137
0138 T_TEST_OUTPUT(fixture,
0139 "B:fixture\n"
0140 "L:setup begin\n"
0141 "P:0:0:UI1/More:test-fixture.c:13\n"
0142 "P:1:0:UI1/More:test-fixture.c:14\n"
0143 "P:2:0:UI1/More:test-fixture.c:18\n"
0144 "L:setup end\n"
0145 "P:3:0:UI1/More:test-fixture.c:125\n"
0146 "L:setup 2 begin\n"
0147 "P:4.0:0:UI1/More/AndMore:test-fixture.c:71\n"
0148 "P:4.1:0:UI1/More/AndMore:test-fixture.c:72\n"
0149 "P:4.2:0:UI1/More/AndMore:test-fixture.c:76\n"
0150 "L:setup 2 end\n"
0151 "P:4.3:0:UI1/More/AndMore:test-fixture.c:127\n"
0152 "L:teardown 2 begin\n"
0153 "P:4.4:0:UI1/More/AndMore:test-fixture.c:98\n"
0154 "P:4.5:0:UI1/More/AndMore:test-fixture.c:100\n"
0155 "L:teardown 2 end\n"
0156 "L:setup 2 begin\n"
0157 "P:4.0:0:UI1/More/AndMore:test-fixture.c:71\n"
0158 "P:4.1:0:UI1/More/AndMore:test-fixture.c:72\n"
0159 "P:4.2:0:UI1/More/AndMore:test-fixture.c:76\n"
0160 "L:setup 2 end\n"
0161 "P:4.3:0:UI1/More/AndMore:test-fixture.c:131\n"
0162 "F:4.4:0:UI1/More/AndMore:test-fixture.c:132:test fails and we stop the test case\n"
0163 "L:stop 2 begin\n"
0164 "P:4.5:0:UI1/More/AndMore:test-fixture.c:86\n"
0165 "L:stop 2 end\n"
0166 "L:stop begin\n"
0167 "P:4.6:0:UI1/More/AndMore:test-fixture.c:28\n"
0168 "L:stop end\n"
0169 "L:teardown 2 begin\n"
0170 "P:4.7:0:UI1/More/AndMore:test-fixture.c:98\n"
0171 "P:4.8:0:UI1/More/AndMore:test-fixture.c:100\n"
0172 "L:teardown 2 end\n"
0173 "L:teardown begin\n"
0174 "P:4:0:UI1/More:test-fixture.c:40\n"
0175 "P:5:0:UI1/More:test-fixture.c:42\n"
0176 "L:teardown end\n"
0177 "E:fixture:N:21:F:1:D:0.001000\n");
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215