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 * \author Bernie Innocenti <bernie@codewiz.org>
39 #include <struct/fifobuf.h>
40 #include <struct/kfile_fifo.h>
42 #include <cfg/compiler.h>
44 #include <cfg/debug.h>
47 int kfilefifo_testSetup(void)
53 int kfilefifo_testRun(void)
55 #define FIFOBUF_LEN 256
57 uint8_t buf[FIFOBUF_LEN];
60 fifo_init(&fifo, buf, sizeof(buf));
62 ASSERT(fifo_isempty(&fifo));
63 ASSERT(!fifo_isfull(&fifo));
65 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
67 ASSERT(!fifo_isfull(&fifo));
71 ASSERT(fifo_isfull(&fifo));
73 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
75 ASSERT(!fifo_isempty(&fifo));
76 ASSERT(fifo_pop(&fifo) == i);
79 ASSERT(fifo_isempty(&fifo));
81 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
83 ASSERT(!fifo_isfull(&fifo));
86 ASSERT(fifo_isfull(&fifo));
88 ASSERT(!fifo_isfull(&fifo));
89 ASSERT(fifo_isempty(&fifo));
92 kfilefifo_init(&kfifo, &fifo);
94 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
96 ASSERT(!fifo_isfull(&fifo));
100 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
101 ASSERT(kfile_getc(&kfifo.fd) == i);
103 ASSERT(kfile_getc(&kfifo.fd) == EOF);
104 ASSERT(fifo_isempty(&fifo));
106 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
107 ASSERT(kfile_putc(i, &kfifo.fd) == i);
109 ASSERT(fifo_isfull(&fifo));
111 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
113 ASSERT(!fifo_isempty(&fifo));
114 ASSERT(fifo_pop(&fifo) == i);
117 ASSERT(fifo_isempty(&fifo));
119 for (int i = 0; i < FIFOBUF_LEN - 1; i++)
120 ASSERT(kfile_putc(i, &kfifo.fd) == i);
122 ASSERT(fifo_isfull(&fifo));
123 ASSERT(kfile_putc('a', &kfifo.fd) == EOF);
126 ASSERT(!fifo_isfull(&fifo));
127 ASSERT(fifo_isempty(&fifo));
128 ASSERT(kfile_getc(&kfifo.fd) == EOF);
130 ASSERT(kfile_write(&kfifo.fd, "hello world", 11) == 11);
131 ASSERT(kfile_write(&kfifo.fd, "hello world", FIFOBUF_LEN) == FIFOBUF_LEN - 1 - 11);
133 uint8_t test_buf[FIFOBUF_LEN];
134 ASSERT(kfile_read(&kfifo.fd, test_buf, FIFOBUF_LEN + 20) == FIFOBUF_LEN - 1);
136 ASSERT(!fifo_isfull(&fifo));
137 ASSERT(fifo_isempty(&fifo));
138 ASSERT(kfile_getc(&kfifo.fd) == EOF);
142 int kfilefifo_testTearDown(void)
147 TEST_MAIN(kfilefifo);