| 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 | |||
| 7 | static int dummy_user_param = 42; | ||
| 8 | |||
| 9 | 1 | static gate_bool_t test_filesystem_root_callback(gate_file_entry_t const* entry, void* userparam) | |
| 10 | { | ||
| 11 | 1 | gate_stream_t* strm = (gate_stream_t*)gate_console(); | |
| 12 | |||
| 13 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(userparam, &dummy_user_param); |
| 14 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(entry != NULL); |
| 15 | |||
| 16 | 1 | gate_stream_println_cstr(strm, entry->path); | |
| 17 | |||
| 18 | 1 | return true; | |
| 19 | } | ||
| 20 | |||
| 21 | |||
| 22 | 1 | GATE_TEST_FUNCTION(test_filesystem) | |
| 23 | { | ||
| 24 | static gate_string_t const test_file_path = GATE_STRING_INIT_STATIC("gatecore_test_files.txt"); | ||
| 25 | 1 | gate_filestream_t* ptr_stream = NULL; | |
| 26 | 1 | gate_size_t written = 0; | |
| 27 | char buffer[16]; | ||
| 28 | 1 | gate_size_t returned = 0; | |
| 29 | 1 | gate_int64_t pos = 0; | |
| 30 | |||
| 31 | 1 | GATE_TEST_UNIT_BEGIN(test_filesystem); | |
| 32 | |||
| 33 |
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)); |
| 34 | |||
| 35 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (gate_file_exists(&test_file_path) == GATE_RESULT_OK) |
| 36 | { | ||
| 37 | ✗ | gate_file_delete(&test_file_path); | |
| 38 | } | ||
| 39 | |||
| 40 |
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)); |
| 41 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_stream != NULL); |
| 42 | |||
| 43 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_stream_write(ptr_stream, "X", 1, &written)); |
| 44 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_stream_flush(ptr_stream)); |
| 45 |
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)); |
| 46 | 1 | gate_object_release(ptr_stream); | |
| 47 | 1 | ptr_stream = NULL; | |
| 48 | |||
| 49 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_REQUIRE_OK(gate_file_exists(&test_file_path)); |
| 50 | |||
| 51 |
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)); |
| 52 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_REQUIRE(ptr_stream != NULL); |
| 53 |
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)); |
| 54 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(returned, 1); |
| 55 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(buffer[0], 'X'); |
| 56 |
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)); |
| 57 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(returned, 1); |
| 58 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(buffer[0], 'X'); |
| 59 |
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)); |
| 60 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(pos, 0); |
| 61 |
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)); |
| 62 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(returned, 1); |
| 63 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | GATE_TEST_CHECK_EQUAL(buffer[0], 'X'); |
| 64 |
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)); |
| 65 | 1 | gate_object_release(ptr_stream); | |
| 66 | 1 | ptr_stream = NULL; | |
| 67 | |||
| 68 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | GATE_TEST_CHECK_OK(gate_file_delete(&test_file_path)); |
| 69 | |||
| 70 | 1 | GATE_TEST_UNIT_END; | |
| 71 | } | ||
| 72 |