4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
33 * \brief FIFO and KFileFifo test.
35 * \version $Id: kfilefifo_test.c 1962 2008-12-02 15:37:17Z batt $
36 * \author Bernie Innocenti <bernie@codewiz.org>
40 #include <struct/fifobuf.h>
41 #include <struct/kfile_fifo.h>
43 #include <cfg/compiler.h>
45 #include <cfg/debug.h>
48 int kfilefifo_testSetup(void)
54 int kfilefifo_testRun(void)
56 #define FIFOBUF_LEN 256
58 uint8_t buf[FIFOBUF_LEN];
61 fifo_init(&fifo, buf, sizeof(buf));
63 ASSERT(fifo_isempty(&fifo));
64 ASSERT(!fifo_isfull(&fifo));
66 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
68 ASSERT(!fifo_isfull(&fifo));
72 ASSERT(fifo_isfull(&fifo));
74 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
76 ASSERT(!fifo_isempty(&fifo));
77 ASSERT(fifo_pop(&fifo) == i);
80 ASSERT(fifo_isempty(&fifo));
82 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
84 ASSERT(!fifo_isfull(&fifo));
87 ASSERT(fifo_isfull(&fifo));
89 ASSERT(!fifo_isfull(&fifo));
90 ASSERT(fifo_isempty(&fifo));
93 kfilefifo_init(&kfifo, &fifo);
95 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
97 ASSERT(!fifo_isfull(&fifo));
101 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
102 ASSERT(kfile_getc(&kfifo.fd) == i);
104 ASSERT(kfile_getc(&kfifo.fd) == EOF);
105 ASSERT(fifo_isempty(&fifo));
107 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
108 ASSERT(kfile_putc(i, &kfifo.fd) == i);
110 ASSERT(fifo_isfull(&fifo));
112 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
114 ASSERT(!fifo_isempty(&fifo));
115 ASSERT(fifo_pop(&fifo) == i);
118 ASSERT(fifo_isempty(&fifo));
120 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
121 ASSERT(kfile_putc(i, &kfifo.fd) == i);
123 ASSERT(fifo_isfull(&fifo));
124 ASSERT(kfile_putc('a', &kfifo.fd) == EOF);
127 ASSERT(!fifo_isfull(&fifo));
128 ASSERT(fifo_isempty(&fifo));
129 ASSERT(kfile_getc(&kfifo.fd) == EOF);
131 ASSERT(kfile_write(&kfifo.fd, "hello world", 11) == 11);
132 ASSERT(kfile_write(&kfifo.fd, "hello world", FIFOBUF_LEN) == FIFOBUF_LEN - 1 - 11);
134 uint8_t test_buf[FIFOBUF_LEN];
135 ASSERT(kfile_read(&kfifo.fd, test_buf, FIFOBUF_LEN + 20) == FIFOBUF_LEN - 1);
137 ASSERT(!fifo_isfull(&fifo));
138 ASSERT(fifo_isempty(&fifo));
139 ASSERT(kfile_getc(&kfifo.fd) == EOF);
143 int kfilefifo_testTearDown(void)
148 TEST_MAIN(kfilefifo);