-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXisoDiscFormatTests.cs
More file actions
109 lines (91 loc) · 3.29 KB
/
Copy pathXisoDiscFormatTests.cs
File metadata and controls
109 lines (91 loc) · 3.29 KB
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
using XISOSharp.Cli;
using XISOSharp.Models;
namespace XISOSharp.Tests;
/// <summary>
/// Tests for <see cref="VolumeInfo.DiscFormat"/> — the friendly disc-layout
/// identity derived from the probe offset (<c>RAW</c>, <c>GLOBAL (XGD2)</c>,
/// <c>XGD3</c>, <c>XGD2 Hybrid</c>, <c>XGD1</c>), surfaced by <c>-i</c>.
/// </summary>
[Collection("Sequential")]
public class XisoDiscFormatTests : IDisposable
{
private readonly List<string> _tempDirs = [];
private readonly TextWriter _savedOut = Logger.Out;
private readonly StringWriter _logCapture = new();
public XisoDiscFormatTests()
{
Logger.Out = _logCapture;
}
public void Dispose()
{
Logger.Out = _savedOut;
Logger.Quiet = false;
Logger.RealQuiet = false;
foreach (string dir in _tempDirs)
{
try
{
if (Directory.Exists(dir)) Directory.Delete(dir, true);
}
catch
{
/* best effort cleanup */
}
}
}
private string CreateTempDir(string prefix)
{
string dir = Path.Combine(Path.GetTempPath(), $"{prefix}_{Guid.NewGuid():N}");
Directory.CreateDirectory(dir);
_tempDirs.Add(dir);
return dir;
}
[Theory]
[InlineData(0L, "RAW")]
[InlineData(0x0FD90000L, "GLOBAL (XGD2)")]
[InlineData(0x02080000L, "XGD3")]
[InlineData(0x89D80000L, "XGD2 Hybrid")]
[InlineData(0x18300000L, "XGD1")]
[InlineData(0x12345678L, "Unknown")]
public void DiscFormat_MapsKnownOffsets(long discLseek, string expected)
{
VolumeInfo vol = new(true, 0, 0, discLseek, 0, 0);
Assert.Equal(expected, vol.DiscFormat);
}
[Theory]
[InlineData(0L)]
[InlineData(0x02080000L)]
public void DiscFormat_InvalidVolume_ReturnsUnknown(long discLseek)
{
// An invalid probe carries no layout identity even when the offset
// happens to be zero or match a known layout.
VolumeInfo vol = new(false, 0, 0, discLseek, 0, 0);
Assert.Equal("Unknown", vol.DiscFormat);
}
[Fact]
public void DiscFormat_PackedIso_RoundTripsRaw()
{
string srcDir = CreateTempDir("xiso_discfmt_src");
File.WriteAllText(Path.Combine(srcDir, "readme.txt"), "hello");
string outputDir = CreateTempDir("xiso_discfmt_out");
int result = XisoWriter.CreateXiso(srcDir, outputDir, null, null, out string? isoPath, null, null);
Assert.Equal(0, result);
Assert.NotNull(isoPath);
VolumeInfo vol = XisoReader.GetVolumeInfo(isoPath);
Assert.True(vol.IsValid);
Assert.Equal(0, vol.DiscLseek);
Assert.Equal("RAW", vol.DiscFormat);
}
[Fact]
public void Cli_Info_PrintsDiscFormat()
{
string srcDir = CreateTempDir("xiso_discfmt_cli_src");
File.WriteAllText(Path.Combine(srcDir, "readme.txt"), "hello");
string outputDir = CreateTempDir("xiso_discfmt_cli_out");
int result = XisoWriter.CreateXiso(srcDir, outputDir, null, null, out string? isoPath, null, null);
Assert.Equal(0, result);
Assert.NotNull(isoPath);
Assert.Equal(0, Program.Main(["-i", isoPath]));
Assert.Contains("Disc Format: RAW", _logCapture.ToString(), StringComparison.OrdinalIgnoreCase);
}
}