Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: tools/battor_agent/battor_protocol_types_unittest.cc

Issue 1966413002: [battor agent] Move code for stringifying bytes into a util file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed signed/unsigned char problems Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/battor_agent/battor_agent.gyp ('k') | tools/battor_agent/serial_utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/battor_agent/battor_protocol_types_unittest.cc
diff --git a/tools/battor_agent/battor_protocol_types_unittest.cc b/tools/battor_agent/battor_protocol_types_unittest.cc
index 46416cdd44b25cc2f0efb5e9f7f8870ead90dd34..cdd9ec109a2bdc675a06b32c8d26c0bc8d85a0c7 100644
--- a/tools/battor_agent/battor_protocol_types_unittest.cc
+++ b/tools/battor_agent/battor_protocol_types_unittest.cc
@@ -8,6 +8,7 @@
#include <string>
#include "testing/gtest/include/gtest/gtest.h"
+#include "tools/battor_agent/serial_utils.h"
using namespace testing;
@@ -15,22 +16,6 @@ namespace battor {
namespace {
-// Prints the character array as hex to a comma-separated list.
-std::string CharArrayToFormattedString(const unsigned char* arr,
- size_t length) {
- std::string s;
-
- char num_buff[6];
- for (size_t i = 0; i < length; ++i) {
- // We use sprintf because stringstream's hex support wants to print our
- // characters as signed.
- sprintf(num_buff, "0x%02hhx,", arr[i]);
- s += num_buff;
- }
-
- return s;
-}
-
const BattOrEEPROM kUnserializedEEPROM{
{0, 0, 0, 1}, 2, "serialno", 3, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24,
@@ -55,12 +40,12 @@ TEST(BattOrProtocolTypeTest, EEPROMSerializesCorrectly) {
// the EEPROM will change in the future and we'll need to update the
// serialized version when it does, it makes sense to print the bytes as a
// string that can just be copied and pasted into kSerializedEEPROM.
- const unsigned char* eeprom_bytes =
- reinterpret_cast<const unsigned char*>(&kUnserializedEEPROM);
+ const char* eeprom_bytes =
+ reinterpret_cast<const char*>(&kUnserializedEEPROM);
- ASSERT_EQ(
- CharArrayToFormattedString(kSerializedEEPROM, sizeof(kSerializedEEPROM)),
- CharArrayToFormattedString(eeprom_bytes, sizeof(kUnserializedEEPROM)));
+ ASSERT_EQ(CharArrayToString(reinterpret_cast<const char*>(kSerializedEEPROM),
+ sizeof(kSerializedEEPROM)),
+ CharArrayToString(eeprom_bytes, sizeof(kUnserializedEEPROM)));
}
} // namespace battor
« no previous file with comments | « tools/battor_agent/battor_agent.gyp ('k') | tools/battor_agent/serial_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698