3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
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.
22 * https://www.FreeRTOS.org
23 * https://github.com/FreeRTOS
26 /*! @file queue_delete_static_utest.c */
28 /* C runtime includes. */
33 #include "../queue_utest_common.h"
37 #include "FreeRTOSConfig.h"
40 #include "mock_fake_port.h"
42 /* ============================ GLOBAL VARIABLES =========================== */
44 /* ========================== CALLBACK FUNCTIONS =========================== */
46 /* ============================= Unity Fixtures ============================= */
63 int suiteTearDown( int numFailures )
65 return commonSuiteTearDown( numFailures );
68 /* ========================== Helper functions =========================== */
70 /* ============================= Test Cases ============================== */
73 * @brief Test vQueueDelete with an invalid QueueHandle
74 * @coverage vQueueDelete
76 void test_vQueueDelete_invalid_handle( void )
78 EXPECT_ASSERT_BREAK( vQueueDelete( NULL ) );
82 * @brief Test vQueueDelete with a statically allocated queue of size 6 x 4 bytes
83 * @coverage vQueueDelete
85 void test_vQueueDelete_empty( void )
87 void * queueBuffer = malloc( sizeof( StaticQueue_t ) );
88 void * queueData = malloc( 6 * sizeof( uint32_t ) );
89 QueueHandle_t xQueue = xQueueCreateStatic( 6, sizeof( uint32_t ), queueData, queueBuffer );
91 /* Verify that no call to malloc occurred */
92 TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
94 vQueueDelete( xQueue );
95 /* Veirfy that free was not called */
96 TEST_ASSERT_EQUAL_PTR( NULL, getLastFreedAddress() );
102 * @brief Test vQueueDelete with a half-full queue of size 6 x 4 bytes
103 * @coverage vQueueDelete
105 void test_vQueueDelete_half_full( void )
107 void * queueBuffer = malloc( sizeof( StaticQueue_t ) );
108 void * queueData = malloc( 6 * sizeof( uint32_t ) );
109 QueueHandle_t xQueue = xQueueCreateStatic( 6, sizeof( uint32_t ), queueData, queueBuffer );
111 /* Verify that no call to malloc occurred */
112 TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
114 for( uint32_t i = 0; i < 3; i++ )
116 xQueueSend( xQueue, &i, 0 );
119 vQueueDelete( xQueue );
121 /* Veirfy that free was not called */
122 TEST_ASSERT_EQUAL_PTR( NULL, getLastFreedAddress() );
128 * @brief Test vQueueDelete with a full queue of size 6 x 4 bytes
129 * @coverage vQueueDelete
131 void test_vQueueDelete_full( void )
133 void * queueBuffer = malloc( sizeof( StaticQueue_t ) );
134 void * queueData = malloc( 6 * sizeof( uint32_t ) );
135 QueueHandle_t xQueue = xQueueCreateStatic( 6, sizeof( uint32_t ), queueData, queueBuffer );
137 /* Verify that no call to malloc occurred */
138 TEST_ASSERT_EQUAL( 0, getLastMallocSize() );
140 for( uint32_t i = 0; i < 6; i++ )
142 xQueueSend( xQueue, &i, 0 );
145 vQueueDelete( xQueue );
147 /* Veirfy that free was not called */
148 TEST_ASSERT_EQUAL_PTR( NULL, getLastFreedAddress() );