all repos — mgba @ d0f404a6ba7c0588d3a3c7b43225a32f4fc2d8a6

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_DEFINE(resizeMem) {
 75	uint8_t bytes[32];
 76	struct VFile* vf = VFileFromMemory(bytes, 32);
 77	assert_non_null(vf);
 78	assert_int_equal(vf->size(vf), 32);
 79	vf->truncate(vf, 64);
 80	assert_int_equal(vf->size(vf), 32);
 81	vf->truncate(vf, 16);
 82	assert_int_equal(vf->size(vf), 32);
 83	vf->close(vf);
 84}
 85
 86M_TEST_DEFINE(resizeConstMem) {
 87	uint8_t bytes[32];
 88	struct VFile* vf = VFileFromConstMemory(bytes, 32);
 89	assert_non_null(vf);
 90	assert_int_equal(vf->size(vf), 32);
 91	vf->truncate(vf, 64);
 92	assert_int_equal(vf->size(vf), 32);
 93	vf->truncate(vf, 16);
 94	assert_int_equal(vf->size(vf), 32);
 95	vf->close(vf);
 96}
 97
 98M_TEST_DEFINE(resizeMemChunk) {
 99	uint8_t bytes[32];
100	struct VFile* vf = VFileMemChunk(bytes, 32);
101	assert_non_null(vf);
102	assert_int_equal(vf->size(vf), 32);
103	vf->truncate(vf, 64);
104	assert_int_equal(vf->size(vf), 64);
105	vf->truncate(vf, 16);
106	assert_int_equal(vf->size(vf), 16);
107	vf->close(vf);
108}
109
110M_TEST_SUITE_DEFINE(VFS,
111#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
112	cmocka_unit_test(openNullPathR),
113	cmocka_unit_test(openNullPathW),
114	cmocka_unit_test(openNullPathCreate),
115	cmocka_unit_test(openNullPathWCreate),
116#endif
117	cmocka_unit_test(openNullMem0),
118	cmocka_unit_test(openNullMemNonzero),
119	cmocka_unit_test(openNullConstMem0),
120	cmocka_unit_test(openNullConstMemNonzero),
121	cmocka_unit_test(openNullMemChunk0),
122	cmocka_unit_test(openNonNullMemChunk0),
123	cmocka_unit_test(openNullMemChunkNonzero),
124	cmocka_unit_test(resizeMem),
125	cmocka_unit_test(resizeConstMem),
126	cmocka_unit_test(resizeMemChunk))