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