From daeaa242b82384b96194df32ffd412bd64220a95 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 13 Jun 2020 11:21:33 +0200 Subject: [PATCH] Add new types to be used for M_LET: * m_serial_bin_write_t * m_serial_bin_read_t --- m-serial-bin.h | 11 +++++++++++ tests/test-mserial-bin.c | 18 +++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/m-serial-bin.h b/m-serial-bin.h index 8d56eeb0..f0dc1e1f 100644 --- a/m-serial-bin.h +++ b/m-serial-bin.h @@ -263,6 +263,12 @@ static inline void m_serial_bin_write_clear(m_serial_write_t serial) } +/* Define a synonym of m_serial_read_t to the BIN serializer with its proper OPLIST */ +typedef m_serial_write_t m_serial_bin_write_t; +#define M_OPL_m_serial_bin_write_t() \ + (INIT_WITH(m_serial_bin_write_init), CLEAR(m_serial_bin_write_clear), TYPE(m_serial_bin_write_t) ) + + /* Read from the stream 'serial' a boolean. Set '*b' with the boolean value if succeeds Return M_SERIAL_OK_DONE if it succeeds, M_SERIAL_FAIL otherwise */ @@ -493,4 +499,9 @@ static inline void m_serial_bin_read_clear(m_serial_read_t serial) (void) serial; // Nothing to do } +/* Define a synonym of m_serial_read_t to the BIN serializer with its proper OPLIST */ +typedef m_serial_read_t m_serial_bin_read_t; +#define M_OPL_m_serial_bin_read_t() \ + (INIT_WITH(m_serial_bin_read_init), CLEAR(m_serial_bin_read_clear), TYPE(m_serial_bin_read_t) ) + #endif diff --git a/tests/test-mserial-bin.c b/tests/test-mserial-bin.c index ecc2f892..4d5890fc 100644 --- a/tests/test-mserial-bin.c +++ b/tests/test-mserial-bin.c @@ -71,18 +71,18 @@ static void test_out_empty(void) FILE *f = fopen ("a-mbin.dat", "wt"); if (!f) abort(); - m_serial_bin_write_init(out, f); - ret = my2_out_serial(out, el1); - assert (ret == M_SERIAL_OK_DONE); - m_serial_bin_write_clear(out); + M_LET( (serial, f), m_serial_bin_write_t) { + ret = my2_out_serial(out, el1); + assert (ret == M_SERIAL_OK_DONE); + } fclose(f); f = fopen ("a-mbin.dat", "rt"); if (!f) abort(); - m_serial_bin_read_init(in, f); - ret = my2_in_serial(el2, in); - assert (ret == M_SERIAL_OK_DONE); - m_serial_bin_read_clear(in); + M_LET( (serial, f), m_serial_bin_read_t) { + ret = my2_in_serial(el2, in); + assert (ret == M_SERIAL_OK_DONE); + } fclose(f); assert (my2_equal_p (el1, el2)); @@ -142,7 +142,7 @@ static void test_out_fill(void) int main(void) { - //test_out_empty(); + test_out_empty(); test_out_fill(); exit(0); }