| 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 <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 "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 // Make sure non-existent archive returns error. | 48 // Make sure non-existent archive returns error. |
| 49 archive = data_dir_.AppendASCII("archive.non_existent.7z"); | 49 archive = data_dir_.AppendASCII("archive.non_existent.7z"); |
| 50 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), ERROR_FILE_NOT_FOUND); | 50 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), ERROR_FILE_NOT_FOUND); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Test that we can extract archives successfully. | 53 // Test that we can extract archives successfully. |
| 54 TEST_F(LzmaUtilTest, UnPackTest) { | 54 TEST_F(LzmaUtilTest, UnPackTest) { |
| 55 base::FilePath extract_dir(temp_dir_.path()); | 55 base::FilePath extract_dir(temp_dir_.path()); |
| 56 extract_dir = extract_dir.AppendASCII("UnPackTest"); | 56 extract_dir = extract_dir.AppendASCII("UnPackTest"); |
| 57 ASSERT_FALSE(base::PathExists(extract_dir)); | 57 ASSERT_FALSE(base::PathExists(extract_dir)); |
| 58 EXPECT_TRUE(file_util::CreateDirectory(extract_dir)); | 58 EXPECT_TRUE(base::CreateDirectory(extract_dir)); |
| 59 ASSERT_TRUE(base::PathExists(extract_dir)); | 59 ASSERT_TRUE(base::PathExists(extract_dir)); |
| 60 | 60 |
| 61 base::FilePath archive = data_dir_.AppendASCII("archive1.7z"); | 61 base::FilePath archive = data_dir_.AppendASCII("archive1.7z"); |
| 62 LzmaUtil lzma_util; | 62 LzmaUtil lzma_util; |
| 63 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), NO_ERROR); | 63 EXPECT_EQ(lzma_util.OpenArchive(archive.value()), NO_ERROR); |
| 64 std::wstring unpacked_file; | 64 std::wstring unpacked_file; |
| 65 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file), | 65 EXPECT_EQ(lzma_util.UnPack(extract_dir.value(), &unpacked_file), |
| 66 NO_ERROR); | 66 NO_ERROR); |
| 67 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("a.exe"))); | 67 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("a.exe"))); |
| 68 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("a.exe").value()); | 68 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("a.exe").value()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 89 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("archive\\a.exe"))); | 89 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("archive\\a.exe"))); |
| 90 EXPECT_TRUE(base::PathExists( | 90 EXPECT_TRUE(base::PathExists( |
| 91 extract_dir.AppendASCII("archive\\sub_dir\\text.txt"))); | 91 extract_dir.AppendASCII("archive\\sub_dir\\text.txt"))); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Test the static method that can be used to unpack archives. | 94 // Test the static method that can be used to unpack archives. |
| 95 TEST_F(LzmaUtilTest, UnPackArchiveTest) { | 95 TEST_F(LzmaUtilTest, UnPackArchiveTest) { |
| 96 base::FilePath extract_dir(temp_dir_.path()); | 96 base::FilePath extract_dir(temp_dir_.path()); |
| 97 extract_dir = extract_dir.AppendASCII("UnPackArchiveTest"); | 97 extract_dir = extract_dir.AppendASCII("UnPackArchiveTest"); |
| 98 ASSERT_FALSE(base::PathExists(extract_dir)); | 98 ASSERT_FALSE(base::PathExists(extract_dir)); |
| 99 EXPECT_TRUE(file_util::CreateDirectory(extract_dir)); | 99 EXPECT_TRUE(base::CreateDirectory(extract_dir)); |
| 100 ASSERT_TRUE(base::PathExists(extract_dir)); | 100 ASSERT_TRUE(base::PathExists(extract_dir)); |
| 101 | 101 |
| 102 base::FilePath archive = data_dir_.AppendASCII("archive1.7z"); | 102 base::FilePath archive = data_dir_.AppendASCII("archive1.7z"); |
| 103 std::wstring unpacked_file; | 103 std::wstring unpacked_file; |
| 104 EXPECT_EQ(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(), | 104 EXPECT_EQ(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(), |
| 105 &unpacked_file), NO_ERROR); | 105 &unpacked_file), NO_ERROR); |
| 106 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("a.exe"))); | 106 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("a.exe"))); |
| 107 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("a.exe").value()); | 107 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("a.exe").value()); |
| 108 | 108 |
| 109 archive = data_dir_.AppendASCII("archive2.7z"); | 109 archive = data_dir_.AppendASCII("archive2.7z"); |
| 110 EXPECT_EQ(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(), | 110 EXPECT_EQ(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(), |
| 111 &unpacked_file), NO_ERROR); | 111 &unpacked_file), NO_ERROR); |
| 112 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("b.exe"))); | 112 EXPECT_TRUE(base::PathExists(extract_dir.AppendASCII("b.exe"))); |
| 113 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("b.exe").value()); | 113 EXPECT_TRUE(unpacked_file == extract_dir.AppendASCII("b.exe").value()); |
| 114 | 114 |
| 115 archive = data_dir_.AppendASCII("invalid_archive.7z"); | 115 archive = data_dir_.AppendASCII("invalid_archive.7z"); |
| 116 EXPECT_NE(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(), | 116 EXPECT_NE(LzmaUtil::UnPackArchive(archive.value(), extract_dir.value(), |
| 117 &unpacked_file), NO_ERROR); | 117 &unpacked_file), NO_ERROR); |
| 118 } | 118 } |
| OLD | NEW |