test-ring.c revision e0dd92729e68e0005866a890d8209ddcf3568805
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2014 David Herrmann <dh.herrmann@gmail.com>
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <locale.h>
#include <errno.h>
#include "def.h"
#include "ring.h"
#include "util.h"
static void test_ring(void) {
static const char buf[8192];
struct ring r;
size_t l;
int s;
memset(&r, 0, sizeof(r));
assert_se(l == 0);
assert_se(!s);
assert_se(l == 1);
ring_pull(&r, 2048);
assert_se(ring_get_size(&r) == 0);
assert_se(l == 0);
assert_se(ring_get_size(&r) == 0);
assert_se(!s);
assert_se(l == 1);
assert_se(!s);
assert_se(l == 2);
ring_pull(&r, 2048);
assert_se(l == 1);
ring_pull(&r, 1);
assert_se(ring_get_size(&r) == 0);
assert_se(!s);
assert_se(!s);
assert_se(l == 1);
ring_pull(&r, 1);
assert_se(!s);
assert_se(l == 2);
ring_clear(&r);
assert_se(ring_get_size(&r) == 0);
}
log_open();
test_ring();
return 0;
}