Skip to content

Commit

Permalink
v1.4.1, Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ied206 committed Oct 20, 2019
2 parents 9035b22 + 4721004 commit d3843b2
Show file tree
Hide file tree
Showing 21 changed files with 466 additions and 94 deletions.
2 changes: 1 addition & 1 deletion ManagedWimLib.Tests/AddTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down
2 changes: 1 addition & 1 deletion ManagedWimLib.Tests/DeleteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down
159 changes: 159 additions & 0 deletions ManagedWimLib.Tests/ErrorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
Licensed under LGPLv3
Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2019 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;
using System.Linq;


namespace ManagedWimLib.Tests
{
[TestClass]
[TestCategory("WimLib")]
public class ErrorTests
{
[TestMethod]
public void GetLastError()
{
string[] paths = new string[] { @"\NOTEXIST.bin", @"NOTGLOB?.cue" };

// Default is Wim.SetPrintErrors(true);
CheckErrorTemplate("XPRESS.wim", paths, true);

Wim.SetPrintErrors(false);
CheckErrorTemplate("LZX.wim", paths, false);

Wim.SetPrintErrors(true);
CheckErrorTemplate("LZMS.wim", paths, true);
}

public void CheckErrorTemplate(string fileName, string[] paths, bool printError)
{
string destDir = TestHelper.GetTempDir();
try
{
Directory.CreateDirectory(destDir);

bool[] _checked = new bool[5];
for (int i = 0; i < _checked.Length; i++)
_checked[i] = false;
CallbackStatus ProgressCallback(ProgressMsg msg, object info, object progctx)
{
switch (msg)
{
case ProgressMsg.EXTRACT_TREE_BEGIN:
{
ProgressInfo_Extract m = (ProgressInfo_Extract)info;
Assert.IsNotNull(m);

_checked[0] = true;
}
break;
case ProgressMsg.EXTRACT_TREE_END:
{
ProgressInfo_Extract m = (ProgressInfo_Extract)info;
Assert.IsNotNull(m);

_checked[1] = true;
}
break;
case ProgressMsg.EXTRACT_FILE_STRUCTURE:
{
ProgressInfo_Extract m = (ProgressInfo_Extract)info;
Assert.IsNotNull(m);

_checked[2] = true;
}
break;
case ProgressMsg.EXTRACT_STREAMS:
{
ProgressInfo_Extract m = (ProgressInfo_Extract)info;
Assert.IsNotNull(m);

_checked[3] = true;
}
break;
case ProgressMsg.EXTRACT_METADATA:
{
ProgressInfo_Extract m = (ProgressInfo_Extract)info;
Assert.IsNotNull(m);

_checked[4] = true;
}
break;
}
return CallbackStatus.CONTINUE;
}

string wimFile = Path.Combine(TestSetup.SampleDir, fileName);
using (Wim wim = Wim.OpenWim(wimFile, OpenFlags.DEFAULT))
{
wim.RegisterCallback(ProgressCallback);

wim.ExtractPaths(1, destDir, paths, ExtractFlags.GLOB_PATHS);
}

// The callback must not have been called
Assert.IsFalse(_checked.Any(x => x));

// The files must not exist
foreach (string path in paths.Select(x => TestHelper.NormalizePath(x.TrimStart('\\'))))
{
if (path.IndexOfAny(new char[] { '*', '?' }) == -1)
{ // No wlidcard
Assert.IsFalse(File.Exists(Path.Combine(destDir, path)));
}
else
{ // With wildcard
string destFullPath = Path.Combine(destDir, path);
string[] files = Directory.GetFiles(Path.GetDirectoryName(destFullPath), Path.GetFileName(destFullPath), SearchOption.AllDirectories);
Assert.IsFalse(0 < files.Length);
}
}

// Read error message
string[] errorMsgs = Wim.GetErrors();
ErrorPrintState printState = Wim.ErrorPrintState;
if (printError)
{
Assert.IsNotNull(errorMsgs);
Assert.AreEqual(ErrorPrintState.PrintOn, printState);
Assert.IsTrue(0 < errorMsgs.Length);
foreach (string errorMsg in errorMsgs)
Console.WriteLine(errorMsg);
}
else
{
Assert.IsNull(errorMsgs);
Assert.AreEqual(ErrorPrintState.PrintOff, printState);
}
}
finally
{
if (Directory.Exists(destDir))
Directory.Delete(destDir, true);
}
}
}
}
2 changes: 1 addition & 1 deletion ManagedWimLib.Tests/ExportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down
2 changes: 1 addition & 1 deletion ManagedWimLib.Tests/ExtractTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down
2 changes: 1 addition & 1 deletion ManagedWimLib.Tests/GetInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down
2 changes: 1 addition & 1 deletion ManagedWimLib.Tests/GetVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down
6 changes: 3 additions & 3 deletions ManagedWimLib.Tests/IterateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand All @@ -29,11 +29,11 @@ You should have received a copy of the GNU Lesser General Public License
namespace ManagedWimLib.Tests
{
[TestClass]
[TestCategory("WimLib")]
public class IterateTests
{
#region IterateDirTree
[TestMethod]
[TestCategory("WimLib")]
public void IterateDirTree()
{
IterateDirTree_Template("XPRESS.wim");
Expand All @@ -57,7 +57,7 @@ CallbackStatus IterateCallback(DirEntry dentry, object userData)
string wimFile = Path.Combine(TestSetup.SampleDir, wimFileName);
using (Wim wim = Wim.OpenWim(wimFile, OpenFlags.DEFAULT))
{
wim.IterateDirTree(1, TestHelper.RootPath, IterateFlags.RECURSIVE, IterateCallback);
wim.IterateDirTree(1, Wim.RootPath, IterateFlags.RECURSIVE, IterateCallback);
}

TestHelper.CheckPathList(SampleSet.Src01, entries);
Expand Down
2 changes: 1 addition & 1 deletion ManagedWimLib.Tests/JoinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down
4 changes: 2 additions & 2 deletions ManagedWimLib.Tests/ReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down Expand Up @@ -78,7 +78,7 @@ CallbackStatus IterateCallback(DirEntry dentry, object userData)
string wimFile = Path.Combine(TestSetup.SampleDir, wimFileName);
using (Wim wim = Wim.OpenWim(destWimFile, OpenFlags.DEFAULT))
{
wim.IterateDirTree(imageCount + 1, TestHelper.RootPath, IterateFlags.RECURSIVE, IterateCallback);
wim.IterateDirTree(imageCount + 1, Wim.RootPath, IterateFlags.RECURSIVE, IterateCallback);
}

TestHelper.CheckPathList(set, entries);
Expand Down
2 changes: 1 addition & 1 deletion ManagedWimLib.Tests/RenameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down
2 changes: 1 addition & 1 deletion ManagedWimLib.Tests/SetInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down
2 changes: 1 addition & 1 deletion ManagedWimLib.Tests/SetOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down
4 changes: 2 additions & 2 deletions ManagedWimLib.Tests/SplitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down Expand Up @@ -111,7 +111,7 @@ CallbackStatus IterateCallback(DirEntry dentry, object userData)
WimInfo wi = wim.GetWimInfo();
Assert.IsTrue(wi.ImageCount == 1);

wim.IterateDirTree(1, TestHelper.RootPath, IterateFlags.RECURSIVE, IterateCallback);
wim.IterateDirTree(1, Wim.RootPath, IterateFlags.RECURSIVE, IterateCallback);
}

TestHelper.CheckPathList(SampleSet.Src03, entries);
Expand Down
15 changes: 2 additions & 13 deletions ManagedWimLib.Tests/TestSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down Expand Up @@ -146,17 +146,6 @@ public static Tuple<string, bool>[] NormalizePaths(IEnumerable<Tuple<string, boo
{
return tuples.Select(x => new Tuple<string, bool>(NormalizePath(x.Item1), x.Item2)).ToArray();
}

public static string RootPath
{
get
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return @"\";
else
return @"/";
}
}
#endregion

#region File Check
Expand Down Expand Up @@ -384,7 +373,7 @@ CallbackStatus IterateCallback(DirEntry dentry, object userData)

using (Wim wim = Wim.OpenWim(wimFile, OpenFlags.DEFAULT))
{
wim.IterateDirTree(1, TestHelper.RootPath, IterateFlags.RECURSIVE, IterateCallback);
wim.IterateDirTree(1, Wim.RootPath, IterateFlags.RECURSIVE, IterateCallback);
}

return entries;
Expand Down
10 changes: 5 additions & 5 deletions ManagedWimLib.Tests/UpdateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Derived from wimlib's original header files
Copyright (C) 2012-2018 Eric Biggers
C# Wrapper written by Hajin Jang
Copyright (C) 2017-2018 Hajin Jang
Copyright (C) 2017-2019 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
Expand Down Expand Up @@ -130,7 +130,7 @@ CallbackStatus IterateCallback(DirEntry dentry, object userData)

using (Wim wim = Wim.OpenWim(destWimFile, OpenFlags.DEFAULT))
{
wim.IterateDirTree(1, TestHelper.RootPath, IterateFlags.RECURSIVE, IterateCallback, entries);
wim.IterateDirTree(1, Wim.RootPath, IterateFlags.RECURSIVE, IterateCallback, entries);
}

Assert.IsTrue(tested.Value);
Expand All @@ -141,19 +141,19 @@ CallbackStatus IterateCallback(DirEntry dentry, object userData)
case UpdateOp.ADD:
{
UpdateCommand.UpdateAdd add = cmd.Add;
Assert.IsTrue(entries.Contains(Path.Combine(TestHelper.RootPath, add.WimTargetPath), StringComparer.Ordinal));
Assert.IsTrue(entries.Contains(Path.Combine(Wim.RootPath, add.WimTargetPath), StringComparer.Ordinal));
}
break;
case UpdateOp.DELETE:
{
UpdateCommand.UpdateDelete del = cmd.Delete;
Assert.IsFalse(entries.Contains(Path.Combine(TestHelper.RootPath, del.WimPath), StringComparer.Ordinal));
Assert.IsFalse(entries.Contains(Path.Combine(Wim.RootPath, del.WimPath), StringComparer.Ordinal));
}
break;
case UpdateOp.RENAME:
{
UpdateCommand.UpdateRename ren = cmd.Rename;
Assert.IsTrue(entries.Contains(Path.Combine(TestHelper.RootPath, ren.WimTargetPath), StringComparer.Ordinal));
Assert.IsTrue(entries.Contains(Path.Combine(Wim.RootPath, ren.WimTargetPath), StringComparer.Ordinal));
}
break;
}
Expand Down
Loading

0 comments on commit d3843b2

Please sign in to comment.