LexLeo 0.0.0-dev+f8e5087-dirty
Technical documentation
Loading...
Searching...
No Matches
unit_test_stdio_stream.c
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-3.0-or-later
2 * Copyright (C) 2026 Sylvain Labopin
3 */
4
43
46
48
49#include "osal/mem/osal_mem.h"
51
52// for white-box tests
56
60
61#include "lexleo_cmocka.h"
62
79static void test_stdio_stream_default_cfg(void **state)
80{
81 (void)state;
82
84
85 assert_int_equal(ret.reserved, 0);
86}
87
113static void test_stdio_stream_default_env(void **state) {
114 (void)state;
115
116 const osal_stdio_ops_t *dummy_stdio_ops_p =
117 (const osal_stdio_ops_t *)(uintptr_t)0x1111u;
118 const osal_mem_ops_t *dummy_mem_p =
119 (const osal_mem_ops_t *)(uintptr_t)0x1234u;
120
121 const stream_env_t dummy_port_env = {0};
122 const stream_env_t *dummy_port_env_p = &dummy_port_env;
123
125 dummy_stdio_ops_p,
126 dummy_mem_p,
127 dummy_port_env_p);
128
129 assert_ptr_equal(ret.stdio_ops, dummy_stdio_ops_p);
130 assert_ptr_equal(ret.mem, dummy_mem_p);
131 assert_memory_equal(&ret.port_env, dummy_port_env_p, sizeof(ret.port_env));
132}
133
223
242typedef enum {
243 OUT_CHECK_NONE,
244 OUT_EXPECT_NULL,
245 OUT_EXPECT_NON_NULL,
246 OUT_EXPECT_UNCHANGED
247} out_expect_t;
248
256typedef struct {
257 const char *name;
258
259 // arrange
262 size_t fail_call_idx; // 0 = no OOM, otherwise 1-based
263
264 // assert
265 stream_status_t expected_ret;
266 out_expect_t out_expect;
267} test_stdio_stream_create_stream_case_t;
268
278typedef struct {
279 // runtime resources
280 stream_t *out;
281
282 // injection
284
287
288 const test_stdio_stream_create_stream_case_t *tc;
289} test_stdio_stream_create_stream_fixture_t;
290
291//-----------------------------------------------------------------------------
292// FIXTURES
293//-----------------------------------------------------------------------------
294
298static int setup_stdio_stream_create_stream(void **state)
299{
300 const test_stdio_stream_create_stream_case_t *tc =
301 (const test_stdio_stream_create_stream_case_t *)(*state);
302
303 test_stdio_stream_create_stream_fixture_t *fx =
304 (test_stdio_stream_create_stream_fixture_t *)malloc(sizeof(*fx));
305 if (!fx) return -1;
306
307 osal_memset(fx, 0, sizeof(*fx));
308 fx->tc = tc;
309
310 fake_memory_reset();
311 if (tc->scenario == STDIO_STREAM_CREATE_STREAM_SCENARIO_OOM && tc->fail_call_idx > 0) {
312 fake_memory_fail_only_on_call(tc->fail_call_idx);
313 }
314
315 fake_stdio_reset();
316
317 // DI
318 fx->env.stdio_ops = osal_stdio_test_fake_ops();
319 fx->env.mem = osal_mem_test_fake_ops();
320 fx->env.port_env.mem = osal_mem_test_fake_ops();
321
322 fx->args.kind = tc->kind;
323
324 fx->cfg.reserved = 0; /* Reserved for future use. */
325
326 *state = fx;
327 return 0;
328}
329
333static int teardown_stdio_stream_create_stream(void **state)
334{
335 test_stdio_stream_create_stream_fixture_t *fx =
336 (test_stdio_stream_create_stream_fixture_t *)(*state);
337
338 if (fx->out) {
339 stream_destroy(&fx->out);
340 fx->out = NULL;
341 }
342
343 assert_true(fake_memory_no_leak());
344 assert_true(fake_memory_no_invalid_free());
345 assert_true(fake_memory_no_double_free());
346
347 free(fx);
348 return 0;
349}
350
351//-----------------------------------------------------------------------------
352// TEST
353//-----------------------------------------------------------------------------
354
358static void test_stdio_stream_create_stream(void **state)
359{
360 test_stdio_stream_create_stream_fixture_t *fx =
361 (test_stdio_stream_create_stream_fixture_t *)(*state);
362 const test_stdio_stream_create_stream_case_t *tc = fx->tc;
363
364 // ARRANGE
367
368 stream_t **out_arg = &fx->out;
369 const stdio_stream_args_t *args_arg = &fx->args;
370 const stdio_stream_cfg_t *cfg_arg = &fx->cfg;
371 const stdio_stream_env_t *env_arg = &fx->env;
372
373 // invalid args
374 if (tc->scenario == STDIO_STREAM_CREATE_STREAM_SCENARIO_OUT_NULL) out_arg = NULL;
375 if (tc->scenario == STDIO_STREAM_CREATE_STREAM_SCENARIO_ARGS_NULL) args_arg = NULL;
376 if (tc->scenario == STDIO_STREAM_CREATE_STREAM_SCENARIO_CFG_NULL) cfg_arg = NULL;
377 if (tc->scenario == STDIO_STREAM_CREATE_STREAM_SCENARIO_ENV_NULL) env_arg = NULL;
378
379 // ensure OUT_EXPECT_UNCHANGED is meaningful
380 if (tc->out_expect == OUT_EXPECT_UNCHANGED && out_arg != NULL) {
381 fx->out = (stream_t *)(uintptr_t)0xDEADC0DEu; // sentinel
382 }
383
384 stream_t *out_arg_snapshot = fx->out;
385
386 // ACT
387 ret = stdio_stream_create_stream(out_arg, args_arg, cfg_arg, env_arg);
388
389 // ASSERT
390 assert_int_equal(ret, tc->expected_ret);
391
392 switch (tc->out_expect) {
393 case OUT_CHECK_NONE: break;
394 case OUT_EXPECT_NULL: assert_null(fx->out); break;
395 case OUT_EXPECT_NON_NULL: assert_non_null(fx->out); break;
396 case OUT_EXPECT_UNCHANGED:
397 assert_ptr_equal(out_arg_snapshot, fx->out);
398 fx->out = NULL; // prevent teardown from destroying sentinel
399 break;
400 default: fail();
401 }
402
403 if (tc->scenario == STDIO_STREAM_CREATE_STREAM_SCENARIO_OK) {
404 const uint8_t payload[] = { 'O', 'K' };
405 size_t n = stream_write(fx->out, payload, sizeof(payload), &st);
406
407 assert_int_equal(st, STREAM_STATUS_OK);
408 assert_int_equal(n, sizeof(payload));
409
410 assert_int_equal(
411 fake_stdio_write_call_count(fake_stdio_stdout()),
412 1u
413 );
414 assert_int_equal(
415 fake_stdio_buffered_len(fake_stdio_stdout()),
416 sizeof(payload)
417 );
418 assert_memory_equal(
419 fake_stdio_buffered_backing(fake_stdio_stdout()),
420 payload,
421 sizeof(payload)
422 );
423 }
424}
425
426//-----------------------------------------------------------------------------
427// CASES
428//-----------------------------------------------------------------------------
429
430static const test_stdio_stream_create_stream_case_t
431CASE_STDIO_STREAM_CREATE_STREAM_OUT_NULL = {
432 .name = "stdio_stream_create_stream_out_null",
435 .fail_call_idx = 0,
436
437 .expected_ret = STREAM_STATUS_INVALID,
438 .out_expect = OUT_CHECK_NONE
439};
440
441static const test_stdio_stream_create_stream_case_t
442CASE_STDIO_STREAM_CREATE_STREAM_ARGS_NULL = {
443 .name = "stdio_stream_create_stream_arg_null",
446 .fail_call_idx = 0,
447
448 .expected_ret = STREAM_STATUS_INVALID,
449 .out_expect = OUT_EXPECT_UNCHANGED
450};
451
452static const test_stdio_stream_create_stream_case_t
453CASE_STDIO_STREAM_CREATE_STREAM_CFG_NULL = {
454 .name = "stdio_stream_create_stream_cfg_null",
457 .fail_call_idx = 0,
458
459 .expected_ret = STREAM_STATUS_INVALID,
460 .out_expect = OUT_EXPECT_UNCHANGED
461};
462
463static const test_stdio_stream_create_stream_case_t
464CASE_STDIO_STREAM_CREATE_STREAM_ENV_NULL = {
465 .name = "stdio_stream_create_stream_env_null",
468 .fail_call_idx = 0,
469
470 .expected_ret = STREAM_STATUS_INVALID,
471 .out_expect = OUT_EXPECT_UNCHANGED
472};
473
474static const test_stdio_stream_create_stream_case_t
475CASE_STDIO_STREAM_CREATE_STREAM_UNSUPPORTED_KIND = {
476 .name = "stdio_stream_create_stream_unsupported_kind",
479 .fail_call_idx = 0,
480
481 .expected_ret = STREAM_STATUS_INVALID,
482 .out_expect = OUT_EXPECT_UNCHANGED
483};
484
485static const test_stdio_stream_create_stream_case_t
486CASE_STDIO_STREAM_CREATE_STREAM_OOM_1 = {
487 .name = "stdio_stream_create_stream_oom_1",
490 .fail_call_idx = 1,
491
492 .expected_ret = STREAM_STATUS_OOM,
493 .out_expect = OUT_EXPECT_UNCHANGED
494};
495
496static const test_stdio_stream_create_stream_case_t
497CASE_STDIO_STREAM_CREATE_STREAM_OK = {
498 .name = "stdio_stream_create_stream_ok",
501 .fail_call_idx = 0,
502
503 .expected_ret = STREAM_STATUS_OK,
504 .out_expect = OUT_EXPECT_NON_NULL
505};
506
507//-----------------------------------------------------------------------------
508// CASES REGISTRY
509//-----------------------------------------------------------------------------
510
511#define STDIO_STREAM_CREATE_STREAM_CASES(X) \
512X(CASE_STDIO_STREAM_CREATE_STREAM_OUT_NULL) \
513X(CASE_STDIO_STREAM_CREATE_STREAM_ARGS_NULL) \
514X(CASE_STDIO_STREAM_CREATE_STREAM_CFG_NULL) \
515X(CASE_STDIO_STREAM_CREATE_STREAM_ENV_NULL) \
516X(CASE_STDIO_STREAM_CREATE_STREAM_UNSUPPORTED_KIND) \
517X(CASE_STDIO_STREAM_CREATE_STREAM_OOM_1) \
518X(CASE_STDIO_STREAM_CREATE_STREAM_OK)
519
520#define STDIO_STREAM_MAKE_CREATE_STREAM_TEST(case_sym) \
521LEXLEO_MAKE_TEST(stdio_stream_create_stream, case_sym)
522
523static const struct CMUnitTest stdio_stream_create_stream_tests[] = {
524 STDIO_STREAM_CREATE_STREAM_CASES(
525 STDIO_STREAM_MAKE_CREATE_STREAM_TEST)
526};
527
528#undef STDIO_STREAM_CREATE_STREAM_CASES
529#undef STDIO_STREAM_MAKE_CREATE_STREAM_TEST
530
643
649typedef enum {
650 DESC_CHECK_NONE,
651 DESC_EXPECT_EMPTY,
652 DESC_EXPECT_VALID
653} desc_expect_t;
654
662typedef struct {
663 const char *name;
664
665 // arrange
667 size_t fail_call_idx; // 0 = no OOM, otherwise 1-based
668
669 // assert
670 stream_status_t expected_ret;
671 desc_expect_t desc_expect;
672} test_stdio_stream_create_desc_case_t;
673
684typedef struct {
685 // runtime resources
687
688 // injection
690 const osal_mem_ops_t *mem;
691
692 stream_key_t key;
694
695 const test_stdio_stream_create_desc_case_t *tc;
696} test_stdio_stream_create_desc_fixture_t;
697
698//-----------------------------------------------------------------------------
699// FIXTURES
700//-----------------------------------------------------------------------------
701
706static int setup_stdio_stream_create_desc(void **state)
707{
708 const test_stdio_stream_create_desc_case_t *tc =
709 (const test_stdio_stream_create_desc_case_t *)(*state);
710
711 test_stdio_stream_create_desc_fixture_t *fx =
712 (test_stdio_stream_create_desc_fixture_t *)malloc(sizeof(*fx));
713 if (!fx) return -1;
714
715 osal_memset(fx, 0, sizeof(*fx));
716 fx->tc = tc;
717
718 fake_memory_reset();
719 if (tc->scenario == STDIO_STREAM_CREATE_DESC_SCENARIO_OOM && tc->fail_call_idx > 0) {
720 fake_memory_fail_only_on_call(tc->fail_call_idx);
721 }
722
723 fake_stdio_reset();
724
725 // DI
726 fx->env.stdio_ops = osal_stdio_test_fake_ops();
727 fx->env.mem = osal_mem_test_fake_ops();
728 fx->env.port_env.mem = osal_mem_test_fake_ops();
729 fx->mem = osal_mem_test_fake_ops();
730
731 fx->key = "stdio";
732
733 fx->cfg.reserved = 0;
734
735 *state = fx;
736 return 0;
737}
738
743static int teardown_stdio_stream_create_desc(void **state)
744{
745 test_stdio_stream_create_desc_fixture_t *fx =
746 (test_stdio_stream_create_desc_fixture_t *)(*state);
747
748 if (fx->out.ud_dtor) fx->out.ud_dtor(fx->out.ud, fx->mem);
749
750 assert_true(fake_memory_no_leak());
751 assert_true(fake_memory_no_invalid_free());
752 assert_true(fake_memory_no_double_free());
753
754 free(fx);
755 return 0;
756}
757
758//-----------------------------------------------------------------------------
759// TEST
760//-----------------------------------------------------------------------------
761
766static void test_stdio_stream_create_desc(void **state)
767{
768 test_stdio_stream_create_desc_fixture_t *fx =
769 (test_stdio_stream_create_desc_fixture_t *)(*state);
770 const test_stdio_stream_create_desc_case_t *tc = fx->tc;
771
772 // ARRANGE
774
775 stream_adapter_desc_t *out_arg = &fx->out;
776 stream_key_t key_arg = fx->key;
777 const stdio_stream_cfg_t *cfg_arg = &fx->cfg;
778 const stdio_stream_env_t *env_arg = &fx->env;
779 const osal_mem_ops_t *mem_arg = fx->mem;
780
781 // invalid args
782 if (tc->scenario == STDIO_STREAM_CREATE_DESC_SCENARIO_OUT_NULL) out_arg = NULL;
783 if (tc->scenario == STDIO_STREAM_CREATE_DESC_SCENARIO_KEY_NULL) key_arg = NULL;
784 if (tc->scenario == STDIO_STREAM_CREATE_DESC_SCENARIO_KEY_EMPTY) key_arg = "";
785 if (tc->scenario == STDIO_STREAM_CREATE_DESC_SCENARIO_CFG_NULL) cfg_arg = NULL;
786 if (tc->scenario == STDIO_STREAM_CREATE_DESC_SCENARIO_ENV_NULL) env_arg = NULL;
787 if (tc->scenario == STDIO_STREAM_CREATE_DESC_SCENARIO_MEM_NULL) mem_arg = NULL;
788
789 if (tc->desc_expect == DESC_EXPECT_EMPTY && out_arg != NULL) {
790 fx->out.key = (stream_key_t)(uintptr_t)0xDEADC0DEu;
791 fx->out.ctor = (void *)(uintptr_t)0xDEADC0DEu;
792 fx->out.ud = (void *)(uintptr_t)0xDEADC0DEu;
793 fx->out.ud_dtor = (void *)(uintptr_t)0xDEADC0DEu;
794 }
795
796 // ACT
797 ret = stdio_stream_create_desc(out_arg, key_arg, cfg_arg, env_arg, mem_arg);
798
799 // ASSERT
800 assert_int_equal(ret, tc->expected_ret);
801
802 if (tc->desc_expect == DESC_EXPECT_EMPTY) {
803 assert_null(fx->out.key);
804 assert_null(fx->out.ctor);
805 assert_null(fx->out.ud);
806 assert_null(fx->out.ud_dtor);
807 }
808 else if (tc->desc_expect == DESC_EXPECT_VALID) {
809 assert_true(fx->out.key != (stream_key_t)(uintptr_t)0xDEADC0DEu);
810 assert_non_null(fx->out.key);
811 assert_true(*fx->out.key != '\0');
812 assert_true(fx->out.ctor != (void *)(uintptr_t)0xDEADC0DEu);
813 assert_non_null(fx->out.ctor);
814 assert_true(fx->out.ud != (void *)(uintptr_t)0xDEADC0DEu);
815 assert_non_null(fx->out.ud);
816 assert_true(fx->out.ud_dtor != (void *)(uintptr_t)0xDEADC0DEu);
817 assert_non_null(fx->out.ud_dtor);
818 }
819 else {
820 assert_true(tc->desc_expect == DESC_CHECK_NONE);
821 }
822}
823
824//-----------------------------------------------------------------------------
825// CASES
826//-----------------------------------------------------------------------------
827
828static const test_stdio_stream_create_desc_case_t
829CASE_STDIO_STREAM_CREATE_DESC_OUT_NULL = {
830 .name = "stdio_stream_create_desc_out_null",
832 .fail_call_idx = 0,
833
834 .expected_ret = STREAM_STATUS_INVALID,
835 .desc_expect = DESC_CHECK_NONE
836};
837
838static const test_stdio_stream_create_desc_case_t
839CASE_STDIO_STREAM_CREATE_DESC_KEY_NULL = {
840 .name = "stdio_stream_create_desc_key_null",
842 .fail_call_idx = 0,
843
844 .expected_ret = STREAM_STATUS_INVALID,
845 .desc_expect = DESC_EXPECT_EMPTY
846};
847
848static const test_stdio_stream_create_desc_case_t
849CASE_STDIO_STREAM_CREATE_DESC_KEY_EMPTY = {
850 .name = "stdio_stream_create_desc_key_empty",
852 .fail_call_idx = 0,
853
854 .expected_ret = STREAM_STATUS_INVALID,
855 .desc_expect = DESC_EXPECT_EMPTY
856};
857
858static const test_stdio_stream_create_desc_case_t
859CASE_STDIO_STREAM_CREATE_DESC_CFG_NULL = {
860 .name = "stdio_stream_create_desc_cfg_null",
862 .fail_call_idx = 0,
863
864 .expected_ret = STREAM_STATUS_INVALID,
865 .desc_expect = DESC_EXPECT_EMPTY
866};
867
868static const test_stdio_stream_create_desc_case_t
869CASE_STDIO_STREAM_CREATE_DESC_ENV_NULL = {
870 .name = "stdio_stream_create_desc_env_null",
872 .fail_call_idx = 0,
873
874 .expected_ret = STREAM_STATUS_INVALID,
875 .desc_expect = DESC_EXPECT_EMPTY
876};
877
878static const test_stdio_stream_create_desc_case_t
879CASE_STDIO_STREAM_CREATE_DESC_MEM_NULL = {
880 .name = "stdio_stream_create_desc_mem_null",
882 .fail_call_idx = 0,
883
884 .expected_ret = STREAM_STATUS_INVALID,
885 .desc_expect = DESC_EXPECT_EMPTY
886};
887
888static const test_stdio_stream_create_desc_case_t
889CASE_STDIO_STREAM_CREATE_DESC_OOM_1 = {
890 .name = "stdio_stream_create_desc_oom_1",
892 .fail_call_idx = 1,
893
894 .expected_ret = STREAM_STATUS_OOM,
895 .desc_expect = DESC_EXPECT_EMPTY
896};
897
898static const test_stdio_stream_create_desc_case_t
899CASE_STDIO_STREAM_CREATE_DESC_OK = {
900 .name = "stdio_stream_create_desc_ok",
902 .fail_call_idx = 0,
903
904 .expected_ret = STREAM_STATUS_OK,
905 .desc_expect = DESC_EXPECT_VALID
906};
907
908//-----------------------------------------------------------------------------
909// CASES REGISTRY
910//-----------------------------------------------------------------------------
911
912#define STDIO_STREAM_CREATE_DESC_CASES(X) \
913X(CASE_STDIO_STREAM_CREATE_DESC_OUT_NULL) \
914X(CASE_STDIO_STREAM_CREATE_DESC_KEY_NULL) \
915X(CASE_STDIO_STREAM_CREATE_DESC_KEY_EMPTY) \
916X(CASE_STDIO_STREAM_CREATE_DESC_CFG_NULL) \
917X(CASE_STDIO_STREAM_CREATE_DESC_ENV_NULL) \
918X(CASE_STDIO_STREAM_CREATE_DESC_MEM_NULL) \
919X(CASE_STDIO_STREAM_CREATE_DESC_OOM_1) \
920X(CASE_STDIO_STREAM_CREATE_DESC_OK)
921
922#define STDIO_STREAM_MAKE_CREATE_DESC_TEST(case_sym) \
923LEXLEO_MAKE_TEST(stdio_stream_create_desc, case_sym)
924
925static const struct CMUnitTest create_desc_stdio_stream_tests[] = {
926 STDIO_STREAM_CREATE_DESC_CASES(
927 STDIO_STREAM_MAKE_CREATE_DESC_TEST)
928};
929
930#undef STDIO_STREAM_CREATE_DESC_CASES
931#undef STDIO_STREAM_MAKE_CREATE_DESC_TEST
932
1015
1025typedef struct {
1026 const char *name;
1027
1028 // arrange
1031 size_t fail_call_idx; // 0 = no OOM, otherwise 1-based
1032
1033 // assert
1034 stream_status_t expected_ret;
1035 out_expect_t out_expect;
1036} test_stdio_stream_ctor_case_t;
1037
1047typedef struct {
1048 // runtime resources
1049 stream_t *out;
1051
1052 // injection
1054
1057
1058 const test_stdio_stream_ctor_case_t *tc;
1059} test_stdio_stream_ctor_fixture_t;
1060
1061//-----------------------------------------------------------------------------
1062// FIXTURES
1063//-----------------------------------------------------------------------------
1064
1068static int setup_stdio_stream_ctor(void **state)
1069{
1070 const test_stdio_stream_ctor_case_t *tc =
1071 (const test_stdio_stream_ctor_case_t *)(*state);
1072
1073 test_stdio_stream_ctor_fixture_t *fx =
1074 (test_stdio_stream_ctor_fixture_t *)malloc(sizeof(*fx));
1075 if (!fx) return -1;
1076
1077 osal_memset(fx, 0, sizeof(*fx));
1078 fx->tc = tc;
1079
1080 fake_memory_reset();
1081 if (tc->scenario == STDIO_STREAM_CTOR_SCENARIO_OOM && tc->fail_call_idx > 0) {
1082 fake_memory_fail_only_on_call(tc->fail_call_idx);
1083 }
1084
1085 fake_stdio_reset();
1086
1087 // DI
1088 fx->env.stdio_ops = osal_stdio_test_fake_ops();
1089 fx->env.mem = osal_mem_test_fake_ops();
1090 fx->env.port_env.mem = osal_mem_test_fake_ops();
1091 fx->args.kind = tc->kind;
1092 fx->cfg.reserved = 0; /* Reserved for future use. */
1093 fx->ud.cfg = fx->cfg;
1094 fx->ud.env = fx->env;
1095
1096 *state = fx;
1097 return 0;
1098}
1099
1103static int teardown_stdio_stream_ctor(void **state)
1104{
1105 test_stdio_stream_ctor_fixture_t *fx =
1106 (test_stdio_stream_ctor_fixture_t *)(*state);
1107
1108 if (fx->out) {
1109 stream_destroy(&fx->out);
1110 fx->out = NULL;
1111 }
1112
1113 assert_true(fake_memory_no_leak());
1114 assert_true(fake_memory_no_invalid_free());
1115 assert_true(fake_memory_no_double_free());
1116
1117 free(fx);
1118 return 0;
1119}
1120
1121//-----------------------------------------------------------------------------
1122// TEST
1123//-----------------------------------------------------------------------------
1124
1128static void test_stdio_stream_ctor(void **state)
1129{
1130 test_stdio_stream_ctor_fixture_t *fx =
1131 (test_stdio_stream_ctor_fixture_t *)(*state);
1132 const test_stdio_stream_ctor_case_t *tc = fx->tc;
1133
1134 // ARRANGE
1137
1138 stream_t **out_arg = &fx->out;
1139 const stdio_stream_args_t *args_arg = &fx->args;
1140 const void *ud_arg = (const void *)&fx->ud;
1141
1142 // invalid args
1143 if (tc->scenario == STDIO_STREAM_CTOR_SCENARIO_OUT_NULL) out_arg = NULL;
1144 if (tc->scenario == STDIO_STREAM_CTOR_SCENARIO_ARGS_NULL) args_arg = NULL;
1145 if (tc->scenario == STDIO_STREAM_CTOR_SCENARIO_UD_NULL) ud_arg = NULL;
1146
1147 // ensure OUT_EXPECT_UNCHANGED is meaningful
1148 if (tc->out_expect == OUT_EXPECT_UNCHANGED && out_arg != NULL) {
1149 fx->out = (stream_t *)(uintptr_t)0xDEADC0DEu; // sentinel
1150 }
1151
1152 stream_t *out_arg_snapshot = fx->out;
1153
1154 // ACT
1155 ret = stdio_stream_ctor(ud_arg, args_arg, out_arg);
1156
1157 // ASSERT
1158 assert_int_equal(ret, tc->expected_ret);
1159
1160 switch (tc->out_expect) {
1161 case OUT_CHECK_NONE: break;
1162 case OUT_EXPECT_NULL: assert_null(fx->out); break;
1163 case OUT_EXPECT_NON_NULL: assert_non_null(fx->out); break;
1164 case OUT_EXPECT_UNCHANGED:
1165 assert_ptr_equal(out_arg_snapshot, fx->out);
1166 fx->out = NULL; // prevent teardown from destroying sentinel
1167 break;
1168 default: fail();
1169 }
1170
1171 if (tc->scenario == STDIO_STREAM_CTOR_SCENARIO_OK) {
1172 const uint8_t payload[] = { 'O', 'K' };
1173 size_t n = stream_write(fx->out, payload, sizeof(payload), &st);
1174
1175 assert_int_equal(st, STREAM_STATUS_OK);
1176 assert_int_equal(n, sizeof(payload));
1177
1178 assert_int_equal(
1179 fake_stdio_write_call_count(fake_stdio_stdout()),
1180 1u
1181 );
1182 assert_int_equal(
1183 fake_stdio_buffered_len(fake_stdio_stdout()),
1184 sizeof(payload)
1185 );
1186 assert_memory_equal(
1187 fake_stdio_buffered_backing(fake_stdio_stdout()),
1188 payload,
1189 sizeof(payload)
1190 );
1191 }
1192}
1193
1194//-----------------------------------------------------------------------------
1195// CASES
1196//-----------------------------------------------------------------------------
1197
1198static const test_stdio_stream_ctor_case_t
1199CASE_STDIO_STREAM_CTOR_OUT_NULL = {
1200 .name = "stdio_stream_ctor_out_null",
1203 .fail_call_idx = 0,
1204
1205 .expected_ret = STREAM_STATUS_INVALID,
1206 .out_expect = OUT_CHECK_NONE
1207};
1208
1209static const test_stdio_stream_ctor_case_t
1210CASE_STDIO_STREAM_CTOR_ARGS_NULL = {
1211 .name = "stdio_stream_ctor_args_null",
1214 .fail_call_idx = 0,
1215
1216 .expected_ret = STREAM_STATUS_INVALID,
1217 .out_expect = OUT_EXPECT_UNCHANGED
1218};
1219
1220static const test_stdio_stream_ctor_case_t
1221CASE_STDIO_STREAM_CTOR_UD_NULL = {
1222 .name = "stdio_stream_ctor_ud_null",
1225 .fail_call_idx = 0,
1226
1227 .expected_ret = STREAM_STATUS_INVALID,
1228 .out_expect = OUT_EXPECT_UNCHANGED
1229};
1230
1231static const test_stdio_stream_ctor_case_t
1232CASE_STDIO_STREAM_CTOR_UNSUPPORTED_KIND = {
1233 .name = "stdio_stream_ctor_unsupported_kind",
1236 .fail_call_idx = 0,
1237
1238 .expected_ret = STREAM_STATUS_INVALID,
1239 .out_expect = OUT_EXPECT_UNCHANGED
1240};
1241
1242static const test_stdio_stream_ctor_case_t
1243CASE_STDIO_STREAM_CTOR_OOM_1 = {
1244 .name = "stdio_stream_ctor_oom_1",
1247 .fail_call_idx = 1,
1248
1249 .expected_ret = STREAM_STATUS_OOM,
1250 .out_expect = OUT_EXPECT_UNCHANGED
1251};
1252
1253static const test_stdio_stream_ctor_case_t
1254CASE_STDIO_STREAM_CTOR_OK = {
1255 .name = "stdio_stream_ctor_ok",
1258 .fail_call_idx = 0,
1259
1260 .expected_ret = STREAM_STATUS_OK,
1261 .out_expect = OUT_EXPECT_NON_NULL
1262};
1263
1264//-----------------------------------------------------------------------------
1265// CASES REGISTRY
1266//-----------------------------------------------------------------------------
1267
1268#define STDIO_STREAM_CTOR_CASES(X) \
1269X(CASE_STDIO_STREAM_CTOR_OUT_NULL) \
1270X(CASE_STDIO_STREAM_CTOR_ARGS_NULL) \
1271X(CASE_STDIO_STREAM_CTOR_UD_NULL) \
1272X(CASE_STDIO_STREAM_CTOR_UNSUPPORTED_KIND) \
1273X(CASE_STDIO_STREAM_CTOR_OOM_1) \
1274X(CASE_STDIO_STREAM_CTOR_OK)
1275
1276#define STDIO_STREAM_MAKE_CTOR_TEST(case_sym) \
1277LEXLEO_MAKE_TEST(stdio_stream_ctor, case_sym)
1278
1279static const struct CMUnitTest stdio_stream_ctor_tests[] = {
1280 STDIO_STREAM_CTOR_CASES(
1281 STDIO_STREAM_MAKE_CTOR_TEST)
1282};
1283
1284#undef STDIO_STREAM_CTOR_CASES
1285#undef STDIO_STREAM_MAKE_CTOR_TEST
1286
1439
1460typedef struct {
1461 const char *name;
1462
1463 /* arrange */
1466 uint8_t write_data[FAKE_STDIO_BUF_SIZE];
1467 size_t write_len;
1468 bool pass_status_ptr;
1469
1470 /* assert */
1471 size_t expected_ret;
1472 stream_status_t expected_st;
1473 uint8_t expected_buffered_backing[FAKE_STDIO_BUF_SIZE];
1474 size_t expected_buffered_len;
1475 bool expect_backing_invariance;
1476} test_stdio_stream_write_case_t;
1477
1494typedef struct {
1495 /* runtime resources */
1496 stream_t *s;
1497 uint8_t buffered_backing_snapshot[FAKE_STDIO_BUF_SIZE];
1498 size_t buffered_backing_snapshot_len;
1499
1500 /* DI */
1503
1505
1506 /* status storage used when `st != NULL` */
1507 stream_status_t st;
1508
1509 const test_stdio_stream_write_case_t *tc;
1510} test_stdio_stream_write_fixture_t;
1511
1512//-----------------------------------------------------------------------------
1513// FIXTURES
1514//-----------------------------------------------------------------------------
1515
1520static int setup_stdio_stream_write(void **state)
1521{
1522 const test_stdio_stream_write_case_t *tc =
1523 (const test_stdio_stream_write_case_t *)(*state);
1524
1525 test_stdio_stream_write_fixture_t *fx =
1526 (test_stdio_stream_write_fixture_t *)malloc(sizeof(*fx));
1527 if (!fx) return -1;
1528
1529 osal_memset(fx, 0, sizeof(*fx));
1530 fx->tc = tc;
1531
1532 fake_stdio_reset();
1533 fake_memory_reset();
1534
1535 // DI
1536 fx->env.stdio_ops = osal_stdio_test_fake_ops();
1537 fx->env.mem = osal_mem_test_fake_ops();
1538 fx->env.port_env.mem = osal_mem_test_fake_ops();
1539
1540 // creation of the stream handle with stdio_stream backend
1541 fx->cfg.reserved = 0;
1542 fx->args.kind = tc->kind;
1543 if (stdio_stream_create_stream(&fx->s, &fx->args, &fx->cfg, &fx->env) != STREAM_STATUS_OK) {
1544 free(fx);
1545 return -1;
1546 }
1547
1548 *state = fx;
1549 return 0;
1550}
1551
1556static int teardown_stdio_stream_write(void **state)
1557{
1558 test_stdio_stream_write_fixture_t *fx =
1559 (test_stdio_stream_write_fixture_t *)(*state);
1560
1561 if (fx->s) {
1562 stream_destroy(&fx->s);
1563 fx->s = NULL;
1564 }
1565
1566 assert_true(fake_memory_no_leak());
1567 assert_true(fake_memory_no_invalid_free());
1568 assert_true(fake_memory_no_double_free());
1569
1570 free(fx);
1571 return 0;
1572}
1573
1574//-----------------------------------------------------------------------------
1575// TEST
1576//-----------------------------------------------------------------------------
1577
1586static void test_stdio_stream_write(void **state)
1587{
1588 test_stdio_stream_write_fixture_t *fx =
1589 (test_stdio_stream_write_fixture_t *)(*state);
1590 const test_stdio_stream_write_case_t *tc = fx->tc;
1591
1592 OSAL_STDIO *stdio = ((stdio_stream_t *)fx->s->backend)->stdio;
1593
1594 // ARRANGE
1595 size_t ret = 0;
1597
1598 const void *buf_arg = tc->write_data;
1599 size_t n_arg = tc->write_len;
1600 stream_status_t *st_arg = &st;
1601
1602 if (tc->scenario == STDIO_STREAM_WRITE_SCENARIO_ZERO_LEN) {
1603 n_arg = 0;
1604 }
1606 buf_arg = NULL;
1607 n_arg = 0;
1608 }
1610 buf_arg = NULL;
1611 }
1612 if (!tc->pass_status_ptr) st_arg = NULL;
1613
1614 if (tc->expect_backing_invariance) {
1615 fx->buffered_backing_snapshot_len = fake_stdio_buffered_len(stdio);
1617 fx->buffered_backing_snapshot,
1618 fake_stdio_buffered_backing(stdio),
1619 FAKE_STDIO_BUF_SIZE
1620 );
1621 }
1622
1623 // ACT
1624 ret = stream_write(fx->s, buf_arg, n_arg, st_arg);
1625
1626 // ASSERT
1627 assert_int_equal((int)ret, (int)tc->expected_ret);
1628 if (tc->pass_status_ptr) {
1629 assert_int_equal((int)st, (int)tc->expected_st);
1630 }
1631
1632 assert_int_equal(
1633 (int)fake_stdio_buffered_len(stdio),
1634 (int)tc->expected_buffered_len);
1635 if (tc->expected_buffered_len > 0) {
1636 assert_memory_equal(
1637 fake_stdio_buffered_backing(stdio),
1638 tc->expected_buffered_backing,
1639 tc->expected_buffered_len
1640 );
1641 }
1642
1643 if (tc->expect_backing_invariance) {
1644 assert_int_equal(
1645 (int)fake_stdio_buffered_len(stdio),
1646 (int)fx->buffered_backing_snapshot_len
1647 );
1648 assert_memory_equal(
1649 fake_stdio_buffered_backing(stdio),
1650 fx->buffered_backing_snapshot,
1651 FAKE_STDIO_BUF_SIZE
1652 );
1653 }
1654}
1655
1656//-----------------------------------------------------------------------------
1657// CASES
1658//-----------------------------------------------------------------------------
1659
1660static const test_stdio_stream_write_case_t
1661CASE_STDIO_STREAM_WRITE_ZERO_LEN = {
1662 .name = "stdio_stream_write_zero_len",
1665 .pass_status_ptr = true,
1666
1667 .expected_ret = 0,
1668 .expected_st = STREAM_STATUS_OK,
1669 .expected_buffered_len = 0,
1670 .expect_backing_invariance = true
1671};
1672
1673static const test_stdio_stream_write_case_t
1674CASE_STDIO_STREAM_WRITE_BUF_NULL_ZERO_LEN = {
1675 .name = "stdio_stream_write_buf_null_zero_len",
1678 .pass_status_ptr = true,
1679
1680 .expected_ret = 0,
1681 .expected_st = STREAM_STATUS_OK,
1682 .expected_buffered_len = 0,
1683 .expect_backing_invariance = true
1684};
1685
1686static const test_stdio_stream_write_case_t
1687CASE_STDIO_STREAM_WRITE_BUF_NULL_NONZERO = {
1688 .name = "stdio_stream_write_buf_null_nonzero",
1691 .write_len = 1,
1692 .pass_status_ptr = true,
1693
1694 .expected_ret = 0,
1695 .expected_st = STREAM_STATUS_INVALID,
1696 .expected_buffered_len = 0,
1697 .expect_backing_invariance = true
1698};
1699
1700static const test_stdio_stream_write_case_t
1701CASE_STDIO_STREAM_WRITE_STDIN_FORBIDDEN = {
1702 .name = "stdio_stream_write_stdin_forbidden",
1705 .write_data ={ 0x01, 0x02, 0x03 },
1706 .write_len = 3,
1707 .pass_status_ptr = true,
1708
1709 .expected_ret = 0,
1710 .expected_st = STREAM_STATUS_IO_ERROR,
1711 .expect_backing_invariance = true
1712};
1713
1714static const test_stdio_stream_write_case_t
1715CASE_STDIO_STREAM_WRITE_ST_NULL_STDOUT = {
1716 .name = "stdio_stream_write_st_null_stdout",
1719 .write_data ={ 0x01, 0x02, 0x03 },
1720 .write_len = 3,
1721 .pass_status_ptr = false,
1722
1723 .expected_ret = 3,
1724 .expected_buffered_backing ={ 0x01, 0x02, 0x03 },
1725 .expected_buffered_len = 3,
1726};
1727
1728static const test_stdio_stream_write_case_t
1729CASE_STDIO_STREAM_WRITE_ST_NULL_STDERR = {
1730 .name = "stdio_stream_write_st_null_stderr",
1733 .write_data ={ 0x01, 0x02, 0x03 },
1734 .write_len = 3,
1735 .pass_status_ptr = false,
1736
1737 .expected_ret = 3,
1738 .expected_buffered_backing ={ 0x01, 0x02, 0x03 },
1739 .expected_buffered_len = 3,
1740};
1741
1742static const test_stdio_stream_write_case_t
1743CASE_STDIO_STREAM_WRITE_OK_STDOUT = {
1744 .name = "stdio_stream_write_ok_stdout",
1747 .write_data ={ 0x01, 0x02, 0x03 },
1748 .write_len = 3,
1749 .pass_status_ptr = true,
1750
1751 .expected_ret = 3,
1752 .expected_st = STREAM_STATUS_OK,
1753 .expected_buffered_backing ={ 0x01, 0x02, 0x03 },
1754 .expected_buffered_len = 3,
1755};
1756
1757static const test_stdio_stream_write_case_t
1758CASE_STDIO_STREAM_WRITE_OK_STDERR = {
1759 .name = "stdio_stream_write_ok_stderr",
1762 .write_data ={ 0x01, 0x02, 0x03 },
1763 .write_len = 3,
1764 .pass_status_ptr = true,
1765
1766 .expected_ret = 3,
1767 .expected_st = STREAM_STATUS_OK,
1768 .expected_buffered_backing ={ 0x01, 0x02, 0x03 },
1769 .expected_buffered_len = 3,
1770};
1771
1772//-----------------------------------------------------------------------------
1773// CASES REGISTRY
1774//-----------------------------------------------------------------------------
1775
1776#define STDIO_STREAM_WRITE_CASES(X) \
1777X(CASE_STDIO_STREAM_WRITE_ZERO_LEN) \
1778X(CASE_STDIO_STREAM_WRITE_BUF_NULL_ZERO_LEN) \
1779X(CASE_STDIO_STREAM_WRITE_BUF_NULL_NONZERO) \
1780X(CASE_STDIO_STREAM_WRITE_STDIN_FORBIDDEN) \
1781X(CASE_STDIO_STREAM_WRITE_ST_NULL_STDOUT) \
1782X(CASE_STDIO_STREAM_WRITE_ST_NULL_STDERR) \
1783X(CASE_STDIO_STREAM_WRITE_OK_STDOUT) \
1784X(CASE_STDIO_STREAM_WRITE_OK_STDERR)
1785
1786#define STDIO_STREAM_MAKE_WRITE_TEST(case_sym) \
1787LEXLEO_MAKE_TEST(stdio_stream_write, case_sym)
1788
1789static const struct CMUnitTest stdio_stream_write_tests[] = {
1790 STDIO_STREAM_WRITE_CASES(STDIO_STREAM_MAKE_WRITE_TEST)
1791};
1792
1793#undef STDIO_STREAM_WRITE_CASES
1794#undef STDIO_STREAM_MAKE_WRITE_TEST
1795
1965
1988typedef struct {
1989 const char *name;
1990
1991 /* arrange */
1994 uint8_t buffered_backing[FAKE_STDIO_BUF_SIZE];
1995 size_t buffered_len;
1996 size_t read_len;
1997 bool pass_status_ptr;
1998
1999 /* assert */
2000 size_t expected_ret;
2001 stream_status_t expected_st;
2002 uint8_t expected_buf[FAKE_STDIO_BUF_SIZE];
2003 size_t expected_pos;
2004 bool expect_buf_invariance;
2005} test_stdio_stream_read_case_t;
2006
2024typedef struct {
2025 /* runtime resources */
2026 stream_t *s;
2027 uint8_t buffered_backing_snapshot[FAKE_STDIO_BUF_SIZE];
2028 size_t buffered_backing_snapshot_len;
2029
2030 /* DI */
2033
2035
2036 /* status storage used when `st != NULL` */
2037 stream_status_t st;
2038
2039 const test_stdio_stream_read_case_t *tc;
2040} test_stdio_stream_read_fixture_t;
2041
2042//-----------------------------------------------------------------------------
2043// FIXTURES
2044//-----------------------------------------------------------------------------
2045
2050static int setup_stdio_stream_read(void **state)
2051{
2052 const test_stdio_stream_read_case_t *tc =
2053 (const test_stdio_stream_read_case_t *)(*state);
2054
2055 test_stdio_stream_read_fixture_t *fx =
2056 (test_stdio_stream_read_fixture_t *)malloc(sizeof(*fx));
2057 if (!fx) return -1;
2058
2059 osal_memset(fx, 0, sizeof(*fx));
2060 fx->tc = tc;
2061
2062 fake_stdio_reset();
2063 fake_memory_reset();
2064
2065 // DI
2066 fx->env.stdio_ops = osal_stdio_test_fake_ops();
2067 fx->env.mem = osal_mem_test_fake_ops();
2068 fx->env.port_env.mem = osal_mem_test_fake_ops();
2069
2070 // creation of the stream handle with stdio_stream backend
2071 fx->cfg.reserved = 0;
2072 fx->args.kind = tc->kind;
2073 if (stdio_stream_create_stream(&fx->s, &fx->args, &fx->cfg, &fx->env) != STREAM_STATUS_OK) {
2074 free(fx);
2075 return -1;
2076 }
2077
2078 // seed fake stdio stream
2079 OSAL_STDIO *stdio = ((stdio_stream_t *)fx->s->backend)->stdio;
2080 fake_stdio_set_buffered_backing(
2081 stdio,
2082 tc->buffered_backing,
2083 tc->buffered_len
2084 );
2085 assert_int_equal(
2086 (int)fake_stdio_read_pos(stdio),
2087 0
2088 );
2089
2090 *state = fx;
2091 return 0;
2092}
2093
2098static int teardown_stdio_stream_read(void **state)
2099{
2100 test_stdio_stream_read_fixture_t *fx =
2101 (test_stdio_stream_read_fixture_t *)(*state);
2102
2103 if (fx->s) {
2104 stream_destroy(&fx->s);
2105 fx->s = NULL;
2106 }
2107
2108 assert_true(fake_memory_no_leak());
2109 assert_true(fake_memory_no_invalid_free());
2110 assert_true(fake_memory_no_double_free());
2111
2112 free(fx);
2113 return 0;
2114}
2115
2116//-----------------------------------------------------------------------------
2117// TEST
2118//-----------------------------------------------------------------------------
2119
2128static void test_stdio_stream_read(void **state)
2129{
2130 test_stdio_stream_read_fixture_t *fx =
2131 (test_stdio_stream_read_fixture_t *)(*state);
2132 const test_stdio_stream_read_case_t *tc = fx->tc;
2133
2134 OSAL_STDIO *stdio = ((stdio_stream_t *)fx->s->backend)->stdio;
2135
2136 // ARRANGE
2137 size_t ret = 0;
2138 uint8_t buf[FAKE_STDIO_BUF_SIZE] = { 0 };
2139 void *buf_arg = buf;
2140 size_t n_arg = tc->read_len;
2142 stream_status_t *st_arg = &st;
2143
2144 if (tc->scenario == STDIO_STREAM_READ_SCENARIO_ZERO_LEN) {
2145 n_arg = 0;
2146 }
2148 buf_arg = NULL;
2149 n_arg = 0;
2150 }
2151 if (tc->scenario == STDIO_STREAM_READ_SCENARIO_BUF_NULL_NONZERO) {
2152 buf_arg = NULL;
2153 }
2154 if (!tc->pass_status_ptr) st_arg = NULL;
2155
2156
2157 fx->buffered_backing_snapshot_len = fake_stdio_buffered_len(stdio);
2159 fx->buffered_backing_snapshot,
2160 fake_stdio_buffered_backing(stdio),
2161 FAKE_STDIO_BUF_SIZE
2162 );
2163
2164 // ACT
2165 ret = stream_read(fx->s, buf_arg, n_arg, st_arg);
2166
2167 // ASSERT
2168 assert_int_equal(
2169 (int)ret,
2170 (int)tc->expected_ret
2171 );
2172 if (tc->pass_status_ptr) {
2173 assert_int_equal(
2174 (int)st,
2175 (int)tc->expected_st
2176 );
2177 }
2178
2179 const uint8_t *buffered_backing = fake_stdio_buffered_backing(stdio);
2180 const uint8_t zeros_buf[FAKE_STDIO_BUF_SIZE] = { 0 };
2181
2182 if (tc->expected_ret > 0) {
2183 assert_memory_equal(
2184 buf,
2185 tc->expected_buf,
2186 tc->expected_ret
2187 );
2188 assert_memory_equal(
2189 buf + tc->expected_ret,
2190 zeros_buf + tc->expected_ret,
2191 FAKE_STDIO_BUF_SIZE - tc->expected_ret
2192 );
2193 }
2194
2195 assert_int_equal(
2196 (int)fake_stdio_read_pos(stdio),
2197 (int)tc->expected_pos
2198 );
2199
2200 if (tc->expect_buf_invariance) {
2201 assert_memory_equal(
2202 buf,
2203 zeros_buf,
2204 FAKE_STDIO_BUF_SIZE
2205 );
2206 }
2207
2208 // assert backing buffer invariance
2209 assert_int_equal(
2210 (int)fake_stdio_buffered_len(stdio),
2211 (int)fx->buffered_backing_snapshot_len
2212 );
2213 assert_memory_equal(
2214 buffered_backing,
2215 fx->buffered_backing_snapshot,
2216 FAKE_STDIO_BUF_SIZE
2217 );
2218
2219}
2220
2221//-----------------------------------------------------------------------------
2222// CASES
2223//-----------------------------------------------------------------------------
2224
2225static const test_stdio_stream_read_case_t
2226CASE_STDIO_READ_READ_ZERO_LEN = {
2227 .name = "stdio_stream_read_zero_len",
2230 .buffered_backing = { 0x01, 0x02, 0x03 },
2231 .buffered_len = 3,
2232 .read_len = 0,
2233 .pass_status_ptr = true,
2234
2235 .expected_ret = 0,
2236 .expected_st = STREAM_STATUS_OK,
2237 .expected_buf = { 0 },
2238 .expected_pos = 0,
2239 .expect_buf_invariance = true
2240};
2241
2242static const test_stdio_stream_read_case_t
2243CASE_STDIO_READ_READ_BUF_NULL_ZERO_LEN = {
2244 .name = "stdio_stream_read_buf_null_zero_len",
2247 .buffered_backing = { 0x01, 0x02, 0x03 },
2248 .buffered_len = 3,
2249 .read_len = 0,
2250 .pass_status_ptr = true,
2251
2252 .expected_ret = 0,
2253 .expected_st = STREAM_STATUS_OK,
2254 .expected_buf = { 0 },
2255 .expected_pos = 0,
2256 .expect_buf_invariance = true
2257};
2258
2259static const test_stdio_stream_read_case_t
2260CASE_STDIO_READ_READ_BUF_NULL_NONZERO = {
2261 .name = "stdio_stream_read_buf_null_nonzero",
2264 .buffered_backing = { 0x01, 0x02, 0x03 },
2265 .buffered_len = 3,
2266 .read_len = 2,
2267 .pass_status_ptr = true,
2268
2269 .expected_ret = 0,
2270 .expected_st = STREAM_STATUS_INVALID,
2271 .expected_buf = { 0 },
2272 .expected_pos = 0,
2273 .expect_buf_invariance = true
2274};
2275
2276static const test_stdio_stream_read_case_t
2277CASE_STDIO_READ_READ_STDOUT_FORBIDDEN = {
2278 .name = "stdio_stream_read_stdout_forbidden",
2281 .buffered_backing = { 0x01, 0x02, 0x03 },
2282 .buffered_len = 3,
2283 .read_len = 2,
2284 .pass_status_ptr = true,
2285
2286 .expected_ret = 0,
2287 .expected_st = STREAM_STATUS_IO_ERROR,
2288 .expected_buf = { 0 },
2289 .expected_pos = 0,
2290 .expect_buf_invariance = true
2291};
2292
2293static const test_stdio_stream_read_case_t
2294CASE_STDIO_READ_READ_STDERR_FORBIDDEN = {
2295 .name = "stdio_stream_read_stderr_forbidden",
2298 .buffered_backing = { 0x01, 0x02, 0x03 },
2299 .buffered_len = 3,
2300 .read_len = 2,
2301 .pass_status_ptr = true,
2302
2303 .expected_ret = 0,
2304 .expected_st = STREAM_STATUS_IO_ERROR,
2305 .expected_buf = { 0 },
2306 .expected_pos = 0,
2307 .expect_buf_invariance = true
2308};
2309
2310static const test_stdio_stream_read_case_t
2311CASE_STDIO_READ_READ_ST_NULL_STDIN = {
2312 .name = "stdio_stream_read_st_null_stdin",
2315 .buffered_backing = { 0x01, 0x02, 0x03 },
2316 .buffered_len = 3,
2317 .read_len = 2,
2318 .pass_status_ptr = false,
2319
2320 .expected_ret = 2,
2321 .expected_buf = { 0x01, 0x02 },
2322 .expected_pos = 2,
2323 .expect_buf_invariance = false
2324};
2325
2326static const test_stdio_stream_read_case_t
2327CASE_STDIO_READ_READ_OK_STDIN = {
2328 .name = "stdio_stream_read_ok_stdin",
2331 .buffered_backing = { 0x01, 0x02, 0x03 },
2332 .buffered_len = 3,
2333 .read_len = 2,
2334 .pass_status_ptr = true,
2335
2336 .expected_ret = 2,
2337 .expected_st = STREAM_STATUS_OK,
2338 .expected_buf = { 0x01, 0x02 },
2339 .expected_pos = 2,
2340 .expect_buf_invariance = false
2341};
2342
2343static const test_stdio_stream_read_case_t
2344CASE_STDIO_READ_READ_PARTIAL_STDIN = {
2345 .name = "stdio_stream_read_partial_stdin",
2348 .buffered_backing = { 0x01, 0x02, 0x03 },
2349 .buffered_len = 3,
2350 .read_len = 4,
2351 .pass_status_ptr = true,
2352
2353 .expected_ret = 3,
2354 .expected_st = STREAM_STATUS_OK,
2355 .expected_buf = { 0x01, 0x02, 0x03 },
2356 .expected_pos = 3,
2357 .expect_buf_invariance = false
2358};
2359
2360//-----------------------------------------------------------------------------
2361// CASES REGISTRY
2362//-----------------------------------------------------------------------------
2363
2364#define STDIO_STREAM_READ_CASES(X) \
2365X(CASE_STDIO_READ_READ_ZERO_LEN) \
2366X(CASE_STDIO_READ_READ_BUF_NULL_ZERO_LEN) \
2367X(CASE_STDIO_READ_READ_BUF_NULL_NONZERO) \
2368X(CASE_STDIO_READ_READ_STDOUT_FORBIDDEN) \
2369X(CASE_STDIO_READ_READ_STDERR_FORBIDDEN) \
2370X(CASE_STDIO_READ_READ_ST_NULL_STDIN) \
2371X(CASE_STDIO_READ_READ_OK_STDIN) \
2372X(CASE_STDIO_READ_READ_PARTIAL_STDIN)
2373
2374#define STDIO_STREAM_MAKE_READ_TEST(case_sym) \
2375LEXLEO_MAKE_TEST(stdio_stream_read, case_sym)
2376
2377static const struct CMUnitTest stdio_stream_read_tests[] = {
2378 STDIO_STREAM_READ_CASES(STDIO_STREAM_MAKE_READ_TEST)
2379};
2380
2381#undef STDIO_STREAM_READ_CASES
2382#undef STDIO_STREAM_MAKE_READ_TEST
2383
2469
2493typedef struct {
2494 const char *name;
2495
2496 /* arrange */
2499 uint8_t initial_buffered_backing[FAKE_STDIO_BUF_SIZE];
2500 size_t initial_buffered_len;
2501 uint8_t initial_sink_backing[FAKE_STDIO_BUF_SIZE];
2502 size_t initial_sink_len;
2503
2504 /* assert */
2505 stream_status_t expected_status;
2506 uint8_t expected_buffered_backing[FAKE_STDIO_BUF_SIZE];
2507 size_t expected_buffered_len;
2508 uint8_t expected_sink_backing[FAKE_STDIO_BUF_SIZE];
2509 size_t expected_sink_len;
2510 bool expect_buffered_invariance;
2511 bool expect_sink_invariance;
2512} test_stdio_stream_flush_case_t;
2513
2531typedef struct {
2532 /* runtime resources */
2533 stream_t *s;
2534 uint8_t buffered_backing_snapshot[FAKE_STDIO_BUF_SIZE];
2535 size_t buffered_backing_snapshot_len;
2536 uint8_t sink_backing_snapshot[FAKE_STDIO_BUF_SIZE];
2537 size_t sink_backing_snapshot_len;
2538
2539 /* DI */
2542
2544
2545 const test_stdio_stream_flush_case_t *tc;
2546} test_stdio_stream_flush_fixture_t;
2547
2548//-----------------------------------------------------------------------------
2549// FIXTURES
2550//-----------------------------------------------------------------------------
2551
2556static int setup_stdio_stream_flush(void **state)
2557{
2558 const test_stdio_stream_flush_case_t *tc =
2559 (const test_stdio_stream_flush_case_t *)(*state);
2560
2561 test_stdio_stream_flush_fixture_t *fx =
2562 (test_stdio_stream_flush_fixture_t *)malloc(sizeof(*fx));
2563 if (!fx) return -1;
2564
2565 osal_memset(fx, 0, sizeof(*fx));
2566 fx->tc = tc;
2567
2568 fake_stdio_reset();
2569 fake_memory_reset();
2570
2571 // DI
2572 fx->env.stdio_ops = osal_stdio_test_fake_ops();
2573 fx->env.mem = osal_mem_test_fake_ops();
2574 fx->env.port_env.mem = osal_mem_test_fake_ops();
2575
2576 // creation of the stream handle with stdio_stream backend
2577 fx->cfg.reserved = 0;
2578 fx->args.kind = tc->kind;
2579 if (stdio_stream_create_stream(&fx->s, &fx->args, &fx->cfg, &fx->env) != STREAM_STATUS_OK) {
2580 free(fx);
2581 return -1;
2582 }
2583
2584 // seed fake stdio stream
2585 OSAL_STDIO *stdio = ((stdio_stream_t *)fx->s->backend)->stdio;
2586 fake_stdio_set_buffered_backing(
2587 stdio,
2588 tc->initial_buffered_backing,
2589 tc->initial_buffered_len
2590 );
2591 fake_stdio_set_sink_backing(
2592 stdio,
2593 tc->initial_sink_backing,
2594 tc->initial_sink_len
2595 );
2596
2597 *state = fx;
2598 return 0;
2599}
2600
2605static int teardown_stdio_stream_flush(void **state)
2606{
2607 test_stdio_stream_flush_fixture_t *fx =
2608 (test_stdio_stream_flush_fixture_t *)(*state);
2609
2610 if (fx->s) {
2611 stream_destroy(&fx->s);
2612 fx->s = NULL;
2613 }
2614
2615 assert_true(fake_memory_no_leak());
2616 assert_true(fake_memory_no_invalid_free());
2617 assert_true(fake_memory_no_double_free());
2618
2619 free(fx);
2620 return 0;
2621}
2622
2623//-----------------------------------------------------------------------------
2624// TEST
2625//-----------------------------------------------------------------------------
2626
2635static void test_stdio_stream_flush(void **state)
2636{
2637 test_stdio_stream_flush_fixture_t *fx =
2638 (test_stdio_stream_flush_fixture_t *)(*state);
2639 const test_stdio_stream_flush_case_t *tc = fx->tc;
2640
2641 OSAL_STDIO *stdio = ((stdio_stream_t *)fx->s->backend)->stdio;
2642
2643 // ARRANGE
2645
2646 fx->buffered_backing_snapshot_len = fake_stdio_buffered_len(stdio);
2648 fx->buffered_backing_snapshot,
2649 fake_stdio_buffered_backing(stdio),
2650 FAKE_STDIO_BUF_SIZE
2651 );
2652
2653 fx->sink_backing_snapshot_len = fake_stdio_sink_len(stdio);
2655 fx->sink_backing_snapshot,
2656 fake_stdio_sink_backing(stdio),
2657 FAKE_STDIO_BUF_SIZE
2658 );
2659
2660 // ACT
2661 status = stream_flush(fx->s);
2662
2663 // ASSERT
2664 assert_int_equal(
2665 (int)status,
2666 (int)tc->expected_status
2667 );
2668
2669 const uint8_t *buffered_backing = fake_stdio_buffered_backing(stdio);
2670 const uint8_t *sink_backing = fake_stdio_sink_backing(stdio);
2671
2672 assert_int_equal(
2673 (int)fake_stdio_buffered_len(stdio),
2674 (int)tc->expected_buffered_len
2675 );
2676 assert_memory_equal(
2677 buffered_backing,
2678 tc->expected_buffered_backing,
2679 FAKE_STDIO_BUF_SIZE
2680 );
2681
2682 assert_int_equal(
2683 (int)fake_stdio_sink_len(stdio),
2684 (int)tc->expected_sink_len
2685 );
2686 assert_memory_equal(
2687 sink_backing,
2688 tc->expected_sink_backing,
2689 FAKE_STDIO_BUF_SIZE
2690 );
2691
2692 if (tc->expect_buffered_invariance) {
2693 assert_int_equal(
2694 (int)fake_stdio_buffered_len(stdio),
2695 (int)fx->buffered_backing_snapshot_len
2696 );
2697 assert_memory_equal(
2698 buffered_backing,
2699 fx->buffered_backing_snapshot,
2700 FAKE_STDIO_BUF_SIZE
2701 );
2702 }
2703
2704 if (tc->expect_sink_invariance) {
2705 assert_int_equal(
2706 (int)fake_stdio_sink_len(stdio),
2707 (int)fx->sink_backing_snapshot_len
2708 );
2709 assert_memory_equal(
2710 sink_backing,
2711 fx->sink_backing_snapshot,
2712 FAKE_STDIO_BUF_SIZE
2713 );
2714 }
2715}
2716
2717//-----------------------------------------------------------------------------
2718// CASES
2719//-----------------------------------------------------------------------------
2720
2721static const test_stdio_stream_flush_case_t
2722CASE_STDIO_STREAM_FLUSH_STDIN_FORBIDDEN = {
2723 .name = "stdio_stream_flush_stdin_forbidden",
2726 .initial_buffered_backing = { 0x01, 0x02, 0x03 },
2727 .initial_buffered_len = 3,
2728 .initial_sink_backing = { 0x0a, 0x0b },
2729 .initial_sink_len = 2,
2730
2731 .expected_status = STREAM_STATUS_IO_ERROR,
2732 .expected_buffered_backing = { 0x01, 0x02, 0x03 },
2733 .expected_buffered_len = 3,
2734 .expected_sink_backing = { 0x0a, 0x0b },
2735 .expected_sink_len = 2,
2736 .expect_buffered_invariance = true,
2737 .expect_sink_invariance = true
2738};
2739
2740static const test_stdio_stream_flush_case_t
2741CASE_STDIO_STREAM_FLUSH_OK_STDOUT = {
2742 .name = "stdio_stream_flush_ok_stdout",
2745 .initial_buffered_backing = { 0x01, 0x02, 0x03 },
2746 .initial_buffered_len = 3,
2747 .initial_sink_backing = { 0x0a, 0x0b },
2748 .initial_sink_len = 2,
2749
2750 .expected_status = STREAM_STATUS_OK,
2751 .expected_buffered_backing = { 0 },
2752 .expected_buffered_len = 0,
2753 .expected_sink_backing = { 0x0a, 0x0b, 0x01, 0x02, 0x03 },
2754 .expected_sink_len = 5,
2755 .expect_buffered_invariance = false,
2756 .expect_sink_invariance = false
2757};
2758
2759static const test_stdio_stream_flush_case_t
2760CASE_STDIO_STREAM_FLUSH_OK_STDERR = {
2761 .name = "stdio_stream_flush_ok_stderr",
2764 .initial_buffered_backing = { 0x01, 0x02, 0x03 },
2765 .initial_buffered_len = 3,
2766 .initial_sink_backing = { 0x0a, 0x0b },
2767 .initial_sink_len = 2,
2768
2769 .expected_status = STREAM_STATUS_OK,
2770 .expected_buffered_backing = { 0 },
2771 .expected_buffered_len = 0,
2772 .expected_sink_backing = { 0x0a, 0x0b, 0x01, 0x02, 0x03 },
2773 .expected_sink_len = 5,
2774 .expect_buffered_invariance = false,
2775 .expect_sink_invariance = false
2776};
2777
2778//-----------------------------------------------------------------------------
2779// CASES REGISTRY
2780//-----------------------------------------------------------------------------
2781
2782#define STDIO_STREAM_FLUSH_CASES(X) \
2783X(CASE_STDIO_STREAM_FLUSH_STDIN_FORBIDDEN) \
2784X(CASE_STDIO_STREAM_FLUSH_OK_STDOUT) \
2785X(CASE_STDIO_STREAM_FLUSH_OK_STDERR)
2786
2787#define STDIO_STREAM_MAKE_FLUSH_TEST(case_sym) \
2788LEXLEO_MAKE_TEST(stdio_stream_flush, case_sym)
2789
2790static const struct CMUnitTest stdio_stream_flush_tests[] = {
2791 STDIO_STREAM_FLUSH_CASES(STDIO_STREAM_MAKE_FLUSH_TEST)
2792};
2793
2794#undef STDIO_STREAM_FLUSH_CASES
2795#undef STDIO_STREAM_MAKE_FLUSH_TEST
2796
2873
2887typedef struct {
2888 const char *name;
2889
2890 /* arrange */
2893
2894 /* assert */
2895 bool expected_handle_is_null;
2896 bool expect_no_leak;
2897} test_stdio_stream_close_case_t;
2898
2914typedef struct {
2915 /* runtime resources */
2916 stream_t *s;
2917
2918 /* DI */
2921
2923
2924 const test_stdio_stream_close_case_t *tc;
2925} test_stdio_stream_close_fixture_t;
2926
2927//-----------------------------------------------------------------------------
2928// FIXTURES
2929//-----------------------------------------------------------------------------
2930
2935static int setup_stdio_stream_close(void **state)
2936{
2937 const test_stdio_stream_close_case_t *tc =
2938 (const test_stdio_stream_close_case_t *)(*state);
2939
2940 test_stdio_stream_close_fixture_t *fx =
2941 (test_stdio_stream_close_fixture_t *)malloc(sizeof(*fx));
2942 if (!fx) return -1;
2943
2944 osal_memset(fx, 0, sizeof(*fx));
2945 fx->tc = tc;
2946
2947 fake_stdio_reset();
2948 fake_memory_reset();
2949
2950 // DI
2951 fx->env.stdio_ops = osal_stdio_test_fake_ops();
2952 fx->env.mem = osal_mem_test_fake_ops();
2953 fx->env.port_env.mem = osal_mem_test_fake_ops();
2954
2955 // creation of the stream handle with stdio_stream backend
2956 fx->cfg.reserved = 0;
2957 fx->args.kind = tc->kind;
2958 if (stdio_stream_create_stream(&fx->s, &fx->args, &fx->cfg, &fx->env) != STREAM_STATUS_OK) {
2959 free(fx);
2960 return -1;
2961 }
2962
2963 *state = fx;
2964 return 0;
2965}
2966
2971static int teardown_stdio_stream_close(void **state)
2972{
2973 test_stdio_stream_close_fixture_t *fx =
2974 (test_stdio_stream_close_fixture_t *)(*state);
2975
2976 if (fx->s) {
2977 stream_destroy(&fx->s);
2978 fx->s = NULL;
2979 }
2980
2981 assert_true(fake_memory_no_leak());
2982 assert_true(fake_memory_no_invalid_free());
2983 assert_true(fake_memory_no_double_free());
2984
2985 free(fx);
2986 return 0;
2987}
2988
2989//-----------------------------------------------------------------------------
2990// TEST
2991//-----------------------------------------------------------------------------
2992
3001static void test_stdio_stream_close(void **state)
3002{
3003 test_stdio_stream_close_fixture_t *fx =
3004 (test_stdio_stream_close_fixture_t *)(*state);
3005 const test_stdio_stream_close_case_t *tc = fx->tc;
3006
3007 // ARRANGE
3008 stream_t *s_before = fx->s;
3009
3010 // ACT
3011 stream_destroy(&fx->s);
3012
3013 // ASSERT
3014 (void)s_before;
3015
3016 assert_int_equal(
3017 (int)(fx->s == NULL),
3018 (int)tc->expected_handle_is_null
3019 );
3020}
3021
3022//-----------------------------------------------------------------------------
3023// CASES
3024//-----------------------------------------------------------------------------
3025
3026static const test_stdio_stream_close_case_t
3027CASE_STDIO_STREAM_CLOSE_OK_STDIN = {
3028 .name = "stdio_stream_close_ok_stdin",
3031
3032 .expected_handle_is_null = true,
3033 .expect_no_leak = true
3034};
3035
3036static const test_stdio_stream_close_case_t
3037CASE_STDIO_STREAM_CLOSE_OK_STDOUT = {
3038 .name = "stdio_stream_close_ok_stdout",
3041
3042 .expected_handle_is_null = true,
3043 .expect_no_leak = true
3044};
3045
3046static const test_stdio_stream_close_case_t
3047CASE_STDIO_STREAM_CLOSE_OK_STDERR = {
3048 .name = "stdio_stream_close_ok_stderr",
3051
3052 .expected_handle_is_null = true,
3053 .expect_no_leak = true
3054};
3055
3056//-----------------------------------------------------------------------------
3057// CASES REGISTRY
3058//-----------------------------------------------------------------------------
3059
3060#define STDIO_STREAM_CLOSE_CASES(X) \
3061X(CASE_STDIO_STREAM_CLOSE_OK_STDIN) \
3062X(CASE_STDIO_STREAM_CLOSE_OK_STDOUT) \
3063X(CASE_STDIO_STREAM_CLOSE_OK_STDERR)
3064
3065#define STDIO_STREAM_MAKE_CLOSE_TEST(case_sym) \
3066LEXLEO_MAKE_TEST(stdio_stream_close, case_sym)
3067
3068static const struct CMUnitTest stdio_stream_close_tests[] = {
3069 STDIO_STREAM_CLOSE_CASES(STDIO_STREAM_MAKE_CLOSE_TEST)
3070};
3071
3072#undef STDIO_STREAM_CLOSE_CASES
3073#undef STDIO_STREAM_MAKE_CLOSE_TEST
3074
3077//-----------------------------------------------------------------------------
3078// MAIN
3079//-----------------------------------------------------------------------------
3080
3081int main(void) {
3082 static const struct CMUnitTest stdio_stream_non_parametric_tests[] = {
3083 cmocka_unit_test(test_stdio_stream_default_cfg),
3084 cmocka_unit_test(test_stdio_stream_default_env)
3085 };
3086
3087 int failed = 0;
3088 failed += cmocka_run_group_tests(stdio_stream_non_parametric_tests, NULL, NULL);
3089 failed += cmocka_run_group_tests(stdio_stream_create_stream_tests, NULL, NULL);
3090 failed += cmocka_run_group_tests(create_desc_stdio_stream_tests, NULL, NULL);
3091 failed += cmocka_run_group_tests(stdio_stream_ctor_tests, NULL, NULL);
3092 failed += cmocka_run_group_tests(stdio_stream_write_tests, NULL, NULL);
3093 failed += cmocka_run_group_tests(stdio_stream_read_tests, NULL, NULL);
3094 failed += cmocka_run_group_tests(stdio_stream_flush_tests, NULL, NULL);
3095 failed += cmocka_run_group_tests(stdio_stream_close_tests, NULL, NULL);
3096
3097 return failed;
3098}
3099
void * osal_memset(void *s, int c, size_t n)
Definition osal_mem.c:30
void * osal_memcpy(void *dest, const void *src, size_t n)
Definition osal_mem.c:25
const osal_mem_ops_t * osal_mem_test_fake_ops(void)
const osal_stdio_ops_t * osal_stdio_test_fake_ops(void)
Composition Root API for wiring the stdio_stream adapter into the stream factory.
stream_status_t stdio_stream_ctor(const void *ud, const void *args, stream_t **out)
Factory-compatible constructor callback for the stdio_stream adapter.
stream_status_t stdio_stream_create_stream(stream_t **out, const stdio_stream_args_t *args, const stdio_stream_cfg_t *cfg, const stdio_stream_env_t *env)
Create a standard-I/O-backed stream instance.
stdio_stream_env_t stdio_stream_default_env(const osal_stdio_ops_t *stdio_ops, const osal_mem_ops_t *mem, const stream_env_t *port_env)
Build a default environment for the stdio_stream adapter.
stdio_stream_cfg_t stdio_stream_default_cfg(void)
Return a default configuration for the stdio_stream adapter.
stream_status_t stdio_stream_create_desc(stream_adapter_desc_t *out, stream_key_t key, const stdio_stream_cfg_t *cfg, const stdio_stream_env_t *env, const osal_mem_ops_t *mem)
Build a stream adapter descriptor for the stdio_stream adapter.
Private constructor user-data stored in stdio_stream factory descriptors.
Private backend handle definition for the stdio_stream adapter.
stdio_stream_kind_t
@ STDIO_STREAM_KIND_STDERR
Standard error stream.
@ STDIO_STREAM_KIND_STDOUT
Standard output stream.
@ STDIO_STREAM_KIND_STDIN
Standard input stream.
@ STDIO_STREAM_KIND_COUNT
Number of supported standard I/O stream kinds.
Borrower-facing runtime operations for the stream port.
stream_status_t stream_flush(stream_t *s)
Flush a stream.
Definition stream.c:62
size_t stream_write(stream_t *s, const void *buf, size_t n, stream_status_t *st)
Write bytes to a stream.
Definition stream.c:38
size_t stream_read(stream_t *s, void *buf, size_t n, stream_status_t *st)
Read bytes from a stream.
Definition stream.c:19
Private stream handle definition for the stream port.
const char * stream_key_t
Public identifier type for a registered stream adapter.
Lifecycle services for stream_t handles.
void stream_destroy(stream_t **s)
Destroy a stream handle.
Definition stream.c:98
stream_status_t
Public status codes used by the stream port.
@ STREAM_STATUS_INVALID
@ STREAM_STATUS_IO_ERROR
@ STREAM_STATUS_OK
@ STREAM_STATUS_OOM
Creation arguments for the stdio_stream adapter.
Configuration type for the stdio_stream adapter.
int reserved
Reserved configuration field.
Private constructor user-data for stdio_stream factory registration.
Injected dependencies for the stdio_stream adapter.
const osal_stdio_ops_t * stdio_ops
Borrowed OSAL stdio operations table.
stream_env_t port_env
Borrowed stream port environment.
const osal_mem_ops_t * mem
Borrowed memory operations table for adapter-owned allocations.
Private backend handle for the stdio_stream adapter.
Public descriptor used to register a concrete stream adapter.
Runtime environment for the stream port.
Definition stream_env.h:35
Private handle structure for a stream_t.
stdio_stream_flush_scenario_t
Scenarios for stdio_stream_flush().
@ STDIO_STREAM_FLUSH_SCENARIO_STDIN_FORBIDDEN
@ STDIO_STREAM_FLUSH_SCENARIO_OK_STDOUT
@ STDIO_STREAM_FLUSH_SCENARIO_OK_STDERR
stdio_stream_create_stream_scenario_t
Scenarios for stdio_stream_create_stream().
@ STDIO_STREAM_CREATE_STREAM_SCENARIO_ENV_NULL
@ STDIO_STREAM_CREATE_STREAM_SCENARIO_OOM
@ STDIO_STREAM_CREATE_STREAM_SCENARIO_ARGS_NULL
@ STDIO_STREAM_CREATE_STREAM_SCENARIO_OUT_NULL
@ STDIO_STREAM_CREATE_STREAM_SCENARIO_CFG_NULL
@ STDIO_STREAM_CREATE_STREAM_SCENARIO_UNSUPPORTED_KIND
@ STDIO_STREAM_CREATE_STREAM_SCENARIO_OK
stdio_stream_write_scenario_t
Scenarios for stdio_stream_write().
@ STDIO_STREAM_WRITE_SCENARIO_ST_NULL_STDERR
@ STDIO_STREAM_WRITE_SCENARIO_OK_STDERR
@ STDIO_STREAM_WRITE_SCENARIO_ZERO_LEN
@ STDIO_STREAM_WRITE_SCENARIO_BUF_NULL_ZERO_LEN
@ STDIO_STREAM_WRITE_SCENARIO_STDIN_FORBIDDEN
@ STDIO_STREAM_WRITE_SCENARIO_OK_STDOUT
@ STDIO_STREAM_WRITE_SCENARIO_ST_NULL_STDOUT
@ STDIO_STREAM_WRITE_SCENARIO_BUF_NULL_NONZERO
stdio_stream_read_scenario_t
Scenarios for stdio_stream_read().
@ STDIO_STREAM_READ_SCENARIO_BUF_NULL_ZERO_LEN
@ STDIO_STREAM_READ_SCENARIO_OK_STDIN
@ STDIO_STREAM_READ_SCENARIO_PARTIAL_STDIN
@ STDIO_STREAM_READ_SCENARIO_ST_NULL_STDIN
@ STDIO_STREAM_READ_SCENARIO_STDOUT_FORBIDDEN
@ STDIO_STREAM_READ_SCENARIO_BUF_NULL_NONZERO
@ STDIO_STREAM_READ_SCENARIO_STDERR_FORBIDDEN
@ STDIO_STREAM_READ_SCENARIO_ZERO_LEN
stdio_stream_create_desc_scenario_t
Scenarios for stdio_stream_create_desc().
@ STDIO_STREAM_CREATE_DESC_SCENARIO_OOM
@ STDIO_STREAM_CREATE_DESC_SCENARIO_KEY_NULL
@ STDIO_STREAM_CREATE_DESC_SCENARIO_CFG_NULL
@ STDIO_STREAM_CREATE_DESC_SCENARIO_OUT_NULL
@ STDIO_STREAM_CREATE_DESC_SCENARIO_KEY_EMPTY
@ STDIO_STREAM_CREATE_DESC_SCENARIO_MEM_NULL
@ STDIO_STREAM_CREATE_DESC_SCENARIO_OK
@ STDIO_STREAM_CREATE_DESC_SCENARIO_ENV_NULL
int main(void)
static void test_stdio_stream_default_env(void **state)
Test stdio_stream_default_env().
stdio_stream_close_scenario_t
Scenarios for stdio_stream_close().
@ STDIO_STREAM_CLOSE_SCENARIO_OK_STDIN
@ STDIO_STREAM_CLOSE_SCENARIO_OK_STDERR
@ STDIO_STREAM_CLOSE_SCENARIO_OK_STDOUT
stdio_stream_ctor_scenario_t
Scenarios for stdio_stream_ctor().
@ STDIO_STREAM_CTOR_SCENARIO_ARGS_NULL
@ STDIO_STREAM_CTOR_SCENARIO_OUT_NULL
@ STDIO_STREAM_CTOR_SCENARIO_UNSUPPORTED_KIND
@ STDIO_STREAM_CTOR_SCENARIO_OK
@ STDIO_STREAM_CTOR_SCENARIO_OOM
@ STDIO_STREAM_CTOR_SCENARIO_UD_NULL
static void test_stdio_stream_default_cfg(void **state)
Test stdio_stream_default_cfg().