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 ;
@@ -44,19 +45,32 @@ public void Teardown()
44
45
}
45
46
46
47
[ Test ]
47
- 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 (
48
62
[ Values ( "" , "-o archive" , "--output-path archive" ) ] string options )
49
63
{
50
64
var path = Path . Combine ( Context . UnityDataFolder , "assetbundle" ) ;
51
65
52
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "archive" , "extract" , path } . Concat ( options . Split ( " " , StringSplitOptions . RemoveEmptyEntries ) ) . ToArray ( ) ) ) ;
66
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "archive" , "extract" , path } . Concat ( options . Split ( " " , StringSplitOptions . RemoveEmptyEntries ) ) . ToArray ( ) ) ) ;
53
67
Assert . IsTrue ( File . Exists ( Path . Combine ( m_TestOutputFolder , "archive" , "CAB-5d40f7cad7c871cf2ad2af19ac542994" ) ) ) ;
54
68
Assert . IsTrue ( File . Exists ( Path . Combine ( m_TestOutputFolder , "archive" , "CAB-5d40f7cad7c871cf2ad2af19ac542994.resS" ) ) ) ;
55
69
Assert . IsTrue ( File . Exists ( Path . Combine ( m_TestOutputFolder , "archive" , "CAB-5d40f7cad7c871cf2ad2af19ac542994.resource" ) ) ) ;
56
70
}
57
71
58
72
[ Test ]
59
- public void ArchiveList_ListFilesCorrectly ( )
73
+ public async Task ArchiveList_ListFilesCorrectly ( )
60
74
{
61
75
var path = Path . Combine ( Context . UnityDataFolder , "assetbundle" ) ;
62
76
@@ -65,7 +79,7 @@ public void ArchiveList_ListFilesCorrectly()
65
79
var currentOut = Console . Out ;
66
80
Console . SetOut ( sw ) ;
67
81
68
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "archive" , "list" , path } ) ) ;
82
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "archive" , "list" , path } ) ) ;
69
83
70
84
var lines = sw . ToString ( ) . Split ( sw . NewLine ) ;
71
85
@@ -85,13 +99,13 @@ public void ArchiveList_ListFilesCorrectly()
85
99
}
86
100
87
101
[ Test ]
88
- public void DumpText_DefaultArgs_TextFileCreatedCorrectly (
102
+ public async Task DumpText_DefaultArgs_TextFileCreatedCorrectly (
89
103
[ Values ( "" , "-f text" , "--output-format text" ) ] string options )
90
104
{
91
105
var path = Path . Combine ( Context . UnityDataFolder , "assetbundle" ) ;
92
106
var outputFile = Path . Combine ( m_TestOutputFolder , "CAB-5d40f7cad7c871cf2ad2af19ac542994.txt" ) ;
93
107
94
- 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 ( ) ) ) ;
95
109
Assert . IsTrue ( File . Exists ( outputFile ) ) ;
96
110
97
111
var content = File . ReadAllText ( outputFile ) ;
@@ -105,13 +119,13 @@ public void DumpText_DefaultArgs_TextFileCreatedCorrectly(
105
119
}
106
120
107
121
[ Test ]
108
- public void DumpText_SkipLargeArrays_TextFileCreatedCorrectly (
122
+ public async Task DumpText_SkipLargeArrays_TextFileCreatedCorrectly (
109
123
[ Values ( "-s" , "--skip-large-arrays" ) ] string options )
110
124
{
111
125
var path = Path . Combine ( Context . UnityDataFolder , "assetbundle" ) ;
112
126
var outputFile = Path . Combine ( m_TestOutputFolder , "CAB-5d40f7cad7c871cf2ad2af19ac542994.txt" ) ;
113
127
114
- 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 ( ) ) ) ;
115
129
Assert . IsTrue ( File . Exists ( outputFile ) ) ;
116
130
117
131
var content = File . ReadAllText ( outputFile ) ;
@@ -125,48 +139,48 @@ public void DumpText_SkipLargeArrays_TextFileCreatedCorrectly(
125
139
}
126
140
127
141
[ Test ]
128
- public void Analyze_DefaultArgs_DatabaseCorrect ( )
142
+ public async Task Analyze_DefaultArgs_DatabaseCorrect ( )
129
143
{
130
144
var databasePath = Path . Combine ( m_TestOutputFolder , "database.db" ) ;
131
145
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
132
146
133
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "analyze" , analyzePath } ) ) ;
147
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "analyze" , analyzePath } ) ) ;
134
148
135
149
ValidateDatabase ( databasePath , false ) ;
136
150
}
137
151
138
152
[ Test ]
139
- public void Analyze_WithRefs_DatabaseCorrect (
153
+ public async Task Analyze_WithRefs_DatabaseCorrect (
140
154
[ Values ( "-r" , "--extract-references" ) ] string options )
141
155
{
142
156
var databasePath = Path . Combine ( m_TestOutputFolder , "database.db" ) ;
143
157
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
144
158
145
- 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 ( ) ) ) ;
146
160
147
161
ValidateDatabase ( databasePath , true ) ;
148
162
}
149
163
150
164
[ Test ]
151
- public void Analyze_WithPattern_DatabaseCorrect (
165
+ public async Task Analyze_WithPattern_DatabaseCorrect (
152
166
[ Values ( "-p *." , "--search-pattern *." ) ] string options )
153
167
{
154
168
var databasePath = Path . Combine ( m_TestOutputFolder , "database.db" ) ;
155
169
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
156
170
157
- 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 ( ) ) ) ;
158
172
159
173
ValidateDatabase ( databasePath , false ) ;
160
174
}
161
175
162
176
[ Test ]
163
- public void Analyze_WithPatternNoMatch_DatabaseEmpty (
177
+ public async Task Analyze_WithPatternNoMatch_DatabaseEmpty (
164
178
[ Values ( "-p *.x" , "--search-pattern *.x" ) ] string options )
165
179
{
166
180
var databasePath = Path . Combine ( m_TestOutputFolder , "database.db" ) ;
167
181
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
168
182
169
- 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 ( ) ) ) ;
170
184
171
185
using var db = new SQLiteConnection ( $ "Data Source={ databasePath } ;Version=3;New=True;Foreign Keys=False;") ;
172
186
db . Open ( ) ;
@@ -180,13 +194,13 @@ public void Analyze_WithPatternNoMatch_DatabaseEmpty(
180
194
}
181
195
182
196
[ Test ]
183
- public void Analyze_WithOutputFile_DatabaseCorrect (
197
+ public async Task Analyze_WithOutputFile_DatabaseCorrect (
184
198
[ Values ( "-o my_database" , "--output-file my_database" ) ] string options )
185
199
{
186
200
var databasePath = Path . Combine ( m_TestOutputFolder , "my_database" ) ;
187
201
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
188
202
189
- 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 ( ) ) ) ;
190
204
191
205
ValidateDatabase ( databasePath , false ) ;
192
206
}
@@ -263,12 +277,12 @@ public void Teardown()
263
277
}
264
278
265
279
[ Test ]
266
- public void Analyze_PlayerData_DatabaseCorrect ( )
280
+ public async Task Analyze_PlayerData_DatabaseCorrect ( )
267
281
{
268
282
var databasePath = Path . Combine ( m_TestOutputFolder , "database.db" ) ;
269
283
var analyzePath = Path . Combine ( Context . UnityDataFolder ) ;
270
284
271
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "analyze" , analyzePath , "-r" } ) ) ;
285
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "analyze" , analyzePath , "-r" } ) ) ;
272
286
273
287
using var db = new SQLiteConnection ( $ "Data Source={ databasePath } ;Version=3;New=True;Foreign Keys=False;") ;
274
288
db . Open ( ) ;
@@ -294,12 +308,12 @@ public void Analyze_PlayerData_DatabaseCorrect()
294
308
}
295
309
296
310
[ Test ]
297
- public void DumpText_PlayerData_TextFileCreatedCorrectly ( )
311
+ public async Task DumpText_PlayerData_TextFileCreatedCorrectly ( )
298
312
{
299
313
var path = Path . Combine ( Context . UnityDataFolder , "level0" ) ;
300
314
var outputFile = Path . Combine ( m_TestOutputFolder , "level0.txt" ) ;
301
315
302
- Assert . AreEqual ( 0 , Program . Main ( new string [ ] { "dump" , path } ) ) ;
316
+ Assert . AreEqual ( 0 , await Program . Main ( new string [ ] { "dump" , path } ) ) ;
303
317
Assert . IsTrue ( File . Exists ( outputFile ) ) ;
304
318
305
319
var content = File . ReadAllText ( outputFile ) ;
0 commit comments