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

Side by Side Diff: chrome/installer/util/lzma_util_unittest.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 <windows.h> 5 #include <windows.h>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
11 #include "chrome/common/chrome_paths.h" 11 #include "chrome/common/chrome_paths.h"
12 #include "chrome/installer/util/lzma_util.h" 12 #include "chrome/installer/util/lzma_util.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace { 15 namespace {
16 class LzmaUtilTest : public testing::Test { 16 class LzmaUtilTest : public testing::Test {
17 protected: 17 protected:
18 virtual void SetUp() { 18 virtual void SetUp() {
19 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); 19 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_));
20 data_dir_ = data_dir_.AppendASCII("installer"); 20 data_dir_ = data_dir_.AppendASCII("installer");
21 ASSERT_TRUE(file_util::PathExists(data_dir_)); 21 ASSERT_TRUE(base::PathExists(data_dir_));
22 22
23 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 23 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
24 } 24 }
25 25
26 base::ScopedTempDir temp_dir_; 26 base::ScopedTempDir temp_dir_;
27 27
28 // The path to input data used in tests. 28 // The path to input data used in tests.
29 base::FilePath data_dir_; 29 base::FilePath data_dir_;
30 }; 30 };
31 }; 31 };
(...skipping 16 matching lines...) Expand all
48 48
49 // Make sure non-existent archive returns error. 49 // Make sure non-existent archive returns error.
50 archive = data_dir_.AppendASCII("archive.non_existent.7z"); 50 archive = data_dir_.AppendASCII("archive.non_existent.7z");
51 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), ERROR_FILE_NOT_FOUND); 51 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), ERROR_FILE_NOT_FOUND);
52 } 52 }
53 53
54 // Test that we can extract archives successfully. 54 // Test that we can extract archives successfully.
55 TEST_F(LzmaUtilTest, UnPackTest) { 55 TEST_F(LzmaUtilTest, UnPackTest) {
56 base::FilePath extract_dir(temp_dir_.path()); 56 base::FilePath extract_dir(temp_dir_.path());
57 extract_dir = extract_dir.AppendASCII("UnPackTest"); 57 extract_dir = extract_dir.AppendASCII("UnPackTest");
58 ASSERT_FALSE(file_util::PathExists(extract_dir)); 58 ASSERT_FALSE(base::PathExists(extract_dir));
59 EXPECT_TRUE(file_util::CreateDirectory(extract_dir)); 59 EXPECT_TRUE(file_util::CreateDirectory(extract_dir));
60 ASSERT_TRUE(file_util::PathExists(extract_dir)); 60 ASSERT_TRUE(base::PathExists(extract_dir));
61 61
62 base::FilePath archive = data_dir_.AppendASCII("archive1.7z"); 62 base::FilePath archive = data_dir_.AppendASCII("archive1.7z");
63 LzmaUtil lzma_util; 63 LzmaUtil lzma_util;
64 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), NO_ERROR); 64 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), NO_ERROR);
65 std::wstring unpacked_file; 65 std::wstring unpacked_file;
66 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file), 66 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file),
67 NO_ERROR); 67 NO_ERROR);
68 EXPECT_TRUE(file_util::PathExists(extract_dir.AppendASCII("a.exe"))); 68 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("a.exe")));
69 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("a.exe").value()); 69 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("a.exe").value());
70 70
71 archive = data_dir_.AppendASCII("archive2.7z"); 71 archive = data_dir_.AppendASCII("archive2.7z");
72 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), NO_ERROR); 72 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), NO_ERROR);
73 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file), 73 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file),
74 NO_ERROR); 74 NO_ERROR);
75 EXPECT_TRUE(file_util::PathExists(extract_dir.AppendASCII("b.exe"))); 75 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("b.exe")));
76 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("b.exe").value()); 76 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("b.exe").value());
77 77
78 lzma_util.CloseArchive(); 78 lzma_util.CloseArchive();
79 archive = data_dir_.AppendASCII("invalid_archive.7z"); 79 archive = data_dir_.AppendASCII("invalid_archive.7z");
80 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file), 80 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file),
81 ERROR_INVALID_HANDLE); 81 ERROR_INVALID_HANDLE);
82 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), NO_ERROR); 82 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), NO_ERROR);
83 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file), 83 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file),
84 ERROR_INVALID_HANDLE); 84 ERROR_INVALID_HANDLE);
85 85
86 archive = data_dir_.AppendASCII("archive3.7z"); 86 archive = data_dir_.AppendASCII("archive3.7z");
87 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), NO_ERROR); 87 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), NO_ERROR);
88 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file), 88 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file),
89 NO_ERROR); 89 NO_ERROR);
90 EXPECT_TRUE(file_util::PathExists(extract_dir.AppendASCII("archive\\a.exe"))); 90 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("archive\\a.exe")));
91 EXPECT_TRUE(file_util::PathExists( 91 EXPECT_TRUE(base::PathExists(
92 extract_dir.AppendASCII("archive\\sub_dir\\text.txt"))); 92 extract_dir.AppendASCII("archive\\sub_dir\\text.txt")));
93 } 93 }
94 94
95 // Test the static method that can be used to unpack archives. 95 // Test the static method that can be used to unpack archives.
96 TEST_F(LzmaUtilTest, UnPackArchiveTest) { 96 TEST_F(LzmaUtilTest, UnPackArchiveTest) {
97 base::FilePath extract_dir(temp_dir_.path()); 97 base::FilePath extract_dir(temp_dir_.path());
98 extract_dir = extract_dir.AppendASCII("UnPackArchiveTest"); 98 extract_dir = extract_dir.AppendASCII("UnPackArchiveTest");
99 ASSERT_FALSE(file_util::PathExists(extract_dir)); 99 ASSERT_FALSE(base::PathExists(extract_dir));
100 EXPECT_TRUE(file_util::CreateDirectory(extract_dir)); 100 EXPECT_TRUE(file_util::CreateDirectory(extract_dir));
101 ASSERT_TRUE(file_util::PathExists(extract_dir)); 101 ASSERT_TRUE(base::PathExists(extract_dir));
102 102
103 base::FilePath archive = data_dir_.AppendASCII("archive1.7z"); 103 base::FilePath archive = data_dir_.AppendASCII("archive1.7z");
104 std::wstring unpacked_file; 104 std::wstring unpacked_file;
105 EXPECT_EQ(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(), 105 EXPECT_EQ(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(),
106 &unpacked_file), NO_ERROR); 106 &unpacked_file), NO_ERROR);
107 EXPECT_TRUE(file_util::PathExists(extract_dir.AppendASCII("a.exe"))); 107 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("a.exe")));
108 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("a.exe").value()); 108 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("a.exe").value());
109 109
110 archive = data_dir_.AppendASCII("archive2.7z"); 110 archive = data_dir_.AppendASCII("archive2.7z");
111 EXPECT_EQ(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(), 111 EXPECT_EQ(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(),
112 &unpacked_file), NO_ERROR); 112 &unpacked_file), NO_ERROR);
113 EXPECT_TRUE(file_util::PathExists(extract_dir.AppendASCII("b.exe"))); 113 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("b.exe")));
114 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("b.exe").value()); 114 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("b.exe").value());
115 115
116 archive = data_dir_.AppendASCII("invalid_archive.7z"); 116 archive = data_dir_.AppendASCII("invalid_archive.7z");
117 EXPECT_NE(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(), 117 EXPECT_NE(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(),
118 &unpacked_file), NO_ERROR); 118 &unpacked_file), NO_ERROR);
119 } 119 }
OLDNEW
« no previous file with comments | « chrome/installer/util/logging_installer_unittest.cc ('k') | chrome/installer/util/master_preferences.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698