| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 <string.h> | 5 #include <string.h> |
| 6 #include <unistd.h> | 6 #include <unistd.h> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 #include <gtest/gtest.h> | 9 #include <gtest/gtest.h> |
| 10 #include "update_engine/decompressing_file_writer.h" | 10 #include "update_engine/decompressing_file_writer.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 const unsigned int k10bytesSize = 10; | 68 const unsigned int k10bytesSize = 10; |
| 69 const unsigned int kUncompressedFileSize = strlen(k10bytes) * 1024 * 1024; | 69 const unsigned int kUncompressedFileSize = strlen(k10bytes) * 1024 * 1024; |
| 70 uncompressed_file.Open(kPath.c_str(), | 70 uncompressed_file.Open(kPath.c_str(), |
| 71 O_CREAT | O_LARGEFILE | O_TRUNC | O_WRONLY, 0644); | 71 O_CREAT | O_LARGEFILE | O_TRUNC | O_WRONLY, 0644); |
| 72 for (unsigned int i = 0; i < kUncompressedFileSize / k10bytesSize; i++) { | 72 for (unsigned int i = 0; i < kUncompressedFileSize / k10bytesSize; i++) { |
| 73 ASSERT_EQ(k10bytesSize, uncompressed_file.Write("0123456789", 10)); | 73 ASSERT_EQ(k10bytesSize, uncompressed_file.Write("0123456789", 10)); |
| 74 } | 74 } |
| 75 uncompressed_file.Close(); | 75 uncompressed_file.Close(); |
| 76 | 76 |
| 77 // compress the file | 77 // compress the file |
| 78 system((string("cat ") + kPath + " | gzip > " + kPathgz).c_str()); | 78 EXPECT_EQ(0, |
| 79 system((string("cat ") + kPath + " | gzip > " + kPathgz).c_str())); |
| 79 | 80 |
| 80 // Now read the compressed file and put it into a DecompressingFileWriter | 81 // Now read the compressed file and put it into a DecompressingFileWriter |
| 81 MockFileWriter mock_file_writer; | 82 MockFileWriter mock_file_writer; |
| 82 GzipDecompressingFileWriter decompressing_file_writer(&mock_file_writer); | 83 GzipDecompressingFileWriter decompressing_file_writer(&mock_file_writer); |
| 83 | 84 |
| 84 const string path("unused"); | 85 const string path("unused"); |
| 85 ASSERT_EQ(0, decompressing_file_writer.Open( | 86 ASSERT_EQ(0, decompressing_file_writer.Open( |
| 86 path.c_str(), O_CREAT | O_LARGEFILE | O_TRUNC | O_WRONLY, 0644)); | 87 path.c_str(), O_CREAT | O_LARGEFILE | O_TRUNC | O_WRONLY, 0644)); |
| 87 | 88 |
| 88 // Open compressed file for reading: | 89 // Open compressed file for reading: |
| 89 int fd_in = open(kPathgz.c_str(), O_LARGEFILE | O_RDONLY, 0); | 90 int fd_in = open(kPathgz.c_str(), O_LARGEFILE | O_RDONLY, 0); |
| 90 ASSERT_GE(fd_in, 0); | 91 ASSERT_GE(fd_in, 0); |
| 91 char buf[100]; | 92 char buf[100]; |
| 92 int sz; | 93 int sz; |
| 93 while ((sz = read(fd_in, buf, sizeof(buf))) > 0) { | 94 while ((sz = read(fd_in, buf, sizeof(buf))) > 0) { |
| 94 decompressing_file_writer.Write(buf, sz); | 95 decompressing_file_writer.Write(buf, sz); |
| 95 } | 96 } |
| 96 close(fd_in); | 97 close(fd_in); |
| 97 decompressing_file_writer.Close(); | 98 decompressing_file_writer.Close(); |
| 98 | 99 |
| 99 ASSERT_EQ(kUncompressedFileSize, mock_file_writer.bytes().size()); | 100 ASSERT_EQ(kUncompressedFileSize, mock_file_writer.bytes().size()); |
| 100 for (unsigned int i = 0; i < kUncompressedFileSize; i++) { | 101 for (unsigned int i = 0; i < kUncompressedFileSize; i++) { |
| 101 ASSERT_EQ(mock_file_writer.bytes()[i], '0' + (i % 10)) << "i = " << i; | 102 ASSERT_EQ(mock_file_writer.bytes()[i], '0' + (i % 10)) << "i = " << i; |
| 102 } | 103 } |
| 103 unlink(kPath.c_str()); | 104 unlink(kPath.c_str()); |
| 104 unlink(kPathgz.c_str()); | 105 unlink(kPathgz.c_str()); |
| 105 } | 106 } |
| 106 | 107 |
| 107 } // namespace chromeos_update_engine | 108 } // namespace chromeos_update_engine |
| OLD | NEW |