test-prioq.c revision 30bdd695250eeecbf0b36c1e3c90d67ca03953ed
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering This file is part of systemd.
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering Copyright 2013 Lennart Poettering
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering systemd is free software; you can redistribute it and/or modify it
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering under the terms of the GNU Lesser General Public License as published by
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering (at your option) any later version.
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering systemd is distributed in the hope that it will be useful, but
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering Lesser General Public License for more details.
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering You should have received a copy of the GNU Lesser General Public License
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
b070e7f3c9ed680c821bd89d42506695f2438506Lennart Poetteringstatic int unsigned_compare(const void *a, const void *b) {
b070e7f3c9ed680c821bd89d42506695f2438506Lennart Poettering const unsigned *x = a, *y = b;
3ed08c446cfaaae2b234fdfeb0c34ab6b4748c3eLennart Poetteringstatic void test_unsigned(void) {
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering for (i = 0; i < ELEMENTSOF(buffer); i++) {
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering u = (unsigned) rand();
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering assert_se(prioq_put(q, UINT_TO_PTR(u), NULL) >= 0);
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering qsort(buffer, ELEMENTSOF(buffer), sizeof(buffer[0]), unsigned_compare);
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering for (i = 0; i < ELEMENTSOF(buffer); i++) {
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering assert_se(prioq_size(q) == ELEMENTSOF(buffer) - i);
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poetteringstatic int test_compare(const void *a, const void *b) {
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering const struct test *x = a, *y = b;
18c7ed186be28800a2eeb37ad31c9c44480d3d9cLennart Poetteringstatic unsigned test_hash(const void *a) {
18c7ed186be28800a2eeb37ad31c9c44480d3d9cLennart Poettering const struct test *x = a;
fe6521272ba203ec8f0d5a94f0729960b3f90525Lennart Poetteringstatic void test_struct(void) {
d0bbc21caa6e68693a47db60c93e99422bf2a858Lennart Poettering unsigned previous = 0, i;
d0bbc21caa6e68693a47db60c93e99422bf2a858Lennart Poettering for (i = 0; i < SET_SIZE; i++) {
b070e7f3c9ed680c821bd89d42506695f2438506Lennart Poettering if (i % 4 == 0) {
7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49eLennart Poettering assert_se(prioq_size(q) == (SET_SIZE * 3 / 4) - i);