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/nvmFunc.h"
18 sjme_jboolean
configNvmLocalPopDouble(
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_DOUBLE
].max
= 2;
38 frame
->treads
[SJME_JAVA_TYPE_ID_DOUBLE
].stackBaseIndex
= 1;
45 /** Mock set for test. */
46 static const sjme_mock_configSet mockNvmLocalPopDouble
=
48 configNvmLocalPopDouble
,
54 sjme_mock_doNvmThread
,
60 sjme_attrUnused
SJME_TEST_DECLARE(testNvmLocalPopDouble
)
63 sjme_nvm_frame
* frame
;
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 &mockNvmLocalPopDouble
, 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_DOUBLE
];
80 longsTread
->values
.jdoubles
[1].hi
= 0x12345678;
81 longsTread
->values
.jdoubles
[1].lo
= 0x9ABCDEF0;
82 longsTread
->count
= longsTread
->stackBaseIndex
+ 1;
84 stack
->order
[0] = SJME_JAVA_TYPE_ID_DOUBLE
;
86 /* Pop integer from the stack to the first local. */
87 oldNumStack
= stack
->count
;
88 if (!sjme_nvm_localPopDouble(frame
, 0))
89 return sjme_unit_fail(test
, "Failed to pop local double.");
91 /* New stack should be lower. */
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
.jdoubles
[0].hi
,
97 "Popped stack into local was not the correct value.");
98 sjme_unit_equalI(test
, 0x9ABCDEF0, longsTread
->values
.jdoubles
[0].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
.jdoubles
[1].hi
,
103 "Stack value did not get cleared.");
104 sjme_unit_equalI(test
, 0, longsTread
->values
.jdoubles
[1].lo
,
105 "Stack value did not get cleared.");
108 return SJME_TEST_RESULT_PASS
;