]> begriffs open source - cmsis-freertos/blob - Test/CMock/queue/dynamic/queue_delete_dynamic_utest.c
Update README.md - branch main is now the base branch
[cmsis-freertos] / Test / CMock / queue / dynamic / queue_delete_dynamic_utest.c
1 /*
2  * FreeRTOS V202111.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  */
26 /*! @file queue_delete_dynamic_utest.c */
27
28 /* C runtime includes. */
29 #include <stdlib.h>
30 #include <stdbool.h>
31 #include <string.h>
32
33 #include "../queue_utest_common.h"
34
35 /* Queue includes */
36 #include "FreeRTOS.h"
37 #include "FreeRTOSConfig.h"
38 #include "queue.h"
39
40 #include "mock_fake_port.h"
41
42 /* ============================  GLOBAL VARIABLES =========================== */
43
44 /* =========================== CALLBACK FUNCTIONS =========================== */
45
46 /* ============================= Unity Fixtures ============================= */
47
48 void setUp( void )
49 {
50     commonSetUp();
51 }
52
53 void tearDown( void )
54 {
55     commonTearDown();
56 }
57
58 void suiteSetUp()
59 {
60     commonSuiteSetUp();
61 }
62
63 int suiteTearDown( int numFailures )
64 {
65     return commonSuiteTearDown( numFailures );
66 }
67
68 /* ===========================  Helper functions ============================ */
69
70 /* ==============================  Test Cases =============================== */
71
72 /**
73  * @brief Test vQueueDelete with an invalid QueueHandle
74  * @coverage vQueueDelete
75  */
76 void test_vQueueDelete_invalid_handle( void )
77 {
78     EXPECT_ASSERT_BREAK( vQueueDelete( NULL ) );
79 }
80
81 /**
82  * @brief Test vQueueDelete with a statically allocated queue of size 6 x 4 bytes
83  * @coverage vQueueDelete
84  */
85 void test_vQueueDelete_empty( void )
86 {
87     QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
88
89     TEST_ASSERT_EQUAL( QUEUE_T_SIZE + ( 6 * 4 ), getLastMallocSize() );
90
91     vQueueDelete( xQueue );
92     TEST_ASSERT_EQUAL_PTR( ( void * ) xQueue, getLastFreedAddress() );
93 }
94
95 /**
96  * @brief Test vQueueDelete with a half-full queue of size 6 x 4 bytes
97  * @coverage vQueueDelete
98  */
99 void test_vQueueDelete_half_full( void )
100 {
101     QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
102
103     TEST_ASSERT_EQUAL( QUEUE_T_SIZE + ( 6 * 4 ), getLastMallocSize() );
104
105     for( uint32_t i = 0; i < 3; i++ )
106     {
107         xQueueSend( xQueue, &i, 0 );
108     }
109
110     vQueueDelete( xQueue );
111     TEST_ASSERT_EQUAL_PTR( ( void * ) xQueue, getLastFreedAddress() );
112 }
113
114 /**
115  * @brief Test vQueueDelete with a full queue of size 6 x 4 bytes
116  * @coverage vQueueDelete
117  */
118 void test_vQueueDelete_full( void )
119 {
120     QueueHandle_t xQueue = xQueueCreate( 6, sizeof( uint32_t ) );
121
122     TEST_ASSERT_EQUAL( QUEUE_T_SIZE + ( 6 * 4 ), getLastMallocSize() );
123
124     for( uint32_t i = 0; i < 6; i++ )
125     {
126         xQueueSend( xQueue, &i, 0 );
127     }
128
129     vQueueDelete( xQueue );
130     TEST_ASSERT_EQUAL_PTR( ( void * ) xQueue, getLastFreedAddress() );
131 }