| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "test_files.h" | ||
| 2 | |||
| 3 | #include "gate/tests.h" | ||
| 4 | #include "gate/files.h" | ||
| 5 | #include "gate/console.h" | ||
| 6 | #include "gate/platforms.h" | ||
| 7 | |||
| 8 | static int dummy_user_param = 42; | ||
| 9 | |||
| 10 | 1 | static gate_bool_t GATE_CALL test_filesystem_root_callback(gate_file_entry_t const* entry, void* userparam) | |
| 11 | { | ||
| 12 | 1 | gate_stream_t* strm = (gate_stream_t*)gate_console(); | |
| 13 | |||
| 14 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(userparam, &dummy_user_param); |
| 15 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(entry != NULL); |
| 16 | |||
| 17 | 1 | gate_stream_println_cstr(strm, entry->path); | |
| 18 | |||
| 19 | 1 | return true; | |
| 20 | } | ||
| 21 | |||
| 22 | |||
| 23 | 1 | GATE_TEST_FUNCTION(test_filesystem) | |
| 24 | { | ||
| 25 | static gate_string_t const test_file_path = GATE_STRING_INIT_STATIC("gatecore_test_files.txt"); | ||
| 26 | 1 | gate_filestream_t* ptr_stream = NULL; | |
| 27 | 1 | gate_size_t written = 0; | |
| 28 | char buffer[16]; | ||
| 29 | 1 | gate_size_t returned = 0; | |
| 30 | 1 | gate_int64_t pos = 0; | |
| 31 | |||
| 32 | 1 | GATE_TEST_UNIT_BEGIN(test_filesystem); | |
| 33 | |||
| 34 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_file_root_list(&test_filesystem_root_callback, &dummy_user_param)); |
| 35 | |||
| 36 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (gate_file_exists(&test_file_path) == GATE_RESULT_OK) |
| 37 | { | ||
| 38 | ✗ | gate_file_delete(&test_file_path); | |
| 39 | } | ||
| 40 | |||
| 41 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_REQUIRE_OK(gate_file_openstream(&test_file_path, GATE_STREAM_OPEN_WRITE, &ptr_stream)); |
| 42 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_stream != NULL); |
| 43 | |||
| 44 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_stream_write(ptr_stream, "X", 1, &written)); |
| 45 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_stream_flush(ptr_stream)); |
| 46 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_stream_close(ptr_stream, GATE_STREAM_CLOSE_DEFAULT)); |
| 47 | 1 | gate_object_release(ptr_stream); | |
| 48 | 1 | ptr_stream = NULL; | |
| 49 | |||
| 50 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_REQUIRE_OK(gate_file_exists(&test_file_path)); |
| 51 | |||
| 52 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_REQUIRE_OK(gate_file_openstream(&test_file_path, GATE_STREAM_OPEN_READ, &ptr_stream)); |
| 53 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_stream != NULL); |
| 54 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_stream_peek(ptr_stream, buffer, sizeof(buffer), &returned)); |
| 55 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(returned, 1); |
| 56 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(buffer[0], 'X'); |
| 57 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_stream_read(ptr_stream, buffer, sizeof(buffer), &returned)); |
| 58 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(returned, 1); |
| 59 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(buffer[0], 'X'); |
| 60 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_stream_seek(ptr_stream, 0, GATE_STREAM_SEEK_BEGIN, &pos)); |
| 61 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(pos, 0); |
| 62 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_stream_read(ptr_stream, buffer, sizeof(buffer), &returned)); |
| 63 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(returned, 1); |
| 64 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(buffer[0], 'X'); |
| 65 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_stream_close(ptr_stream, GATE_STREAM_CLOSE_DEFAULT)); |
| 66 | 1 | gate_object_release(ptr_stream); | |
| 67 | 1 | ptr_stream = NULL; | |
| 68 | |||
| 69 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_file_delete(&test_file_path)); |
| 70 | |||
| 71 | { | ||
| 72 | /* test file access with native platform stream interface */ | ||
| 73 | gate_platform_stream_t pfs; | ||
| 74 | gate_int64_t pos; | ||
| 75 | 1 | gate_platform_stream_set_invalid(&pfs); | |
| 76 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_platform_stream_valid(pfs), false); |
| 77 | |||
| 78 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_platform_stream_open(test_file_path.str, GATE_PLATFORM_STREAM_OPEN_WRITE, 0, &pfs)); |
| 79 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_platform_stream_valid(pfs), true); |
| 80 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_platform_stream_write(pfs, "T", 1, &written)); |
| 81 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(written, 1); |
| 82 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_platform_stream_close(&pfs)); |
| 83 | |||
| 84 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_platform_stream_open(test_file_path.str, GATE_PLATFORM_STREAM_OPEN_READ, 0, &pfs)); |
| 85 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(gate_platform_stream_valid(pfs), true); |
| 86 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_platform_stream_read(pfs, buffer, sizeof(buffer), &returned)); |
| 87 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_platform_stream_seek(pfs, 0, GATE_PLATFORM_STREAM_ORIGIN_CURRENT, &pos)); |
| 88 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_platform_stream_seek(pfs, -1, GATE_PLATFORM_STREAM_ORIGIN_END, &pos)); |
| 89 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_platform_stream_seek(pfs, 0, GATE_PLATFORM_STREAM_ORIGIN_BEGIN, &pos)); |
| 90 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(returned, 1); |
| 91 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_platform_stream_close(&pfs)); |
| 92 | |||
| 93 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_file_delete(&test_file_path)); |
| 94 | } | ||
| 95 | |||
| 96 | 1 | GATE_TEST_UNIT_END; | |
| 97 | } | ||
| 98 |