Changeset ac307b2 in mainline for uspace/lib/c/test/adt/circ_buf.c
- Timestamp:
- 2017-11-25T11:12:23Z (7 years ago)
- 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. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/test/adt/circ_buf.c
rf571ca49 rac307b2 1 1 /* 2 * Copyright (c) 201 0 Vojtech Horky2 * Copyright (c) 2017 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @file 29 #include <adt/circ_buf.h> 30 #include <pcut/pcut.h> 31 32 PCUT_INIT 33 34 PCUT_TEST_SUITE(circ_buf); 35 36 enum { 37 buffer_size = 16 38 }; 39 40 static 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. 30 46 */ 47 PCUT_TEST(push_pop) 48 { 49 circ_buf_t cbuf; 50 int i; 51 int j; 52 int rc; 31 53 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)); 36 55 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 } 38 62 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); 42 79 } 43 80 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 81 PCUT_EXPORT(circ_buf);
Note:
See TracChangeset
for help on using the changeset viewer.