[runtime] Replace pedump boehm dependency with sgen dependency
[mono.git] / mcs / class / System.IO.Compression.FileSystem / Test / System.IO.Compression.FileSystem / ZipTest.cs
1 //
2 // ZipTest.cs
3 //
4 // Author:
5 //       João Matos <joao.matos@xamarin.com>
6 //
7 // Copyright (c) 2013 Xamarin Inc. (http://www.xamarin.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26
27 using System;
28 using System.IO;
29 using System.IO.Compression;
30 using System.Linq;
31 using System.Security.Cryptography;
32 using NUnit.Framework;
33
34 namespace MonoTests.System.IO.Compression.FileSystem
35 {
36         [TestFixture]
37         public class ZipArchiveTests
38         {
39                 [TearDown]
40                 public void Dispose()
41                 {
42                         File.Delete ("foo.zip");
43                 }
44
45                 [Test]
46                 public void ZipCreateFromDirectory()
47                 {
48                         if (File.Exists ("foo.zip"))
49                                 File.Delete ("foo.zip");
50
51                         ZipFile.CreateFromDirectory ("foo", "foo.zip");
52                         Assert.IsTrue(File.Exists("foo.zip"));
53
54                         using (var archive = new ZipArchive (File.Open ("foo.zip", FileMode.Open),
55                                 ZipArchiveMode.Read))
56                         {
57                                 Assert.IsNotNull (archive.GetEntry ("foo.txt"));
58                                 Assert.IsNotNull (archive.GetEntry ("bar.txt"));
59
60                                 Assert.IsNotNull (archive.GetEntry ("foobar/foo.txt"));
61                                 Assert.IsNotNull (archive.GetEntry ("foobar/bar.txt"));                         
62                         }
63                 }
64
65                 [Test]
66                 public void ZipCreateFromDirectoryIncludeBase()
67                 {
68                         if (File.Exists ("foo.zip"))
69                                 File.Delete ("foo.zip");
70
71                         ZipFile.CreateFromDirectory ("foo", "foo.zip", CompressionLevel.Fastest,
72                                 includeBaseDirectory: true);
73                         Assert.IsTrue (File.Exists ("foo.zip"));
74
75                         using (var archive = new ZipArchive (File.Open ("foo.zip", FileMode.Open),
76                                 ZipArchiveMode.Read))
77                         {
78                                 Assert.IsNotNull (archive.GetEntry ("foo/foo.txt"));
79                                 Assert.IsNotNull (archive.GetEntry ("foo/bar.txt"));
80
81                                 Assert.IsNotNull (archive.GetEntry ("foo/foobar/foo.txt"));
82                                 Assert.IsNotNull (archive.GetEntry ("foo/foobar/bar.txt"));                             
83                         }
84                 }               
85
86                 [Test]
87                 public void ZipExtractToDirectory()
88                 {
89                         if (Directory.Exists ("extract"))
90                                 Directory.Delete ("extract", true);
91
92                         if (File.Exists ("foo.zip"))
93                                 File.Delete ("foo.zip");
94
95                         ZipFile.CreateFromDirectory ("foo", "foo.zip");
96
97                         ZipFile.ExtractToDirectory ("foo.zip", "extract");
98                         Assert.IsTrue(Directory.Exists ("extract"));
99
100                         Assert.IsTrue (File.Exists ("extract/foo.txt"));
101                         Assert.IsTrue (File.Exists ("extract/bar.txt"));
102                         Assert.IsTrue (Directory.Exists ("extract/foobar"));
103                         Assert.IsTrue (File.Exists ("extract/foobar/foo.txt"));
104                         Assert.IsTrue (File.Exists ("extract/foobar/bar.txt"));
105
106                         Directory.Delete ("extract", true);
107                 }
108         }
109 }