1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
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 // -------------------------------------------------------------------------*/
14 #include "sjme/nvm/romInternal.h"
18 static sjme_lpcstr testRomNames
[3] =
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
];
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
;
56 /** Mock set for test. */
57 static const sjme_mock_configSet mockRomSuiteClassPathById
=
59 configRomSuiteClassPathById
,
64 sjme_mock_doRomLibrary
,
65 sjme_mock_doRomLibrary
,
66 sjme_mock_doRomLibrary
,
73 * Tests getting classpath entries by Id.
77 SJME_TEST_DECLARE(testRomSuiteClassPathById
)
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
,
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
,
99 return sjme_unit_fail(test
, "Could not emit backwards ids?");
102 suite
= mockState
.romSuites
[0];
104 /* Resolve forward names first. */
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],
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],
120 /* Resolve backwards names last. */
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?");
137 return SJME_TEST_RESULT_PASS
;