/thirdparty/breakpad/third_party/protobuf/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc

http://github.com/tomahawk-player/tomahawk · C++ · 40 lines · 28 code · 5 blank · 7 comment · 2 complexity · 24852336a47d67309ad5e7d175bc63a9 MD5 · raw file

  1. // Copyright 2008 Google Inc. All Rights Reserved.
  2. // Author: xpeng@google.com (Peter Peng)
  3. #include <google/protobuf/stubs/common.h>
  4. #include <gtest/gtest.h>
  5. namespace google {
  6. namespace protobuf {
  7. namespace internal {
  8. namespace {
  9. TEST(StructurallyValidTest, ValidUTF8String) {
  10. // On GCC, this string can be written as:
  11. // "abcd 1234 - \u2014\u2013\u2212"
  12. // MSVC seems to interpret \u differently.
  13. string valid_str("abcd 1234 - \342\200\224\342\200\223\342\210\222 - xyz789");
  14. EXPECT_TRUE(IsStructurallyValidUTF8(valid_str.data(),
  15. valid_str.size()));
  16. // Additional check for pointer alignment
  17. for (int i = 1; i < 8; ++i) {
  18. EXPECT_TRUE(IsStructurallyValidUTF8(valid_str.data() + i,
  19. valid_str.size() - i));
  20. }
  21. }
  22. TEST(StructurallyValidTest, InvalidUTF8String) {
  23. const string invalid_str("abcd\xA0\xB0\xA0\xB0\xA0\xB0 - xyz789");
  24. EXPECT_FALSE(IsStructurallyValidUTF8(invalid_str.data(),
  25. invalid_str.size()));
  26. // Additional check for pointer alignment
  27. for (int i = 1; i < 8; ++i) {
  28. EXPECT_FALSE(IsStructurallyValidUTF8(invalid_str.data() + i,
  29. invalid_str.size() - i));
  30. }
  31. }
  32. } // namespace
  33. } // namespace internal
  34. } // namespace protobuf
  35. } // namespace google