mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-07-03 23:56:54 +08:00
添加结构体测试框架
This commit is contained in:
parent
ff7f587b00
commit
015ecd1cf9
@ -14,7 +14,7 @@
|
|||||||
* @brief 데淃뚠죗꿎桿
|
* @brief 데淃뚠죗꿎桿
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void test_queue1_num(void)
|
static void test_queue_num(void)
|
||||||
{
|
{
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
int data[] = { 1,2,3,4,5,6,7,8,9,10 };
|
int data[] = { 1,2,3,4,5,6,7,8,9,10 };
|
||||||
@ -80,6 +80,78 @@ static void test_queue1_num(void)
|
|||||||
TEST_ASSERT_NULL(queue);
|
TEST_ASSERT_NULL(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_queue_struct(void)
|
||||||
|
{
|
||||||
|
uint32_t i = 0;
|
||||||
|
struct _student data[] = {
|
||||||
|
{"zhao", 1001}, {"qian", 1002}, {"sun", 1003}, {"li", 1004},
|
||||||
|
"zhou", 1005, "wu", 1006, "zheng", 1007, "wang", 1008,
|
||||||
|
};
|
||||||
|
struct _student temp;
|
||||||
|
uint32_t len = sizeof(data) / sizeof(data[0]) - 1;
|
||||||
|
|
||||||
|
queue_t queue = queue_new();
|
||||||
|
TEST_ASSERT_NOT_NULL(queue);
|
||||||
|
|
||||||
|
queue_init(queue, sizeof(struct _student));
|
||||||
|
queue->print_obj = print_struct;
|
||||||
|
|
||||||
|
TEST_ASSERT_TRUE(queue->clear(queue));
|
||||||
|
|
||||||
|
TEST_ASSERT_FALSE(queue->front(queue, &temp));
|
||||||
|
TEST_ASSERT_FALSE(queue->back(queue, &temp));
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_TRUE(queue->push(queue, &data[i]));
|
||||||
|
TEST_ASSERT_EQUAL_INT(i + 1, queue->size(queue));
|
||||||
|
|
||||||
|
TEST_ASSERT_TRUE(queue->front(queue, &temp));
|
||||||
|
TEST_ASSERT_EQUAL_INT(data[0].id, temp.id);
|
||||||
|
TEST_ASSERT_EQUAL_STRING(data[0].name, temp.name);
|
||||||
|
|
||||||
|
TEST_ASSERT_TRUE(queue->back(queue, &temp));
|
||||||
|
TEST_ASSERT_EQUAL_INT(data[i].id, temp.id);
|
||||||
|
TEST_ASSERT_EQUAL_STRING(data[i].name, temp.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_ASSERT_FALSE(queue->empty(queue));
|
||||||
|
TEST_ASSERT_TRUE(queue->clear(queue));
|
||||||
|
TEST_ASSERT_TRUE(queue->empty(queue));
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_TRUE(queue->push(queue, &data[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// while (!queue->empty(queue))
|
||||||
|
for(i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
TEST_ASSERT_TRUE(queue->front(queue, &temp));
|
||||||
|
TEST_ASSERT_EQUAL_INT(data[i].id, temp.id);
|
||||||
|
TEST_ASSERT_EQUAL_STRING(data[i].name, temp.name);
|
||||||
|
|
||||||
|
TEST_ASSERT_TRUE(queue->back(queue, &temp));
|
||||||
|
TEST_ASSERT_EQUAL_INT(data[len - 1].id, temp.id);
|
||||||
|
TEST_ASSERT_EQUAL_STRING(data[len - 1].name, temp.name);
|
||||||
|
|
||||||
|
TEST_ASSERT_TRUE(queue->pop(queue, &temp));
|
||||||
|
|
||||||
|
if (!queue->empty(queue))
|
||||||
|
{
|
||||||
|
TEST_ASSERT_TRUE(queue->front(queue, &temp));
|
||||||
|
TEST_ASSERT_EQUAL_INT(data[i + 1].id, temp.id);
|
||||||
|
TEST_ASSERT_EQUAL_STRING(data[i + 1].name, temp.name);
|
||||||
|
|
||||||
|
TEST_ASSERT_TRUE(queue->back(queue, &temp));
|
||||||
|
TEST_ASSERT_EQUAL_INT(data[len - 1].id, temp.id);
|
||||||
|
TEST_ASSERT_EQUAL_STRING(data[len - 1].name, temp.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TEST_ASSERT_TRUE(queue->empty(queue));
|
||||||
|
TEST_ASSERT_FALSE(queue->pop(queue, &temp));
|
||||||
|
queue_free(&queue);
|
||||||
|
TEST_ASSERT_NULL(queue);
|
||||||
|
}
|
||||||
|
|
||||||
static void test_queue2_num(void)
|
static void test_queue2_num(void)
|
||||||
{
|
{
|
||||||
@ -182,7 +254,9 @@ static void test_queue2_fifo_num(void)
|
|||||||
void test_queue(void)
|
void test_queue(void)
|
||||||
{
|
{
|
||||||
// TEST_MESSAGE("----- test_queue -----");
|
// TEST_MESSAGE("----- test_queue -----");
|
||||||
RUN_TEST(test_queue1_num);
|
RUN_TEST(test_queue_num);
|
||||||
|
RUN_TEST(test_queue_struct);
|
||||||
|
|
||||||
RUN_TEST(test_queue2_num);
|
RUN_TEST(test_queue2_num);
|
||||||
RUN_TEST(test_queue2_fifo_num);
|
RUN_TEST(test_queue2_fifo_num);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user