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 "ui/base/resource/data_pack.h" | 5 #include "ui/base/resource/data_pack.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 ASSERT_TRUE(pack.GetStringPiece(1, &data)); | 132 ASSERT_TRUE(pack.GetStringPiece(1, &data)); |
133 EXPECT_EQ(0U, data.length()); | 133 EXPECT_EQ(0U, data.length()); |
134 ASSERT_TRUE(pack.GetStringPiece(10, &data)); | 134 ASSERT_TRUE(pack.GetStringPiece(10, &data)); |
135 EXPECT_EQ(0U, data.length()); | 135 EXPECT_EQ(0U, data.length()); |
136 | 136 |
137 // Try looking up an invalid key. | 137 // Try looking up an invalid key. |
138 ASSERT_FALSE(pack.HasResource(140)); | 138 ASSERT_FALSE(pack.HasResource(140)); |
139 ASSERT_FALSE(pack.GetStringPiece(140, &data)); | 139 ASSERT_FALSE(pack.GetStringPiece(140, &data)); |
140 } | 140 } |
141 | 141 |
| 142 TEST(DataPackTest, LoadFromBuffer) { |
| 143 DataPack pack(SCALE_FACTOR_100P); |
| 144 |
| 145 ASSERT_TRUE(pack.LoadFromBuffer( |
| 146 base::StringPiece(kSamplePakContents, kSamplePakSize))); |
| 147 |
| 148 base::StringPiece data; |
| 149 ASSERT_TRUE(pack.HasResource(4)); |
| 150 ASSERT_TRUE(pack.GetStringPiece(4, &data)); |
| 151 EXPECT_EQ("this is id 4", data); |
| 152 ASSERT_TRUE(pack.HasResource(6)); |
| 153 ASSERT_TRUE(pack.GetStringPiece(6, &data)); |
| 154 EXPECT_EQ("this is id 6", data); |
| 155 |
| 156 // Try reading zero-length data blobs, just in case. |
| 157 ASSERT_TRUE(pack.GetStringPiece(1, &data)); |
| 158 EXPECT_EQ(0U, data.length()); |
| 159 ASSERT_TRUE(pack.GetStringPiece(10, &data)); |
| 160 EXPECT_EQ(0U, data.length()); |
| 161 |
| 162 // Try looking up an invalid key. |
| 163 ASSERT_FALSE(pack.HasResource(140)); |
| 164 ASSERT_FALSE(pack.GetStringPiece(140, &data)); |
| 165 } |
| 166 |
142 INSTANTIATE_TEST_CASE_P(WriteBINARY, DataPackTest, ::testing::Values( | 167 INSTANTIATE_TEST_CASE_P(WriteBINARY, DataPackTest, ::testing::Values( |
143 DataPack::BINARY)); | 168 DataPack::BINARY)); |
144 INSTANTIATE_TEST_CASE_P(WriteUTF8, DataPackTest, ::testing::Values( | 169 INSTANTIATE_TEST_CASE_P(WriteUTF8, DataPackTest, ::testing::Values( |
145 DataPack::UTF8)); | 170 DataPack::UTF8)); |
146 INSTANTIATE_TEST_CASE_P(WriteUTF16, DataPackTest, ::testing::Values( | 171 INSTANTIATE_TEST_CASE_P(WriteUTF16, DataPackTest, ::testing::Values( |
147 DataPack::UTF16)); | 172 DataPack::UTF16)); |
148 | 173 |
149 TEST(DataPackTest, LoadFileWithTruncatedHeader) { | 174 TEST(DataPackTest, LoadFileWithTruncatedHeader) { |
150 base::FilePath data_path; | 175 base::FilePath data_path; |
151 ASSERT_TRUE(PathService::Get(UI_DIR_TEST_DATA, &data_path)); | 176 ASSERT_TRUE(PathService::Get(UI_DIR_TEST_DATA, &data_path)); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 kSampleCorruptPakSize), | 242 kSampleCorruptPakSize), |
218 static_cast<int>(kSampleCorruptPakSize)); | 243 static_cast<int>(kSampleCorruptPakSize)); |
219 | 244 |
220 // Reading asset #10 should now fail as it extends past the end of the file. | 245 // Reading asset #10 should now fail as it extends past the end of the file. |
221 ASSERT_TRUE(pack.HasResource(10)); | 246 ASSERT_TRUE(pack.HasResource(10)); |
222 ASSERT_FALSE(pack.GetStringPiece(10, &data)); | 247 ASSERT_FALSE(pack.GetStringPiece(10, &data)); |
223 } | 248 } |
224 #endif | 249 #endif |
225 | 250 |
226 } // namespace ui | 251 } // namespace ui |
OLD | NEW |