all repos — mgba @ 8561c80a1c43392523ca3be614f2ae8d72b3a469

mGBA Game Boy Advance Emulator

src/util/test/vfs.c (view raw)

 1/* Copyright (c) 2013-2016 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "util/test/suite.h"
 7
 8#include "util/vfs.h"
 9
10#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
11M_TEST_DEFINE(openNullPathR) {
12	struct VFile* vf = VFileOpen(NULL, O_RDONLY);
13	assert_null(vf);
14}
15
16M_TEST_DEFINE(openNullPathW) {
17	struct VFile* vf = VFileOpen(NULL, O_WRONLY);
18	assert_null(vf);
19}
20
21M_TEST_DEFINE(openNullPathCreate) {
22	struct VFile* vf = VFileOpen(NULL, O_CREAT);
23	assert_null(vf);
24}
25
26M_TEST_DEFINE(openNullPathWCreate) {
27	struct VFile* vf = VFileOpen(NULL, O_WRONLY | O_CREAT);
28	assert_null(vf);
29}
30#endif
31
32M_TEST_DEFINE(openNullMem0) {
33	struct VFile* vf = VFileFromMemory(NULL, 0);
34	assert_null(vf);
35}
36
37M_TEST_DEFINE(openNullMemNonzero) {
38	struct VFile* vf = VFileFromMemory(NULL, 32);
39	assert_null(vf);
40}
41
42M_TEST_DEFINE(openNullConstMem0) {
43	struct VFile* vf = VFileFromConstMemory(NULL, 0);
44	assert_null(vf);
45}
46
47M_TEST_DEFINE(openNullConstMemNonzero) {
48	struct VFile* vf = VFileFromConstMemory(NULL, 32);
49	assert_null(vf);
50}
51
52M_TEST_DEFINE(openNullMemChunk0) {
53	struct VFile* vf = VFileMemChunk(NULL, 0);
54	assert_non_null(vf);
55	assert_int_equal(vf->size(vf), 0);
56	vf->close(vf);
57}
58
59M_TEST_DEFINE(openNonNullMemChunk0) {
60	const uint8_t bytes[32] = {};
61	struct VFile* vf = VFileMemChunk(bytes, 0);
62	assert_non_null(vf);
63	assert_int_equal(vf->size(vf), 0);
64	vf->close(vf);
65}
66
67M_TEST_DEFINE(openNullMemChunkNonzero) {
68	struct VFile* vf = VFileMemChunk(NULL, 32);
69	assert_non_null(vf);
70	assert_int_equal(vf->size(vf), 32);
71	vf->close(vf);
72}
73
74M_TEST_SUITE_DEFINE(VFS,
75#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
76	cmocka_unit_test(openNullPathR),
77	cmocka_unit_test(openNullPathW),
78	cmocka_unit_test(openNullPathCreate),
79	cmocka_unit_test(openNullPathWCreate),
80#endif
81	cmocka_unit_test(openNullMem0),
82	cmocka_unit_test(openNullMemNonzero),
83	cmocka_unit_test(openNullConstMem0),
84	cmocka_unit_test(openNullConstMemNonzero),
85	cmocka_unit_test(openNullMemChunk0),
86	cmocka_unit_test(openNonNullMemChunk0),
87	cmocka_unit_test(openNullMemChunkNonzero))