3
3
using System . IO ;
4
4
using System . Linq ;
5
5
using System . Text . RegularExpressions ;
6
+ using System . Threading . Tasks ;
6
7
using NUnit . Framework ;
7
8
using UnityDataTools . TestCommon ;
8
9
using UnityDataTools . FileSystem ;
@@ -18,7 +19,7 @@ public class UnityDataToolTests : AssetBundleTestFixture
18
19
public UnityDataToolTests ( Context context ) : base ( context )
19
20
{
20
21
}
21
-
22
+
22
23
protected override void OnLoadExpectedData ( Context context )
23
24
{
24
25
// Uncomment to regenerate expected data.
@@ -36,25 +37,40 @@ public void OneTimeSetup()
36
37
[ TearDown ]
37
38
public void Teardown ( )
38
39
{
39
- foreach ( var file in new DirectoryInfo ( m_TestOutputFolder ) . EnumerateFiles ( ) )
40
- {
41
- file . Delete ( ) ;
42
- }
40
+ var testDir = new DirectoryInfo ( m_TestOutputFolder ) ;
41
+ testDir . EnumerateFiles ( )
42
+ . ToList ( ) . ForEach ( f => f . Delete ( ) ) ;
43
+ testDir . EnumerateDirectories ( )
44
+ . ToList ( ) . ForEach ( d => d . Delete ( true ) ) ;
43
45
}
44
-
46
+
45
47
[ Test ]
46
- public void ArchiveExtract_FilesExtractedSuccessfully ( )
48
+ public async Task InvalidFile (
49
+ [ Values (
50
+ new string [ ] { "archive" , "extract" } ,
51
+ new string [ ] { "archive" , "list" } ,
52
+ new string [ ] { "dump" }
53
+ ) ] string [ ] args )
54
+ {
55
+ var path = Path . Combine ( Context . TestDataFolder , "invalidfile" ) ;
56
+ var command = args . Append ( path ) ;
57
+ Assert . AreNotEqual ( 0 , await Program . Main ( command . ToArray ( ) ) ) ;
58
+ }
59
+
60
+ [ Test ]
61
+ public async Task ArchiveExtract_FilesExtractedSuccessfully (
62
+ [ Values ( "" , "-o archive" , "--output-path archive" ) ] string options )
47
63
{
48
64
var path = Path . Combine ( Context . UnityDataFolder , "assetbundle" ) ;
49
65
50
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "archive" , "extract" , path } ) ) ;
51
- Assert . IsTrue ( File . Exists ( Path . Combine ( m_TestOutputFolder , "CAB-5d40f7cad7c871cf2ad2af19ac542994" ) ) ) ;
52
- Assert . IsTrue ( File . Exists ( Path . Combine ( m_TestOutputFolder , "CAB-5d40f7cad7c871cf2ad2af19ac542994.resS" ) ) ) ;
53
- Assert . IsTrue ( File . Exists ( Path . Combine ( m_TestOutputFolder , "CAB-5d40f7cad7c871cf2ad2af19ac542994.resource" ) ) ) ;
66
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "archive" , "extract" , path } . Concat ( options . Split ( " " , StringSplitOptions . RemoveEmptyEntries ) ) . ToArray ( ) ) ) ;
67
+ Assert . IsTrue ( File . Exists ( Path . Combine ( m_TestOutputFolder , "archive" , " CAB-5d40f7cad7c871cf2ad2af19ac542994") ) ) ;
68
+ Assert . IsTrue ( File . Exists ( Path . Combine ( m_TestOutputFolder , "archive" , " CAB-5d40f7cad7c871cf2ad2af19ac542994.resS") ) ) ;
69
+ Assert . IsTrue ( File . Exists ( Path . Combine ( m_TestOutputFolder , "archive" , " CAB-5d40f7cad7c871cf2ad2af19ac542994.resource") ) ) ;
54
70
}
55
71
56
72
[ Test ]
57
- public void ArchiveList_ListFilesCorrectly ( )
73
+ public async Task ArchiveList_ListFilesCorrectly ( )
58
74
{
59
75
var path = Path . Combine ( Context . UnityDataFolder , "assetbundle" ) ;
60
76
@@ -63,7 +79,7 @@ public void ArchiveList_ListFilesCorrectly()
63
79
var currentOut = Console . Out ;
64
80
Console . SetOut ( sw ) ;
65
81
66
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "archive" , "list" , path } ) ) ;
82
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "archive" , "list" , path } ) ) ;
67
83
68
84
var lines = sw . ToString ( ) . Split ( sw . NewLine ) ;
69
85
@@ -83,13 +99,13 @@ public void ArchiveList_ListFilesCorrectly()
83
99
}
84
100
85
101
[ Test ]
86
- public void DumpText_DefaultArgs_TextFileCreatedCorrectly (
102
+ public async Task DumpText_DefaultArgs_TextFileCreatedCorrectly (
87
103
[ Values ( "" , "-f text" , "--output-format text" ) ] string options )
88
104
{
89
105
var path = Path . Combine ( Context . UnityDataFolder , "assetbundle" ) ;
90
106
var outputFile = Path . Combine ( m_TestOutputFolder , "CAB-5d40f7cad7c871cf2ad2af19ac542994.txt" ) ;
91
107
92
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "dump" , path } . Concat ( options . Split ( " " , StringSplitOptions . RemoveEmptyEntries ) ) . ToArray ( ) ) ) ;
108
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "dump" , path } . Concat ( options . Split ( " " , StringSplitOptions . RemoveEmptyEntries ) ) . ToArray ( ) ) ) ;
93
109
Assert . IsTrue ( File . Exists ( outputFile ) ) ;
94
110
95
111
var content = File . ReadAllText ( outputFile ) ;
@@ -103,13 +119,13 @@ public void DumpText_DefaultArgs_TextFileCreatedCorrectly(
103
119
}
104
120
105
121
[ Test ]
106
- public void DumpText_SkipLargeArrays_TextFileCreatedCorrectly (
122
+ public async Task DumpText_SkipLargeArrays_TextFileCreatedCorrectly (
107
123
[ Values ( "-s" , "--skip-large-arrays" ) ] string options )
108
124
{
109
125
var path = Path . Combine ( Context . UnityDataFolder , "assetbundle" ) ;
110
126
var outputFile = Path . Combine ( m_TestOutputFolder , "CAB-5d40f7cad7c871cf2ad2af19ac542994.txt" ) ;
111
127
112
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "dump" , path } . Concat ( options . Split ( " " , StringSplitOptions . RemoveEmptyEntries ) ) . ToArray ( ) ) ) ;
128
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "dump" , path } . Concat ( options . Split ( " " , StringSplitOptions . RemoveEmptyEntries ) ) . ToArray ( ) ) ) ;
113
129
Assert . IsTrue ( File . Exists ( outputFile ) ) ;
114
130
115
131
var content = File . ReadAllText ( outputFile ) ;
@@ -123,48 +139,48 @@ public void DumpText_SkipLargeArrays_TextFileCreatedCorrectly(
123
139
}
124
140
125
141
[ Test ]
126
- public void Analyze_DefaultArgs_DatabaseCorrect ( )
142
+ public async Task Analyze_DefaultArgs_DatabaseCorrect ( )
127
143
{
128
144
var databasePath = Path . Combine ( m_TestOutputFolder , "database.db" ) ;
129
145
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
130
146
131
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "analyze" , analyzePath } ) ) ;
147
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "analyze" , analyzePath } ) ) ;
132
148
133
149
ValidateDatabase ( databasePath , false ) ;
134
150
}
135
151
136
152
[ Test ]
137
- public void Analyze_WithRefs_DatabaseCorrect (
153
+ public async Task Analyze_WithRefs_DatabaseCorrect (
138
154
[ Values ( "-r" , "--extract-references" ) ] string options )
139
155
{
140
156
var databasePath = Path . Combine ( m_TestOutputFolder , "database.db" ) ;
141
157
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
142
158
143
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "analyze" , analyzePath } . Concat ( options . Split ( " " ) ) . ToArray ( ) ) ) ;
159
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "analyze" , analyzePath } . Concat ( options . Split ( " " ) ) . ToArray ( ) ) ) ;
144
160
145
161
ValidateDatabase ( databasePath , true ) ;
146
162
}
147
163
148
164
[ Test ]
149
- public void Analyze_WithPattern_DatabaseCorrect (
165
+ public async Task Analyze_WithPattern_DatabaseCorrect (
150
166
[ Values ( "-p *." , "--search-pattern *." ) ] string options )
151
167
{
152
168
var databasePath = Path . Combine ( m_TestOutputFolder , "database.db" ) ;
153
169
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
154
170
155
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "analyze" , analyzePath } . Concat ( options . Split ( " " ) ) . ToArray ( ) ) ) ;
171
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "analyze" , analyzePath } . Concat ( options . Split ( " " ) ) . ToArray ( ) ) ) ;
156
172
157
173
ValidateDatabase ( databasePath , false ) ;
158
174
}
159
175
160
176
[ Test ]
161
- public void Analyze_WithPatternNoMatch_DatabaseEmpty (
177
+ public async Task Analyze_WithPatternNoMatch_DatabaseEmpty (
162
178
[ Values ( "-p *.x" , "--search-pattern *.x" ) ] string options )
163
179
{
164
180
var databasePath = Path . Combine ( m_TestOutputFolder , "database.db" ) ;
165
181
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
166
182
167
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "analyze" , analyzePath } . Concat ( options . Split ( " " ) ) . ToArray ( ) ) ) ;
183
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "analyze" , analyzePath } . Concat ( options . Split ( " " ) ) . ToArray ( ) ) ) ;
168
184
169
185
using var db = new SQLiteConnection ( $ "Data Source={ databasePath } ;Version=3;New=True;Foreign Keys=False;") ;
170
186
db . Open ( ) ;
@@ -178,13 +194,13 @@ public void Analyze_WithPatternNoMatch_DatabaseEmpty(
178
194
}
179
195
180
196
[ Test ]
181
- public void Analyze_WithOutputFile_DatabaseCorrect (
197
+ public async Task Analyze_WithOutputFile_DatabaseCorrect (
182
198
[ Values ( "-o my_database" , "--output-file my_database" ) ] string options )
183
199
{
184
200
var databasePath = Path . Combine ( m_TestOutputFolder , "my_database" ) ;
185
201
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
186
202
187
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "analyze" , analyzePath } . Concat ( options . Split ( " " ) ) . ToArray ( ) ) ) ;
203
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "analyze" , analyzePath } . Concat ( options . Split ( " " ) ) . ToArray ( ) ) ) ;
188
204
189
205
ValidateDatabase ( databasePath , false ) ;
190
206
}
@@ -197,7 +213,7 @@ private void ValidateDatabase(string databasePath, bool withRefs)
197
213
using ( var cmd = db . CreateCommand ( ) )
198
214
{
199
215
cmd . CommandText =
200
- @"SELECT
216
+ @"SELECT
201
217
(SELECT COUNT(*) FROM animation_clips),
202
218
(SELECT COUNT(*) FROM asset_bundles),
203
219
(SELECT COUNT(*) FROM assets),
@@ -259,21 +275,21 @@ public void Teardown()
259
275
file . Delete ( ) ;
260
276
}
261
277
}
262
-
278
+
263
279
[ Test ]
264
- public void Analyze_PlayerData_DatabaseCorrect ( )
280
+ public async Task Analyze_PlayerData_DatabaseCorrect ( )
265
281
{
266
282
var databasePath = Path . Combine ( m_TestOutputFolder , "database.db" ) ;
267
283
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
268
284
269
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "analyze" , analyzePath , "-r" } ) ) ;
270
-
285
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "analyze" , analyzePath , "-r" } ) ) ;
286
+
271
287
using var db = new SQLiteConnection ( $ "Data Source={ databasePath } ;Version=3;New=True;Foreign Keys=False;") ;
272
288
db . Open ( ) ;
273
289
using var cmd = db . CreateCommand ( ) ;
274
290
275
291
cmd . CommandText =
276
- @"SELECT
292
+ @"SELECT
277
293
(SELECT COUNT(*) FROM asset_bundles),
278
294
(SELECT COUNT(*) FROM assets),
279
295
(SELECT COUNT(*) FROM objects),
@@ -290,14 +306,14 @@ public void Analyze_PlayerData_DatabaseCorrect()
290
306
Assert . Greater ( reader . GetInt32 ( 3 ) , 0 ) ;
291
307
Assert . AreEqual ( 1 , reader . GetInt32 ( 4 ) ) ;
292
308
}
293
-
309
+
294
310
[ Test ]
295
- public void DumpText_PlayerData_TextFileCreatedCorrectly ( )
311
+ public async Task DumpText_PlayerData_TextFileCreatedCorrectly ( )
296
312
{
297
313
var path = Path . Combine ( Context . UnityDataFolder , "level0" ) ;
298
314
var outputFile = Path . Combine ( m_TestOutputFolder , "level0.txt" ) ;
299
315
300
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "dump" , path } ) ) ;
316
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "dump" , path } ) ) ;
301
317
Assert . IsTrue ( File . Exists ( outputFile ) ) ;
302
318
303
319
var content = File . ReadAllText ( outputFile ) ;
0 commit comments