Collect all of the various spread out 3rd party licenses to a single file.
[SquirrelJME.git] / nanocoat / tests / testNvmLocalPopInteger.c
blobc4ca9d22c73e33ae6e53de6b59badbd6e08b21a4
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/nvmFunc.h"
15 #include "test.h"
16 #include "unit.h"
18 sjme_jboolean configNvmLocalPopInteger(
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_ERROR_NULL_ARGUMENTS;
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_INTEGER].max = 2;
38 frame->treads[SJME_JAVA_TYPE_ID_INTEGER].stackBaseIndex = 1;
39 break;
42 return SJME_JNI_TRUE;
45 /** Mock set for test. */
46 static const sjme_mock_configSet mockNvmLocalPopInteger =
48 configNvmLocalPopInteger,
51 /* Mock calls. */
53 sjme_mock_doNvmState,
54 sjme_mock_doNvmThread,
55 sjme_mock_doNvmFrame,
56 NULL
60 sjme_attrUnused SJME_TEST_DECLARE(testNvmLocalPopInteger)
62 sjme_mock state;
63 sjme_nvm_frame* frame;
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];
79 stack = frame->stack;
80 intsTread->values.jints[1] = 0x12345678;
81 intsTread->count = intsTread->stackBaseIndex + 1;
82 stack->count = 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.");
102 /* Success! */
103 return SJME_TEST_RESULT_PASS;