From 2b1a0599c4530c34b57ba109917904451b55214e Mon Sep 17 00:00:00 2001 From: Tomasz Wasilczyk Date: Tue, 12 Sep 2023 15:26:15 +0000 Subject: [PATCH] Don't depend on String8 cast to C string Bug: 295394788 Test: m checkbuild Change-Id: I5b86ae56250d409a23ab3f2bc72b725bcf6ab23e --- healthd/BatteryMonitor.cpp | 56 +++++++++++++------------ healthd/BatteryMonitor_v1.cpp | 38 ++++++++--------- libutils/CallStack.cpp | 2 +- libutils/String16_test.cpp | 70 ++++++++++++++++---------------- libutils/String8_test.cpp | 16 ++++---- trusty/stats/test/stats_test.cpp | 22 +++++----- 6 files changed, 102 insertions(+), 102 deletions(-) diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index e4cf582fb..0c976322d 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -432,7 +432,7 @@ void BatteryMonitor::updateValues(void) { } if (readFromFile(mHealthdConfig->batteryTechnologyPath, &buf) > 0) - mHealthInfo->batteryTechnology = String8(buf.c_str()); + mHealthInfo->batteryTechnology = buf; if (readFromFile(mHealthdConfig->chargingPolicyPath, &buf) > 0) mHealthInfo->chargingPolicy = getBatteryChargingPolicy(buf.c_str()); @@ -786,39 +786,35 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/status", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) - mHealthdConfig->batteryStatusPath = path; + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryStatusPath = path; } if (mHealthdConfig->batteryHealthPath.empty()) { path.clear(); path.appendFormat("%s/%s/health", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) - mHealthdConfig->batteryHealthPath = path; + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryHealthPath = path; } if (mHealthdConfig->batteryPresentPath.empty()) { path.clear(); path.appendFormat("%s/%s/present", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) - mHealthdConfig->batteryPresentPath = path; + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryPresentPath = path; } if (mHealthdConfig->batteryCapacityPath.empty()) { path.clear(); path.appendFormat("%s/%s/capacity", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) - mHealthdConfig->batteryCapacityPath = path; + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryCapacityPath = path; } if (mHealthdConfig->batteryVoltagePath.empty()) { path.clear(); path.appendFormat("%s/%s/voltage_now", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) { + if (access(path.c_str(), R_OK) == 0) { mHealthdConfig->batteryVoltagePath = path; } } @@ -827,7 +823,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/charge_full", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryFullChargePath = path; } @@ -835,7 +831,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/current_now", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryCurrentNowPath = path; } @@ -843,27 +839,29 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/cycle_count", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryCycleCountPath = path; } if (mHealthdConfig->batteryCapacityLevelPath.empty()) { path.clear(); path.appendFormat("%s/%s/capacity_level", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) mHealthdConfig->batteryCapacityLevelPath = path; + if (access(path.c_str(), R_OK) == 0) { + mHealthdConfig->batteryCapacityLevelPath = path; + } } if (mHealthdConfig->batteryChargeTimeToFullNowPath.empty()) { path.clear(); path.appendFormat("%s/%s/time_to_full_now", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryChargeTimeToFullNowPath = path; } if (mHealthdConfig->batteryFullChargeDesignCapacityUahPath.empty()) { path.clear(); path.appendFormat("%s/%s/charge_full_design", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryFullChargeDesignCapacityUahPath = path; } @@ -871,7 +869,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/current_avg", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryCurrentAvgPath = path; } @@ -879,7 +877,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/charge_counter", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryChargeCounterPath = path; } @@ -887,7 +885,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/temp", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) { + if (access(path.c_str(), R_OK) == 0) { mHealthdConfig->batteryTemperaturePath = path; } } @@ -896,19 +894,19 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/technology", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryTechnologyPath = path; } if (mHealthdConfig->batteryStateOfHealthPath.empty()) { path.clear(); path.appendFormat("%s/%s/state_of_health", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) { + if (access(path.c_str(), R_OK) == 0) { mHealthdConfig->batteryStateOfHealthPath = path; } else { path.clear(); path.appendFormat("%s/%s/health_index", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryStateOfHealthPath = path; } } @@ -916,32 +914,36 @@ void BatteryMonitor::init(struct healthd_config *hc) { if (mHealthdConfig->batteryHealthStatusPath.empty()) { path.clear(); path.appendFormat("%s/%s/health_status", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) mHealthdConfig->batteryHealthStatusPath = path; + if (access(path.c_str(), R_OK) == 0) { + mHealthdConfig->batteryHealthStatusPath = path; + } } if (mHealthdConfig->batteryManufacturingDatePath.empty()) { path.clear(); path.appendFormat("%s/%s/manufacturing_date", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryManufacturingDatePath = path; } if (mHealthdConfig->batteryFirstUsageDatePath.empty()) { path.clear(); path.appendFormat("%s/%s/first_usage_date", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) mHealthdConfig->batteryFirstUsageDatePath = path; + if (access(path.c_str(), R_OK) == 0) { + mHealthdConfig->batteryFirstUsageDatePath = path; + } } if (mHealthdConfig->chargingStatePath.empty()) { path.clear(); path.appendFormat("%s/%s/charging_state", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) mHealthdConfig->chargingStatePath = path; + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->chargingStatePath = path; } if (mHealthdConfig->chargingPolicyPath.empty()) { path.clear(); path.appendFormat("%s/%s/charging_policy", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) mHealthdConfig->chargingPolicyPath = path; + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->chargingPolicyPath = path; } break; diff --git a/healthd/BatteryMonitor_v1.cpp b/healthd/BatteryMonitor_v1.cpp index 686c338cc..2e0cfc971 100644 --- a/healthd/BatteryMonitor_v1.cpp +++ b/healthd/BatteryMonitor_v1.cpp @@ -352,7 +352,7 @@ void BatteryMonitor::updateValues(void) { mHealthInfo->batteryHealth = getBatteryHealth(buf.c_str()); if (readFromFile(mHealthdConfig->batteryTechnologyPath, &buf) > 0) - mHealthInfo->batteryTechnology = String8(buf.c_str()); + mHealthInfo->batteryTechnology = buf; double MaxPower = 0; @@ -639,39 +639,35 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/status", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) - mHealthdConfig->batteryStatusPath = path; + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryStatusPath = path; } if (mHealthdConfig->batteryHealthPath.empty()) { path.clear(); path.appendFormat("%s/%s/health", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) - mHealthdConfig->batteryHealthPath = path; + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryHealthPath = path; } if (mHealthdConfig->batteryPresentPath.empty()) { path.clear(); path.appendFormat("%s/%s/present", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) - mHealthdConfig->batteryPresentPath = path; + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryPresentPath = path; } if (mHealthdConfig->batteryCapacityPath.empty()) { path.clear(); path.appendFormat("%s/%s/capacity", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) - mHealthdConfig->batteryCapacityPath = path; + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryCapacityPath = path; } if (mHealthdConfig->batteryVoltagePath.empty()) { path.clear(); path.appendFormat("%s/%s/voltage_now", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) { + if (access(path.c_str(), R_OK) == 0) { mHealthdConfig->batteryVoltagePath = path; } } @@ -680,7 +676,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/charge_full", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryFullChargePath = path; } @@ -688,7 +684,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/current_now", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryCurrentNowPath = path; } @@ -696,27 +692,29 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/cycle_count", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryCycleCountPath = path; } if (mHealthdConfig->batteryCapacityLevelPath.empty()) { path.clear(); path.appendFormat("%s/%s/capacity_level", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) mHealthdConfig->batteryCapacityLevelPath = path; + if (access(path.c_str(), R_OK) == 0) { + mHealthdConfig->batteryCapacityLevelPath = path; + } } if (mHealthdConfig->batteryChargeTimeToFullNowPath.empty()) { path.clear(); path.appendFormat("%s/%s/time_to_full_now", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryChargeTimeToFullNowPath = path; } if (mHealthdConfig->batteryFullChargeDesignCapacityUahPath.empty()) { path.clear(); path.appendFormat("%s/%s/charge_full_design", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryFullChargeDesignCapacityUahPath = path; } @@ -724,7 +722,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/current_avg", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryCurrentAvgPath = path; } @@ -732,7 +730,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/charge_counter", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryChargeCounterPath = path; } @@ -740,7 +738,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/temp", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) { + if (access(path.c_str(), R_OK) == 0) { mHealthdConfig->batteryTemperaturePath = path; } } @@ -749,7 +747,7 @@ void BatteryMonitor::init(struct healthd_config *hc) { path.clear(); path.appendFormat("%s/%s/technology", POWER_SUPPLY_SYSFS_PATH, name); - if (access(path, R_OK) == 0) + if (access(path.c_str(), R_OK) == 0) mHealthdConfig->batteryTechnologyPath = path; } diff --git a/libutils/CallStack.cpp b/libutils/CallStack.cpp index 4dcb35b36..11f2c9262 100644 --- a/libutils/CallStack.cpp +++ b/libutils/CallStack.cpp @@ -82,7 +82,7 @@ String8 CallStack::toString(const char* prefix) const { void CallStack::print(Printer& printer) const { for (size_t i = 0; i < mFrameLines.size(); i++) { - printer.printLine(mFrameLines[i]); + printer.printLine(mFrameLines[i].c_str()); } } diff --git a/libutils/String16_test.cpp b/libutils/String16_test.cpp index c6e6f746a..6f4642e8f 100644 --- a/libutils/String16_test.cpp +++ b/libutils/String16_test.cpp @@ -33,50 +33,50 @@ using namespace android; TEST(String16Test, FromChar16_t) { String16 tmp(u"Verify me"); - EXPECT_STR16EQ(u"Verify me", tmp); + EXPECT_STR16EQ(u"Verify me", tmp.c_str()); } TEST(String16Test, FromChar16_tSized) { String16 tmp(u"Verify me", 7); - EXPECT_STR16EQ(u"Verify ", tmp); + EXPECT_STR16EQ(u"Verify ", tmp.c_str()); } TEST(String16Test, FromChar) { String16 tmp("Verify me"); - EXPECT_STR16EQ(u"Verify me", tmp); + EXPECT_STR16EQ(u"Verify me", tmp.c_str()); } TEST(String16Test, FromCharSized) { String16 tmp("Verify me", 7); - EXPECT_STR16EQ(u"Verify ", tmp); + EXPECT_STR16EQ(u"Verify ", tmp.c_str()); } TEST(String16Test, Copy) { String16 tmp("Verify me"); String16 another = tmp; - EXPECT_STR16EQ(u"Verify me", tmp); - EXPECT_STR16EQ(u"Verify me", another); + EXPECT_STR16EQ(u"Verify me", tmp.c_str()); + EXPECT_STR16EQ(u"Verify me", another.c_str()); } TEST(String16Test, CopyAssign) { String16 tmp("Verify me"); String16 another; another = tmp; - EXPECT_STR16EQ(u"Verify me", tmp); - EXPECT_STR16EQ(u"Verify me", another); + EXPECT_STR16EQ(u"Verify me", tmp.c_str()); + EXPECT_STR16EQ(u"Verify me", another.c_str()); } TEST(String16Test, Move) { String16 tmp("Verify me"); String16 another(std::move(tmp)); - EXPECT_STR16EQ(u"Verify me", another); + EXPECT_STR16EQ(u"Verify me", another.c_str()); } TEST(String16Test, MoveAssign) { String16 tmp("Verify me"); String16 another; another = std::move(tmp); - EXPECT_STR16EQ(u"Verify me", another); + EXPECT_STR16EQ(u"Verify me", another.c_str()); } TEST(String16Test, Size) { @@ -88,27 +88,27 @@ TEST(String16Test, setTo) { String16 tmp("Verify me"); tmp.setTo(u"New content"); EXPECT_EQ(11U, tmp.size()); - EXPECT_STR16EQ(u"New content", tmp); + EXPECT_STR16EQ(u"New content", tmp.c_str()); } TEST(String16Test, Append) { String16 tmp("Verify me"); tmp.append(String16("Hello")); EXPECT_EQ(14U, tmp.size()); - EXPECT_STR16EQ(u"Verify meHello", tmp); + EXPECT_STR16EQ(u"Verify meHello", tmp.c_str()); } TEST(String16Test, Insert) { String16 tmp("Verify me"); tmp.insert(6, u"Insert"); EXPECT_EQ(15U, tmp.size()); - EXPECT_STR16EQ(u"VerifyInsert me", tmp); + EXPECT_STR16EQ(u"VerifyInsert me", tmp.c_str()); } TEST(String16Test, ReplaceAll) { String16 tmp("Verify verify Verify"); tmp.replaceAll(u'r', u'!'); - EXPECT_STR16EQ(u"Ve!ify ve!ify Ve!ify", tmp); + EXPECT_STR16EQ(u"Ve!ify ve!ify Ve!ify", tmp.c_str()); } TEST(String16Test, Compare) { @@ -127,8 +127,8 @@ TEST(String16Test, StaticString) { TEST(String16Test, StaticStringCopy) { StaticString16 tmp(u"Verify me"); String16 another = tmp; - EXPECT_STR16EQ(u"Verify me", tmp); - EXPECT_STR16EQ(u"Verify me", another); + EXPECT_STR16EQ(u"Verify me", tmp.c_str()); + EXPECT_STR16EQ(u"Verify me", another.c_str()); EXPECT_TRUE(tmp.isStaticString()); EXPECT_TRUE(another.isStaticString()); } @@ -136,7 +136,7 @@ TEST(String16Test, StaticStringCopy) { TEST(String16Test, StaticStringMove) { StaticString16 tmp(u"Verify me"); String16 another(std::move(tmp)); - EXPECT_STR16EQ(u"Verify me", another); + EXPECT_STR16EQ(u"Verify me", another.c_str()); EXPECT_TRUE(another.isStaticString()); } @@ -157,7 +157,7 @@ TEST(String16Test, StaticStringAppend) { StaticString16 tmp(u"Verify me"); tmp.append(String16("Hello")); EXPECT_EQ(14U, tmp.size()); - EXPECT_STR16EQ(u"Verify meHello", tmp); + EXPECT_STR16EQ(u"Verify meHello", tmp.c_str()); EXPECT_FALSE(tmp.isStaticString()); } @@ -165,14 +165,14 @@ TEST(String16Test, StaticStringInsert) { StaticString16 tmp(u"Verify me"); tmp.insert(6, u"Insert"); EXPECT_EQ(15U, tmp.size()); - EXPECT_STR16EQ(u"VerifyInsert me", tmp); + EXPECT_STR16EQ(u"VerifyInsert me", tmp.c_str()); EXPECT_FALSE(tmp.isStaticString()); } TEST(String16Test, StaticStringReplaceAll) { StaticString16 tmp(u"Verify verify Verify"); tmp.replaceAll(u'r', u'!'); - EXPECT_STR16EQ(u"Ve!ify ve!ify Ve!ify", tmp); + EXPECT_STR16EQ(u"Ve!ify ve!ify Ve!ify", tmp.c_str()); EXPECT_FALSE(tmp.isStaticString()); } @@ -185,17 +185,17 @@ TEST(String16Test, StringSetToStaticString) { StaticString16 tmp(u"Verify me"); String16 another(u"nonstatic"); another = tmp; - EXPECT_STR16EQ(u"Verify me", tmp); - EXPECT_STR16EQ(u"Verify me", another); + EXPECT_STR16EQ(u"Verify me", tmp.c_str()); + EXPECT_STR16EQ(u"Verify me", another.c_str()); } TEST(String16Test, StringCopyAssignFromStaticString) { StaticString16 tmp(u"Verify me"); String16 another(u"nonstatic"); another = tmp; - EXPECT_STR16EQ(u"Verify me", another); + EXPECT_STR16EQ(u"Verify me", another.c_str()); EXPECT_TRUE(another.isStaticString()); - EXPECT_STR16EQ(u"Verify me", tmp); + EXPECT_STR16EQ(u"Verify me", tmp.c_str()); EXPECT_TRUE(tmp.isStaticString()); } @@ -203,7 +203,7 @@ TEST(String16Test, StringMoveAssignFromStaticString) { StaticString16 tmp(u"Verify me"); String16 another(u"nonstatic"); another = std::move(tmp); - EXPECT_STR16EQ(u"Verify me", another); + EXPECT_STR16EQ(u"Verify me", another.c_str()); EXPECT_TRUE(another.isStaticString()); } @@ -221,19 +221,19 @@ TEST(String16Test, OverreadUtf8Conversion) { TEST(String16Test, ValidUtf8Conversion) { String16 another("abcdef"); EXPECT_EQ(6U, another.size()); - EXPECT_STR16EQ(another, u"abcdef"); + EXPECT_STR16EQ(another.c_str(), u"abcdef"); } TEST(String16Test, append) { String16 s; EXPECT_EQ(OK, s.append(String16(u"foo"))); - EXPECT_STR16EQ(u"foo", s); + EXPECT_STR16EQ(u"foo", s.c_str()); EXPECT_EQ(OK, s.append(String16(u"bar"))); - EXPECT_STR16EQ(u"foobar", s); + EXPECT_STR16EQ(u"foobar", s.c_str()); EXPECT_EQ(OK, s.append(u"baz", 0)); - EXPECT_STR16EQ(u"foobar", s); + EXPECT_STR16EQ(u"foobar", s.c_str()); EXPECT_EQ(NO_MEMORY, s.append(u"baz", SIZE_MAX)); - EXPECT_STR16EQ(u"foobar", s); + EXPECT_STR16EQ(u"foobar", s.c_str()); } TEST(String16Test, insert) { @@ -241,19 +241,19 @@ TEST(String16Test, insert) { // Inserting into the empty string inserts at the start. EXPECT_EQ(OK, s.insert(123, u"foo")); - EXPECT_STR16EQ(u"foo", s); + EXPECT_STR16EQ(u"foo", s.c_str()); // Inserting zero characters at any position is okay, but won't expand the string. EXPECT_EQ(OK, s.insert(123, u"foo", 0)); - EXPECT_STR16EQ(u"foo", s); + EXPECT_STR16EQ(u"foo", s.c_str()); // Inserting past the end of a non-empty string appends. EXPECT_EQ(OK, s.insert(123, u"bar")); - EXPECT_STR16EQ(u"foobar", s); + EXPECT_STR16EQ(u"foobar", s.c_str()); EXPECT_EQ(OK, s.insert(3, u"!")); - EXPECT_STR16EQ(u"foo!bar", s); + EXPECT_STR16EQ(u"foo!bar", s.c_str()); EXPECT_EQ(NO_MEMORY, s.insert(3, u"", SIZE_MAX)); - EXPECT_STR16EQ(u"foo!bar", s); + EXPECT_STR16EQ(u"foo!bar", s.c_str()); } diff --git a/libutils/String8_test.cpp b/libutils/String8_test.cpp index 9c12cb12d..e1fd13a9e 100644 --- a/libutils/String8_test.cpp +++ b/libutils/String8_test.cpp @@ -100,19 +100,19 @@ TEST_F(String8Test, CheckUtf32Conversion) { TEST_F(String8Test, ValidUtf16Conversion) { char16_t tmp[] = u"abcdef"; String8 valid = String8(String16(tmp)); - EXPECT_STREQ(valid, "abcdef"); + EXPECT_STREQ(valid.c_str(), "abcdef"); } TEST_F(String8Test, append) { String8 s; EXPECT_EQ(OK, s.append("foo")); - EXPECT_STREQ("foo", s); + EXPECT_STREQ("foo", s.c_str()); EXPECT_EQ(OK, s.append("bar")); - EXPECT_STREQ("foobar", s); + EXPECT_STREQ("foobar", s.c_str()); EXPECT_EQ(OK, s.append("baz", 0)); - EXPECT_STREQ("foobar", s); + EXPECT_STREQ("foobar", s.c_str()); EXPECT_EQ(NO_MEMORY, s.append("baz", SIZE_MAX)); - EXPECT_STREQ("foobar", s); + EXPECT_STREQ("foobar", s.c_str()); } TEST_F(String8Test, removeAll) { @@ -123,12 +123,12 @@ TEST_F(String8Test, removeAll) { // expect to return true and string content should remain unchanged EXPECT_TRUE(s.removeAll("")); - EXPECT_STREQ("Hello, world!", s); + EXPECT_STREQ("Hello, world!", s.c_str()); // expect to return false EXPECT_FALSE(s.removeAll("x")); - EXPECT_STREQ("Hello, world!", s); + EXPECT_STREQ("Hello, world!", s.c_str()); EXPECT_TRUE(s.removeAll("o")); - EXPECT_STREQ("Hell, wrld!", s); + EXPECT_STREQ("Hell, wrld!", s.c_str()); } diff --git a/trusty/stats/test/stats_test.cpp b/trusty/stats/test/stats_test.cpp index 1edddeb5a..1d6eb34a6 100644 --- a/trusty/stats/test/stats_test.cpp +++ b/trusty/stats/test/stats_test.cpp @@ -252,20 +252,20 @@ TEST_F(TrustyStatsTest, CheckAtoms) { ::testing::AnyOf(::testing::Eq(TrustyAtoms::TrustyAppCrashed), ::testing::Eq(TrustyAtoms::TrustyError), ::testing::Eq(TrustyAtoms::TrustyStorageError))); - ASSERT_STREQ(String8(vendorAtom.reverseDomainName), "google.android.trusty"); + ASSERT_EQ(String8(vendorAtom.reverseDomainName), "google.android.trusty"); switch (vendorAtom.atomId) { case TrustyAtoms::TrustyAppCrashed: ++atomAppCrashedCnt; - ASSERT_STREQ(String8(vendorAtom.values[0].get()), - "5247d19b-cf09-4272-a450-3ef20dbefc14"); + ASSERT_EQ(String8(vendorAtom.values[0].get()), + "5247d19b-cf09-4272-a450-3ef20dbefc14"); break; case TrustyAtoms::TrustyStorageError: ++atomStorageErrorCnt; ASSERT_EQ(vendorAtom.values[0].get(), 5); - ASSERT_STREQ(String8(vendorAtom.values[1].get()), - "5247d19b-cf09-4272-a450-3ef20dbefc14"); - ASSERT_STREQ(String8(vendorAtom.values[2].get()), - "5247d19b-cf09-4272-a450-3ef20dbefc14"); + ASSERT_EQ(String8(vendorAtom.values[1].get()), + "5247d19b-cf09-4272-a450-3ef20dbefc14"); + ASSERT_EQ(String8(vendorAtom.values[2].get()), + "5247d19b-cf09-4272-a450-3ef20dbefc14"); ASSERT_EQ(vendorAtom.values[3].get(), 1); ASSERT_EQ(vendorAtom.values[4].get(), 3); ASSERT_EQ(vendorAtom.values[5].get(), @@ -330,13 +330,13 @@ TEST_F(TrustyMetricsCrashTest, CheckTrustyCrashAtoms) { ::testing::AnyOf(::testing::Eq(TrustyAtoms::TrustyAppCrashed), ::testing::Eq(TrustyAtoms::TrustyError), ::testing::Eq(TrustyAtoms::TrustyStorageError))); - ASSERT_STREQ(String8(vendorAtom.reverseDomainName), "google.android.trusty"); + ASSERT_EQ(String8(vendorAtom.reverseDomainName), "google.android.trusty"); switch (vendorAtom.atomId) { case TrustyAtoms::TrustyAppCrashed: ++atomAppCrashedCnt; - ASSERT_STREQ(String8(vendorAtom.values[0].get()), - kTrustyCrasherUuid); + ASSERT_EQ(String8(vendorAtom.values[0].get()), + kTrustyCrasherUuid); atomCrashReasons.push_back(vendorAtom.values[1].get()); break; case TrustyAtoms::TrustyStorageError: @@ -344,7 +344,7 @@ TEST_F(TrustyMetricsCrashTest, CheckTrustyCrashAtoms) { break; case TrustyAtoms::TrustyError: ++atomTrustyErrorCnt; - ASSERT_STREQ(String8(vendorAtom.values[1].get()), ""); + ASSERT_EQ(String8(vendorAtom.values[1].get()), ""); break; default: FAIL() << "Unknown vendor atom ID: " << vendorAtom.atomId;