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

Side by Side Diff: app/data_pack_unittest.cc

Issue 6263008: Move ResourceBundle, DataPack to ui/base (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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 | « app/data_pack.cc ('k') | app/l10n_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "app/data_pack.h"
6
7 #include "base/file_path.h"
8 #include "base/file_util.h"
9 #include "base/path_service.h"
10 #include "base/scoped_temp_dir.h"
11 #include "base/string_piece.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace app {
15
16 TEST(DataPackTest, Load) {
17 FilePath data_path;
18 PathService::Get(base::DIR_SOURCE_ROOT, &data_path);
19 data_path = data_path.Append(
20 FILE_PATH_LITERAL("app/test/data/data_pack_unittest/sample.pak"));
21
22 DataPack pack;
23 ASSERT_TRUE(pack.Load(data_path));
24
25 base::StringPiece data;
26 ASSERT_TRUE(pack.GetStringPiece(4, &data));
27 EXPECT_EQ("this is id 4", data);
28 ASSERT_TRUE(pack.GetStringPiece(6, &data));
29 EXPECT_EQ("this is id 6", data);
30
31 // Try reading zero-length data blobs, just in case.
32 ASSERT_TRUE(pack.GetStringPiece(1, &data));
33 EXPECT_EQ(0U, data.length());
34 ASSERT_TRUE(pack.GetStringPiece(10, &data));
35 EXPECT_EQ(0U, data.length());
36
37 // Try looking up an invalid key.
38 ASSERT_FALSE(pack.GetStringPiece(140, &data));
39 }
40
41 TEST(DataPackTest, Write) {
42 ScopedTempDir dir;
43 ASSERT_TRUE(dir.CreateUniqueTempDir());
44 FilePath file = dir.path().Append(FILE_PATH_LITERAL("data.pak"));
45
46 std::string one("one");
47 std::string two("two");
48 std::string three("three");
49 std::string four("four");
50 std::string fifteen("fifteen");
51
52 std::map<uint32, base::StringPiece> resources;
53 resources.insert(std::make_pair(1, base::StringPiece(one)));
54 resources.insert(std::make_pair(2, base::StringPiece(two)));
55 resources.insert(std::make_pair(15, base::StringPiece(fifteen)));
56 resources.insert(std::make_pair(3, base::StringPiece(three)));
57 resources.insert(std::make_pair(4, base::StringPiece(four)));
58 ASSERT_TRUE(DataPack::WritePack(file, resources));
59
60 // Now try to read the data back in.
61 DataPack pack;
62 ASSERT_TRUE(pack.Load(file));
63
64 base::StringPiece data;
65 ASSERT_TRUE(pack.GetStringPiece(1, &data));
66 EXPECT_EQ(one, data);
67 ASSERT_TRUE(pack.GetStringPiece(2, &data));
68 EXPECT_EQ(two, data);
69 ASSERT_TRUE(pack.GetStringPiece(3, &data));
70 EXPECT_EQ(three, data);
71 ASSERT_TRUE(pack.GetStringPiece(4, &data));
72 EXPECT_EQ(four, data);
73 ASSERT_TRUE(pack.GetStringPiece(15, &data));
74 EXPECT_EQ(fifteen, data);
75 }
76
77 } // namespace app
OLDNEW
« no previous file with comments | « app/data_pack.cc ('k') | app/l10n_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698