Compile fixes.
[SquirrelJME.git] / nanocoat / tests / testRomSuiteClassPathById.c
blob54f858629f5bae1545ebae764dcc27a27aad5c35
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 "sjme/nvm/romInternal.h"
15 #include "test.h"
16 #include "unit.h"
18 static sjme_lpcstr testRomNames[3] =
20 "squirrels.jar",
21 "are.jar",
22 "cute.jar"
25 static sjme_jboolean configRomSuiteClassPathById(
26 sjme_attrInNotNull sjme_mock* inState,
27 sjme_attrInNotNull sjme_mock_configWork* inCurrent)
29 sjme_mock_configDataRomSuite* romSuite;
30 sjme_mock_configDataRomLibrary* romLibrary;
32 romLibrary = &inCurrent->data.romLibrary;
33 romSuite = &inCurrent->data.romSuite;
35 switch (inCurrent->type)
37 case SJME_MOCK_DO_TYPE_ROM_LIBRARY:
38 romLibrary->id = inCurrent->indexType + 1;
39 romLibrary->name = testRomNames[inCurrent->indexType];
40 break;
42 case SJME_MOCK_DO_TYPE_ROM_SUITE:
43 if (sjme_error_is(sjme_list_newV(
44 inState->allocPool, sjme_rom_library, 0, 3,
45 &romSuite->cacheLibraries,
46 inState->romLibraries[0],
47 inState->romLibraries[1],
48 inState->romLibraries[2])))
49 return SJME_JNI_FALSE;
50 break;
53 return SJME_JNI_TRUE;
56 /** Mock set for test. */
57 static const sjme_mock_configSet mockRomSuiteClassPathById =
59 configRomSuiteClassPathById,
62 /* Mock calls. */
64 sjme_mock_doRomLibrary,
65 sjme_mock_doRomLibrary,
66 sjme_mock_doRomLibrary,
67 sjme_mock_doRomSuite,
68 NULL
72 /**
73 * Tests getting classpath entries by Id.
75 * @since 2023/12/21
77 SJME_TEST_DECLARE(testRomSuiteClassPathById)
79 sjme_mock mockState;
80 sjme_rom_suite suite;
81 sjme_list_sjme_jint* forwardIds;
82 sjme_list_sjme_jint* backwardIds;
83 sjme_list_sjme_rom_library* result;
85 /* Initialize mocks. */
86 memset(&mockState, 0, sizeof(mockState));
87 if (!sjme_mock_act(test, &mockState,
88 &mockRomSuiteClassPathById, 0))
89 return sjme_unit_fail(test, "Could not run mocks.");
91 /* Calculate both forwards and backwards Ids. */
92 if (sjme_error_is(sjme_list_newV(mockState.allocPool,
93 sjme_jint, 0, 3, &forwardIds,
94 1, 2, 3)))
95 return sjme_unit_fail(test, "Could not emit forward ids?");
96 if (sjme_error_is(sjme_list_newV(mockState.allocPool,
97 sjme_jint, 0, 3, &backwardIds,
98 3, 2, 1)))
99 return sjme_unit_fail(test, "Could not emit backwards ids?");
101 /* Get the suite. */
102 suite = mockState.romSuites[0];
104 /* Resolve forward names first. */
105 result = NULL;
106 if (sjme_error_is(sjme_rom_resolveClassPathById(suite,
107 forwardIds, &result)) || result == NULL)
108 return sjme_unit_fail(test, "Could not resolve ids?");
110 /* The libraries must match! */
111 sjme_unit_equalI(test, 3, result->length,
112 "Length does not match?");
113 sjme_unit_equalP(test, mockState.romLibraries[0], result->elements[0],
114 "First incorrect?");
115 sjme_unit_equalP(test, mockState.romLibraries[1], result->elements[1],
116 "Second incorrect?");
117 sjme_unit_equalP(test, mockState.romLibraries[2], result->elements[2],
118 "Third incorrect?");
120 /* Resolve backwards names last. */
121 result = NULL;
122 if (sjme_error_is(sjme_rom_resolveClassPathById(suite,
123 backwardIds, &result)) || result == NULL)
124 return sjme_unit_fail(test, "Could not resolve reverse ids?");
126 /* The libraries must match! */
127 sjme_unit_equalI(test, 3, result->length,
128 "Reverse length does not match?");
129 sjme_unit_equalP(test, mockState.romLibraries[0], result->elements[2],
130 "Reverse first incorrect?");
131 sjme_unit_equalP(test, mockState.romLibraries[1], result->elements[1],
132 "Reverse second incorrect?");
133 sjme_unit_equalP(test, mockState.romLibraries[2], result->elements[0],
134 "Reverse third incorrect?");
136 /* Success! */
137 return SJME_TEST_RESULT_PASS;