1 // Copyright 2018 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 5 #include "base/strings/string16.h" 6 #include "base/rand_util.h" 7 #include "base/strings/utf_string_conversions.h" 8 #include "mojo/public/cpp/base/big_buffer_mojom_traits.h" 9 #include "mojo/public/cpp/base/string16_mojom_traits.h" 10 #include "mojo/public/cpp/test_support/test_utils.h" 11 #include "mojo/public/mojom/base/string16.mojom.h" 12 #include "testing/gtest/include/gtest/gtest.h" 13 14 namespace mojo_base { 15 namespace string16_unittest { 16 17 TEST(String16Test, Empty) { 18 base::string16 in; 19 base::string16 out; 20 ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::String16>(&in, &out)); 21 EXPECT_EQ(in, out); 22 } 23 24 TEST(String16Test, NonEmpty) { 25 base::string16 in = base::ASCIIToUTF16("hello world"); 26 base::string16 out; 27 ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::String16>(&in, &out)); 28 EXPECT_EQ(in, out); 29 } 30 31 TEST(BigString16Test, Empty) { 32 base::string16 in; 33 base::string16 out; 34 ASSERT_TRUE( 35 mojo::test::SerializeAndDeserialize<mojom::BigString16>(&in, &out)); 36 EXPECT_EQ(in, out); 37 } 38 39 TEST(BigString16Test, Short) { 40 base::string16 in = base::ASCIIToUTF16("hello world"); 41 base::string16 out; 42 ASSERT_TRUE( 43 mojo::test::SerializeAndDeserialize<mojom::BigString16>(&in, &out)); 44 EXPECT_EQ(in, out); 45 } 46 47 TEST(BigString16Test, Long) { 48 constexpr size_t kLargeStringSize = 1024 * 1024; 49 50 base::string16 in(kLargeStringSize, 0); 51 base::RandBytes(&in[0], kLargeStringSize); 52 53 base::string16 out; 54 ASSERT_TRUE( 55 mojo::test::SerializeAndDeserialize<mojom::BigString16>(&in, &out)); 56 EXPECT_EQ(in, out); 57 } 58 59 } // namespace string16_unittest 60 } // namespace mojo_base 61