From e656b220d7f2c0a3eb7d9c0426dc8a46132c5336 Mon Sep 17 00:00:00 2001 From: Charlie Tytler Date: Thu, 16 Apr 2020 19:49:52 -0400 Subject: [PATCH] Add (failing) unit tests which reproduce issue #6 --- Sources/Test/StreamdeckContextTest.cpp | 9 ++++++++- Sources/Test/StringUtilitiesTest.cpp | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Sources/Test/StreamdeckContextTest.cpp b/Sources/Test/StreamdeckContextTest.cpp index e41e67f5..1597dfc0 100644 --- a/Sources/Test/StreamdeckContextTest.cpp +++ b/Sources/Test/StreamdeckContextTest.cpp @@ -292,7 +292,6 @@ TEST_F(StreamdeckContextComparisonTestFixture, dcs_id_float_compare_to_alphanume EXPECT_EQ(esd_connection_manager.state_, 0); } TEST_F(StreamdeckContextComparisonTestFixture, dcs_id_float_compare_to_empty) { - // Send game state as empty -- should treat as string and not try comparison. const std::string mock_dcs_message = "header*123="; mock_dcs.DcsSend(mock_dcs_message); @@ -300,6 +299,14 @@ TEST_F(StreamdeckContextComparisonTestFixture, dcs_id_float_compare_to_empty) { context_with_greater_than.updateContextState(&dcs_interface, &esd_connection_manager); EXPECT_EQ(esd_connection_manager.state_, 0); } +TEST_F(StreamdeckContextComparisonTestFixture, dcs_id_float_compare_to_string_of_spaces) { + // Send game state value as string of spaces -- should treat as (non-numeric) string and not try comparison. + const std::string mock_dcs_message = "header*123= "; + mock_dcs.DcsSend(mock_dcs_message); + dcs_interface.update_dcs_state(); + context_with_greater_than.updateContextState(&dcs_interface, &esd_connection_manager); + EXPECT_EQ(esd_connection_manager.state_, 0); +} TEST_F(StreamdeckContextComparisonTestFixture, dcs_id_float_compare_to_dcs_id_float) { // Send DCS ID as a float -- should not read update. const std::string mock_dcs_message = "header*123.0=2.0"; diff --git a/Sources/Test/StringUtilitiesTest.cpp b/Sources/Test/StringUtilitiesTest.cpp index 05280f79..ca4a2d9a 100644 --- a/Sources/Test/StringUtilitiesTest.cpp +++ b/Sources/Test/StringUtilitiesTest.cpp @@ -30,6 +30,11 @@ TEST(StringUtilitiesTest, is_integer_with_trailing_spaces) { EXPECT_EQ(std::stoi("0 "), 0); } +TEST(StringUtilitiesTest, is_integer_with_only_spaces) { + EXPECT_FALSE(is_integer(" ")); + EXPECT_FALSE(is_integer(" ")); +} + TEST(StringUtilitiesTest, is_integer_with_alpha_chars) { EXPECT_FALSE(is_integer("25a")); EXPECT_FALSE(is_integer("b-25")); @@ -67,6 +72,11 @@ TEST(StringUtilitiesTest, is_number_with_trailing_spaces) { EXPECT_EQ(std::stod("0 "), 0); } +TEST(StringUtilitiesTest, is_number_with_only_spaces) { + EXPECT_FALSE(is_number(" ")); + EXPECT_FALSE(is_number(" ")); +} + TEST(StringUtilitiesTest, is_number_with_alpha_chars) { EXPECT_FALSE(is_number("25a")); EXPECT_FALSE(is_number("b-25"));