| 
									
										
										
										
											2019-03-20 16:11:42 +07:00
										 |  |  | /* 
 | 
					
						
							|  |  |  |  * The MIT License (MIT) | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-05-14 11:48:05 +07:00
										 |  |  |  * Copyright (c) 2019 Ha Thach (tinyusb.org) | 
					
						
							| 
									
										
										
										
											2019-03-20 16:11:42 +07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  |  * all copies or substantial portions of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
					
						
							|  |  |  |  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  |  * THE SOFTWARE. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file is part of the TinyUSB stack. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-01-15 15:22:48 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "unity.h"
 | 
					
						
							| 
									
										
										
										
											2013-01-16 12:43:17 +07:00
										 |  |  | #include "fifo.h"
 | 
					
						
							| 
									
										
										
										
											2013-01-15 15:22:48 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-16 13:25:02 +07:00
										 |  |  | #define FIFO_SIZE 10
 | 
					
						
							| 
									
										
										
										
											2018-07-04 00:22:15 +07:00
										 |  |  | TU_FIFO_DEF(ff, FIFO_SIZE, uint8_t, false); | 
					
						
							| 
									
										
										
										
											2013-01-16 13:25:02 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-15 15:22:48 +07:00
										 |  |  | void setUp(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-04 00:22:15 +07:00
										 |  |  |   tu_fifo_clear(&ff); | 
					
						
							| 
									
										
										
										
											2013-01-15 15:22:48 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void tearDown(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-16 13:25:02 +07:00
										 |  |  | void test_normal(void) | 
					
						
							| 
									
										
										
										
											2013-01-15 15:22:48 +07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-01-16 13:25:02 +07:00
										 |  |  |   uint8_t i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for(i=0; i < FIFO_SIZE; i++) | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2018-07-04 00:22:15 +07:00
										 |  |  |     tu_fifo_write(&ff, &i); | 
					
						
							| 
									
										
										
										
											2013-01-16 13:25:02 +07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for(i=0; i < FIFO_SIZE; i++) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     uint8_t c; | 
					
						
							| 
									
										
										
										
											2018-07-04 00:22:15 +07:00
										 |  |  |     tu_fifo_read(&ff, &c); | 
					
						
							| 
									
										
										
										
											2013-01-16 13:25:02 +07:00
										 |  |  |     TEST_ASSERT_EQUAL(i, c); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-01-15 15:22:48 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-16 13:25:02 +07:00
										 |  |  | void test_is_empty(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-17 20:51:41 +07:00
										 |  |  |   uint8_t temp; | 
					
						
							| 
									
										
										
										
											2018-07-04 00:22:15 +07:00
										 |  |  |   TEST_ASSERT_TRUE(tu_fifo_is_empty(&ff)); | 
					
						
							|  |  |  |   tu_fifo_write(&ff, &temp); | 
					
						
							|  |  |  |   TEST_ASSERT_FALSE(tu_fifo_is_empty(&ff)); | 
					
						
							| 
									
										
										
										
											2013-01-16 13:25:02 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void test_is_full(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   uint8_t i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-04 00:22:15 +07:00
										 |  |  |   TEST_ASSERT_FALSE(tu_fifo_is_full(&ff)); | 
					
						
							| 
									
										
										
										
											2013-01-16 13:25:02 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   for(i=0; i < FIFO_SIZE; i++) | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2018-07-04 00:22:15 +07:00
										 |  |  |     tu_fifo_write(&ff, &i); | 
					
						
							| 
									
										
										
										
											2013-01-16 13:25:02 +07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-04 00:22:15 +07:00
										 |  |  |   TEST_ASSERT_TRUE(tu_fifo_is_full(&ff)); | 
					
						
							| 
									
										
										
										
											2013-01-16 13:25:02 +07:00
										 |  |  | } |