elevator_unittest.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "chrome/elevation_service/elevator.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. namespace elevation_service {
  7. class ElevatorTest : public ::testing::Test {};
  8. TEST_F(ElevatorTest, StringHandlingTest) {
  9. std::string str;
  10. const std::string kFirstString("hello again");
  11. Elevator::AppendStringWithLength(kFirstString, str);
  12. EXPECT_EQ(sizeof(uint32_t) + kFirstString.length(), str.length());
  13. const std::string kSecondString("another string");
  14. Elevator::AppendStringWithLength(kSecondString, str);
  15. EXPECT_EQ(sizeof(uint32_t) + kFirstString.length() + sizeof(uint32_t) +
  16. kSecondString.length(),
  17. str.length());
  18. const std::string first_str = Elevator::PopFromStringFront(str);
  19. EXPECT_EQ(kFirstString, first_str);
  20. EXPECT_EQ(sizeof(uint32_t) + kSecondString.length(), str.length());
  21. const std::string second_str = Elevator::PopFromStringFront(str);
  22. EXPECT_EQ(kSecondString, second_str);
  23. const std::string error_str = Elevator::PopFromStringFront(str);
  24. EXPECT_TRUE(error_str.empty());
  25. std::string str2;
  26. Elevator::AppendStringWithLength("", str2);
  27. EXPECT_EQ(sizeof(uint32_t), str2.length());
  28. std::string empty_str = Elevator::PopFromStringFront(str2);
  29. EXPECT_TRUE(empty_str.empty());
  30. }
  31. } // namespace elevation_service