Reboot test: save large files

[ Merge of http://go/wvgerrit/143629 ]

The standard b2a_hex only saves about 2k, so we need a special version
that can handle larger strings. This is needed because a license file
is about 7k.

Bug: 194342751
Test: GtsMediaTestCases on sunfish
Change-Id: I6a6ac3f8f4fa6d9cd8a0119fc64fc8f3cc5f3ae8
This commit is contained in:
Rahul Frias
2022-03-13 18:33:39 -07:00
parent 57353b4941
commit 520368cea2
3 changed files with 32 additions and 9 deletions

View File

@@ -13,8 +13,8 @@
#include "log.h"
using wvutil::a2b_hex;
using wvutil::b2a_hex;
using wvutil::FileSystem;
using wvutil::unlimited_b2a_hex;
namespace wvcdm {
FileSystem* RebootTest::file_system_;
@@ -33,11 +33,11 @@ std::string EncodeString(const std::string& data) {
// If there are any unprintable characters, except whitespace, or if we
// close a brace before we open it, then just use hex.
if (!printable || braces_count < 0) {
return "0x" + b2a_hex(data) + ",";
return "0x" + unlimited_b2a_hex(data) + ",";
}
}
// If we left any braces open, then use hex.
if (braces_count != 0) return "0x" + b2a_hex(data) + ",";
if (braces_count != 0) return "0x" + unlimited_b2a_hex(data) + ",";
return "{" + data + "},";
}
@@ -51,12 +51,12 @@ std::string EncodeKey(const std::string& data) {
}
// When decoding, we assume that a key starting with "0x" is in hex. So we
// can't have any keys that start with "0x".
if (data.substr(0, 2) == "0x") return "0x" + b2a_hex(data) + ":";
if (data.substr(0, 2) == "0x") return "0x" + unlimited_b2a_hex(data) + ":";
// If the key is just is not printable, or if it has unmatched braces, then
// we use hex. Otherwise, we surround the whole string with braces.
for (size_t i = 0; i < data.length(); i++) {
if (!isprint(data[i]) || (data[i] == ':')) {
return "0x" + b2a_hex(data) + ":";
return "0x" + unlimited_b2a_hex(data) + ":";
}
}
return data + ":";
@@ -247,6 +247,10 @@ TEST_F(RebootTest, TestDumpUtil) {
// This key looks like it might be hex. It should show up as hex in the
// save file.
map1["0x_bad_key_00"] = "value is ok";
std::string big_string = "start with something {binary";
// Double big_string 8 times, i.e. times 256, so it's bigger than 2k:
for (int i = 0; i < 8; i++) big_string = big_string + big_string;
map1["big_file"] = big_string;
const std::string dump2 = DumpData(map1);
std::map<std::string, std::string> map3;
EXPECT_TRUE(ParseDump(dump2, &map3));