OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits.h> | 5 #include <limits.h> |
6 #include <stddef.h> | 6 #include <stddef.h> |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 | 113 |
114 } // namespace | 114 } // namespace |
115 | 115 |
116 TEST(PickleTest, EncodeDecode) { | 116 TEST(PickleTest, EncodeDecode) { |
117 Pickle pickle; | 117 Pickle pickle; |
118 | 118 |
119 EXPECT_TRUE(pickle.WriteBool(testbool1)); | 119 EXPECT_TRUE(pickle.WriteBool(testbool1)); |
120 EXPECT_TRUE(pickle.WriteBool(testbool2)); | 120 EXPECT_TRUE(pickle.WriteBool(testbool2)); |
121 EXPECT_TRUE(pickle.WriteInt(testint)); | 121 EXPECT_TRUE(pickle.WriteInt(testint)); |
122 EXPECT_TRUE( | 122 EXPECT_TRUE(pickle.WriteLong(testlong)); |
123 pickle.WriteLongUsingDangerousNonPortableLessPersistableForm(testlong)); | |
124 EXPECT_TRUE(pickle.WriteUInt16(testuint16)); | 123 EXPECT_TRUE(pickle.WriteUInt16(testuint16)); |
125 EXPECT_TRUE(pickle.WriteUInt32(testuint32)); | 124 EXPECT_TRUE(pickle.WriteUInt32(testuint32)); |
126 EXPECT_TRUE(pickle.WriteInt64(testint64)); | 125 EXPECT_TRUE(pickle.WriteInt64(testint64)); |
127 EXPECT_TRUE(pickle.WriteUInt64(testuint64)); | 126 EXPECT_TRUE(pickle.WriteUInt64(testuint64)); |
128 EXPECT_TRUE(pickle.WriteSizeT(testsizet)); | 127 EXPECT_TRUE(pickle.WriteSizeT(testsizet)); |
129 EXPECT_TRUE(pickle.WriteFloat(testfloat)); | 128 EXPECT_TRUE(pickle.WriteFloat(testfloat)); |
130 EXPECT_TRUE(pickle.WriteDouble(testdouble)); | 129 EXPECT_TRUE(pickle.WriteDouble(testdouble)); |
131 EXPECT_TRUE(pickle.WriteString(teststring)); | 130 EXPECT_TRUE(pickle.WriteString(teststring)); |
132 EXPECT_TRUE(pickle.WriteString16(teststring16)); | 131 EXPECT_TRUE(pickle.WriteString16(teststring16)); |
133 EXPECT_TRUE(pickle.WriteString(testrawstring)); | 132 EXPECT_TRUE(pickle.WriteString(testrawstring)); |
(...skipping 19 matching lines...) Expand all Loading... |
153 // Under the hood size_t is always written as a 64-bit value, so simulate a | 152 // Under the hood size_t is always written as a 64-bit value, so simulate a |
154 // 64-bit size_t even on 32-bit architectures by explicitly writing a | 153 // 64-bit size_t even on 32-bit architectures by explicitly writing a |
155 // uint64_t. | 154 // uint64_t. |
156 EXPECT_TRUE(pickle.WriteUInt64(testuint64)); | 155 EXPECT_TRUE(pickle.WriteUInt64(testuint64)); |
157 | 156 |
158 PickleIterator iter(pickle); | 157 PickleIterator iter(pickle); |
159 size_t outsizet; | 158 size_t outsizet; |
160 if (sizeof(size_t) < sizeof(uint64_t)) { | 159 if (sizeof(size_t) < sizeof(uint64_t)) { |
161 // ReadSizeT() should return false when the original written value can't be | 160 // ReadSizeT() should return false when the original written value can't be |
162 // represented as a size_t. | 161 // represented as a size_t. |
163 EXPECT_FALSE(iter.ReadSizeT(&outsizet)); | 162 #if GTEST_HAS_DEATH_TEST |
| 163 EXPECT_DEATH(ignore_result(iter.ReadSizeT(&outsizet)), ""); |
| 164 #endif |
164 } else { | 165 } else { |
165 EXPECT_TRUE(iter.ReadSizeT(&outsizet)); | 166 EXPECT_TRUE(iter.ReadSizeT(&outsizet)); |
166 EXPECT_EQ(testuint64, outsizet); | 167 EXPECT_EQ(testuint64, outsizet); |
167 } | 168 } |
168 } | 169 } |
169 | 170 |
170 // Tests that we can handle really small buffers. | 171 // Tests that we can handle really small buffers. |
171 TEST(PickleTest, SmallBuffer) { | 172 TEST(PickleTest, SmallBuffer) { |
172 scoped_ptr<char[]> buffer(new char[1]); | 173 scoped_ptr<char[]> buffer(new char[1]); |
173 | 174 |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 const char* out_data = nullptr; | 570 const char* out_data = nullptr; |
570 EXPECT_TRUE(iter.ReadBytes(&out_data, out_data_length)); | 571 EXPECT_TRUE(iter.ReadBytes(&out_data, out_data_length)); |
571 EXPECT_EQ(data, std::string(out_data, out_data_length)); | 572 EXPECT_EQ(data, std::string(out_data, out_data_length)); |
572 | 573 |
573 int out_value; | 574 int out_value; |
574 EXPECT_TRUE(iter.ReadInt(&out_value)); | 575 EXPECT_TRUE(iter.ReadInt(&out_value)); |
575 EXPECT_EQ(42, out_value); | 576 EXPECT_EQ(42, out_value); |
576 } | 577 } |
577 | 578 |
578 } // namespace base | 579 } // namespace base |
OLD | NEW |