2021-10-01 00:21:50 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
extern "C" {
|
|
|
|
#include "dataArg.h"
|
|
|
|
#include "dataString.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-03-02 10:34:33 +08:00
|
|
|
uint8_t* self = content_init((char*)"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);
|
2021-11-15 09:35:48 +08:00
|
|
|
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
|
|
|
|
2022-01-05 22:36:28 +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);
|
2022-01-05 22:36:28 +08:00
|
|
|
ASSERT_EQ(totleSize, 24);
|
2021-10-01 00:21:50 +08:00
|
|
|
|
2021-11-13 16:42:01 +08:00
|
|
|
ASSERT_EQ(hash_time33((char*)"name"), nameHash);
|
2022-03-02 10:34:33 +08:00
|
|
|
ASSERT_EQ(ARG_TYPE_NONE, type);
|
2021-10-01 00:21:50 +08:00
|
|
|
|
2021-11-13 16:42:01 +08:00
|
|
|
content_deinit(self);
|
|
|
|
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-03-02 10:34:33 +08:00
|
|
|
uint8_t* self = content_init((char*)"", ARG_TYPE_NONE, NULL, 0, NULL);
|
2021-11-13 16:42:01 +08:00
|
|
|
self = content_setName(self, (char*)"name");
|
2022-03-02 10:34:33 +08:00
|
|
|
self = content_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);
|
2021-11-15 09:35:48 +08:00
|
|
|
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
|
|
|
|
2022-01-05 22:36:28 +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);
|
2022-01-05 22:36:28 +08:00
|
|
|
ASSERT_EQ(totleSize, 24);
|
2021-10-01 00:21:50 +08:00
|
|
|
|
2021-11-15 09:35:48 +08:00
|
|
|
ASSERT_EQ(hash_time33((char*)"name"), nameHash);
|
2022-03-02 10:34:33 +08:00
|
|
|
ASSERT_EQ(ARG_TYPE_NONE, type);
|
2021-10-01 00:21:50 +08:00
|
|
|
|
2021-11-13 16:42:01 +08:00
|
|
|
content_deinit(self);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-10-01 00:21:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(content, next) {
|
2022-03-02 10:34:33 +08:00
|
|
|
uint8_t* c1 = content_init((char*)"c1", ARG_TYPE_NONE, NULL, 0, NULL);
|
|
|
|
uint8_t* c2 = content_init((char*)"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);
|
|
|
|
content_deinit(c1);
|
|
|
|
content_deinit(c2);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2021-10-01 00:21:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(content, setNext) {
|
2022-03-02 10:34:33 +08:00
|
|
|
uint8_t* c1 = content_init((char*)"c1", ARG_TYPE_NONE, NULL, 0, NULL);
|
|
|
|
content_setNext(c1, content_init((char*)"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);
|
|
|
|
EXPECT_EQ(c2NameHash, hash_time33((char*)"c2"));
|
|
|
|
content_deinit(c1);
|
|
|
|
content_deinit(c2);
|
|
|
|
EXPECT_EQ(pikaMemNow(), 0);
|
2022-01-25 02:40:11 +08:00
|
|
|
}
|
|
|
|
#endif
|