1 /* $OpenBSD: ibuf_test.c,v 1.4 2023/06/19 17:22:46 claudio Exp $ */ 2 /* 3 * Copyright (c) Tobias Stoeckmann <tobias@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <sys/queue.h> 19 #include <sys/types.h> 20 #include <sys/uio.h> 21 22 #include <imsg.h> 23 #include <limits.h> 24 #include <stdint.h> 25 #include <stdio.h> 26 27 int 28 test_ibuf_open(void) 29 { 30 struct ibuf *buf; 31 32 if ((buf = ibuf_open(1)) == NULL) 33 return 1; 34 35 ibuf_free(buf); 36 return 0; 37 } 38 39 int 40 test_ibuf_dynamic(void) 41 { 42 struct ibuf *buf; 43 44 if (ibuf_dynamic(100, 0) != NULL) 45 return 1; 46 47 if ((buf = ibuf_dynamic(10, SIZE_MAX)) == NULL) 48 return 1; 49 50 ibuf_free(buf); 51 return 0; 52 } 53 54 int 55 test_ibuf_reserve(void) 56 { 57 struct ibuf *buf; 58 int ret; 59 60 if ((buf = ibuf_dynamic(10, SIZE_MAX)) == NULL) { 61 return 1; 62 } 63 64 if (ibuf_reserve(buf, SIZE_MAX) != NULL) { 65 ibuf_free(buf); 66 return 1; 67 } 68 69 if (ibuf_reserve(buf, 10) == NULL) { 70 ibuf_free(buf); 71 return 1; 72 } 73 74 ret = (ibuf_reserve(buf, SIZE_MAX) != NULL); 75 76 ibuf_free(buf); 77 return ret; 78 } 79 80 int 81 test_ibuf_seek(void) 82 { 83 struct ibuf *buf; 84 int ret; 85 86 if ((buf = ibuf_open(10)) == NULL) 87 return 1; 88 89 ret = (ibuf_seek(buf, 1, SIZE_MAX) != NULL); 90 91 ibuf_free(buf); 92 return ret; 93 } 94 95 int 96 main(void) 97 { 98 extern char *__progname; 99 100 int ret = 0; 101 102 if (test_ibuf_open() != 0) { 103 printf("FAILED: test_ibuf_open\n"); 104 ret = 1; 105 } else 106 printf("SUCCESS: test_ibuf_open\n"); 107 108 if (test_ibuf_dynamic() != 0) { 109 printf("FAILED: test_ibuf_dynamic\n"); 110 ret = 1; 111 } else 112 printf("SUCCESS: test_ibuf_dynamic\n"); 113 114 if (test_ibuf_reserve() != 0) { 115 printf("FAILED: test_ibuf_reserve\n"); 116 ret = 1; 117 } else 118 printf("SUCCESS: test_ibuf_reserve\n"); 119 120 if (test_ibuf_seek() != 0) { 121 printf("FAILED: test_ibuf_seek\n"); 122 ret = 1; 123 } else 124 printf("SUCCESS: test_ibuf_seek\n"); 125 126 if (ret != 0) { 127 printf("FAILED: %s\n", __progname); 128 return 1; 129 } 130 131 return 0; 132 } 133