Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: blimp/helium/serializable_struct_unittest.cc

Issue 2602103002: Delete blimp/helium and remove references to it from dependent targets (Closed)
Patch Set: . Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « blimp/helium/serializable_struct.cc ('k') | blimp/helium/stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 #include <vector>
7
8 #include "base/macros.h"
9 #include "blimp/helium/serializable_struct.h"
10 #include "blimp/helium/stream_helpers.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h"
13 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite .h"
14
15 namespace blimp {
16 namespace helium {
17 namespace {
18
19 struct EmptyStruct : public SerializableStruct {
20 EmptyStruct() {}
21 ~EmptyStruct() override {}
22
23 private:
24 DISALLOW_COPY_AND_ASSIGN(EmptyStruct);
25 };
26
27 struct TwoFieldStruct : public SerializableStruct {
28 TwoFieldStruct() : field_1(this), field_2(this) {}
29 ~TwoFieldStruct() override {}
30
31 Field<int32_t> field_1;
32 Field<int32_t> field_2;
33
34 private:
35 DISALLOW_COPY_AND_ASSIGN(TwoFieldStruct);
36 };
37
38 class SerializableStructTest : public testing::Test {
39 public:
40 SerializableStructTest() {}
41 ~SerializableStructTest() override = default;
42
43 private:
44 DISALLOW_COPY_AND_ASSIGN(SerializableStructTest);
45 };
46
47 TEST_F(SerializableStructTest, ByteFormatTwoFieldsSet) {
48 TwoFieldStruct test_struct;
49 test_struct.field_1.Set(5);
50 test_struct.field_2.Set(6);
51
52 std::string changeset;
53 google::protobuf::io::StringOutputStream raw_output_stream(&changeset);
54 google::protobuf::io::CodedOutputStream output_stream(&raw_output_stream);
55 test_struct.Serialize(&output_stream);
56 output_stream.Trim();
57
58 EXPECT_EQ("\x5\x6", changeset);
59 }
60
61 TEST_F(SerializableStructTest, ByteFormatOneFieldSet) {
62 TwoFieldStruct test_struct;
63 test_struct.field_2.Set(6);
64
65 std::string changeset;
66 google::protobuf::io::StringOutputStream raw_output_stream(&changeset);
67 google::protobuf::io::CodedOutputStream output_stream(&raw_output_stream);
68 test_struct.Serialize(&output_stream);
69 output_stream.Trim();
70
71 EXPECT_EQ(0x00, changeset[0]);
72 EXPECT_EQ(0x06, changeset[1]);
73 }
74
75 TEST_F(SerializableStructTest, EmptyStruct) {
76 EmptyStruct test_struct;
77
78 std::string changeset;
79 google::protobuf::io::StringOutputStream raw_output_stream(&changeset);
80 google::protobuf::io::CodedOutputStream output_stream(&raw_output_stream);
81 test_struct.Serialize(&output_stream);
82 output_stream.Trim();
83
84 EXPECT_TRUE(changeset.empty());
85 }
86
87 } // namespace
88 } // namespace helium
89 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/helium/serializable_struct.cc ('k') | blimp/helium/stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698