From a3ece09e665bcb0169f6b666d1ff27418060c003 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 29 Apr 2024 22:44:02 +0200 Subject: [PATCH] Add new tests for exception and bitsets --- tests/except-bitset.c | 75 +++++++++++++++++++++++++++++++++++++++++++ tests/except-string.c | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 tests/except-bitset.c diff --git a/tests/except-bitset.c b/tests/except-bitset.c new file mode 100644 index 00000000..7e1efc4d --- /dev/null +++ b/tests/except-bitset.c @@ -0,0 +1,75 @@ +/* + * Test that the bitset module properly support exceptions + * + * Copyright (c) 2017-2024, Patrick Pelissier + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + 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 REGENTS 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 REGENTS AND 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. +*/ +#include "test-obj-except.h" +#include "m-string.h" +#include "m-bitset.h" + +M_TRY_DEF_ONCE() + +static void test1(unsigned n) +{ + FILE *f = m_core_fopen ("a-ebitset.dat", "wt"); + assert(f != NULL); + M_TRY(test1) { + M_LET(data, tmp, bitset_t) { + for(unsigned i = 0; i < 100*n; i++) { + bitset_push_back(data, (bool) (i % 2)); + } + bitset_set(tmp, data); + bitset_resize(tmp, 10000); + bitset_reserve(tmp, 20000); + bitset_push_at(tmp, 23, true); + M_LET( (tmp2, tmp), bitset_t) { + bitset_out_str(f, tmp2); + } + M_LET(str, string_t) { + bitset_get_str(str, tmp, false); + bool b = bitset_parse_str(tmp, string_get_cstr(str), NULL); + assert(b); + } + } + } M_CATCH(test1, 0) { + // Nothing to do + } + fclose(f); + + f = m_core_fopen ("a-ebitset.dat", "rt"); + assert(f != NULL); + M_TRY(test1) { + M_LET(data, bitset_t) { + bool b = bitset_in_str(data, f); + (void)b; + } + } M_CATCH(test1, 0) { + // Nothing to do + } + fclose(f); +} + +int main(void) +{ + do_test1(test1); + exit(0); +} diff --git a/tests/except-string.c b/tests/except-string.c index 8e8832aa..1caa7421 100644 --- a/tests/except-string.c +++ b/tests/except-string.c @@ -1,5 +1,5 @@ /* - * Test that the list module properly support exceptions + * Test that the string module properly support exceptions * * Copyright (c) 2017-2024, Patrick Pelissier * All rights reserved.