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

Side by Side Diff: base/pickle_unittest.cc

Issue 1619363002: Add compile time checks against longs being used in IPC structs on 32 bit Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: one more per Dmitry Created 4 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
OLDNEW
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
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
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
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
OLDNEW
« base/pickle.cc ('K') | « base/pickle.cc ('k') | base/trace_event/trace_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698