-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathResourceGenerationTests.cs
More file actions
121 lines (100 loc) · 5.38 KB
/
Copy pathResourceGenerationTests.cs
File metadata and controls
121 lines (100 loc) · 5.38 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
110
111
112
113
114
115
116
117
118
119
120
121
using System.IO;
using SirenSharp.Models;
using SirenSharp.Services;
using SirenSharp.Services.Backends;
using SirenSharp.Services.Exporters;
using Xunit;
namespace SirenSharp.Tests
{
public class ResourceGenerationTests
{
private static GenericFiveMExporter BuildGenerator()
{
var verifier = new AwcVerifier();
var packBuilder = new AudioPackBuilder(
new WavSanitizer(new WavFormatAnalyzer()),
new DataGenerator());
return new GenericFiveMExporter(
packBuilder,
new CodeWalkerAwcBuildBackend(verifier),
new Services.Backends.Native.NativeAwcBuildBackend());
}
[Fact]
public void GenerateResource_ProducesHealthyPack()
{
using var dir = new TempDir();
// One already-compatible mono source and one stereo source that must be
// downmixed during generation - exercises the full sanitize -> encode path.
var wail = WavFixtures.MonoPcm16(dir.File("wail.wav"), seconds: 1.0, freq: 600);
var yelp = WavFixtures.StereoPcm16(dir.File("yelp.wav"), seconds: 1.0, freq: 900);
var soundSet = new SoundSet("lspd");
soundSet.AddSound(new Sound(wail));
soundSet.AddSound(new Sound(yelp));
var options = new ResourceGenerationOptions
{
ResourceName = "test_sirens",
DlcName = "policesirens",
FolderPath = dir.Path,
FxVersion = "cerulean",
SoundSets = new List<SoundSet> { soundSet }
};
var result = BuildGenerator().Export(options, null);
Assert.True(result.Success, string.Join(" | ", result.Diagnostics.Errors));
var resourceDir = Path.Combine(dir.Path, "test_sirens");
Assert.True(File.Exists(Path.Combine(resourceDir, "fxmanifest.lua")));
Assert.True(File.Exists(Path.Combine(resourceDir, "SIRENSHARP_NOTES.txt")));
Assert.True(File.Exists(Path.Combine(resourceDir, "data", "policesirens.dat54.rel")));
Assert.True(File.Exists(Path.Combine(resourceDir, "data", "policesirens.dat54.nametable")));
var awcPath = Path.Combine(resourceDir, "dlc_policesirens", "lspd.awc");
Assert.True(File.Exists(awcPath));
// The raw/ working directory is cleaned up after generation.
Assert.False(Directory.Exists(Path.Combine(resourceDir, "raw")));
// Post-generation verification passed and the AWC clears the silent-file gate.
Assert.All(result.AwcVerifications, v => Assert.True(v.IsHealthy, v.Summary));
var awcSize = new FileInfo(awcPath).Length;
Assert.True(awcSize > 2048, $"AWC was only {awcSize} bytes");
var manifest = File.ReadAllText(Path.Combine(resourceDir, "fxmanifest.lua"));
Assert.Contains("fx_version 'cerulean'", manifest);
Assert.Contains("dlc_policesirens/lspd.awc", manifest);
Assert.Contains("data_file \"AUDIO_WAVEPACK\" \"dlc_policesirens\"", manifest);
Assert.Contains("data/policesirens.dat54.rel", manifest);
var nametable = File.ReadAllText(Path.Combine(resourceDir, "data", "policesirens.dat54.nametable"));
Assert.Contains("lspd_soundset\0", nametable);
Assert.Contains("wail_s\0", nametable);
Assert.Contains("yelp_s\0", nametable);
}
[Fact]
public void GenerateResource_WithTester_EmitsRunnableTesterAndPrefilledConfig()
{
using var dir = new TempDir();
var wail = WavFixtures.MonoPcm16(dir.File("wail.wav"));
var soundSet = new SoundSet("lspd");
soundSet.AddSound(new Sound(wail));
var options = new ResourceGenerationOptions
{
ResourceName = "test_sirens",
DlcName = "policesirens",
FolderPath = dir.Path,
GenerateInGameTester = true,
SoundSets = new List<SoundSet> { soundSet }
};
var result = BuildGenerator().Export(options, null);
Assert.True(result.Success, string.Join(" | ", result.Diagnostics.Errors));
var testerDir = Path.Combine(dir.Path, "sirensharp-audio-test");
Assert.Equal(testerDir, result.TesterPath);
// Template (RageUI + scripts) extracted from the embedded resource.
Assert.True(File.Exists(Path.Combine(testerDir, "fxmanifest.lua")));
Assert.True(File.Exists(Path.Combine(testerDir, "client.lua")));
Assert.True(File.Exists(Path.Combine(testerDir, "RageUI", "src", "RageUI.lua")));
// config.lua is generated from the project's names.
var config = File.ReadAllText(Path.Combine(testerDir, "config.lua"));
Assert.Contains("dlc = 'policesirens'", config);
Assert.Contains("name = 'lspd'", config);
Assert.Contains("'wail'", config);
// RageUI's IsVisible requires a panels callback - omitting it crashes the menu.
// Both menu blocks (main + soundset submenu) must supply one.
var clientLua = File.ReadAllText(Path.Combine(testerDir, "client.lua"));
Assert.Equal(2, System.Text.RegularExpressions.Regex.Matches(clientLua, @"end, function\(Panels\) end\)").Count);
}
}
}