-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSplitTests.cs
127 lines (105 loc) · 4.5 KB
/
SplitTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Licensed under LGPLv3
Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-present Hajin Jang
This file is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option) any
later version.
This file is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this file; if not, see http://www.gnu.org/licenses/.
*/
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace ManagedWimLib.Tests
{
[TestClass]
[TestCategory(TestSetup.WimLib)]
public class SplitTests
{
#region SplitImage
[TestMethod]
public void Split()
{
SplitTemplate("Src03", (1024 + 512) * 1024);
}
public void SplitTemplate(string testSet, ulong partSize)
{
string srcDir = Path.Combine(TestSetup.SampleDir, testSet);
string destDir = TestHelper.GetTempDir();
string wimFile = Path.Combine(destDir, "LZX.wim");
string splitWimFile = Path.Combine(destDir, "Split.swm");
string splitWildcard = Path.Combine(destDir, "Split*.swm");
try
{
Directory.CreateDirectory(destDir);
bool[] _checked = new bool[2];
for (int i = 0; i < _checked.Length; i++)
_checked[i] = false;
CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx)
{
switch (msg)
{
case ProgressMsg.SplitBeginPart:
{
SplitProgress m = (SplitProgress)info;
Assert.IsNotNull(m);
_checked[0] = true;
}
break;
case ProgressMsg.SplitEndPart:
{
SplitProgress m = (SplitProgress)info;
Assert.IsNotNull(m);
_checked[1] = true;
}
break;
}
return CallbackStatus.Continue;
}
using (Wim wim = Wim.CreateNewWim(CompressionType.LZX))
{
wim.AddImage(srcDir, "UnitTest", null, AddFlags.NoAcls);
wim.Write(wimFile, Wim.AllImages, WriteFlags.None, Wim.DefaultThreads);
}
TestHelper.CheckWimPath(SampleSet.Src03, wimFile);
using (Wim wim = Wim.OpenWim(wimFile, OpenFlags.None, ProgressCallback))
{
wim.Split(splitWimFile, partSize, WriteFlags.None);
}
Assert.IsTrue(_checked.All(x => x));
List<Tuple<string, bool>> entries = new List<Tuple<string, bool>>();
int IterateCallback(DirEntry dentry, object userData)
{
string path = dentry.FullPath;
bool isDir = (dentry.Attributes & FileAttributes.Directory) != 0;
entries.Add(new Tuple<string, bool>(path, isDir));
return Wim.IterateCallbackSuccess;
}
using (Wim wim = Wim.OpenWim(splitWimFile, OpenFlags.None))
{
wim.ReferenceResourceFile(splitWildcard, RefFlags.GlobEnable | RefFlags.GlobErrOnNoMatch, OpenFlags.None);
WimInfo wi = wim.GetWimInfo();
Assert.IsTrue(wi.ImageCount == 1);
wim.IterateDirTree(1, Wim.RootPath, IterateDirTreeFlags.Recursive, IterateCallback);
}
TestHelper.CheckPathList(SampleSet.Src03, entries);
}
finally
{
if (Directory.Exists(destDir))
Directory.Delete(destDir, true);
}
}
#endregion
}
}