Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2b1a0599 authored by Tomasz Wasilczyk's avatar Tomasz Wasilczyk
Browse files

Don't depend on String8 cast to C string

Bug: 295394788
Test: m checkbuild
Change-Id: I5b86ae56250d409a23ab3f2bc72b725bcf6ab23e
parent d741c232
Loading
Loading
Loading
Loading
+29 −27
Original line number Diff line number Diff line
@@ -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;
+18 −20
Original line number Diff line number Diff line
@@ -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;
                }

+1 −1
Original line number Diff line number Diff line
@@ -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());
    }
}

+35 −35
Original line number Diff line number Diff line
@@ -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());
}
+8 −8
Original line number Diff line number Diff line
@@ -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());
}
Loading