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 <string>
6
7 #include "base/rand_util.h"
8 #include "mojo/public/cpp/base/big_buffer_mojom_traits.h"
9 #include "mojo/public/cpp/base/big_string_mojom_traits.h"
10 #include "mojo/public/cpp/test_support/test_utils.h"
11 #include "mojo/public/mojom/base/big_string.mojom.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace mojo_base {
15 namespace big_string_unittest {
16
TEST(BigStringTest,Empty)17 TEST(BigStringTest, Empty) {
18 std::string in;
19 std::string out;
20 ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::BigString>(&in, &out));
21 EXPECT_EQ(in, out);
22 }
23
TEST(BigStringTest,Short)24 TEST(BigStringTest, Short) {
25 std::string in("hello world");
26 std::string out;
27 ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::BigString>(&in, &out));
28 EXPECT_EQ(in, out);
29 }
30
TEST(BigStringTest,Long)31 TEST(BigStringTest, Long) {
32 constexpr size_t kLargeStringSize = 1024 * 1024;
33
34 std::string in(kLargeStringSize, 0);
35 base::RandBytes(&in[0], kLargeStringSize);
36
37 std::string out;
38 ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::BigString>(&in, &out));
39 EXPECT_EQ(in, out);
40 }
41
42 } // namespace big_string_unittest
43 } // namespace mojo_base
44