Changeset ac307b2 in mainline for uspace/lib/c/test/adt/circ_buf.c


Ignore:
Timestamp:
2017-11-25T11:12:23Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
98cb5e0d
Parents:
f571ca49 (diff), 0851a3d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into callcaps

File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/test/adt/circ_buf.c

    rf571ca49 rac307b2  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2017 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @file
     29#include <adt/circ_buf.h>
     30#include <pcut/pcut.h>
     31
     32PCUT_INIT
     33
     34PCUT_TEST_SUITE(circ_buf);
     35
     36enum {
     37        buffer_size = 16
     38};
     39
     40static int buffer[buffer_size];
     41
     42/** Basic insertion/deletion test.
     43 *
     44 * Test initialization, emptiness, pushing buffer until it is full,
     45 * then emptying it again.
    3046 */
     47PCUT_TEST(push_pop)
     48{
     49        circ_buf_t cbuf;
     50        int i;
     51        int j;
     52        int rc;
    3153
    32 #include <assert.h>
    33 #include <errno.h>
    34 #include <mem.h>
    35 #include <ops/char_dev.h>
     54        circ_buf_init(&cbuf, buffer, buffer_size, sizeof(int));
    3655
    37 #include "test1.h"
     56        for (i = 0; i < buffer_size; i++) {
     57                PCUT_ASSERT_INT_EQUALS(buffer_size - i, circ_buf_nfree(&cbuf));
     58                PCUT_ASSERT_INT_EQUALS(i, circ_buf_nused(&cbuf));
     59                rc = circ_buf_push(&cbuf, &i);
     60                PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     61        }
    3862
    39 static int impl_char_read(ddf_fun_t *fun, char *buf, size_t count) {
    40         memset(buf, 0, count);
    41         return count;
     63        rc = circ_buf_push(&cbuf, &i);
     64        PCUT_ASSERT_ERRNO_VAL(EAGAIN, rc);
     65
     66        for (i = 0; i < buffer_size; i++) {
     67                PCUT_ASSERT_INT_EQUALS(i, circ_buf_nfree(&cbuf));
     68                PCUT_ASSERT_INT_EQUALS(buffer_size - i, circ_buf_nused(&cbuf));
     69                rc = circ_buf_pop(&cbuf, &j);
     70                PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     71                PCUT_ASSERT_INT_EQUALS(i, j);
     72        }
     73
     74        PCUT_ASSERT_INT_EQUALS(buffer_size, circ_buf_nfree(&cbuf));
     75        PCUT_ASSERT_INT_EQUALS(0, circ_buf_nused(&cbuf));
     76
     77        rc = circ_buf_pop(&cbuf, &j);
     78        PCUT_ASSERT_ERRNO_VAL(EAGAIN, rc);
    4279}
    4380
    44 static int imp_char_write(ddf_fun_t *fun, char *buf, size_t count) {
    45         return count;
    46 }
    47 
    48 static char_dev_ops_t char_dev_ops = {
    49         .read = &impl_char_read,
    50         .write = &imp_char_write
    51 };
    52 
    53 ddf_dev_ops_t char_device_ops = {
    54         .interfaces[CHAR_DEV_IFACE] = &char_dev_ops
    55 };
    56 
     81PCUT_EXPORT(circ_buf);
Note: See TracChangeset for help on using the changeset viewer.