Add proper support for exception for DEQUE
This commit is contained in:
1 parent
0f883d2ecf
commit
5c36e045ff
3 files changed
+125
-24
No files matched your search
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Test that the deque 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-deque.h"
|
||||
#include "m-string.h"
|
||||
|
||||
M_TRY_DEF_ONCE()
|
||||
|
||||
DEQUE_DEF(list_obj, test_obj_except__t, TEST_OBJ_EXCEPT_OPLIST)
|
||||
#define M_OPL_list_obj_t() LIST_OPLIST(list_obj, TEST_OBJ_EXCEPT_OPLIST)
|
||||
|
||||
static void test1(unsigned n)
|
||||
{
|
||||
FILE *f = m_core_fopen ("a-edeque.dat", "wt");
|
||||
assert(f != NULL);
|
||||
M_TRY(test1) {
|
||||
M_LET(obj, test_obj_except__t)
|
||||
M_LET(list, tmp, list_obj_t) {
|
||||
for(unsigned i = 0; i < n; i++) {
|
||||
test_obj_except__set_ui(obj, i);
|
||||
list_obj_push_back(list, obj);
|
||||
}
|
||||
list_obj_set(tmp, list);
|
||||
M_LET( (tmp2, tmp), list_obj_t) {
|
||||
list_obj_out_str(f, tmp2);
|
||||
}
|
||||
list_obj_push_back_new(tmp);
|
||||
M_LET(str, string_t) {
|
||||
list_obj_get_str(str, tmp, false);
|
||||
bool b = list_obj_parse_str(list, string_get_cstr(str), NULL);
|
||||
assert(b);
|
||||
}
|
||||
list_obj_emplace_back_ui(list, 345);
|
||||
list_obj_emplace_back_str(list, "345");
|
||||
}
|
||||
} M_CATCH(test1, 0) {
|
||||
// Nothing to do
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
f = m_core_fopen ("a-edeque.dat", "rt");
|
||||
assert(f != NULL);
|
||||
M_TRY(test1) {
|
||||
M_LET(obj, test_obj_except__t)
|
||||
M_LET(list, tmp, list_obj_t) {
|
||||
bool b = list_obj_in_str(list, f);
|
||||
(void)b;
|
||||
}
|
||||
} M_CATCH(test1, 0) {
|
||||
// Nothing to do
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void test3(unsigned n)
|
||||
{
|
||||
M_TRY(test1) {
|
||||
M_LET(obj, test_obj_except__t)
|
||||
M_LET(list, tmp, list_obj_t) {
|
||||
for(unsigned i = 0; i < n; i++) {
|
||||
test_obj_except__set_ui(obj, i);
|
||||
list_obj_push_front(list, obj);
|
||||
}
|
||||
list_obj_push_front_new(list);
|
||||
list_obj_emplace_front_ui(list, 345);
|
||||
list_obj_emplace_front_str(list, "345");
|
||||
}
|
||||
} M_CATCH(test1, 0) {
|
||||
// Nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
do_test1(test1);
|
||||
do_test1(test3);
|
||||
exit(0);
|
||||
}
|
||||
@@ -137,15 +137,19 @@ static inline void test_obj_except__set_ui(test_obj_except__t d, unsigned int v)
|
||||
|
||||
static inline void test_obj_except__init_set_ui(test_obj_except__t d, unsigned int v)
|
||||
{
|
||||
test_obj_except_trigger();
|
||||
// test_obj_except_trigger(); is already triggered by test_obj_except__init
|
||||
test_obj_except__init(d);
|
||||
// Don't trigger exception for test_obj_except__set_ui now
|
||||
test_obj_except__trigger_exception++;
|
||||
test_obj_except__set_ui(d, v);
|
||||
}
|
||||
|
||||
static inline void test_obj_except__init_set_str(test_obj_except__t d, const char v[])
|
||||
{
|
||||
test_obj_except_trigger();
|
||||
// test_obj_except_trigger(); is already triggered by test_obj_except__init
|
||||
test_obj_except__init(d);
|
||||
// Don't trigger exception for test_obj_except__set_ui now
|
||||
test_obj_except__trigger_exception++;
|
||||
test_obj_except__set_ui(d, (unsigned int) atoi(v) );
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user