BGC Tools
Public Member Functions
BGC.Tests.ZipTests Class Reference

Public Member Functions

void TestZip ()
 

Detailed Description

Definition at line 13 of file ZipTests.cs.

Member Function Documentation

◆ TestZip()

void BGC.Tests.ZipTests.TestZip ( )
inline

Definition at line 16 of file ZipTests.cs.

References BGC.IO.Compression.Zip.CompressDirectory(), BGC.IO.Compression.Zip.DecompressFile(), BGC.IO.DataManagement.PathForDataFile(), and BGC.IO.DataManagement.PathForDataSubDirectory().

17  {
18  string compressedFilePath = DataManagement.PathForDataFile("Test", "ziptest.zip");
19  string compressionPath = DataManagement.PathForDataSubDirectory("Test", "ZipTest");
20  //Clear prior tests
21  Directory.Delete(compressionPath, true);
22 
23  //
24  //Create files with random contents
25  //
26 
27  string[] fileNames = new string[]
28  {
29  "Baron.txt",
30  "Silly test",
31  "Oh_Noes).asdf",
32  "Something is going to happen with this one maybe.int",
33  "What.bgc"
34  };
35 
36  string[] subpaths = new string[]
37  {
38  DataManagement.PathForDataSubDirectory("Test", "ZipTest"),
39  DataManagement.PathForDataSubDirectory("Test", "ZipTest", "SubA"),
40  DataManagement.PathForDataSubDirectory("Test", "ZipTest", "SubB")
41  };
42 
43  string[,] fileContents = new string[subpaths.Length, 5];
44 
45  for (int p = 0; p < subpaths.Length; p++)
46  {
47  string datapath = subpaths[p];
48  for (int i = 0; i < 5; i++)
49  {
50  fileContents[p, i] = $"{UnityEngine.Random.value}\n{UnityEngine.Random.value}";
51  File.WriteAllText(
52  Path.Combine(datapath, fileNames[i]),
53  fileContents[p, i]);
54  }
55  }
56 
57  //
58  //Compress contents
59  //
61  inputPath: compressionPath,
62  outputFilePath: compressedFilePath);
63 
64  //
65  //Delete Original Files
66  //
67  Directory.Delete(compressionPath, true);
68 
69  //
70  //Decompress contents
71  //
73  inputFilePath: compressedFilePath,
74  outputPath: compressionPath);
75 
76  //
77  //Verify Output
78  //
79  for (int p = 0; p < subpaths.Length; p++)
80  {
81  string datapath = subpaths[p];
82  for (int i = 0; i < 5; i++)
83  {
84  Assert.IsTrue(File.Exists(Path.Combine(datapath, fileNames[i])));
85  string fileText = File.ReadAllText(Path.Combine(datapath, fileNames[i]));
86  Assert.IsTrue(fileContents[p, i] == fileText);
87  }
88  }
89 
90  //
91  //Delete Test Files
92  //
93  if (Directory.Exists(compressionPath))
94  {
95  Directory.Delete(compressionPath, true);
96  }
97 
98  //
99  //Delete Zip File
100  //
101  if (File.Exists(compressedFilePath))
102  {
103  File.Delete(compressedFilePath);
104  }
105  }
static bool DecompressFile(string inputFilePath, string outputPath)
Definition: Zip.cs:94
static bool CompressDirectory(string inputPath, string outputFilePath)
Definition: Zip.cs:16
A collection of convenience methods to handle compression and decompression of zip files...
Definition: Zip.cs:14
static string PathForDataSubDirectory(params string[] dataDirectories)
Returns the full path to the dataDirectories directory.
static string PathForDataFile(string dataDirectory, string fileName)
Returns the full path for specified datafile in a data directory
Here is the call graph for this function:

The documentation for this class was generated from the following file: