From f403623ba54ebf8d4fed8e51c8f7a8d497a661d7 Mon Sep 17 00:00:00 2001 From: YarivCol Date: Thu, 5 Oct 2017 07:00:18 -0700 Subject: [PATCH] Add test for empty, full functions in queue and mail --- TESTS/mbedmicro-rtos-mbed/mail/main.cpp | 37 +++++++++++++++++++++ TESTS/mbedmicro-rtos-mbed/queue/main.cpp | 42 +++++++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/TESTS/mbedmicro-rtos-mbed/mail/main.cpp b/TESTS/mbedmicro-rtos-mbed/mail/main.cpp index 3332de41e1..303e937c01 100644 --- a/TESTS/mbedmicro-rtos-mbed/mail/main.cpp +++ b/TESTS/mbedmicro-rtos-mbed/mail/main.cpp @@ -454,6 +454,43 @@ void test_calloc() TEST_ASSERT_EQUAL(0, *mail); } +/** Test mail empty + + Given a mail of uint32_t data + before data is inserted the mail should be empty + after data is inserted the mail shouldn't be empty + */ +void test_mail_empty() +{ + Mail m; + + mail_t *mail = m->alloc(); + + TEST_ASSERT_EQUAL(true, m.empty()); + + m.put(mail); + + TEST_ASSERT_EQUAL(false, m.empty())); +} + +/** Test mail empty + + Given a mail of uint32_t data with size of 1 + before data is inserted the mail shouldn't be full + after data is inserted the mail should be full + */ +void test_mail_full() +{ + Mail m; + + mail_t *mail = m->alloc(); + + TEST_ASSERT_EQUAL(false, m.full()); + + m.put(mail); + + TEST_ASSERT_EQUAL(true, m.full())); +} utest::v1::status_t test_setup(const size_t number_of_cases) { diff --git a/TESTS/mbedmicro-rtos-mbed/queue/main.cpp b/TESTS/mbedmicro-rtos-mbed/queue/main.cpp index 374dc8662c..786507e488 100644 --- a/TESTS/mbedmicro-rtos-mbed/queue/main.cpp +++ b/TESTS/mbedmicro-rtos-mbed/queue/main.cpp @@ -278,6 +278,44 @@ void test_msg_prio() TEST_ASSERT_EQUAL(TEST_UINT_MSG, evt.value.v); } +/** Test queue empty + + Given a queue of uint32_t data + before data is inserted the queue should be empty + after data is inserted the queue shouldn't be empty + */ +void test_queue_empty() +{ + Queue q; + + TEST_ASSERT_EQUAL(true, q.empty()); + + stat = q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT, 1); + + TEST_ASSERT_EQUAL(osOK, stat); + + TEST_ASSERT_EQUAL(false, q.empty())); +} + +/** Test queue empty + + Given a queue of uint32_t data with size of 1 + before data is inserted the queue shouldn't be full + after data is inserted the queue should be full + */ +void test_queue_full() +{ + Queue q; + + TEST_ASSERT_EQUAL(false, q.full()); + + stat = q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT, 1); + + TEST_ASSERT_EQUAL(osOK, stat); + + TEST_ASSERT_EQUAL(true, q.full())); +} + utest::v1::status_t test_setup(const size_t number_of_cases) { GREENTEA_SETUP(5, "default_auto"); @@ -295,7 +333,9 @@ Case cases[] = { Case("Test put full timeout", test_put_full_timeout), Case("Test put full wait forever", test_put_full_waitforever), Case("Test message ordering", test_msg_order), - Case("Test message priority", test_msg_prio) + Case("Test message priority", test_msg_prio), + Case("Test queue empty", test_queue_empty), + Case("Test queue full", test_queue_full) }; Specification specification(test_setup, cases);