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

Side by Side Diff: ui/base/resource/data_pack_unittest.cc

Issue 10151025: Add scale factor tag to data packs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/resource/data_pack.cc ('k') | ui/base/resource/resource_bundle.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 13 matching lines...) Expand all
24 TEST(DataPackTest, Load) { 24 TEST(DataPackTest, Load) {
25 ScopedTempDir dir; 25 ScopedTempDir dir;
26 ASSERT_TRUE(dir.CreateUniqueTempDir()); 26 ASSERT_TRUE(dir.CreateUniqueTempDir());
27 FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); 27 FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak"));
28 28
29 // Dump contents into the pak file. 29 // Dump contents into the pak file.
30 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, kSamplePakSize), 30 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, kSamplePakSize),
31 static_cast<int>(kSamplePakSize)); 31 static_cast<int>(kSamplePakSize));
32 32
33 // Load the file through the data pack API. 33 // Load the file through the data pack API.
34 DataPack pack; 34 DataPack pack(ResourceHandle::kScaleFactor100x);
35 ASSERT_TRUE(pack.Load(data_path)); 35 ASSERT_TRUE(pack.Load(data_path));
36 36
37 base::StringPiece data; 37 base::StringPiece data;
38 ASSERT_TRUE(pack.GetStringPiece(4, &data)); 38 ASSERT_TRUE(pack.GetStringPiece(4, &data));
39 EXPECT_EQ("this is id 4", data); 39 EXPECT_EQ("this is id 4", data);
40 ASSERT_TRUE(pack.GetStringPiece(6, &data)); 40 ASSERT_TRUE(pack.GetStringPiece(6, &data));
41 EXPECT_EQ("this is id 6", data); 41 EXPECT_EQ("this is id 6", data);
42 42
43 // Try reading zero-length data blobs, just in case. 43 // Try reading zero-length data blobs, just in case.
44 ASSERT_TRUE(pack.GetStringPiece(1, &data)); 44 ASSERT_TRUE(pack.GetStringPiece(1, &data));
(...skipping 11 matching lines...) Expand all
56 DataPack::UTF8)); 56 DataPack::UTF8));
57 INSTANTIATE_TEST_CASE_P(WriteUTF16, DataPackTest, ::testing::Values( 57 INSTANTIATE_TEST_CASE_P(WriteUTF16, DataPackTest, ::testing::Values(
58 DataPack::UTF16)); 58 DataPack::UTF16));
59 59
60 TEST(DataPackTest, LoadFileWithTruncatedHeader) { 60 TEST(DataPackTest, LoadFileWithTruncatedHeader) {
61 FilePath data_path; 61 FilePath data_path;
62 PathService::Get(base::DIR_SOURCE_ROOT, &data_path); 62 PathService::Get(base::DIR_SOURCE_ROOT, &data_path);
63 data_path = data_path.Append(FILE_PATH_LITERAL( 63 data_path = data_path.Append(FILE_PATH_LITERAL(
64 "ui/base/test/data/data_pack_unittest/truncated-header.pak")); 64 "ui/base/test/data/data_pack_unittest/truncated-header.pak"));
65 65
66 DataPack pack; 66 DataPack pack(ResourceHandle::kScaleFactor100x);
67 ASSERT_FALSE(pack.Load(data_path)); 67 ASSERT_FALSE(pack.Load(data_path));
68 } 68 }
69 69
70 TEST_P(DataPackTest, Write) { 70 TEST_P(DataPackTest, Write) {
71 ScopedTempDir dir; 71 ScopedTempDir dir;
72 ASSERT_TRUE(dir.CreateUniqueTempDir()); 72 ASSERT_TRUE(dir.CreateUniqueTempDir());
73 FilePath file = dir.path().Append(FILE_PATH_LITERAL("data.pak")); 73 FilePath file = dir.path().Append(FILE_PATH_LITERAL("data.pak"));
74 74
75 std::string one("one"); 75 std::string one("one");
76 std::string two("two"); 76 std::string two("two");
77 std::string three("three"); 77 std::string three("three");
78 std::string four("four"); 78 std::string four("four");
79 std::string fifteen("fifteen"); 79 std::string fifteen("fifteen");
80 80
81 std::map<uint16, base::StringPiece> resources; 81 std::map<uint16, base::StringPiece> resources;
82 resources.insert(std::make_pair(1, base::StringPiece(one))); 82 resources.insert(std::make_pair(1, base::StringPiece(one)));
83 resources.insert(std::make_pair(2, base::StringPiece(two))); 83 resources.insert(std::make_pair(2, base::StringPiece(two)));
84 resources.insert(std::make_pair(15, base::StringPiece(fifteen))); 84 resources.insert(std::make_pair(15, base::StringPiece(fifteen)));
85 resources.insert(std::make_pair(3, base::StringPiece(three))); 85 resources.insert(std::make_pair(3, base::StringPiece(three)));
86 resources.insert(std::make_pair(4, base::StringPiece(four))); 86 resources.insert(std::make_pair(4, base::StringPiece(four)));
87 ASSERT_TRUE(DataPack::WritePack(file, resources, GetParam())); 87 ASSERT_TRUE(DataPack::WritePack(file, resources, GetParam()));
88 88
89 // Now try to read the data back in. 89 // Now try to read the data back in.
90 DataPack pack; 90 DataPack pack(ResourceHandle::kScaleFactor100x);
91 ASSERT_TRUE(pack.Load(file)); 91 ASSERT_TRUE(pack.Load(file));
92 EXPECT_EQ(pack.GetTextEncodingType(), GetParam()); 92 EXPECT_EQ(pack.GetTextEncodingType(), GetParam());
93 93
94 base::StringPiece data; 94 base::StringPiece data;
95 ASSERT_TRUE(pack.GetStringPiece(1, &data)); 95 ASSERT_TRUE(pack.GetStringPiece(1, &data));
96 EXPECT_EQ(one, data); 96 EXPECT_EQ(one, data);
97 ASSERT_TRUE(pack.GetStringPiece(2, &data)); 97 ASSERT_TRUE(pack.GetStringPiece(2, &data));
98 EXPECT_EQ(two, data); 98 EXPECT_EQ(two, data);
99 ASSERT_TRUE(pack.GetStringPiece(3, &data)); 99 ASSERT_TRUE(pack.GetStringPiece(3, &data));
100 EXPECT_EQ(three, data); 100 EXPECT_EQ(three, data);
101 ASSERT_TRUE(pack.GetStringPiece(4, &data)); 101 ASSERT_TRUE(pack.GetStringPiece(4, &data));
102 EXPECT_EQ(four, data); 102 EXPECT_EQ(four, data);
103 ASSERT_TRUE(pack.GetStringPiece(15, &data)); 103 ASSERT_TRUE(pack.GetStringPiece(15, &data));
104 EXPECT_EQ(fifteen, data); 104 EXPECT_EQ(fifteen, data);
105 } 105 }
106 106
107 } // namespace ui 107 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/data_pack.cc ('k') | ui/base/resource/resource_bundle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698