Adjust sourcize.c to use _snprintf if using MSVC.
[SquirrelJME.git] / nanocoat / tests / testNvmLocalPopLong.c
blob16faa3d4a101043f5adaca900b87ae4e288bf4ad
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/nvmFunc.h"
15 #include "test.h"
16 #include "unit.h"
18 sjme_jboolean configNvmLocalPopLong(
19 sjme_attrInNotNull sjme_mock* inState,
20 sjme_attrInNotNull sjme_mock_configWork* inCurrent)
22 sjme_mock_configDataNvmFrame* frame;
24 /* Check. */
25 if (inState == NULL || inCurrent == NULL)
26 return SJME_JNI_FALSE;
28 /* Quick access. */
29 frame = &inCurrent->data.nvmFrame;
31 /* Configure. */
32 switch (inCurrent->type)
34 case SJME_MOCK_DO_TYPE_NVM_FRAME:
35 frame->maxLocals = 1;
36 frame->maxStack = 1;
37 frame->treads[SJME_JAVA_TYPE_ID_LONG].max = 2;
38 frame->treads[SJME_JAVA_TYPE_ID_LONG].stackBaseIndex = 1;
39 break;
42 return SJME_JNI_TRUE;
45 /** Mock set for test. */
46 static const sjme_mock_configSet mockNvmLocalPopLong =
48 configNvmLocalPopLong,
51 /* Mock calls. */
53 sjme_mock_doNvmState,
54 sjme_mock_doNvmThread,
55 sjme_mock_doNvmFrame,
56 NULL
60 sjme_attrUnused SJME_TEST_DECLARE(testNvmLocalPopLong)
62 sjme_mock state;
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 &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];
79 stack = frame->stack;
80 longsTread->values.jlongs[1].part.hi = 0x12345678;
81 longsTread->values.jlongs[1].part.lo = 0x9ABCDEF0;
82 longsTread->count = longsTread->stackBaseIndex + 1;
83 stack->count = 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.");
107 /* Success! */
108 return SJME_TEST_RESULT_PASS;