mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
a09d32d6ac
use f struct support stack check arg
78 lines
1.8 KiB
C
78 lines
1.8 KiB
C
#include "test_common.h"
|
|
TEST_START
|
|
|
|
TEST(stack, NEW) {
|
|
Stack s;
|
|
stack_init(&s);
|
|
stack_deinit(&s);
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
}
|
|
|
|
TEST(stack, size) {
|
|
Stack s;
|
|
stack_init(&s);
|
|
|
|
stack_pushSize(&s, 10);
|
|
stack_pushSize(&s, 20);
|
|
stack_pushSize(&s, 30);
|
|
|
|
EXPECT_EQ(stack_popSize(&s), 30);
|
|
EXPECT_EQ(stack_popSize(&s), 20);
|
|
EXPECT_EQ(stack_popSize(&s), 10);
|
|
|
|
stack_deinit(&s);
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
}
|
|
|
|
TEST(stack, arg) {
|
|
Stack s;
|
|
stack_init(&s);
|
|
|
|
Arg* arg1 = arg_newInt(10);
|
|
Arg* arg2 = arg_newInt(20);
|
|
Arg* arg3 = arg_newInt(30);
|
|
stack_pushArg(&s, arg1);
|
|
stack_pushArg(&s, arg2);
|
|
stack_pushArg(&s, arg3);
|
|
Arg* arg4 = stack_popArg_alloc(&s);
|
|
Arg* arg5 = stack_popArg_alloc(&s);
|
|
Arg* arg6 = stack_popArg_alloc(&s);
|
|
EXPECT_EQ(arg_getInt(arg4), 30);
|
|
EXPECT_EQ(arg_getInt(arg5), 20);
|
|
EXPECT_EQ(arg_getInt(arg6), 10);
|
|
stack_deinit(&s);
|
|
arg_deinit(arg4);
|
|
arg_deinit(arg5);
|
|
arg_deinit(arg6);
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
}
|
|
|
|
TEST(stack, str) {
|
|
Stack s;
|
|
stack_init(&s);
|
|
stack_pushStr(&s, "abc");
|
|
stack_pushStr(&s, "123");
|
|
stack_pushStr(&s, "xyz");
|
|
char buff[32] = {0};
|
|
EXPECT_STREQ(stack_popStr(&s, buff), "xyz");
|
|
EXPECT_STREQ(stack_popStr(&s, buff), "123");
|
|
EXPECT_STREQ(stack_popStr(&s, buff), "abc");
|
|
stack_deinit(&s);
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
}
|
|
|
|
TEST(stack, get_str) {
|
|
Stack s;
|
|
stack_init(&s);
|
|
stack_pushStr(&s, "abc");
|
|
stack_pushStr(&s, "123");
|
|
stack_pushStr(&s, "xyz");
|
|
EXPECT_STREQ(arg_getStr(stack_checkArg(&s, 0)), "xyz");
|
|
EXPECT_STREQ(arg_getStr(stack_checkArg(&s, 0)), "xyz");
|
|
EXPECT_STREQ(arg_getStr(stack_checkArg(&s, 1)), "123");
|
|
EXPECT_STREQ(arg_getStr(stack_checkArg(&s, 2)), "abc");
|
|
stack_deinit(&s);
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
}
|
|
|
|
TEST_END |