diff --git a/src/core_test/codec/common_code.cc b/src/core_test/codec/common_code.cc index 68afc8a..c7032b0 100644 --- a/src/core_test/codec/common_code.cc +++ b/src/core_test/codec/common_code.cc @@ -36,9 +36,8 @@ TEST(CommonCode, basic) { EXPECT_EQ(CommonCode::unsafe_create(TEST_MIRROR_C2).to_horizontal_mirror(), TEST_MIRROR_C2_HM); #ifndef KLSK_NDEBUG - std::ostringstream out; - out << CommonCode::unsafe_create(TEST_C_CODE); // ostream capture - EXPECT_EQ(out.str(), TEST_C_CODE_STR); + EXPECT_OSTREAM(CommonCode::unsafe_create(0), "000000000"); + EXPECT_OSTREAM(CommonCode::unsafe_create(TEST_C_CODE), TEST_C_CODE_STR); #endif } diff --git a/src/core_test/codec/helper/codec.h b/src/core_test/codec/helper/codec.h index 7d8182a..cbd42d2 100644 --- a/src/core_test/codec/helper/codec.h +++ b/src/core_test/codec/helper/codec.h @@ -17,6 +17,18 @@ std::vector all_common_codes(); // ----------------------------------------------------------------------------------------- // +/// Capture ostream output as string. +template +std::string ostream_capture(T obj) { + std::ostringstream out; + out << obj; // ostream capture + return out.str(); +} + +#define EXPECT_OSTREAM(obj, expect) EXPECT_EQ(ostream_capture(obj), expect) + +// ----------------------------------------------------------------------------------------- // + /// Spawn all valid RawCodes in parallel. void raw_code_parallel(std::function)> &&func); diff --git a/src/core_test/codec/raw_code.cc b/src/core_test/codec/raw_code.cc index 4518658..554d90e 100644 --- a/src/core_test/codec/raw_code.cc +++ b/src/core_test/codec/raw_code.cc @@ -31,9 +31,10 @@ TEST(RawCode, basic) { EXPECT_EQ(RawCode::unsafe_create(TEST_MIRROR_R2).to_horizontal_mirror(), TEST_MIRROR_R2_HM); #ifndef KLSK_NDEBUG - std::ostringstream out; - out << RawCode::unsafe_create(TEST_R_CODE); // ostream capture - EXPECT_EQ(out.str(), "603EDF5CAFFF5E2\n| @ + |\n+ + + +\n| ~ + |\n+ * * +\n* . . *\n"); + EXPECT_OSTREAM(RawCode::unsafe_create(0x3F03C), + "00000000003F03C\n@ + . .\n+ + . .\n. . . .\n. . . .\n. . . .\n"); + EXPECT_OSTREAM(RawCode::unsafe_create(TEST_R_CODE), + "603EDF5CAFFF5E2\n| @ + |\n+ + + +\n| ~ + |\n+ * * +\n* . . *\n"); #endif } diff --git a/src/core_test/codec/short_code.cc b/src/core_test/codec/short_code.cc index c587ea9..8577034 100644 --- a/src/core_test/codec/short_code.cc +++ b/src/core_test/codec/short_code.cc @@ -52,9 +52,8 @@ TEST(ShortCode, basic) { EXPECT_EQ(sum, SHORT_CODE_LIMIT); #ifndef KLSK_NDEBUG - std::ostringstream out; - out << ShortCode::unsafe_create(TEST_S_CODE); // ostream capture - EXPECT_EQ(out.str(), TEST_S_CODE_STR); + EXPECT_OSTREAM(ShortCode::unsafe_create(0), "11111"); + EXPECT_OSTREAM(ShortCode::unsafe_create(TEST_S_CODE), TEST_S_CODE_STR); #endif }