@@ -152,10 +152,13 @@ public void Name()
152152 Assert . True ( parts [ 2 ] == "Unknown" || parts [ 2 ] . Length > 0 ) ;
153153 Assert . True ( parts [ 2 ] . Length <= 10 ) ;
154154
155- // The OS and Runtime Info have no guaranteed format/content, but
156- // they must both be "Unknown" or non-empty.
155+ // OS Info must be non-empty and 44 characters or less.
157156 Assert . True ( parts [ 3 ] == "Unknown" || parts [ 3 ] . Length > 0 ) ;
157+ Assert . True ( parts [ 3 ] . Length <= 44 ) ;
158+
159+ // Runtime Info must be non-empty and 44 characters or less.
158160 Assert . True ( parts [ 4 ] == "Unknown" || parts [ 4 ] . Length > 0 ) ;
161+ Assert . True ( parts [ 4 ] . Length <= 44 ) ;
159162 }
160163
161164 // Test the Build() function when it truncates the overall length.
@@ -235,69 +238,98 @@ public void Build_Truncate_Arch()
235238#endif // NET
236239 }
237240
238- // Test the Build() function when one or both of OS and/or Runtime Info
239- // are truncated.
241+ // Test the Build() function when it truncates the OS Info.
240242 [ Fact ]
241- public void Build_Truncate_OS_Runtime_Info ( )
243+ public void Build_Truncate_OS_Info ( )
242244 {
243- // There is no space remaining.
244- Assert . Equal (
245- "A|B|X64|" ,
246- DoBuild ( 8 , "A" , "B" , Architecture . X64 , "C" , "D" ) ) ;
247-
248- // There is 1 char remaining, which is given to the OS Info.
245+ // The OS Info puts the overall length over the max.
249246 Assert . Equal (
250- "A|B|X64|C " ,
251- DoBuild ( 9 , "A" , "B" , Architecture . X64 , "CCC " , "DDD " ) ) ;
247+ "A|B|X64|LongOsI " ,
248+ DoBuild ( 15 , "A" , "B" , Architecture . X64 , "LongOsInfo " , "D " ) ) ;
252249
253- // There are 2 chars remaining; 1 for each Info field, but the pipe
254- // character gets in the way and Runtime Info is truncated.
250+ // The OS Type is longer than its per-field max length of 44.
255251 Assert . Equal (
256- "A|B|X64|C|" ,
257- DoBuild ( 10 , "A" , "B" , Architecture . X64 , "CCC" , "DDD" ) ) ;
258-
259- // There are 3 chars remaining; 1 for each Info field, and 1 for
260- // the pipe.
252+ "A|B|X64|01234567890123456789012345678901234567890123|D" ,
253+ DoBuild (
254+ 128 , "A" , "B" , Architecture . X64 ,
255+ "01234567890123456789012345678901234567890123456789" ,
256+ "D" ) ) ;
257+ }
258+
259+ // Test the Build() function when it truncates the Runtime Info.
260+ [ Fact ]
261+ public void Build_Truncate_Runtime_Info ( )
262+ {
263+ // The Runtime Info puts the overall length over the max.
261264 Assert . Equal (
262- "A|B|X64|C|D" ,
263- DoBuild ( 11 , "A" , "B" , Architecture . X64 , "CCC" , "DDD" ) ) ;
265+ "A|B|X64|C|LongRunt" ,
266+ DoBuild ( 18 , "A" , "B" , Architecture . X64 , "C" ,
267+ "LongRuntimeInfo" ) ) ;
264268
265- // Continue to expand max length until both Info values fit.
266- Assert . Equal (
267- "A|B|X64|CC|D" ,
268- DoBuild ( 12 , "A" , "B" , Architecture . X64 , "CCC" , "DDD" ) ) ;
269+ // The Runtime Type is longer than its per-field max length of 44.
269270 Assert . Equal (
270- "A|B|X64|CC|DD" ,
271- DoBuild ( 13 , "A" , "B" , Architecture . X64 , "CCC" , "DDD" ) ) ;
272- Assert . Equal (
273- "A|B|X64|CCC|DD" ,
274- DoBuild ( 14 , "A" , "B" , Architecture . X64 , "CCC" , "DDD" ) ) ;
275- Assert . Equal (
276- "A|B|X64|CCC|DDD" ,
277- DoBuild ( 15 , "A" , "B" , Architecture . X64 , "CCC" , "DDD" ) ) ;
271+ "A|B|X64|C|01234567890123456789012345678901234567890123" ,
272+ DoBuild (
273+ 128 , "A" , "B" , Architecture . X64 , "C" ,
274+ "01234567890123456789012345678901234567890123456789" ) ) ;
275+ }
278276
279- // OS Info is shorter than half, so Runtime Info gets the rest.
280- Assert . Equal (
281- "A|B|X64|CC|DDD" ,
282- DoBuild ( 14 , "A" , "B" , Architecture . X64 , "CC" , "DDDD" ) ) ;
283- Assert . Equal (
284- "A|B|X64|CC|DDDD" ,
285- DoBuild ( 15 , "A" , "B" , Architecture . X64 , "CC" , "DDDD" ) ) ;
277+ // Test the Build() function when most of the fields are truncated.
278+ [ Fact ]
279+ public void Build_Truncate_Most ( )
280+ {
281+ var name =
282+ DoBuild (
283+ 128 ,
284+ // Driver name > 16 chars.
285+ "A01234567890123456789" ,
286+ // OS Type > 10 chars.
287+ "B01234567890123456789" ,
288+ // Architecture isn't truncated (because .NET Framework
289+ // doesn't have any enum values long enough).
290+ Architecture . X64 ,
291+ // OS Info > 44 chars.
292+ "C01234567890123456789012345678901234567890123456789" ,
293+ // Runtime Info > 44 chars.
294+ "D01234567890123456789012345678901234567890123456789" ) ;
295+ Assert . Equal ( 121 , name . Length ) ;
286296 Assert . Equal (
287- "A|B|X64|CC|DDDD" ,
288- DoBuild ( 16 , "A" , "B" , Architecture . X64 , "CC" , "DDDD" ) ) ;
297+ "A012345678901234|" +
298+ "B012345678|" +
299+ "X64|" +
300+ "C0123456789012345678901234567890123456789012|" +
301+ "D0123456789012345678901234567890123456789012" ,
302+ name ) ;
303+ }
289304
290- // Runtime Info is shorter than half, so OS Info gets the rest.
291- Assert . Equal (
292- "A|B|X64|CCC|DD" ,
293- DoBuild ( 14 , "A" , "B" , Architecture . X64 , "CCCC" , "DD" ) ) ;
294- Assert . Equal (
295- "A|B|X64|CCCC|DD" ,
296- DoBuild ( 15 , "A" , "B" , Architecture . X64 , "CCCC" , "DD" ) ) ;
305+ #if NET
306+ // Test the Build() function when all the fields are truncated.
307+ [ Fact ]
308+ public void Build_Truncate_All ( )
309+ {
310+ var name =
311+ DoBuild (
312+ 128 ,
313+ // Driver name > 16 chars.
314+ "A01234567890123456789" ,
315+ // OS Type > 10 chars.
316+ "B01234567890123456789" ,
317+ // Architecture > 10 chars.
318+ Architecture . LoongArch64 ,
319+ // OS Info > 44 chars.
320+ "C01234567890123456789012345678901234567890123456789" ,
321+ // Runtime Info > 44 chars.
322+ "D01234567890123456789012345678901234567890123456789" ) ;
323+ Assert . Equal ( 128 , name . Length ) ;
297324 Assert . Equal (
298- "A|B|X64|CCCC|DD" ,
299- DoBuild ( 16 , "A" , "B" , Architecture . X64 , "CCCC" , "DD" ) ) ;
325+ "A012345678901234|" +
326+ "B012345678|" +
327+ "LoongArch6|" +
328+ "C0123456789012345678901234567890123456789012|" +
329+ "D0123456789012345678901234567890123456789012" ,
330+ name ) ;
300331 }
332+ #endif // NET
301333
302334 // Test the Clean() function.
303335 [ Fact ]
0 commit comments