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
configNvmLocalPopInteger(
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_ERROR_NULL_ARGUMENTS
;
29 frame
= &inCurrent
->data
.nvmFrame
;
32 switch (inCurrent
->type
)
34 case SJME_MOCK_DO_TYPE_NVM_FRAME
:
37 frame
->treads
[SJME_JAVA_TYPE_ID_INTEGER
].max
= 2;
38 frame
->treads
[SJME_JAVA_TYPE_ID_INTEGER
].stackBaseIndex
= 1;
45 /** Mock set for test. */
46 static const sjme_mock_configSet mockNvmLocalPopInteger
=
48 configNvmLocalPopInteger
,
54 sjme_mock_doNvmThread
,
60 sjme_attrUnused
SJME_TEST_DECLARE(testNvmLocalPopInteger
)
64 sjme_jint oldNumStack
;
65 sjme_nvm_frameTread
* intsTread
;
66 sjme_nvm_frameStack
* stack
;
68 /* Perform the mock. */
69 memset(&state
, 0, sizeof(state
));
70 if (!sjme_mock_act(test
, &state
,
71 &mockNvmLocalPopInteger
, 0))
72 sjme_die("Invalid mock");
74 /* Get initialize frame size. */
75 frame
= state
.threads
[0].nvmThread
->top
;
77 /* Setup integer values. */
78 intsTread
= frame
->treads
[SJME_JAVA_TYPE_ID_INTEGER
];
80 intsTread
->values
.jints
[1] = 0x12345678;
81 intsTread
->count
= intsTread
->stackBaseIndex
+ 1;
83 stack
->order
[0] = SJME_JAVA_TYPE_ID_INTEGER
;
85 /* Pop integer from the stack to the first local. */
86 oldNumStack
= stack
->count
;
87 if (!sjme_nvm_localPopInteger(frame
, 0))
88 return sjme_unit_fail(test
, "Failed to pop local integer.");
90 /* New stack should be lower. */
91 sjme_unit_equalI(test
, stack
->count
, oldNumStack
- 1,
92 "Items in stack not lower?");
94 /* Check that the value was moved over. */
95 sjme_unit_equalI(test
, 0x12345678, intsTread
->values
.jints
[0],
96 "Popped stack into local was not the correct value.");
98 /* And the stack value was cleared. */
99 sjme_unit_equalI(test
, 0, intsTread
->values
.jints
[1],
100 "Stack value did not get cleared.");
103 return SJME_TEST_RESULT_PASS
;