-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSetInfoTests.cs
122 lines (102 loc) · 4.08 KB
/
SetInfoTests.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
/*
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.IO;
namespace ManagedWimLib.Tests
{
[TestClass]
[TestCategory(TestSetup.WimLib)]
public class SetInfoTests
{
#region SetImageInfo
[TestMethod]
public void SetImageInfo()
{
SetImageInfoTemplate("LZX.wim", 1);
SetImageInfoTemplate("MultiImage.wim", 2);
SetImageInfoTemplate("MultiImage.wim", 3);
}
public static void SetImageInfoTemplate(string wimFileName, int imageIndex)
{
string srcWim = Path.Combine(TestSetup.SampleDir, wimFileName);
string destWim = Path.GetTempFileName();
try
{
File.Copy(srcWim, destWim, true);
using (Wim wim = Wim.OpenWim(destWim, OpenFlags.WriteAccess))
{
string imageName = wim.GetImageName(imageIndex);
string imageDesc = wim.GetImageDescription(imageIndex);
string imageFlags = wim.GetImageProperty(imageIndex, "FLAGS");
Assert.IsNotNull(imageName);
Assert.IsNull(imageDesc);
Assert.IsNull(imageFlags);
wim.SetImageName(imageIndex, "NEW_IMAGE");
wim.SetImageDescription(imageIndex, "NEW_DESCRIPTION");
wim.SetImageFlags(imageIndex, "NEW_FLAGS");
Assert.IsFalse(imageName.Equals(wim.GetImageName(imageIndex), StringComparison.Ordinal));
Assert.IsTrue("NEW_IMAGE".Equals(wim.GetImageName(imageIndex), StringComparison.Ordinal));
Assert.IsTrue("NEW_DESCRIPTION".Equals(wim.GetImageDescription(imageIndex)));
Assert.IsTrue("NEW_FLAGS".Equals(wim.GetImageProperty(imageIndex, "FLAGS")));
}
}
finally
{
if (File.Exists(destWim))
File.Delete(destWim);
}
}
#endregion
#region SetWimInfo
[TestMethod]
public void SetWimInfo()
{
SetWimInfoTemplate("MultiImage.wim", 2u);
}
public static void SetWimInfoTemplate(string wimFileName, uint bootIndex)
{
string srcWim = Path.Combine(TestSetup.SampleDir, wimFileName);
string destWim = Path.GetTempFileName();
try
{
File.Copy(srcWim, destWim, true);
using (Wim wim = Wim.OpenWim(destWim, OpenFlags.WriteAccess))
{
WimInfo info = new WimInfo
{
BootIndex = bootIndex,
};
wim.SetWimInfo(info, ChangeFlags.BootIndex);
wim.Overwrite(WriteFlags.None, Wim.DefaultThreads);
}
using (Wim wim = Wim.OpenWim(destWim, OpenFlags.None))
{
WimInfo info = wim.GetWimInfo();
Assert.IsTrue(info.BootIndex == bootIndex);
}
}
finally
{
if (File.Exists(destWim))
File.Delete(destWim);
}
}
#endregion
}
}