-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BroadcastTime string to rate quarters error handling (#716)
Returns zero from string_to_rate_quarters when there is a parse error on the input string. Parse error is defined as not being able to take any prefix of the input string as a valid number. Thus an empty string or "Freddy" turns into zero, but "123asdasd" turns into 123. === * Move from stl stof() to libc strtof(). * Add string_to_rate_quarters unit test.
- Loading branch information
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "utils/async_if_test_helper.hxx" | ||
|
||
#include "openlcb/BroadcastTimeDefs.hxx" | ||
|
||
#if 0 | ||
#define PRINT_ALL_PACKETS() print_all_packets() | ||
#else | ||
#define PRINT_ALL_PACKETS() | ||
#endif | ||
|
||
namespace openlcb | ||
{ | ||
|
||
TEST(BroadcastTimeDefs, string_to_rate_quarters) | ||
{ | ||
int16_t rate; | ||
|
||
rate = BroadcastTimeDefs::string_to_rate_quarters("Freddy"); | ||
EXPECT_EQ(0, rate); | ||
|
||
rate = BroadcastTimeDefs::string_to_rate_quarters("2000"); | ||
EXPECT_EQ(2047, rate); | ||
|
||
rate = BroadcastTimeDefs::string_to_rate_quarters("-2000"); | ||
EXPECT_EQ(-2048, rate); | ||
|
||
rate = BroadcastTimeDefs::string_to_rate_quarters(""); | ||
EXPECT_EQ(0, rate); | ||
|
||
rate = BroadcastTimeDefs::string_to_rate_quarters("-"); | ||
EXPECT_EQ(0, rate); | ||
|
||
rate = BroadcastTimeDefs::string_to_rate_quarters(" "); | ||
EXPECT_EQ(0, rate); | ||
|
||
rate = BroadcastTimeDefs::string_to_rate_quarters("511,75"); | ||
EXPECT_EQ(2044, rate); | ||
|
||
rate = BroadcastTimeDefs::string_to_rate_quarters("1.75"); | ||
EXPECT_EQ(7, rate); | ||
|
||
rate = BroadcastTimeDefs::string_to_rate_quarters("-1.75"); | ||
EXPECT_EQ(-7, rate); | ||
} | ||
|
||
} // namespace openlcb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters