forked from WolvenKit/WolvenKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StressTest.cs
583 lines (498 loc) · 16.1 KB
/
StressTest.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WolvenKit;
using System.Linq;
using System.Collections.Generic;
using System.IO.MemoryMappedFiles;
using System.IO;
using WolvenKit.CR2W;
using WolvenKit.Bundles;
using WolvenKit.Common;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Text;
using System.Security.Cryptography;
using WolvenKit.Common.Extensions;
using Microsoft.Win32;
namespace CR2WTests
{
public static class AssertEx
{
public static async Task<TException>
ThrowsAsync<TException>(Func<Task> action,
bool allowDerivedTypes = true) where TException : Exception
{
try
{
await action();
}
catch (Exception ex)
{
if (allowDerivedTypes && !(ex is TException))
throw new Exception("Delegate threw exception of type " +
ex.GetType().Name + ", but " + typeof(TException).Name +
" or a derived type was expected.", ex);
if (!allowDerivedTypes && ex.GetType() != typeof(TException))
throw new Exception("Delegate threw exception of type " +
ex.GetType().Name + ", but " + typeof(TException).Name +
" was expected.", ex);
return (TException)ex;
}
throw new Exception("Delegate did not throw expected exception " +
typeof(TException).Name + ".");
}
public static Task<Exception> ThrowsAsync(Func<Task> action)
{
return ThrowsAsync<Exception>(action, true);
}
}
[TestClass]
public class StressTest
{
static string bundletag = "*";
static Dictionary<string, MemoryMappedFile> memorymappedbundles;
static BundleManager bm;
[ClassInitialize]
public static void Setup(TestContext context)
{
var tw3Finaldir = "";
// check for W3_DIR environment variable
var W3_DIR = System.Environment.GetEnvironmentVariable("W3_DIR", EnvironmentVariableTarget.User);
if (!string.IsNullOrEmpty(W3_DIR))
tw3Finaldir = W3_DIR;
// else lookup w3 exe
else
{
var exedir = new FileInfo(LookUpW3exe()).Directory.FullName;
if (Directory.Exists(exedir))
tw3Finaldir = exedir;
// else close
else
Assert.IsFalse(true, "Aborting test. No valid Wicther 3 directory found.");
}
memorymappedbundles = new Dictionary<string, MemoryMappedFile>();
bm = new BundleManager();
bm.LoadAll(tw3Finaldir);
//Load MemoryMapped Bundles
foreach (var b in bm.Bundles.Values)
{
var e = b.ArchiveAbsolutePath.GetHashMD5();
memorymappedbundles.Add(e, MemoryMappedFile.CreateFromFile(b.ArchiveAbsolutePath, FileMode.Open, e, 0, MemoryMappedFileAccess.Read));
}
}
private static string LookUpW3exe()
{
const string uninstallkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
const string uninstallkey2 = "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
var w3 = "";
try
{
Parallel.ForEach(Registry.LocalMachine.OpenSubKey(uninstallkey)?.GetSubKeyNames(), item =>
{
var programName = Registry.LocalMachine.OpenSubKey(uninstallkey + item)
?.GetValue("DisplayName");
var installLocation = Registry.LocalMachine.OpenSubKey(uninstallkey + item)
?.GetValue("InstallLocation");
if (programName != null && installLocation != null)
{
if (programName.ToString().Contains("The Witcher 3 - Wild Hunt") ||
programName.ToString().Contains("The Witcher 3: Wild Hunt"))
{
w3 = Directory.GetFiles(installLocation.ToString(), "witcher3.exe",
SearchOption.AllDirectories).First();
}
}
});
Parallel.ForEach(Registry.LocalMachine.OpenSubKey(uninstallkey2)?.GetSubKeyNames(), item =>
{
var programName = Registry.LocalMachine.OpenSubKey(uninstallkey2 + item)
?.GetValue("DisplayName");
var installLocation = Registry.LocalMachine.OpenSubKey(uninstallkey2 + item)
?.GetValue("InstallLocation");
if (programName != null && installLocation != null)
{
if (programName.ToString().Contains("The Witcher 3 - Wild Hunt") ||
programName.ToString().Contains("The Witcher 3: Wild Hunt"))
{
if (Directory.Exists(installLocation.ToString()))
w3 = Directory.GetFiles(installLocation.ToString(), "witcher3.exe",
SearchOption.AllDirectories).First();
}
}
});
return w3;
}
catch (Exception ex)
{
throw ex;
}
}
// Methods to test for the different file types
#region Methods
[TestMethod]
public async Task Cellmap()
{
await Task.Run(() => StressTestExt("cellmap"));
}
[TestMethod]
public async Task Env()
{
await Task.Run(() => StressTestExt("env"));
}
[TestMethod]
public async Task Flyr()
{
await Task.Run(() => StressTestExt("flyr"));
}
[TestMethod]
public async Task Formation()
{
await Task.Run(() => StressTestExt("formation"));
}
[TestMethod]
public async Task Grassmask()
{
await Task.Run(() => StressTestExt("grassmask"));
}
[TestMethod]
public async Task Guiconfig()
{
await Task.Run(() => StressTestExt("guiconfig"));
}
[TestMethod]
public async Task hud()
{
await Task.Run(() => StressTestExt("hud"));
}
[TestMethod]
public async Task journal()
{
await Task.Run(() => StressTestExt("journal"));
}
[TestMethod]
public async Task menu()
{
await Task.Run(() => StressTestExt("menu"));
}
[TestMethod]
public async Task popup()
{
await Task.Run(() => StressTestExt("popup"));
}
[TestMethod]
public async Task redapex()
{
await Task.Run(() => StressTestExt("redapex"));
}
[TestMethod]
public async Task redcloth()
{
await Task.Run(() => StressTestExt("redcloth"));
}
[TestMethod]
public async Task reddest()
{
await Task.Run(() => StressTestExt("reddest"));
}
[TestMethod]
public async Task reddlc()
{
await Task.Run(() => StressTestExt("reddlc"));
}
[TestMethod]
public async Task redexp()
{
await Task.Run(() => StressTestExt("redexp"));
}
[TestMethod]
public async Task redfur()
{
await Task.Run(() => StressTestExt("redfur"));
}
[TestMethod]
public async Task redgame()
{
await Task.Run(() => StressTestExt("redgame"));
}
[TestMethod]
public async Task redicsv()
{
await Task.Run(() => StressTestExt("redicsv"));
}
[TestMethod]
public async Task redswf()
{
await Task.Run(() => StressTestExt("redswf"));
}
[TestMethod]
public async Task redwpset()
{
await Task.Run(() => StressTestExt("redwpset"));
}
[TestMethod]
public async Task spawntree()
{
await Task.Run(() => StressTestExt("spawntree"));
}
[TestMethod]
public async Task texarray()
{
await Task.Run(() => StressTestExt("texarray"));
}
[TestMethod]
public async Task vbrush()
{
await Task.Run(() => StressTestExt("vbrush"));
}
[TestMethod]
public async Task w2am()
{
await Task.Run(() => StressTestExt("w2am"));
}
[TestMethod]
public async Task w2animev()
{
await Task.Run(() => StressTestExt("w2animev"));
}
[TestMethod]
public async Task w2anims()
{
await Task.Run(() => StressTestExt("w2anims"));
}
[TestMethod]
public async Task w2beh()
{
await Task.Run(() => StressTestExt("w2beh"));
}
[TestMethod]
public async Task w2behtree()
{
await Task.Run(() => StressTestExt("w2behtree"));
}
[TestMethod]
public async Task w2cent()
{
await Task.Run(() => StressTestExt("w2cent"));
}
[TestMethod]
public async Task w2comm()
{
await Task.Run(() => StressTestExt("w2comm"));
}
[TestMethod]
public async Task w2cube()
{
await Task.Run(() => StressTestExt("w2cube"));
}
[TestMethod]
public async Task w2cutscene()
{
await Task.Run(() => StressTestExt("w2cutscene"));
}
[TestMethod]
public async Task w2dset()
{
await Task.Run(() => StressTestExt("w2dset"));
}
[TestMethod]
public async Task w2em()
{
await Task.Run(() => StressTestExt("w2em"));
}
[TestMethod]
public async Task w2ent()
{
await Task.Run(() => StressTestExt("w2ent"));
}
//[TestMethod]
//public async Task w2entPatch()
//{
// bundletag = "patch1*";
// await Task.Run(() => StressTestExt("w2ent"));
//}
//[TestMethod]
//public async Task w2entContent0()
//{
// bundletag = "content0*";
// await Task.Run(() => StressTestExt("w2ent"));
//}
//[TestMethod]
//public async Task w2entContents()
//{
// bundletag = "sanscontent0";
// await Task.Run(() => StressTestExt("w2ent"));
//}
[TestMethod]
public async Task w2fnt()
{
//var ret = await Task.Run(() => await Task.Run(() => StressTestExt("w2fnt"));
//Assert.AreEqual(0, ret.Item1, $"Unknown bytes remained -> {ret.Item1}bytes"));
//Assert.AreEqual(0, ret.Item2, $"Unparsed files -> {ret.Item2}"));
//var ex = Assert.ThrowsException<AssertFailedException>(() => { await Task.Run(() => StressTestExt("w2fnt")); });
//var ex = await AssertEx.ThrowsAsync<AssertFailedException>(() => await Task.Run(() => StressTestExt("w2fnt"));
await Task.Run(() => StressTestExt("w2fnt"));
}
[TestMethod]
public async Task w2je()
{
await Task.Run(() => StressTestExt("w2je"));
}
[TestMethod]
public async Task w2job()
{
await Task.Run(() => StressTestExt("w2job"));
}
[TestMethod]
public async Task w2l()
{
await Task.Run(() => StressTestExt("w2l"));
}
[TestMethod]
public async Task w2mesh()
{
await Task.Run(() => StressTestExt("w2mesh"));
}
[TestMethod]
public async Task w2mg()
{
await Task.Run(() => StressTestExt("w2mg"));
}
[TestMethod]
public async Task w2mi()
{
await Task.Run(() => StressTestExt("w2mi"));
}
[TestMethod]
public async Task w2p()
{
await Task.Run(() => StressTestExt("w2p"));
}
[TestMethod]
public async Task w2phase()
{
await Task.Run(() => StressTestExt("w2phase"));
}
[TestMethod]
public async Task w2qm()
{
await Task.Run(() => StressTestExt("w2qm"));
}
[TestMethod]
public async Task w2quest()
{
await Task.Run(() => StressTestExt("w2quest"));
}
[TestMethod]
public async Task w2ragdoll()
{
await Task.Run(() => StressTestExt("w2ragdoll"));
}
[TestMethod]
public async Task w2rig()
{
await Task.Run(() => StressTestExt("w2rig"));
}
[TestMethod]
public async Task w2scene()
{
await Task.Run(() => StressTestExt("w2scene"));
}
[TestMethod]
public async Task w2sf()
{
await Task.Run(() => StressTestExt("w2sf"));
}
[TestMethod]
public async Task w2steer()
{
await Task.Run(() => StressTestExt("w2steer"));
}
[TestMethod]
public async Task w2ter()
{
await Task.Run(() => StressTestExt("w2ter"));
}
[TestMethod]
public async Task w2w()
{
await Task.Run(() => StressTestExt("w2w"));
}
[TestMethod]
public async Task w3app()
{
await Task.Run(() => StressTestExt("w3app"));
}
[TestMethod]
public async Task w3dyng()
{
await Task.Run(() => StressTestExt("w3dyng"));
}
[TestMethod]
public async Task w3fac()
{
await Task.Run(() => StressTestExt("w3fac"));
}
[TestMethod]
public async Task w3occlusion()
{
await Task.Run(() => StressTestExt("w3occlusion"));
}
[TestMethod]
public async Task w3simplex()
{
await Task.Run(() => StressTestExt("w3simplex"));
}
[TestMethod]
public async Task xbm()
{
await Task.Run(() => StressTestExt("xbm"));
}
//Not Cr2w files
/*
[TestMethod]
public async Task buffer()
{
await Task.Run(() => StressTestExt("buffer");
}
[TestMethod]
public async Task navconfig()
{
await Task.Run(() => StressTestExt("navconfig");
}
[TestMethod]
public async Task navgraph()
{
await Task.Run(() => StressTestExt("navgraph");
}
[TestMethod]
public async Task naviobstacles()
{
await Task.Run(() => StressTestExt("naviobstacles");
}
[TestMethod]
public async Task navmesh()
{
await Task.Run(() => StressTestExt("navmesh");
}
[TestMethod]
public async Task navtile()
{
await Task.Run(() => StressTestExt("navtile");
}
*/
#endregion
// Actually do the test
public void StressTestExt(string ext)
{
using (var frm = new frmUnitTest(ext, bundletag, bm))
{
//https://stackoverflow.com/questions/17797670/form-showdialog-does-not-display-window-with-debugging-enabled
frm.Load += (sender, e) => (sender as frmUnitTest).Visible = true;
frm.ShowDialog();
var result = frm.GetResult();
Assert.AreEqual(0, result.Item1, $"Unknown bytes remained -> {result.Item1}bytes");
Assert.AreEqual(0, result.Item2, $"Unparsed files -> {result.Item2}");
}
}
}
}