OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/base/resource/data_pack.h" | 11 #include "ui/base/resource/data_pack.h" |
12 | 12 |
13 namespace ui { | 13 namespace ui { |
14 | 14 |
| 15 extern const char kSamplePakContents[]; |
| 16 extern const size_t kSamplePakSize; |
| 17 |
15 TEST(DataPackTest, Load) { | 18 TEST(DataPackTest, Load) { |
16 FilePath data_path; | 19 ScopedTempDir dir; |
17 PathService::Get(base::DIR_SOURCE_ROOT, &data_path); | 20 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
18 data_path = data_path.Append( | 21 FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); |
19 FILE_PATH_LITERAL("ui/base/test/data/data_pack_unittest/sample.pak")); | |
20 | 22 |
| 23 // Dump contents into the pak file. |
| 24 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, kSamplePakSize), |
| 25 static_cast<int>(kSamplePakSize)); |
| 26 |
| 27 // Load the file through the data pack API. |
21 DataPack pack; | 28 DataPack pack; |
22 ASSERT_TRUE(pack.Load(data_path)); | 29 ASSERT_TRUE(pack.Load(data_path)); |
23 | 30 |
24 base::StringPiece data; | 31 base::StringPiece data; |
25 ASSERT_TRUE(pack.GetStringPiece(4, &data)); | 32 ASSERT_TRUE(pack.GetStringPiece(4, &data)); |
26 EXPECT_EQ("this is id 4", data); | 33 EXPECT_EQ("this is id 4", data); |
27 ASSERT_TRUE(pack.GetStringPiece(6, &data)); | 34 ASSERT_TRUE(pack.GetStringPiece(6, &data)); |
28 EXPECT_EQ("this is id 6", data); | 35 EXPECT_EQ("this is id 6", data); |
29 | 36 |
30 // Try reading zero-length data blobs, just in case. | 37 // Try reading zero-length data blobs, just in case. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 EXPECT_EQ(two, data); | 84 EXPECT_EQ(two, data); |
78 ASSERT_TRUE(pack.GetStringPiece(3, &data)); | 85 ASSERT_TRUE(pack.GetStringPiece(3, &data)); |
79 EXPECT_EQ(three, data); | 86 EXPECT_EQ(three, data); |
80 ASSERT_TRUE(pack.GetStringPiece(4, &data)); | 87 ASSERT_TRUE(pack.GetStringPiece(4, &data)); |
81 EXPECT_EQ(four, data); | 88 EXPECT_EQ(four, data); |
82 ASSERT_TRUE(pack.GetStringPiece(15, &data)); | 89 ASSERT_TRUE(pack.GetStringPiece(15, &data)); |
83 EXPECT_EQ(fifteen, data); | 90 EXPECT_EQ(fifteen, data); |
84 } | 91 } |
85 | 92 |
86 } // namespace ui | 93 } // namespace ui |
OLD | NEW |