2022-05-19 20:52:19 +08:00
|
|
|
#include "test_common.h"
|
2022-10-28 18:39:50 +08:00
|
|
|
TEST_START
|
2021-10-16 18:59:46 +08:00
|
|
|
|
|
|
|
TEST(stack, NEW) {
|
2022-03-30 00:27:04 +08:00
|
|
|
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);
|
|
|
|
|
2022-07-20 10:32:01 +08:00
|
|
|
Arg* arg1 = arg_newInt(10);
|
|
|
|
Arg* arg2 = arg_newInt(20);
|
|
|
|
Arg* arg3 = arg_newInt(30);
|
2022-03-30 00:27:04 +08:00
|
|
|
stack_pushArg(&s, arg1);
|
|
|
|
stack_pushArg(&s, arg2);
|
|
|
|
stack_pushArg(&s, arg3);
|
2022-08-01 10:06:49 +08:00
|
|
|
Arg* arg4 = stack_popArg_alloc(&s);
|
|
|
|
Arg* arg5 = stack_popArg_alloc(&s);
|
|
|
|
Arg* arg6 = stack_popArg_alloc(&s);
|
2022-03-30 00:27:04 +08:00
|
|
|
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);
|
2021-10-16 18:59:46 +08:00
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(stack, str) {
|
2022-03-30 00:27:04 +08:00
|
|
|
Stack s;
|
|
|
|
stack_init(&s);
|
2022-04-30 21:17:19 +08:00
|
|
|
stack_pushStr(&s, "abc");
|
|
|
|
stack_pushStr(&s, "123");
|
|
|
|
stack_pushStr(&s, "xyz");
|
2021-10-16 18:59:46 +08:00
|
|
|
char buff[32] = {0};
|
2022-04-30 21:17:19 +08:00
|
|
|
EXPECT_STREQ(stack_popStr(&s, buff), "xyz");
|
|
|
|
EXPECT_STREQ(stack_popStr(&s, buff), "123");
|
|
|
|
EXPECT_STREQ(stack_popStr(&s, buff), "abc");
|
2022-03-30 00:27:04 +08:00
|
|
|
stack_deinit(&s);
|
2021-10-16 18:59:46 +08:00
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
|
|
|
}
|
2022-10-28 18:39:50 +08:00
|
|
|
|
|
|
|
TEST_END
|