Collect all of the various spread out 3rd party licenses to a single file.
[SquirrelJME.git] / nanocoat / tests / testRomLibraryFindResourceJar.c
blob3e6187c8cacff6af0c7ec0772d7772431e4c8722
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include <string.h>
12 #include "mock.h"
13 #include "proto.h"
14 #include "test.h"
15 #include "unit.h"
17 static sjme_jboolean funcRomLibraryFindResourceJar(
18 sjme_attrInNotNull sjme_mock* inState,
19 sjme_attrInNotNull sjme_mock_configWork* inCurrent)
21 if (inState == NULL || inCurrent == NULL)
22 return SJME_JNI_FALSE;
24 if (inCurrent->type == SJME_MOCK_DO_TYPE_ROM_MOCK_LIBRARY)
25 inCurrent->data.romMockLibrary.isJar = SJME_JNI_TRUE;
27 return SJME_JNI_TRUE;
30 static const sjme_mock_configSet configRomLibraryFindResourceJar =
32 funcRomLibraryFindResourceJar,
36 sjme_mock_doRomMockLibrary,
37 NULL
41 /**
42 * Tests finding a single resource.
44 * @since 2023/12/30
46 SJME_TEST_DECLARE(testRomLibraryFindResourceJar)
48 sjme_rom_library library;
49 sjme_mock mock;
50 sjme_stream_input inputStream;
52 /* Initialize mocks. */
53 memset(&mock, 0, sizeof(mock));
54 if (!sjme_mock_act(test, &mock,
55 &configRomLibraryFindResourceJar, 0))
56 return sjme_unit_fail(test, "Could not initialize mocks");
58 /* Get the library to test. */
59 library = mock.romLibraries[0];
61 /* Try to find a resource. */
62 inputStream = NULL;
63 if (sjme_error_is(sjme_rom_libraryResourceAsStream(library,
64 &inputStream, "hello.txt")) || inputStream == NULL)
65 return sjme_unit_fail(test, "Did not find resource?");
67 /* Just close the stream. */
68 if (sjme_error_is(sjme_stream_inputClose(inputStream)))
69 return sjme_unit_fail(test, "Could not close stream?");
71 /* Success! */
72 return SJME_TEST_RESULT_PASS;