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/nvmFunc.h"
18 sjme_jboolean
configNvmLocalPopLong(
19 sjme_attrInNotNull sjme_mock
* inState
,
20 sjme_attrInNotNull sjme_mock_configWork
* inCurrent
)
22 sjme_mock_configDataNvmFrame
* frame
;
25 if (inState
== NULL
|| inCurrent
== NULL
)
26 return SJME_JNI_FALSE
;
29 frame
= &inCurrent
->data
.nvmFrame
;
32 switch (inCurrent
->type
)
34 case SJME_MOCK_DO_TYPE_NVM_FRAME
:
37 frame
->treads
[SJME_JAVA_TYPE_ID_LONG
].max
= 2;
38 frame
->treads
[SJME_JAVA_TYPE_ID_LONG
].stackBaseIndex
= 1;
45 /** Mock set for test. */
46 static const sjme_mock_configSet mockNvmLocalPopLong
=
48 configNvmLocalPopLong
,
54 sjme_mock_doNvmThread
,
60 sjme_attrUnused
SJME_TEST_DECLARE(testNvmLocalPopLong
)
64 sjme_jint oldNumStack
;
65 sjme_nvm_frameTread
* longsTread
;
66 sjme_nvm_frameStack
* stack
;
68 /* Perform the mock. */
69 memset(&state
, 0, sizeof(state
));
70 if (!sjme_mock_act(test
, &state
,
71 &mockNvmLocalPopLong
, 0))
72 sjme_die("Invalid mock");
74 /* Get initialize frame size. */
75 frame
= state
.threads
[0].nvmThread
->top
;
77 /* Setup integer values. */
78 longsTread
= frame
->treads
[SJME_JAVA_TYPE_ID_LONG
];
80 longsTread
->values
.jlongs
[1].part
.hi
= 0x12345678;
81 longsTread
->values
.jlongs
[1].part
.lo
= 0x9ABCDEF0;
82 longsTread
->count
= longsTread
->stackBaseIndex
+ 1;
84 stack
->order
[0] = SJME_JAVA_TYPE_ID_LONG
;
86 /* Pop integer from the stack to the first local. */
87 oldNumStack
= stack
->count
;
88 if (!sjme_nvm_localPopLong(frame
, 0))
89 return sjme_unit_fail(test
, "Failed to pop local long.");
91 /* New stack should be lowered. */
92 sjme_unit_equalI(test
, stack
->count
, oldNumStack
- 1,
93 "Items in stack not lower?");
95 /* Check that the value was moved over. */
96 sjme_unit_equalI(test
, 0x12345678, longsTread
->values
.jlongs
[0].part
.hi
,
97 "Popped stack into local was not the correct value.");
98 sjme_unit_equalI(test
, 0x9ABCDEF0, longsTread
->values
.jlongs
[0].part
.lo
,
99 "Popped stack into local was not the correct value.");
101 /* And the stack value was cleared. */
102 sjme_unit_equalI(test
, 0, longsTread
->values
.jlongs
[1].part
.hi
,
103 "Stack value did not get cleared.");
104 sjme_unit_equalI(test
, 0, longsTread
->values
.jlongs
[1].part
.lo
,
105 "Stack value did not get cleared.");
108 return SJME_TEST_RESULT_PASS
;