pikapython/port/linux/test/content-test.cpp

99 lines
2.8 KiB
C
Raw Normal View History

#include "test_common.h"
2022-01-25 02:40:11 +08:00
#if 0
2021-10-01 00:21:50 +08:00
TEST(content, init) {
2021-11-13 16:42:01 +08:00
uint8_t contentIn[4] = {0};
contentIn[0] = 1;
contentIn[1] = 2;
contentIn[2] = 3;
contentIn[3] = 4;
2022-05-22 20:50:28 +08:00
Arg* self = content_init("name", ARG_TYPE_NONE, contentIn, 4, NULL);
2021-10-01 00:21:50 +08:00
2021-11-13 16:42:01 +08:00
uint16_t typeOffset = content_typeOffset(self);
uint16_t sizeOffset = content_sizeOffset(self);
uint16_t contentOffset = content_contentOffset(self);
uint16_t totleSize = content_totleSize(self);
2021-10-01 00:21:50 +08:00
2021-11-13 16:42:01 +08:00
Hash nameHash = content_getNameHash(self);
ArgType type = content_getType(self);
2021-11-13 16:42:01 +08:00
uint16_t size = content_getSize(self);
uint8_t* content = content_getContent(self);
2021-10-01 00:21:50 +08:00
ASSERT_EQ(contentOffset, 16);
ASSERT_EQ(typeOffset, 20);
2021-11-13 16:42:01 +08:00
ASSERT_EQ(sizeOffset, 8);
ASSERT_EQ(size, 4);
ASSERT_EQ(content[0], 1);
ASSERT_EQ(content[1], 2);
ASSERT_EQ(content[2], 3);
ASSERT_EQ(content[3], 4);
ASSERT_EQ(totleSize, 24);
2021-10-01 00:21:50 +08:00
2022-04-30 21:17:19 +08:00
ASSERT_EQ(hash_time33("name"), nameHash);
2022-03-02 10:34:33 +08:00
ASSERT_EQ(ARG_TYPE_NONE, type);
2021-10-01 00:21:50 +08:00
arg_freeContent(self);
2021-11-13 16:42:01 +08:00
EXPECT_EQ(pikaMemNow(), 0);
2021-10-01 00:21:50 +08:00
}
TEST(content, set) {
2021-11-13 16:42:01 +08:00
uint8_t contentIn[4] = {0};
contentIn[0] = 1;
contentIn[1] = 2;
contentIn[2] = 3;
contentIn[3] = 4;
2022-05-22 20:50:28 +08:00
Arg* self = content_init("", ARG_TYPE_NONE, NULL, 0, NULL);
2022-04-30 21:17:19 +08:00
self = content_setName(self, "name");
self = arg_setType(self, ARG_TYPE_NONE);
2021-11-13 16:42:01 +08:00
self = content_setContent(self, contentIn, 4);
2021-10-01 00:21:50 +08:00
2021-11-13 16:42:01 +08:00
uint16_t typeOffset = content_typeOffset(self);
uint16_t sizeOffset = content_sizeOffset(self);
uint16_t contentOffset = content_contentOffset(self);
uint16_t totleSize = content_totleSize(self);
2021-10-01 00:21:50 +08:00
2021-11-13 16:42:01 +08:00
Hash nameHash = content_getNameHash(self);
ArgType type = content_getType(self);
2021-11-13 16:42:01 +08:00
uint16_t size = content_getSize(self);
uint8_t* content = content_getContent(self);
2021-10-01 00:21:50 +08:00
ASSERT_EQ(contentOffset, 16);
ASSERT_EQ(typeOffset, 20);
2021-11-13 16:42:01 +08:00
ASSERT_EQ(sizeOffset, 8);
ASSERT_EQ(size, 4);
ASSERT_EQ(content[0], 1);
ASSERT_EQ(content[1], 2);
ASSERT_EQ(content[2], 3);
ASSERT_EQ(content[3], 4);
ASSERT_EQ(totleSize, 24);
2021-10-01 00:21:50 +08:00
2022-04-30 21:17:19 +08:00
ASSERT_EQ(hash_time33("name"), nameHash);
2022-03-02 10:34:33 +08:00
ASSERT_EQ(ARG_TYPE_NONE, type);
2021-10-01 00:21:50 +08:00
arg_freeContent(self);
2021-11-13 16:42:01 +08:00
EXPECT_EQ(pikaMemNow(), 0);
2021-10-01 00:21:50 +08:00
}
TEST(content, next) {
2022-04-30 21:17:19 +08:00
uint8_t* c1 = content_init("c1", ARG_TYPE_NONE, NULL, 0, NULL);
uint8_t* c2 = content_init("c2", ARG_TYPE_NONE, NULL, 0, c1);
2021-11-13 16:42:01 +08:00
uint8_t* c3 = content_getNext(c2);
2021-10-01 00:21:50 +08:00
2021-11-13 16:42:01 +08:00
ASSERT_EQ(c3, c1);
arg_freeContent(c1);
arg_freeContent(c2);
2021-11-13 16:42:01 +08:00
EXPECT_EQ(pikaMemNow(), 0);
2021-10-01 00:21:50 +08:00
}
TEST(content, setNext) {
2022-04-30 21:17:19 +08:00
uint8_t* c1 = content_init("c1", ARG_TYPE_NONE, NULL, 0, NULL);
content_setNext(c1, content_init("c2", ARG_TYPE_NONE, NULL, 0, NULL));
2021-11-13 16:42:01 +08:00
uint8_t* c2 = content_getNext(c1);
Hash c2NameHash = content_getNameHash(c2);
2022-04-30 21:17:19 +08:00
EXPECT_EQ(c2NameHash, hash_time33("c2"));
arg_freeContent(c1);
arg_freeContent(c2);
2021-11-13 16:42:01 +08:00
EXPECT_EQ(pikaMemNow(), 0);
2022-01-25 02:40:11 +08:00
}
#endif