-
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.
Adds hex_to_string helper function to format_utils. (#707)
* Adds hex_to_string helper function to format_utils. * Adds format utils test. * Fix whitespace. * Change API to return nonnegative integer. Fix review comment.
- Loading branch information
1 parent
d5062f6
commit b9207af
Showing
3 changed files
with
101 additions
and
0 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,35 @@ | ||
#include "utils/format_utils.hxx" | ||
|
||
#include "utils/test_main.hxx" | ||
|
||
TEST(HexToString, basic) | ||
{ | ||
string input = "303132"; | ||
string output; | ||
EXPECT_EQ(6u, hex_to_string(input.data(), input.size(), &output)); | ||
EXPECT_EQ("012", output); | ||
|
||
output = "xx"; | ||
EXPECT_EQ(6u, hex_to_string(input.data(), input.size(), &output)); | ||
EXPECT_EQ("xx012", output); | ||
|
||
output.clear(); | ||
input = "0A0BfC"; | ||
EXPECT_EQ(6u, hex_to_string(input.data(), input.size(), &output)); | ||
EXPECT_EQ("\x0a\x0b\xfc", output); | ||
|
||
output.clear(); | ||
input = "30.31.32"; | ||
EXPECT_EQ(2u, hex_to_string(input.data(), input.size(), &output)); | ||
EXPECT_EQ("0", output); | ||
|
||
output.clear(); | ||
EXPECT_EQ(8u, hex_to_string(input.data(), input.size(), &output, true)); | ||
EXPECT_EQ("012", output); | ||
|
||
output.clear(); | ||
input = "303132F"; | ||
EXPECT_EQ(7u, hex_to_string(input.data(), input.size(), &output)); | ||
// lost one nibble, this is ok according to the contract | ||
EXPECT_EQ("012", output); | ||
} |
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