Index: head/etc/mtree/BSD.tests.dist =================================================================== --- head/etc/mtree/BSD.tests.dist (revision 316556) +++ head/etc/mtree/BSD.tests.dist (revision 316557) @@ -1,710 +1,712 @@ # $FreeBSD$ # # Please see the file src/etc/mtree/README before making changes to this file. # /set type=dir uname=root gname=wheel mode=0755 . bin cat .. date .. dd .. expr .. ls .. mv .. pax .. pkill .. pwait .. sh builtins .. errors .. execution .. expansion .. parameters .. parser .. set-e .. .. sleep .. test .. .. cddl lib .. sbin .. usr.bin .. usr.sbin dtrace common aggs .. arithmetic .. arrays .. assocs .. begin .. bitfields .. buffering .. builtinvar .. cg .. clauses .. cpc .. decls .. drops .. dtraceUtil .. end .. enum .. error .. exit .. fbtprovider .. funcs .. grammar .. include .. inline .. io .. ip .. java_api .. json .. lexer .. llquantize .. mdb .. mib .. misc .. multiaggs .. offsetof .. operators .. pid .. plockstat .. pointers .. pragma .. predicates .. preprocessor .. print .. printa .. printf .. privs .. probes .. proc .. profile-n .. providers .. raise .. rates .. safety .. scalars .. sched .. scripting .. sdt .. sizeof .. speculation .. stability .. stack .. stackdepth .. stop .. strlen .. strtoll .. struct .. sugar .. syscall .. sysevent .. tick-n .. trace .. tracemem .. translators .. typedef .. types .. uctf .. union .. usdt .. ustack .. vars .. version .. .. .. zfsd .. .. .. etc rc.d .. .. games .. gnu lib .. usr.bin diff .. .. .. lib atf libatf-c detail .. .. libatf-c++ detail .. .. test-programs .. .. libarchive .. libc c063 .. db .. gen execve .. posix_spawn .. .. hash data .. .. iconv .. inet .. locale .. net getaddrinfo data .. .. .. nss .. regex data .. .. resolv .. rpc .. ssp .. setjmp .. stdio .. stdlib .. string .. sys .. time .. tls dso .. .. termios .. ttyio .. .. libcam .. libcasper services cap_dns .. cap_grp .. cap_pwd .. cap_sysctl .. .. .. libcrypt .. libdevdctl .. libkvm .. libmp .. libnv .. libproc .. librt .. + libsbuf + .. libthr dlopen .. .. libutil .. libxo .. msun .. .. libexec atf atf-check .. atf-sh .. .. rtld-elf .. .. sbin dhclient .. devd .. growfs .. ifconfig .. mdconfig .. .. secure lib .. libexec .. usr.bin .. usr.sbin .. .. share examples tests atf .. plain .. .. .. .. sys acl .. aio .. fifo .. file .. fs tmpfs .. .. geom class concat .. eli .. gate .. gpt .. mirror .. nop .. raid3 .. shsec .. stripe .. uzip etalon .. .. .. .. kern acct .. execve .. pipe .. .. kqueue libkqueue .. .. mac bsdextended .. portacl .. .. mqueue .. netinet .. opencrypto .. pjdfstest chflags .. chmod .. chown .. ftruncate .. granular .. link .. mkdir .. mkfifo .. mknod .. open .. rename .. rmdir .. symlink .. truncate .. unlink .. .. posixshm .. sys .. vfs .. vm .. .. usr.bin apply .. basename .. bmake archives fmt_44bsd .. fmt_44bsd_mod .. fmt_oldbsd .. .. basic t0 .. t1 .. t2 .. t3 .. .. execution ellipsis .. empty .. joberr .. plus .. .. shell builtin .. meta .. path .. path_select .. replace .. select .. .. suffixes basic .. src_wild1 .. src_wild2 .. .. syntax directive-t0 .. enl .. funny-targets .. semi .. .. sysmk t0 2 1 .. .. mk .. .. t1 2 1 .. .. mk .. .. t2 2 1 .. .. mk .. .. .. variables modifier_M .. modifier_t .. opt_V .. t0 .. .. .. bsdcat .. calendar .. cmp .. cpio .. col .. comm .. cut .. diff .. dirname .. file2c .. grep .. gzip .. ident .. indent .. join .. jot .. lastcomm .. limits .. m4 .. mkimg .. ncal .. opensm .. pr .. printf .. sdiff .. sed regress.multitest.out .. .. soelim .. tail .. tar .. timeout .. tr .. truncate .. units .. uudecode .. uuencode .. uniq .. xargs .. xinstall .. xo .. yacc yacc .. .. .. usr.sbin chown .. etcupdate .. extattr .. fstyp .. makefs .. newsyslog .. nmtree .. pw .. rpcbind .. sa .. .. .. # vim: set expandtab ts=4 sw=4: Index: head/lib/libsbuf/Makefile =================================================================== --- head/lib/libsbuf/Makefile (revision 316556) +++ head/lib/libsbuf/Makefile (revision 316557) @@ -1,15 +1,19 @@ # $FreeBSD$ PACKAGE=lib${LIB} LIB= sbuf SHLIBDIR?= /lib SRCS= subr_prf.c subr_sbuf.c SHLIB_MAJOR = 6 SYMBOL_MAPS= ${.CURDIR}/Symbol.map VERSION_DEF= ${.CURDIR}/Version.def +.include + .PATH: ${SRCTOP}/sys/kern + +SUBDIR.${MK_TESTS}+= tests .include Index: head/lib/libsbuf/tests/Makefile =================================================================== --- head/lib/libsbuf/tests/Makefile (nonexistent) +++ head/lib/libsbuf/tests/Makefile (revision 316557) @@ -0,0 +1,11 @@ +# $FreeBSD$ + +ATF_TESTS_C+= sbuf_core_test +ATF_TESTS_C+= sbuf_stdio_test +ATF_TESTS_C+= sbuf_string_test + +LIBADD+= sbuf util + +WARNS?= 6 + +.include Property changes on: head/lib/libsbuf/tests/Makefile ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/lib/libsbuf/tests/sbuf_core_test.c =================================================================== --- head/lib/libsbuf/tests/sbuf_core_test.c (nonexistent) +++ head/lib/libsbuf/tests/sbuf_core_test.c (revision 316557) @@ -0,0 +1,211 @@ +/*- + * Copyright (c) 2017 Ngie Cooper + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "sbuf_test_common.h" + +static char test_string[] = "this is a test string"; +#define TEST_STRING_CHOP_COUNT 5 +_Static_assert(nitems(test_string) > TEST_STRING_CHOP_COUNT, + "test_string is too short"); + +ATF_TC_WITHOUT_HEAD(sbuf_clear_test); +ATF_TC_BODY(sbuf_clear_test, tc) +{ + struct sbuf *sb; + ssize_t buf_len; + pid_t child_proc; + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + ATF_REQUIRE_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed"); + + /* + * Cheat so we can get the contents of the buffer before calling + * sbuf_finish(3) below, making additional sbuf changes impossible. + */ + child_proc = atf_utils_fork(); + if (child_proc == 0) { + sbuf_putbuf(sb); + exit(0); + } + atf_utils_wait(child_proc, 0, test_string, ""); + + sbuf_clear(sb); + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + buf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(buf_len == 0, "sbuf_len (%zd) != 0", buf_len); + ATF_REQUIRE_STREQ_MSG(sbuf_data(sb), "", + "sbuf (\"%s\") was not empty", sbuf_data(sb)); + + sbuf_delete(sb); +} + +ATF_TC_WITHOUT_HEAD(sbuf_done_and_sbuf_finish_test); +ATF_TC_BODY(sbuf_done_and_sbuf_finish_test, tc) +{ + struct sbuf *sb; + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + ATF_CHECK(sbuf_done(sb) == 0); + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + ATF_CHECK(sbuf_done(sb) != 0); + + sbuf_delete(sb); +} + +ATF_TC_WITHOUT_HEAD(sbuf_len_test); +ATF_TC_BODY(sbuf_len_test, tc) +{ + struct sbuf *sb; + ssize_t buf_len, test_string_len; + int i; + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + test_string_len = strlen(test_string); + for (i = 0; i < 20; i++) { + buf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(buf_len == (ssize_t)(i * test_string_len), + "sbuf_len (%zd) != %zu", buf_len, i * test_string_len); + ATF_REQUIRE_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed"); + } + +#ifdef HAVE_SBUF_SET_FLAGS + sbuf_set_flags(sb, SBUF_INCLUDENUL); + ATF_REQUIRE_MSG((ssize_t)(i * test_string_len + 1) == sbuf_len(sb), + "sbuf_len(..) didn't report the NUL char"); +#endif + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + sbuf_delete(sb); +} + +ATF_TC_WITHOUT_HEAD(sbuf_setpos_test); +ATF_TC_BODY(sbuf_setpos_test, tc) +{ + struct sbuf *sb; + size_t test_string_chopped_len, test_string_len; + ssize_t buf_len; + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + /* + * An obvious sanity check -- if sbuf_len(..) lies, these invariants + * are impossible to test. + */ + ATF_REQUIRE(sbuf_len(sb) == 0); + + ATF_CHECK(sbuf_setpos(sb, -1) == -1); + ATF_CHECK(sbuf_setpos(sb, 0) == 0); + ATF_CHECK(sbuf_setpos(sb, 1) == -1); + + ATF_REQUIRE_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed"); + + buf_len = sbuf_len(sb); + test_string_len = strlen(test_string); + test_string_chopped_len = test_string_len - TEST_STRING_CHOP_COUNT; + ATF_REQUIRE_MSG(buf_len == (ssize_t)test_string_len, + "sbuf length (%zd) != test_string length (%zu)", buf_len, + test_string_len); + + /* Out of bounds (under length) */ + ATF_CHECK(sbuf_setpos(sb, -1) == -1); + /* + * Out of bounds (over length) + * + * Note: SBUF_INCLUDENUL not set, so take '\0' into account. + */ + ATF_CHECK(sbuf_setpos(sb, test_string_len + 2) == -1); + /* Within bounds */ + ATF_CHECK(sbuf_setpos(sb, test_string_chopped_len) == 0); + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + buf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(buf_len == (ssize_t)test_string_chopped_len, + "sbuf_setpos didn't truncate string as expected"); + ATF_REQUIRE_MSG(strncmp(sbuf_data(sb), test_string, buf_len) == 0, + "sbuf (\"%s\") != test string (\"%s\") for [0,%zd]", sbuf_data(sb), + test_string, buf_len); + + sbuf_delete(sb); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, sbuf_clear_test); + ATF_TP_ADD_TC(tp, sbuf_done_and_sbuf_finish_test); + ATF_TP_ADD_TC(tp, sbuf_len_test); +#if 0 + /* TODO */ +#ifdef HAVE_SBUF_CLEAR_FLAGS + ATF_TP_ADD_TC(tp, sbuf_clear_flags_test); +#endif +#ifdef HAVE_SBUF_GET_FLAGS + ATF_TP_ADD_TC(tp, sbuf_get_flags_test); +#endif + ATF_TP_ADD_TC(tp, sbuf_new_positive_test); + ATF_TP_ADD_TC(tp, sbuf_new_negative_test); +#ifdef HAVE_SBUF_SET_FLAGS + ATF_TP_ADD_TC(tp, sbuf_set_flags_test); +#endif +#endif + ATF_TP_ADD_TC(tp, sbuf_setpos_test); + + return (atf_no_error()); +} Property changes on: head/lib/libsbuf/tests/sbuf_core_test.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/lib/libsbuf/tests/sbuf_stdio_test.c =================================================================== --- head/lib/libsbuf/tests/sbuf_stdio_test.c (nonexistent) +++ head/lib/libsbuf/tests/sbuf_stdio_test.c (revision 316557) @@ -0,0 +1,160 @@ +/*- + * Copyright (c) 2017 Ngie Cooper + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "sbuf_test_common.h" + +static char test_string[] = "this is a test string"; + +#define MESSAGE_FORMAT "message: %s\n" +#define MESSAGE_SEPARATOR ';' + +static int +sbuf_vprintf_helper(struct sbuf *sb, const char * restrict format, ...) +{ + va_list ap; + int rc; + + va_start(ap, format); + + rc = sbuf_vprintf(sb, format, ap); + + va_end(ap); + + return (rc); +} + +ATF_TC_WITHOUT_HEAD(sbuf_printf_test); +ATF_TC_BODY(sbuf_printf_test, tc) +{ + struct sbuf *sb; + char *test_string_tmp; + + asprintf(&test_string_tmp, "%s%c" MESSAGE_FORMAT, + test_string, MESSAGE_SEPARATOR, test_string); + ATF_REQUIRE_MSG(test_string_tmp != NULL, "asprintf failed"); + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + ATF_REQUIRE_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed"); + ATF_REQUIRE_MSG(sbuf_putc(sb, MESSAGE_SEPARATOR) == 0, + "sbuf_putc failed"); + + ATF_REQUIRE_MSG(sbuf_printf(sb, MESSAGE_FORMAT, test_string) == 0, + "sbuf_printf failed"); + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + ATF_REQUIRE_STREQ_MSG(sbuf_data(sb), test_string_tmp, + "sbuf (\"%s\") != test string (\"%s\")", sbuf_data(sb), + test_string_tmp); + + sbuf_delete(sb); + + free(test_string_tmp); +} + +ATF_TC_WITHOUT_HEAD(sbuf_putbuf_test); +ATF_TC_BODY(sbuf_putbuf_test, tc) +{ + struct sbuf *sb; + pid_t child_proc; + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + ATF_REQUIRE_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed"); + + child_proc = atf_utils_fork(); + if (child_proc == 0) { + sbuf_putbuf(sb); + exit(0); + } + atf_utils_wait(child_proc, 0, test_string, ""); + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + sbuf_delete(sb); +} + +ATF_TC_WITHOUT_HEAD(sbuf_vprintf_test); +ATF_TC_BODY(sbuf_vprintf_test, tc) +{ + struct sbuf *sb; + char *test_string_tmp; + int rc; + + asprintf(&test_string_tmp, "%s%c" MESSAGE_FORMAT, + test_string, MESSAGE_SEPARATOR, test_string); + ATF_REQUIRE_MSG(test_string_tmp != NULL, "asprintf failed"); + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + ATF_REQUIRE_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed"); + ATF_REQUIRE_MSG(sbuf_putc(sb, MESSAGE_SEPARATOR) == 0, + "sbuf_putc failed"); + + rc = sbuf_vprintf_helper(sb, MESSAGE_FORMAT, test_string); + ATF_REQUIRE_MSG(rc == 0, "sbuf_vprintf failed"); + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + ATF_REQUIRE_STREQ_MSG(sbuf_data(sb), test_string_tmp, + "sbuf (\"%s\") != test string (\"%s\")", sbuf_data(sb), + test_string_tmp); + + sbuf_delete(sb); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, sbuf_printf_test); + ATF_TP_ADD_TC(tp, sbuf_putbuf_test); + ATF_TP_ADD_TC(tp, sbuf_vprintf_test); + + return (atf_no_error()); +} Property changes on: head/lib/libsbuf/tests/sbuf_stdio_test.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/lib/libsbuf/tests/sbuf_string_test.c =================================================================== --- head/lib/libsbuf/tests/sbuf_string_test.c (nonexistent) +++ head/lib/libsbuf/tests/sbuf_string_test.c (revision 316557) @@ -0,0 +1,288 @@ +/*- + * Copyright (c) 2017 Ngie Cooper + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "sbuf_test_common.h" + +static char test_string[] = "this is a test string"; +static char test_whitespace_string[] = " \f\n\r\t\v "; +static int test_buffer[] = { 0, 1, 2, 3, 4, 5, }; + +static void +check_buffers_equal(const void *sb_buf, const void *test_buf, size_t len) +{ + + if (memcmp(sb_buf, test_buf, len) != 0) { + printf("sbuf:\n"); + hexdump(sb_buf, len, NULL, 0), + printf("test_buf:\n"); + hexdump(test_buf, len, NULL, 0); + atf_tc_fail("contents of sbuf didn't match test_buf contents"); + } +} + +ATF_TC_WITHOUT_HEAD(sbuf_bcat_test); +ATF_TC_BODY(sbuf_bcat_test, tc) +{ + struct sbuf *sb; + int *test_buffer_tmp; + ssize_t test_sbuf_len; + + test_buffer_tmp = malloc(sizeof(test_buffer) * 2); + ATF_REQUIRE_MSG(test_buffer_tmp != NULL, "malloc failed"); + + memcpy(test_buffer_tmp, test_buffer, sizeof(test_buffer)); + memcpy(&test_buffer_tmp[nitems(test_buffer)], test_buffer, + sizeof(test_buffer)); + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + ATF_CHECK_MSG(sbuf_bcat(sb, test_buffer, sizeof(test_buffer)) == 0, + "sbuf_bcat failed"); + + test_sbuf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)sizeof(test_buffer), + "sbuf_len(..) => %zd (actual) != %zu (expected)", + test_sbuf_len, sizeof(test_buffer)); + + ATF_CHECK_MSG(sbuf_bcat(sb, test_buffer, sizeof(test_buffer)) == 0, + "sbuf_bcat failed"); + + test_sbuf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)(2 * sizeof(test_buffer)), + "sbuf_len(..) => %zd (actual) != %zu (expected)", + test_sbuf_len, 2 * sizeof(test_buffer)); + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + check_buffers_equal(sbuf_data(sb), test_buffer_tmp, + (size_t)test_sbuf_len); + + sbuf_delete(sb); + + free(test_buffer_tmp); +} + +ATF_TC_WITHOUT_HEAD(sbuf_bcpy_test); +ATF_TC_BODY(sbuf_bcpy_test, tc) +{ + struct sbuf *sb; + ssize_t test_sbuf_len; + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + ATF_CHECK_MSG(sbuf_bcpy(sb, test_buffer, sizeof(test_buffer)) == 0, + "sbuf_bcpy failed"); + + test_sbuf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)sizeof(test_buffer), + "sbuf_len(..) => %zd (actual) != %zu (expected)", + test_sbuf_len, sizeof(test_buffer)); + + ATF_CHECK_MSG(sbuf_bcpy(sb, test_buffer, sizeof(test_buffer)) == 0, + "sbuf_bcpy failed"); + + test_sbuf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)sizeof(test_buffer), + "sbuf_len(..) => %zd (actual) != %zu (expected)", + test_sbuf_len, sizeof(test_buffer)); + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + check_buffers_equal(sbuf_data(sb), test_buffer, (size_t)test_sbuf_len); + + sbuf_delete(sb); +} + +ATF_TC_WITHOUT_HEAD(sbuf_cat_test); +ATF_TC_BODY(sbuf_cat_test, tc) +{ + struct sbuf *sb; + char *test_string_tmp; + ssize_t test_sbuf_len; + + asprintf(&test_string_tmp, "%s%s", test_string, test_string); + ATF_REQUIRE_MSG(test_string_tmp != NULL, "asprintf failed"); + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + ATF_CHECK_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed"); + + test_sbuf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string), + "sbuf_len(..) => %zd (actual) != %zu (expected)", + test_sbuf_len, sizeof(test_string)); + + ATF_CHECK_MSG(sbuf_cat(sb, test_string) == 0, "sbuf_cat failed"); + + test_sbuf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string_tmp), + "sbuf_len(..) => %zd (actual) != %zu (expected)", + test_sbuf_len, strlen(test_string_tmp)); + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + ATF_REQUIRE_STREQ_MSG(sbuf_data(sb), test_string_tmp, + "sbuf (\"%s\") != test string (\"%s\")", sbuf_data(sb), + test_string_tmp); + + sbuf_delete(sb); + + free(test_string_tmp); +} + +ATF_TC_WITHOUT_HEAD(sbuf_cpy_test); +ATF_TC_BODY(sbuf_cpy_test, tc) +{ + struct sbuf *sb; + ssize_t test_sbuf_len; + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + ATF_CHECK_MSG(sbuf_cpy(sb, test_string) == 0, "sbuf_cpy failed"); + + test_sbuf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string), + "sbuf_len(..) => %zd (actual) != %zu (expected)", + test_sbuf_len, strlen(test_string)); + + ATF_CHECK_MSG(sbuf_cpy(sb, test_string) == 0, "sbuf_cpy failed"); + + test_sbuf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(test_sbuf_len == (ssize_t)strlen(test_string), + "sbuf_len(..) => %zd (actual) != %zu (expected)", + test_sbuf_len, strlen(test_string)); + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + ATF_REQUIRE_STREQ_MSG(sbuf_data(sb), test_string, + "sbuf (\"%s\") != test string (\"%s\")", sbuf_data(sb), + test_string); + + sbuf_delete(sb); +} + +ATF_TC_WITHOUT_HEAD(sbuf_putc_test); +ATF_TC_BODY(sbuf_putc_test, tc) +{ + struct sbuf *sb; + ssize_t test_sbuf_len; + size_t i; + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + for (i = 0; i <= strlen(test_string); i++) { /* Include the NUL */ + ATF_REQUIRE_MSG(sbuf_putc(sb, test_string[i]) == 0, + "sbuf_putc failed"); + + /* The best we can do until sbuf_finish(3) is called. */ + test_sbuf_len = sbuf_len(sb); + ATF_REQUIRE_MSG((ssize_t)(i + 1) == test_sbuf_len, + "sbuf_len(..) => %zd (actual) != %zu (expected)", + test_sbuf_len, i + 1); + } + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + ATF_REQUIRE_STREQ_MSG(sbuf_data(sb), test_string, + "sbuf (\"%s\") != test string (\"%s\")", sbuf_data(sb), + test_string); + + sbuf_delete(sb); +} + +ATF_TC_WITHOUT_HEAD(sbuf_trim_test); +ATF_TC_BODY(sbuf_trim_test, tc) +{ + struct sbuf *sb; + ssize_t exp_sbuf_len, test_sbuf_len; + + sb = sbuf_new_auto(); + ATF_REQUIRE_MSG(sb != NULL, "sbuf_new_auto failed: %s", + strerror(errno)); + + ATF_CHECK_MSG(sbuf_cpy(sb, test_string) == 0, "sbuf_cpy failed"); + ATF_CHECK_MSG(sbuf_cat(sb, test_whitespace_string) == 0, + "sbuf_cat failed"); + + /* The best we can do until sbuf_finish(3) is called. */ + exp_sbuf_len = (ssize_t)(strlen(test_string) + + strlen(test_whitespace_string)); + test_sbuf_len = sbuf_len(sb); + ATF_REQUIRE_MSG(exp_sbuf_len == test_sbuf_len, + "sbuf_len(..) => %zd (actual) != %zu (expected)", + test_sbuf_len, exp_sbuf_len); + + ATF_REQUIRE_MSG(sbuf_trim(sb) == 0, "sbuf_trim failed"); + + ATF_REQUIRE_MSG(sbuf_finish(sb) == 0, "sbuf_finish failed: %s", + strerror(errno)); + + ATF_REQUIRE_STREQ_MSG(sbuf_data(sb), test_string, + "sbuf (\"%s\") != test string (\"%s\") (trimmed)", sbuf_data(sb), + test_string); + + sbuf_delete(sb); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, sbuf_bcat_test); + ATF_TP_ADD_TC(tp, sbuf_bcpy_test); + ATF_TP_ADD_TC(tp, sbuf_cat_test); + ATF_TP_ADD_TC(tp, sbuf_cpy_test); + ATF_TP_ADD_TC(tp, sbuf_putc_test); + ATF_TP_ADD_TC(tp, sbuf_trim_test); + + return (atf_no_error()); +} Property changes on: head/lib/libsbuf/tests/sbuf_string_test.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/lib/libsbuf/tests/sbuf_test_common.h =================================================================== --- head/lib/libsbuf/tests/sbuf_test_common.h (nonexistent) +++ head/lib/libsbuf/tests/sbuf_test_common.h (revision 316557) @@ -0,0 +1,40 @@ +/*- + * Copyright (c) 2017 Ngie Cooper + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __LIBSBUF_TEST_COMMON_H__ +#define __LIBSBUF_TEST_COMMON_H__ + +#include + +#if __FreeBSD_version > 1100064 +#define HAVE_SBUF_GET_FLAGS +#define HAVE_SBUF_CLEAR_FLAGS +#define HAVE_SBUF_SET_FLAGS +#endif + +#endif Property changes on: head/lib/libsbuf/tests/sbuf_test_common.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property