From a83c95e9f46ef695a55fc7a6911e11846da9903c Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Wed, 23 Apr 2025 08:01:36 -0600 Subject: Merge libobj into libmisc --- libobj/tests/test_nest.c | 73 ------------------------------------------------ 1 file changed, 73 deletions(-) delete mode 100644 libobj/tests/test_nest.c (limited to 'libobj/tests/test_nest.c') diff --git a/libobj/tests/test_nest.c b/libobj/tests/test_nest.c deleted file mode 100644 index f18b018..0000000 --- a/libobj/tests/test_nest.c +++ /dev/null @@ -1,73 +0,0 @@ -/* libobj/tests/test_nest.c - Tests for - * - * Copyright (C) 2025 Luke T. Shumaker - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -#include /* for memcpy() */ - -#include - -#include "test.h" - -/* interfaces *****************************************************************/ - -#define reader_LO_IFACE \ - LO_FUNC(ssize_t, read, void *, size_t) -LO_INTERFACE(reader); - -#define writer_LO_IFACE \ - LO_FUNC(ssize_t, write, void *, size_t) -LO_INTERFACE(writer); - -#define read_writer_LO_IFACE \ - LO_NEST(reader) \ - LO_NEST(writer) -LO_INTERFACE(read_writer); - -/* implementation header ******************************************************/ - -struct myclass { - size_t len; - char buf[512]; -}; -LO_IMPLEMENTATION_H(reader, struct myclass, myclass); -LO_IMPLEMENTATION_H(writer, struct myclass, myclass); -LO_IMPLEMENTATION_H(read_writer, struct myclass, myclass); - -/* implementation main ********************************************************/ - -LO_IMPLEMENTATION_C(reader, struct myclass, myclass, static); -LO_IMPLEMENTATION_C(writer, struct myclass, myclass, static); -LO_IMPLEMENTATION_C(read_writer, struct myclass, myclass, static); - -static ssize_t myclass_read(struct myclass *self, void *buf, size_t count) { - test_assert(self); - if (count > self->len) - count = self->len; - memcpy(buf, self->buf, count); - return count; -} - -static ssize_t myclass_write(struct myclass *self, void *buf, size_t count) { - test_assert(self); - if (self->len) - return -1; - if (count > sizeof(self->buf)) - count = sizeof(self->buf); - memcpy(self->buf, buf, count); - self->len = count; - return count; -} - -/* main test body *************************************************************/ - -int main() { - struct myclass _obj = {0}; - lo_interface read_writer obj = lo_box_myclass_as_read_writer(&_obj); - test_assert(LO_CALL(obj, write, "Hello", 6) == 6); - char buf[6] = {0}; - test_assert(LO_CALL(obj, read, buf, 3) == 3); - test_assert(memcmp(buf, "Hel\0\0\0", 6) == 0); - return 0; -} -- cgit v1.2.3-2-g168b