1 /* $OpenBSD: ibuf_test.c,v 1.5 2023/12/29 16:02:29 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 21 #include <imsg.h> 22 #include <limits.h> 23 #include <stdint.h> 24 #include <stdio.h> 25 26 int 27 test_ibuf_open(void) 28 { 29 struct ibuf *buf; 30 31 if ((buf = ibuf_open(1)) == NULL) 32 return 1; 33 34 ibuf_free(buf); 35 return 0; 36 } 37 38 int 39 test_ibuf_dynamic(void) 40 { 41 struct ibuf *buf; 42 43 if (ibuf_dynamic(100, 0) != NULL) 44 return 1; 45 46 if ((buf = ibuf_dynamic(10, SIZE_MAX)) == NULL) 47 return 1; 48 49 ibuf_free(buf); 50 return 0; 51 } 52 53 int 54 test_ibuf_reserve(void) 55 { 56 struct ibuf *buf; 57 int ret; 58 59 if ((buf = ibuf_dynamic(10, SIZE_MAX)) == NULL) { 60 return 1; 61 } 62 63 if (ibuf_reserve(buf, SIZE_MAX) != NULL) { 64 ibuf_free(buf); 65 return 1; 66 } 67 68 if (ibuf_reserve(buf, 10) == NULL) { 69 ibuf_free(buf); 70 return 1; 71 } 72 73 ret = (ibuf_reserve(buf, SIZE_MAX) != NULL); 74 75 ibuf_free(buf); 76 return ret; 77 } 78 79 int 80 test_ibuf_seek(void) 81 { 82 struct ibuf *buf; 83 int ret; 84 85 if ((buf = ibuf_open(10)) == NULL) 86 return 1; 87 88 ret = (ibuf_seek(buf, 1, SIZE_MAX) != NULL); 89 90 ibuf_free(buf); 91 return ret; 92 } 93 94 int 95 main(void) 96 { 97 extern char *__progname; 98 99 int ret = 0; 100 101 if (test_ibuf_open() != 0) { 102 printf("FAILED: test_ibuf_open\n"); 103 ret = 1; 104 } else 105 printf("SUCCESS: test_ibuf_open\n"); 106 107 if (test_ibuf_dynamic() != 0) { 108 printf("FAILED: test_ibuf_dynamic\n"); 109 ret = 1; 110 } else 111 printf("SUCCESS: test_ibuf_dynamic\n"); 112 113 if (test_ibuf_reserve() != 0) { 114 printf("FAILED: test_ibuf_reserve\n"); 115 ret = 1; 116 } else 117 printf("SUCCESS: test_ibuf_reserve\n"); 118 119 if (test_ibuf_seek() != 0) { 120 printf("FAILED: test_ibuf_seek\n"); 121 ret = 1; 122 } else 123 printf("SUCCESS: test_ibuf_seek\n"); 124 125 if (ret != 0) { 126 printf("FAILED: %s\n", __progname); 127 return 1; 128 } 129 130 return 0; 131 } 132