Changeset 132ab5d1 in mainline for uspace/lib/c/test/adt/circ_buf.c
- Timestamp:
- 2018-01-30T03:20:45Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5a6cc679
- Parents:
- 8bfb163 (diff), 6a5d05b (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
r8bfb163 r132ab5d1 1 1 /* 2 * Copyright (c) 201 1 Martin Decky2 * Copyright (c) 2017 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup mouse_proto 30 * @ingroup input 31 * @{ 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. 32 46 */ 33 /** 34 * @file 35 * @brief ADB protocol driver. 36 */ 47 PCUT_TEST(push_pop) 48 { 49 circ_buf_t cbuf; 50 int i; 51 int j; 52 int rc; 37 53 38 #include <stdbool.h> 39 #include "../mouse.h" 40 #include "../mouse_port.h" 41 #include "../mouse_proto.h" 54 circ_buf_init(&cbuf, buffer, buffer_size, sizeof(int)); 42 55 43 static mouse_dev_t *mouse_dev; 44 static bool b1_pressed; 45 static bool b2_pressed; 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 } 46 62 47 static int adb_proto_init(mouse_dev_t *mdev) 48 { 49 mouse_dev = mdev; 50 b1_pressed = false; 51 b2_pressed = false; 52 53 return 0; 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); 54 79 } 55 80 56 /** Process mouse data */ 57 static void adb_proto_parse(sysarg_t data) 58 { 59 bool b1, b2; 60 uint16_t udx, udy; 61 int dx, dy; 62 63 /* Extract fields. */ 64 b1 = ((data >> 15) & 1) == 0; 65 udy = (data >> 8) & 0x7f; 66 b2 = ((data >> 7) & 1) == 0; 67 udx = data & 0x7f; 68 69 /* Decode 7-bit two's complement signed values. */ 70 dx = (udx & 0x40) ? (udx - 0x80) : udx; 71 dy = (udy & 0x40) ? (udy - 0x80) : udy; 72 73 if (b1 != b1_pressed) { 74 mouse_push_event_button(mouse_dev, 1, b1); 75 b1_pressed = b1; 76 } 77 78 if (b2 != b2_pressed) { 79 mouse_push_event_button(mouse_dev, 2, b2); 80 b1_pressed = b1; 81 } 82 83 if (dx != 0 || dy != 0) 84 mouse_push_event_move(mouse_dev, dx, dy, 0); 85 } 86 87 mouse_proto_ops_t adb_proto = { 88 .parse = adb_proto_parse, 89 .init = adb_proto_init 90 }; 91 92 /** 93 * @} 94 */ 81 PCUT_EXPORT(circ_buf);
Note:
See TracChangeset
for help on using the changeset viewer.