Skip to content

Commit

Permalink
Fix MSVC issues with compound literals
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesLorenz committed Oct 21, 2023
1 parent 272283c commit 68cb02d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion include/rtosc/pretty-format.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @file pretty-format.h
* Header for pretty printer and scanner
*
* @test pretty-format.c
* @test pretty-format.cpp
*/

#ifndef RTOSC_PRETTY_FORMAT
Expand Down
49 changes: 27 additions & 22 deletions test/pretty-format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ void check(const char* arg_val_str, const rtosc_print_options* opt,
check_alt(arg_val_str, opt, tc_base, line, NULL);
}

rtosc_print_options make_print_options(
bool lossless, // will add hex notation behind floats
int floating_point_precision,
const char* sep, // separator for multiple argument values
int linelength,
int compress_ranges)
{
rtosc_print_options res;
res.lossless = lossless; //!< will add hex notation behind floats
res.floating_point_precision = floating_point_precision;
res.sep = sep; //!< separator for multiple argument values
res.linelength = linelength;
res.compress_ranges = compress_ranges;
return res;
}

void scan_and_print_single()
{
/*
Expand All @@ -90,8 +106,7 @@ void scan_and_print_single()
/*
timestamps
*/
rtosc_print_options lossy = ((rtosc_print_options) { false, 3, " ", 80,
true });
auto lossy = make_print_options(false, 3, " ", 80, true);
check_alt("1970-01-02 00:00:00", NULL, "one day after the epoch", __LINE__,
"1970-01-02");
check("2016-11-16 19:44:06", NULL, "a timestamp", __LINE__);
Expand All @@ -114,8 +129,7 @@ void scan_and_print_single()
doubles
*/
// saving this as a float will lose precision
rtosc_print_options prec6 = ((rtosc_print_options) { true, 6, " ", 80,
true });
auto prec6 = make_print_options(true, 6, " ", 80, true);
check_alt("1234567890.098700d", &prec6,
"a double that would not fit into a float", __LINE__,
"1234567890.098700d (0x1.26580b486511ap+30)");
Expand All @@ -129,8 +143,7 @@ void scan_and_print_single()
// rtosc *must* discard the first number and read the lossless one
check_alt("0.0f (-0x1.8p+0)", NULL, "the zero float (0.0f)", __LINE__,
"-1.50 (-0x1.8p+0)");
rtosc_print_options prec0 = ((rtosc_print_options) { true, 0, " ", 80,
true });
auto prec0 = make_print_options(true, 0, " ", 80, true);
// this float may not lose its period (otherwise,
// it would be read as an int!)
check_alt("1.", &prec0, "a float with zero precision", __LINE__,
Expand Down Expand Up @@ -184,8 +197,7 @@ void scan_and_print_single()
/*
identifiers aka symbols
*/
rtosc_print_options shortline_9 = ((rtosc_print_options) { true, 3, " ", 9,
true });
auto shortline_9 = make_print_options(true, 3, " ", 9, true);
check("an_identifier_42", NULL, "a simple identifier", __LINE__);
check("_", NULL, "the identifier \"_\"", __LINE__);
check("truely falseeee infinite nilpferd immediatelyly nowhere MIDINOTE",
Expand Down Expand Up @@ -221,8 +233,7 @@ void scan_and_print_single()
/*
linebreaks
*/
rtosc_print_options shortline = ((rtosc_print_options) { true, 3, " ", 10,
true });
auto shortline = make_print_options(true, 3, " ", 10, true);
check_alt("\"0123456789012345678\"", &shortline,
"string exceeding line length", __LINE__,
"\"0123456\"\\\n"
Expand Down Expand Up @@ -254,8 +265,7 @@ void arrays()
check("[0 1 2]", NULL, "simple integer array", __LINE__);
check("[]", NULL, "empty array", __LINE__);

rtosc_print_options shortline = ((rtosc_print_options)
{ true, 3, " ", 12, true });
auto shortline = make_print_options(true, 3, " ", 12, true);
// TODO: arrays with strings print newline positions wrong
// write *one* generic function rtosc_insert_newlines?
check("[\"123\" \"45\" \"\"\\\n \"6\"]", &shortline,
Expand All @@ -274,10 +284,8 @@ void arrays()

void ranges()
{
rtosc_print_options uncompressed = ((rtosc_print_options) { false, 3, " ",
10, false });
rtosc_print_options simplefloats = ((rtosc_print_options) { false, 2, " ",
80, true });
auto uncompressed = make_print_options(false, 3, " ", 10, false);
auto simplefloats = make_print_options(false, 2, " ", 80, true);

/*
with delta
Expand Down Expand Up @@ -384,10 +392,8 @@ void scan_ranges()
/*
no range conversion
*/
rtosc_print_options uncompressed = ((rtosc_print_options) { false, 3, " ",
80, false });
rtosc_print_options simplefloats = ((rtosc_print_options) { false, 2, " ",
80, true });
auto uncompressed = make_print_options(false, 3, " ", 80, false);
auto simplefloats = make_print_options(false, 2, " ", 80, true);
check("0 1 2 3", NULL, "too less args for range conversion", __LINE__);
check("0.00 1.00 2.00 3.00 4.00", &simplefloats,
"wrong type for range conversion", __LINE__);
Expand Down Expand Up @@ -487,8 +493,7 @@ void messages()
size_t len = 128;
char printed[len];
memset(printed, 0x7f, len); /* init with rubbish */
rtosc_print_options shortline = ((rtosc_print_options) { true, 3, " ", 7,
true });
auto shortline = make_print_options(true, 3, " ", 7, true);
size_t written = rtosc_print_message("/noteOn", scanned, num,
printed, len, &shortline, 0);

Expand Down

0 comments on commit 68cb02d

Please sign in to comment.