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