OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
5 #include "chromeos/binder/buffer_reader.h" | 8 #include "chromeos/binder/buffer_reader.h" |
6 #include "chromeos/binder/writable_transaction_data.h" | 9 #include "chromeos/binder/writable_transaction_data.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
8 | 11 |
9 namespace binder { | 12 namespace binder { |
10 | 13 |
11 TEST(BinderWritableTransactionDataTest, WriteData) { | 14 TEST(BinderWritableTransactionDataTest, WriteData) { |
12 char array[3]; | 15 char array[3]; |
13 for (size_t i = 0; i < sizeof(array); ++i) { | 16 for (size_t i = 0; i < sizeof(array); ++i) { |
14 array[i] = i; | 17 array[i] = i; |
15 } | 18 } |
16 | 19 |
17 WritableTransactionData data; | 20 WritableTransactionData data; |
18 EXPECT_EQ(0u, data.GetDataSize()); | 21 EXPECT_EQ(0u, data.GetDataSize()); |
19 data.WriteData(array, sizeof(array)); | 22 data.WriteData(array, sizeof(array)); |
20 EXPECT_EQ(4u, data.GetDataSize()); // Padded for 4-byte alignment. | 23 EXPECT_EQ(4u, data.GetDataSize()); // Padded for 4-byte alignment. |
21 for (size_t i = 0; i < sizeof(array); ++i) { | 24 for (size_t i = 0; i < sizeof(array); ++i) { |
22 SCOPED_TRACE(i); | 25 SCOPED_TRACE(i); |
23 EXPECT_EQ(array[i], reinterpret_cast<const char*>(data.GetData())[i]); | 26 EXPECT_EQ(array[i], reinterpret_cast<const char*>(data.GetData())[i]); |
24 } | 27 } |
25 } | 28 } |
26 | 29 |
27 TEST(BinderWritableTransactionDataTest, WriteInt32) { | 30 TEST(BinderWritableTransactionDataTest, WriteInt32) { |
28 const int32 kValue = -1234; | 31 const int32_t kValue = -1234; |
29 WritableTransactionData data; | 32 WritableTransactionData data; |
30 data.WriteInt32(kValue); | 33 data.WriteInt32(kValue); |
31 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); | 34 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); |
32 BufferReader reader(reinterpret_cast<const char*>(data.GetData()), | 35 BufferReader reader(reinterpret_cast<const char*>(data.GetData()), |
33 data.GetDataSize()); | 36 data.GetDataSize()); |
34 int32 result = 0; | 37 int32_t result = 0; |
35 EXPECT_TRUE(reader.Read(&result, sizeof(result))); | 38 EXPECT_TRUE(reader.Read(&result, sizeof(result))); |
36 EXPECT_EQ(kValue, result); | 39 EXPECT_EQ(kValue, result); |
37 EXPECT_FALSE(reader.HasMoreData()); | 40 EXPECT_FALSE(reader.HasMoreData()); |
38 } | 41 } |
39 | 42 |
40 TEST(BinderWritableTransactionDataTest, WriteUint32) { | 43 TEST(BinderWritableTransactionDataTest, WriteUint32) { |
41 const uint32 kValue = 1234; | 44 const uint32_t kValue = 1234; |
42 WritableTransactionData data; | 45 WritableTransactionData data; |
43 data.WriteUint32(kValue); | 46 data.WriteUint32(kValue); |
44 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); | 47 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); |
45 BufferReader reader(reinterpret_cast<const char*>(data.GetData()), | 48 BufferReader reader(reinterpret_cast<const char*>(data.GetData()), |
46 data.GetDataSize()); | 49 data.GetDataSize()); |
47 uint32 result = 0; | 50 uint32_t result = 0; |
48 EXPECT_TRUE(reader.Read(&result, sizeof(result))); | 51 EXPECT_TRUE(reader.Read(&result, sizeof(result))); |
49 EXPECT_EQ(kValue, result); | 52 EXPECT_EQ(kValue, result); |
50 EXPECT_FALSE(reader.HasMoreData()); | 53 EXPECT_FALSE(reader.HasMoreData()); |
51 } | 54 } |
52 | 55 |
53 TEST(BinderWritableTransactionDataTest, WriteInt64) { | 56 TEST(BinderWritableTransactionDataTest, WriteInt64) { |
54 const int64 kValue = -1234; | 57 const int64_t kValue = -1234; |
55 WritableTransactionData data; | 58 WritableTransactionData data; |
56 data.WriteInt64(kValue); | 59 data.WriteInt64(kValue); |
57 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); | 60 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); |
58 BufferReader reader(reinterpret_cast<const char*>(data.GetData()), | 61 BufferReader reader(reinterpret_cast<const char*>(data.GetData()), |
59 data.GetDataSize()); | 62 data.GetDataSize()); |
60 int64 result = 0; | 63 int64_t result = 0; |
61 EXPECT_TRUE(reader.Read(&result, sizeof(result))); | 64 EXPECT_TRUE(reader.Read(&result, sizeof(result))); |
62 EXPECT_EQ(kValue, result); | 65 EXPECT_EQ(kValue, result); |
63 EXPECT_FALSE(reader.HasMoreData()); | 66 EXPECT_FALSE(reader.HasMoreData()); |
64 } | 67 } |
65 | 68 |
66 TEST(BinderWritableTransactionDataTest, WriteUint64) { | 69 TEST(BinderWritableTransactionDataTest, WriteUint64) { |
67 const uint64 kValue = 1234; | 70 const uint64_t kValue = 1234; |
68 WritableTransactionData data; | 71 WritableTransactionData data; |
69 data.WriteUint64(kValue); | 72 data.WriteUint64(kValue); |
70 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); | 73 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); |
71 BufferReader reader(reinterpret_cast<const char*>(data.GetData()), | 74 BufferReader reader(reinterpret_cast<const char*>(data.GetData()), |
72 data.GetDataSize()); | 75 data.GetDataSize()); |
73 uint64 result = 0; | 76 uint64_t result = 0; |
74 EXPECT_TRUE(reader.Read(&result, sizeof(result))); | 77 EXPECT_TRUE(reader.Read(&result, sizeof(result))); |
75 EXPECT_EQ(kValue, result); | 78 EXPECT_EQ(kValue, result); |
76 EXPECT_FALSE(reader.HasMoreData()); | 79 EXPECT_FALSE(reader.HasMoreData()); |
77 } | 80 } |
78 | 81 |
79 TEST(BinderWritableTransactionDataTest, WriteFloat) { | 82 TEST(BinderWritableTransactionDataTest, WriteFloat) { |
80 const float kValue = 1234.5678; | 83 const float kValue = 1234.5678; |
81 WritableTransactionData data; | 84 WritableTransactionData data; |
82 data.WriteFloat(kValue); | 85 data.WriteFloat(kValue); |
83 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); | 86 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); |
(...skipping 12 matching lines...) Expand all Loading... |
96 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); | 99 EXPECT_EQ(sizeof(kValue), data.GetDataSize()); |
97 BufferReader reader(reinterpret_cast<const char*>(data.GetData()), | 100 BufferReader reader(reinterpret_cast<const char*>(data.GetData()), |
98 data.GetDataSize()); | 101 data.GetDataSize()); |
99 double result = 0; | 102 double result = 0; |
100 EXPECT_TRUE(reader.Read(&result, sizeof(result))); | 103 EXPECT_TRUE(reader.Read(&result, sizeof(result))); |
101 EXPECT_EQ(kValue, result); | 104 EXPECT_EQ(kValue, result); |
102 EXPECT_FALSE(reader.HasMoreData()); | 105 EXPECT_FALSE(reader.HasMoreData()); |
103 } | 106 } |
104 | 107 |
105 } // namespace binder | 108 } // namespace binder |
OLD | NEW |