diff options
author | Rob Mensching <rob@firegiant.com> | 2022-03-31 11:56:14 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2022-03-31 18:01:06 -0700 |
commit | 47582b162368e8edf7a3b11c13b8e9dabc5f0a26 (patch) | |
tree | 2c4063eff325684bed39de0edacd7866a257ae02 /src/dtf/WixToolsetTests.Dtf.Compression.Zip/ZipTest.cs | |
parent | 167296c42497c4e95f0d5d71168542d747655981 (diff) | |
download | wix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.tar.gz wix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.tar.bz2 wix-47582b162368e8edf7a3b11c13b8e9dabc5f0a26.zip |
Provide managed CA and Embedded UI DTF libraries via NuGet
Lots of refactoring to bring the SFX tooling back into the 'dtf'
layer since they are (in the end) tightly coupled to some DTF
assemblies. Also refactored the DTF tests into their own folder
and added a couple integration tests to build using the new CA/UI
NuGet package.
Closes wixtoolset/issues#6080
Diffstat (limited to 'src/dtf/WixToolsetTests.Dtf.Compression.Zip/ZipTest.cs')
-rw-r--r-- | src/dtf/WixToolsetTests.Dtf.Compression.Zip/ZipTest.cs | 518 |
1 files changed, 0 insertions, 518 deletions
diff --git a/src/dtf/WixToolsetTests.Dtf.Compression.Zip/ZipTest.cs b/src/dtf/WixToolsetTests.Dtf.Compression.Zip/ZipTest.cs deleted file mode 100644 index b264ad5b..00000000 --- a/src/dtf/WixToolsetTests.Dtf.Compression.Zip/ZipTest.cs +++ /dev/null | |||
@@ -1,518 +0,0 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolset.Dtf.Test | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using System.Text; | ||
8 | using System.Collections.Generic; | ||
9 | using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
10 | using WixToolset.Dtf.Compression; | ||
11 | using WixToolset.Dtf.Compression.Zip; | ||
12 | |||
13 | [TestClass] | ||
14 | public class ZipTest | ||
15 | { | ||
16 | public ZipTest() | ||
17 | { | ||
18 | } | ||
19 | |||
20 | [TestInitialize] | ||
21 | public void Initialize() | ||
22 | { | ||
23 | } | ||
24 | |||
25 | [TestCleanup] | ||
26 | public void Cleanup() | ||
27 | { | ||
28 | } | ||
29 | |||
30 | [TestMethod] | ||
31 | public void ZipFileCounts() | ||
32 | { | ||
33 | this.RunZipPackUnpack(0, 10, 0); | ||
34 | this.RunZipPackUnpack(0, 100000, 0); | ||
35 | this.RunZipPackUnpack(1, 10, 0); | ||
36 | this.RunZipPackUnpack(100, 10, 0); | ||
37 | } | ||
38 | |||
39 | [TestMethod] | ||
40 | [Ignore] // Takes too long to run regularly. | ||
41 | public void ZipExtremeFileCounts() | ||
42 | { | ||
43 | this.RunZipPackUnpack(66000, 10, 0); | ||
44 | } | ||
45 | |||
46 | [TestMethod] | ||
47 | public void ZipFileSizes() | ||
48 | { | ||
49 | this.RunZipPackUnpack(1, 0, 0); | ||
50 | for (int n = 1; n <= 33; n++) | ||
51 | { | ||
52 | this.RunZipPackUnpack(1, n, 0); | ||
53 | } | ||
54 | this.RunZipPackUnpack(1, 100 * 1024, 0); | ||
55 | this.RunZipPackUnpack(1, 10 * 1024 * 1024, 0); | ||
56 | } | ||
57 | |||
58 | [Timeout(36000000), TestMethod] | ||
59 | [Ignore] // Takes too long to run regularly. | ||
60 | public void ZipExtremeFileSizes() | ||
61 | { | ||
62 | //this.RunZipPackUnpack(10, 512L * 1024 * 1024, 0); // 5GB | ||
63 | this.RunZipPackUnpack(1, 5L * 1024 * 1024 * 1024, 0, CompressionLevel.None); // 5GB | ||
64 | } | ||
65 | |||
66 | [TestMethod] | ||
67 | public void ZipArchiveCounts() | ||
68 | { | ||
69 | IList<ArchiveFileInfo> fileInfo; | ||
70 | fileInfo = this.RunZipPackUnpack(10, 100 * 1024, 400 * 1024, CompressionLevel.None); | ||
71 | Assert.AreEqual<int>(2, fileInfo[fileInfo.Count - 1].ArchiveNumber, | ||
72 | "Testing whether archive spans the correct # of zip files."); | ||
73 | |||
74 | fileInfo = this.RunZipPackUnpack(2, 90 * 1024, 40 * 1024, CompressionLevel.None); | ||
75 | Assert.AreEqual<int>(2, fileInfo[fileInfo.Count - 1].ArchiveNumber, | ||
76 | "Testing whether archive spans the correct # of zip files."); | ||
77 | } | ||
78 | |||
79 | [TestMethod] | ||
80 | public void ZipProgress() | ||
81 | { | ||
82 | CompressionTestUtil.ExpectedProgress = new List<int[]>(new int[][] { | ||
83 | // StatusType, CurFile,TotalFiles,CurFolder,CurArchive,TotalArchives | ||
84 | new int[] { (int) ArchiveProgressType.StartArchive, 0, 15, 0, 0, 1 }, | ||
85 | new int[] { (int) ArchiveProgressType.StartFile, 0, 15, 0, 0, 1 }, | ||
86 | new int[] { (int) ArchiveProgressType.FinishFile, 0, 15, 0, 0, 1 }, | ||
87 | new int[] { (int) ArchiveProgressType.StartFile, 1, 15, 0, 0, 1 }, | ||
88 | new int[] { (int) ArchiveProgressType.FinishFile, 1, 15, 0, 0, 1 }, | ||
89 | new int[] { (int) ArchiveProgressType.StartFile, 2, 15, 0, 0, 1 }, | ||
90 | new int[] { (int) ArchiveProgressType.FinishFile, 2, 15, 0, 0, 1 }, | ||
91 | new int[] { (int) ArchiveProgressType.StartFile, 3, 15, 0, 0, 1 }, | ||
92 | new int[] { (int) ArchiveProgressType.FinishFile, 3, 15, 0, 0, 1 }, | ||
93 | new int[] { (int) ArchiveProgressType.StartFile, 4, 15, 0, 0, 1 }, | ||
94 | new int[] { (int) ArchiveProgressType.FinishFile, 4, 15, 0, 0, 1 }, | ||
95 | new int[] { (int) ArchiveProgressType.StartFile, 5, 15, 0, 0, 1 }, | ||
96 | new int[] { (int) ArchiveProgressType.FinishFile, 5, 15, 0, 0, 1 }, | ||
97 | new int[] { (int) ArchiveProgressType.StartFile, 6, 15, 0, 0, 1 }, | ||
98 | new int[] { (int) ArchiveProgressType.FinishArchive, 6, 15, 0, 0, 1 }, | ||
99 | new int[] { (int) ArchiveProgressType.StartArchive, 6, 15, 0, 1, 2 }, | ||
100 | new int[] { (int) ArchiveProgressType.FinishFile, 6, 15, 0, 1, 2 }, | ||
101 | new int[] { (int) ArchiveProgressType.StartFile, 7, 15, 0, 1, 2 }, | ||
102 | new int[] { (int) ArchiveProgressType.FinishFile, 7, 15, 0, 1, 2 }, | ||
103 | new int[] { (int) ArchiveProgressType.StartFile, 8, 15, 0, 1, 2 }, | ||
104 | new int[] { (int) ArchiveProgressType.FinishFile, 8, 15, 0, 1, 2 }, | ||
105 | new int[] { (int) ArchiveProgressType.StartFile, 9, 15, 0, 1, 2 }, | ||
106 | new int[] { (int) ArchiveProgressType.FinishFile, 9, 15, 0, 1, 2 }, | ||
107 | new int[] { (int) ArchiveProgressType.StartFile, 10, 15, 0, 1, 2 }, | ||
108 | new int[] { (int) ArchiveProgressType.FinishFile, 10, 15, 0, 1, 2 }, | ||
109 | new int[] { (int) ArchiveProgressType.StartFile, 11, 15, 0, 1, 2 }, | ||
110 | new int[] { (int) ArchiveProgressType.FinishFile, 11, 15, 0, 1, 2 }, | ||
111 | new int[] { (int) ArchiveProgressType.StartFile, 12, 15, 0, 1, 2 }, | ||
112 | new int[] { (int) ArchiveProgressType.FinishArchive, 12, 15, 0, 1, 2 }, | ||
113 | new int[] { (int) ArchiveProgressType.StartArchive, 12, 15, 0, 2, 3 }, | ||
114 | new int[] { (int) ArchiveProgressType.FinishFile, 12, 15, 0, 2, 3 }, | ||
115 | new int[] { (int) ArchiveProgressType.StartFile, 13, 15, 0, 2, 3 }, | ||
116 | new int[] { (int) ArchiveProgressType.FinishFile, 13, 15, 0, 2, 3 }, | ||
117 | new int[] { (int) ArchiveProgressType.StartFile, 14, 15, 0, 2, 3 }, | ||
118 | new int[] { (int) ArchiveProgressType.FinishFile, 14, 15, 0, 2, 3 }, | ||
119 | new int[] { (int) ArchiveProgressType.FinishArchive, 14, 15, 0, 2, 3 }, | ||
120 | // StatusType, CurFile,TotalFiles,CurFolder,CurArchive,TotalArchives | ||
121 | new int[] { (int) ArchiveProgressType.StartArchive, 0, 15, 0, 0, 3 }, | ||
122 | new int[] { (int) ArchiveProgressType.StartFile, 0, 15, 0, 0, 3 }, | ||
123 | new int[] { (int) ArchiveProgressType.FinishFile, 0, 15, 0, 0, 3 }, | ||
124 | new int[] { (int) ArchiveProgressType.StartFile, 1, 15, 0, 0, 3 }, | ||
125 | new int[] { (int) ArchiveProgressType.FinishFile, 1, 15, 0, 0, 3 }, | ||
126 | new int[] { (int) ArchiveProgressType.StartFile, 2, 15, 0, 0, 3 }, | ||
127 | new int[] { (int) ArchiveProgressType.FinishFile, 2, 15, 0, 0, 3 }, | ||
128 | new int[] { (int) ArchiveProgressType.StartFile, 3, 15, 0, 0, 3 }, | ||
129 | new int[] { (int) ArchiveProgressType.FinishFile, 3, 15, 0, 0, 3 }, | ||
130 | new int[] { (int) ArchiveProgressType.StartFile, 4, 15, 0, 0, 3 }, | ||
131 | new int[] { (int) ArchiveProgressType.FinishFile, 4, 15, 0, 0, 3 }, | ||
132 | new int[] { (int) ArchiveProgressType.StartFile, 5, 15, 0, 0, 3 }, | ||
133 | new int[] { (int) ArchiveProgressType.FinishFile, 5, 15, 0, 0, 3 }, | ||
134 | new int[] { (int) ArchiveProgressType.StartFile, 6, 15, 0, 0, 3 }, | ||
135 | new int[] { (int) ArchiveProgressType.FinishArchive, 6, 15, 0, 0, 3 }, | ||
136 | new int[] { (int) ArchiveProgressType.StartArchive, 6, 15, 0, 1, 3 }, | ||
137 | new int[] { (int) ArchiveProgressType.FinishFile, 6, 15, 0, 1, 3 }, | ||
138 | new int[] { (int) ArchiveProgressType.StartFile, 7, 15, 0, 1, 3 }, | ||
139 | new int[] { (int) ArchiveProgressType.FinishFile, 7, 15, 0, 1, 3 }, | ||
140 | new int[] { (int) ArchiveProgressType.StartFile, 8, 15, 0, 1, 3 }, | ||
141 | new int[] { (int) ArchiveProgressType.FinishFile, 8, 15, 0, 1, 3 }, | ||
142 | new int[] { (int) ArchiveProgressType.StartFile, 9, 15, 0, 1, 3 }, | ||
143 | new int[] { (int) ArchiveProgressType.FinishFile, 9, 15, 0, 1, 3 }, | ||
144 | new int[] { (int) ArchiveProgressType.StartFile, 10, 15, 0, 1, 3 }, | ||
145 | new int[] { (int) ArchiveProgressType.FinishFile, 10, 15, 0, 1, 3 }, | ||
146 | new int[] { (int) ArchiveProgressType.StartFile, 11, 15, 0, 1, 3 }, | ||
147 | new int[] { (int) ArchiveProgressType.FinishFile, 11, 15, 0, 1, 3 }, | ||
148 | new int[] { (int) ArchiveProgressType.StartFile, 12, 15, 0, 1, 3 }, | ||
149 | new int[] { (int) ArchiveProgressType.FinishArchive, 12, 15, 0, 1, 3 }, | ||
150 | new int[] { (int) ArchiveProgressType.StartArchive, 12, 15, 0, 2, 3 }, | ||
151 | new int[] { (int) ArchiveProgressType.FinishFile, 12, 15, 0, 2, 3 }, | ||
152 | new int[] { (int) ArchiveProgressType.StartFile, 13, 15, 0, 2, 3 }, | ||
153 | new int[] { (int) ArchiveProgressType.FinishFile, 13, 15, 0, 2, 3 }, | ||
154 | new int[] { (int) ArchiveProgressType.StartFile, 14, 15, 0, 2, 3 }, | ||
155 | new int[] { (int) ArchiveProgressType.FinishFile, 14, 15, 0, 2, 3 }, | ||
156 | new int[] { (int) ArchiveProgressType.FinishArchive, 14, 15, 0, 2, 3 }, | ||
157 | }); | ||
158 | CompressionTestUtil.ExpectedProgress = null; | ||
159 | |||
160 | try | ||
161 | { | ||
162 | this.RunZipPackUnpack(15, 20 * 1024, 130 * 1024, CompressionLevel.None); | ||
163 | } | ||
164 | finally | ||
165 | { | ||
166 | CompressionTestUtil.ExpectedProgress = null; | ||
167 | } | ||
168 | } | ||
169 | |||
170 | [TestMethod] | ||
171 | //[Ignore] // Requires clean environment. | ||
172 | public void ZipArchiveSizes() | ||
173 | { | ||
174 | Console.WriteLine("Testing various values for the maxArchiveSize parameter."); | ||
175 | this.RunZipPackUnpack(5, 1024, Int64.MinValue); | ||
176 | this.RunZipPackUnpack(5, 1024, -1); | ||
177 | this.RunZipPackUnpack(2, 10, 0); | ||
178 | |||
179 | this.RunZipPackUnpack(1, 10, 1); | ||
180 | this.RunZipPackUnpack(2, 10, 2); | ||
181 | this.RunZipPackUnpack(2, 10, 3); | ||
182 | this.RunZipPackUnpack(2, 10, 4); | ||
183 | this.RunZipPackUnpack(2, 10, 5); | ||
184 | this.RunZipPackUnpack(2, 10, 6); | ||
185 | this.RunZipPackUnpack(2, 10, 7); | ||
186 | this.RunZipPackUnpack(5, 10, 8); | ||
187 | this.RunZipPackUnpack(5, 10, 9); | ||
188 | this.RunZipPackUnpack(5, 10, 10); | ||
189 | this.RunZipPackUnpack(5, 10, 11); | ||
190 | this.RunZipPackUnpack(5, 10, 12); | ||
191 | |||
192 | this.RunZipPackUnpack(5, 101, 255); | ||
193 | this.RunZipPackUnpack(5, 102, 256); | ||
194 | this.RunZipPackUnpack(5, 103, 257); | ||
195 | this.RunZipPackUnpack(5, 24000, 32768); | ||
196 | this.RunZipPackUnpack(5, 1024, Int64.MaxValue); | ||
197 | } | ||
198 | |||
199 | [TestMethod] | ||
200 | public void ZipCompLevelParam() | ||
201 | { | ||
202 | Console.WriteLine("Testing various values for the compressionLevel parameter."); | ||
203 | this.RunZipPackUnpack(5, 1024, 0, CompressionLevel.None); | ||
204 | this.RunZipPackUnpack(5, 1024, 0, CompressionLevel.Min); | ||
205 | this.RunZipPackUnpack(5, 1024, 0, CompressionLevel.Normal); | ||
206 | this.RunZipPackUnpack(5, 1024, 0, CompressionLevel.Max); | ||
207 | this.RunZipPackUnpack(5, 1024, 0, (CompressionLevel) ((int) CompressionLevel.None - 1)); | ||
208 | this.RunZipPackUnpack(5, 1024, 0, (CompressionLevel) ((int) CompressionLevel.Max + 1)); | ||
209 | this.RunZipPackUnpack(5, 1024, 0, (CompressionLevel) Int32.MinValue); | ||
210 | this.RunZipPackUnpack(5, 1024, 0, (CompressionLevel) Int32.MaxValue); | ||
211 | } | ||
212 | |||
213 | [TestMethod] | ||
214 | public void ZipInfoGetFiles() | ||
215 | { | ||
216 | IList<ZipFileInfo> fileInfos; | ||
217 | ZipInfo zipInfo = new ZipInfo("testgetfiles.zip"); | ||
218 | |||
219 | int txtSize = 10240; | ||
220 | CompressionTestUtil.GenerateRandomFile("testinfo0.txt", 0, txtSize); | ||
221 | CompressionTestUtil.GenerateRandomFile("testinfo1.txt", 1, txtSize); | ||
222 | CompressionTestUtil.GenerateRandomFile("testinfo2.ini", 2, txtSize); | ||
223 | zipInfo.PackFiles(null, new string[] { "testinfo0.txt", "testinfo1.txt", "testinfo2.ini" }, null); | ||
224 | |||
225 | fileInfos = zipInfo.GetFiles(); | ||
226 | Assert.IsNotNull(fileInfos); | ||
227 | Assert.AreEqual<int>(3, fileInfos.Count); | ||
228 | Assert.AreEqual<string>("testinfo0.txt", fileInfos[0].Name); | ||
229 | Assert.AreEqual<string>("testinfo1.txt", fileInfos[1].Name); | ||
230 | Assert.AreEqual<string>("testinfo2.ini", fileInfos[2].Name); | ||
231 | |||
232 | fileInfos = zipInfo.GetFiles("*.txt"); | ||
233 | Assert.IsNotNull(fileInfos); | ||
234 | Assert.AreEqual<int>(2, fileInfos.Count); | ||
235 | Assert.AreEqual<string>("testinfo0.txt", fileInfos[0].Name); | ||
236 | Assert.AreEqual<string>("testinfo1.txt", fileInfos[1].Name); | ||
237 | |||
238 | fileInfos = zipInfo.GetFiles("testinfo1.txt"); | ||
239 | Assert.IsNotNull(fileInfos); | ||
240 | Assert.AreEqual<int>(1, fileInfos.Count); | ||
241 | Assert.AreEqual<string>("testinfo1.txt", fileInfos[0].Name); | ||
242 | Assert.IsTrue(DateTime.Now - fileInfos[0].LastWriteTime < TimeSpan.FromMinutes(1), | ||
243 | "Checking ZipFileInfo.LastWriteTime is current."); | ||
244 | } | ||
245 | |||
246 | [TestMethod] | ||
247 | //[Ignore] // Requires clean environment. | ||
248 | public void ZipInfoNullParams() | ||
249 | { | ||
250 | int fileCount = 10, fileSize = 1024; | ||
251 | string dirA = String.Format("{0}-{1}-A", fileCount, fileSize); | ||
252 | if (Directory.Exists(dirA)) Directory.Delete(dirA, true); | ||
253 | Directory.CreateDirectory(dirA); | ||
254 | string dirB = String.Format("{0}-{1}-B", fileCount, fileSize); | ||
255 | if (Directory.Exists(dirB)) Directory.Delete(dirB, true); | ||
256 | Directory.CreateDirectory(dirB); | ||
257 | |||
258 | string[] files = new string[fileCount]; | ||
259 | for (int iFile = 0; iFile < fileCount; iFile++) | ||
260 | { | ||
261 | files[iFile] = "zipinfo-" + iFile + ".txt"; | ||
262 | CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[iFile]), iFile, fileSize); | ||
263 | } | ||
264 | |||
265 | ZipInfo zipInfo = new ZipInfo("testnull.zip"); | ||
266 | |||
267 | CompressionTestUtil.TestArchiveInfoNullParams(zipInfo, dirA, dirB, files); | ||
268 | } | ||
269 | |||
270 | [TestMethod] | ||
271 | public void ZipFileInfoNullParams() | ||
272 | { | ||
273 | Exception caughtEx; | ||
274 | ZipInfo zipInfo = new ZipInfo("test.zip"); | ||
275 | int txtSize = 10240; | ||
276 | CompressionTestUtil.GenerateRandomFile("test00.txt", 0, txtSize); | ||
277 | CompressionTestUtil.GenerateRandomFile("test01.txt", 1, txtSize); | ||
278 | zipInfo.PackFiles(null, new string[] { "test00.txt", "test01.txt" }, null); | ||
279 | ZipFileInfo zfi = new ZipFileInfo(zipInfo, "test01.txt"); | ||
280 | |||
281 | caughtEx = null; | ||
282 | try | ||
283 | { | ||
284 | new ZipFileInfo(null, "test00.txt"); | ||
285 | } | ||
286 | catch (Exception ex) { caughtEx = ex; } | ||
287 | Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException)); | ||
288 | caughtEx = null; | ||
289 | try | ||
290 | { | ||
291 | new ZipFileInfo(zipInfo, null); | ||
292 | } | ||
293 | catch (Exception ex) { caughtEx = ex; } | ||
294 | Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException)); | ||
295 | caughtEx = null; | ||
296 | try | ||
297 | { | ||
298 | zfi.CopyTo(null); | ||
299 | } | ||
300 | catch (Exception ex) { caughtEx = ex; } | ||
301 | Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException)); | ||
302 | } | ||
303 | |||
304 | [TestMethod] | ||
305 | public void ZipEngineNullParams() | ||
306 | { | ||
307 | string[] testFiles = new string[] { "test.txt" }; | ||
308 | ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext("test.zip", null, null); | ||
309 | |||
310 | using (ZipEngine zipEngine = new ZipEngine()) | ||
311 | { | ||
312 | zipEngine.CompressionLevel = CompressionLevel.None; | ||
313 | |||
314 | CompressionTestUtil.TestCompressionEngineNullParams(zipEngine, streamContext, testFiles); | ||
315 | } | ||
316 | } | ||
317 | |||
318 | [TestMethod] | ||
319 | public void ZipBadPackStreamContexts() | ||
320 | { | ||
321 | string[] testFiles = new string[] { "test.txt" }; | ||
322 | CompressionTestUtil.GenerateRandomFile(testFiles[0], 0, 20000); | ||
323 | |||
324 | using (ZipEngine zipEngine = new ZipEngine()) | ||
325 | { | ||
326 | zipEngine.CompressionLevel = CompressionLevel.None; | ||
327 | |||
328 | CompressionTestUtil.TestBadPackStreamContexts(zipEngine, "test.zip", testFiles); | ||
329 | } | ||
330 | } | ||
331 | |||
332 | [TestMethod] | ||
333 | public void ZipBadUnpackStreamContexts() | ||
334 | { | ||
335 | int txtSize = 40960; | ||
336 | ZipInfo zipInfo = new ZipInfo("test2.zip"); | ||
337 | CompressionTestUtil.GenerateRandomFile("ziptest-0.txt", 0, txtSize); | ||
338 | CompressionTestUtil.GenerateRandomFile("ziptest-1.txt", 1, txtSize); | ||
339 | zipInfo.PackFiles(null, new string[] { "ziptest-0.txt", "ziptest-1.txt" }, null); | ||
340 | |||
341 | using (ZipEngine zipEngine = new ZipEngine()) | ||
342 | { | ||
343 | CompressionTestUtil.TestBadUnpackStreamContexts(zipEngine, "test2.zip"); | ||
344 | } | ||
345 | } | ||
346 | |||
347 | [TestMethod] | ||
348 | [Ignore] // Failed on build server, need to investigate. | ||
349 | public void ZipTruncatedArchive() | ||
350 | { | ||
351 | ZipInfo zipInfo = new ZipInfo("test-t.zip"); | ||
352 | CompressionTestUtil.GenerateRandomFile("ziptest-0.txt", 0, 5); | ||
353 | CompressionTestUtil.GenerateRandomFile("ziptest-1.txt", 1, 5); | ||
354 | zipInfo.PackFiles(null, new string[] { "ziptest-0.txt", "ziptest-1.txt" }, null); | ||
355 | |||
356 | CompressionTestUtil.TestTruncatedArchive(zipInfo, typeof(ZipException)); | ||
357 | } | ||
358 | |||
359 | /* | ||
360 | [TestMethod] | ||
361 | public void ZipUnpack() | ||
362 | { | ||
363 | IList<ZipFileInfo> fileInfos; | ||
364 | foreach (FileInfo zipFile in new DirectoryInfo("D:\\temp").GetFiles("*.zip")) | ||
365 | { | ||
366 | Console.WriteLine("====================================================="); | ||
367 | Console.WriteLine(zipFile.FullName); | ||
368 | Console.WriteLine("====================================================="); | ||
369 | ZipInfo zipTest = new ZipInfo(zipFile.FullName); | ||
370 | fileInfos = zipTest.GetFiles(); | ||
371 | Assert.AreNotEqual<int>(0, fileInfos.Count); | ||
372 | foreach (ArchiveFileInfo file in fileInfos) | ||
373 | { | ||
374 | Console.WriteLine("{0}\t{1}\t{2}", Path.Combine(file.Path, file.Name), file.Length, file.LastWriteTime); | ||
375 | } | ||
376 | |||
377 | Directory.CreateDirectory(Path.GetFileNameWithoutExtension(zipFile.Name)); | ||
378 | zipTest.Unpack(Path.GetFileNameWithoutExtension(zipFile.Name)); | ||
379 | } | ||
380 | } | ||
381 | */ | ||
382 | |||
383 | /* | ||
384 | [TestMethod] | ||
385 | public void ZipUnpackSelfExtractor() | ||
386 | { | ||
387 | ZipInfo zipTest = new ZipInfo(@"C:\temp\testzip.exe"); | ||
388 | IList<ZipFileInfo> fileInfos = zipTest.GetFiles(); | ||
389 | Assert.AreNotEqual<int>(0, fileInfos.Count); | ||
390 | foreach (ArchiveFileInfo file in fileInfos) | ||
391 | { | ||
392 | Console.WriteLine("{0}\t{1}\t{2}", Path.Combine(file.Path, file.Name), file.Length, file.LastWriteTime); | ||
393 | } | ||
394 | |||
395 | string extractDir = Path.GetFileNameWithoutExtension(zipTest.Name); | ||
396 | Directory.CreateDirectory(extractDir); | ||
397 | zipTest.Unpack(extractDir); | ||
398 | } | ||
399 | */ | ||
400 | |||
401 | private const string TEST_FILENAME_PREFIX = "\x20AC"; | ||
402 | |||
403 | private IList<ArchiveFileInfo> RunZipPackUnpack(int fileCount, long fileSize, | ||
404 | long maxArchiveSize) | ||
405 | { | ||
406 | return this.RunZipPackUnpack(fileCount, fileSize, maxArchiveSize, CompressionLevel.Normal); | ||
407 | } | ||
408 | |||
409 | private IList<ArchiveFileInfo> RunZipPackUnpack(int fileCount, long fileSize, | ||
410 | long maxArchiveSize, CompressionLevel compLevel) | ||
411 | { | ||
412 | Console.WriteLine("Creating zip archive with {0} files of size {1}", | ||
413 | fileCount, fileSize); | ||
414 | Console.WriteLine("MaxArchiveSize={0}, CompressionLevel={1}", maxArchiveSize, compLevel); | ||
415 | |||
416 | string dirA = String.Format("{0}-{1}-A", fileCount, fileSize); | ||
417 | if (Directory.Exists(dirA)) Directory.Delete(dirA, true); | ||
418 | Directory.CreateDirectory(dirA); | ||
419 | string dirB = String.Format("{0}-{1}-B", fileCount, fileSize); | ||
420 | if (Directory.Exists(dirB)) Directory.Delete(dirB, true); | ||
421 | Directory.CreateDirectory(dirB); | ||
422 | |||
423 | string[] files = new string[fileCount]; | ||
424 | for (int iFile = 0; iFile < fileCount; iFile++) | ||
425 | { | ||
426 | files[iFile] = TEST_FILENAME_PREFIX + iFile + ".txt"; | ||
427 | CompressionTestUtil.GenerateRandomFile(Path.Combine(dirA, files[iFile]), iFile, fileSize); | ||
428 | } | ||
429 | |||
430 | string[] archiveNames = new string[1000]; | ||
431 | for (int i = 0; i < archiveNames.Length; i++) | ||
432 | { | ||
433 | if (i < 100) | ||
434 | { | ||
435 | archiveNames[i] = String.Format( | ||
436 | (i == 0 ? "{0}-{1}.zip" : "{0}-{1}.z{2:d02}"), | ||
437 | fileCount, fileSize, i); | ||
438 | } | ||
439 | else | ||
440 | { | ||
441 | archiveNames[i] = String.Format( | ||
442 | "{0}-{1}.{2:d03}", fileCount, fileSize, i); | ||
443 | } | ||
444 | } | ||
445 | |||
446 | string progressTextFile = String.Format("progress_{0}-{1}.txt", fileCount, fileSize); | ||
447 | CompressionTestUtil testUtil = new CompressionTestUtil(progressTextFile); | ||
448 | |||
449 | IList<ArchiveFileInfo> fileInfo; | ||
450 | using (ZipEngine zipEngine = new ZipEngine()) | ||
451 | { | ||
452 | zipEngine.CompressionLevel = compLevel; | ||
453 | |||
454 | File.AppendAllText(progressTextFile, | ||
455 | "\r\n\r\n====================================================\r\nCREATE\r\n\r\n"); | ||
456 | zipEngine.Progress += testUtil.PrintArchiveProgress; | ||
457 | |||
458 | OptionStreamContext streamContext = new OptionStreamContext(archiveNames, dirA, null); | ||
459 | streamContext.OptionHandler = | ||
460 | delegate(string optionName, object[] parameters) | ||
461 | { | ||
462 | // For testing purposes, force zip64 for only moderately large files. | ||
463 | switch (optionName) | ||
464 | { | ||
465 | case "forceZip64": | ||
466 | return fileSize > UInt16.MaxValue; | ||
467 | default: | ||
468 | return null; | ||
469 | } | ||
470 | }; | ||
471 | |||
472 | zipEngine.Pack(streamContext, files, maxArchiveSize); | ||
473 | |||
474 | string checkArchiveName = archiveNames[0]; | ||
475 | if (File.Exists(archiveNames[1])) checkArchiveName = archiveNames[1]; | ||
476 | using (Stream archiveStream = File.OpenRead(checkArchiveName)) | ||
477 | { | ||
478 | bool isArchive = zipEngine.IsArchive(archiveStream); | ||
479 | Assert.IsTrue(isArchive, "Checking that created archive appears valid."); | ||
480 | } | ||
481 | |||
482 | IList<string> createdArchiveNames = new List<string>(archiveNames.Length); | ||
483 | for (int i = 0; i < archiveNames.Length; i++) | ||
484 | { | ||
485 | if (File.Exists(archiveNames[i])) | ||
486 | { | ||
487 | createdArchiveNames.Add(archiveNames[i]); | ||
488 | } | ||
489 | else | ||
490 | { | ||
491 | break; | ||
492 | } | ||
493 | } | ||
494 | |||
495 | Assert.AreNotEqual<int>(0, createdArchiveNames.Count); | ||
496 | |||
497 | Console.WriteLine("Listing zip archive with {0} files of size {1}", | ||
498 | fileCount, fileSize); | ||
499 | File.AppendAllText(progressTextFile, "\r\n\r\nLIST\r\n\r\n"); | ||
500 | fileInfo = zipEngine.GetFileInfo( | ||
501 | new ArchiveFileStreamContext(createdArchiveNames, null, null), null); | ||
502 | |||
503 | Assert.AreEqual<int>(fileCount, fileInfo.Count); | ||
504 | |||
505 | Console.WriteLine("Extracting zip archive with {0} files of size {1}", | ||
506 | fileCount, fileSize); | ||
507 | File.AppendAllText(progressTextFile, "\r\n\r\nEXTRACT\r\n\r\n"); | ||
508 | zipEngine.Unpack(new ArchiveFileStreamContext(createdArchiveNames, dirB, null), null); | ||
509 | } | ||
510 | |||
511 | bool directoryMatch = CompressionTestUtil.CompareDirectories(dirA, dirB); | ||
512 | Assert.IsTrue(directoryMatch, | ||
513 | "Testing whether zip output directory matches input directory."); | ||
514 | |||
515 | return fileInfo; | ||
516 | } | ||
517 | } | ||
518 | } | ||