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

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

Issue 7779019: Removed sample.pak binary from checkout. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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
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"
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 FILE* file = file_util::OpenFile(data_path, "wb");
tony 2011/09/02 23:10:51 Can we just use file_util::WriteFile?
marcvs 2011/09/02 23:27:27 Done.
25 ASSERT_TRUE(file);
26 ASSERT_EQ(fwrite(kSamplePakContents, 1, kSamplePakSize, file),
27 kSamplePakSize);
28 file_util::CloseFile(file);
29
30 // Load the file through the data pack API.
21 DataPack pack; 31 DataPack pack;
22 ASSERT_TRUE(pack.Load(data_path)); 32 ASSERT_TRUE(pack.Load(data_path));
23 33
24 base::StringPiece data; 34 base::StringPiece data;
25 ASSERT_TRUE(pack.GetStringPiece(4, &data)); 35 ASSERT_TRUE(pack.GetStringPiece(4, &data));
26 EXPECT_EQ("this is id 4", data); 36 EXPECT_EQ("this is id 4", data);
27 ASSERT_TRUE(pack.GetStringPiece(6, &data)); 37 ASSERT_TRUE(pack.GetStringPiece(6, &data));
28 EXPECT_EQ("this is id 6", data); 38 EXPECT_EQ("this is id 6", data);
29 39
30 // Try reading zero-length data blobs, just in case. 40 // Try reading zero-length data blobs, just in case.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 EXPECT_EQ(two, data); 87 EXPECT_EQ(two, data);
78 ASSERT_TRUE(pack.GetStringPiece(3, &data)); 88 ASSERT_TRUE(pack.GetStringPiece(3, &data));
79 EXPECT_EQ(three, data); 89 EXPECT_EQ(three, data);
80 ASSERT_TRUE(pack.GetStringPiece(4, &data)); 90 ASSERT_TRUE(pack.GetStringPiece(4, &data));
81 EXPECT_EQ(four, data); 91 EXPECT_EQ(four, data);
82 ASSERT_TRUE(pack.GetStringPiece(15, &data)); 92 ASSERT_TRUE(pack.GetStringPiece(15, &data));
83 EXPECT_EQ(fifteen, data); 93 EXPECT_EQ(fifteen, data);
84 } 94 }
85 95
86 } // namespace ui 96 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698