Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

525 lines
18 KiB

  1. #include "unitlib/unitlib.h"
  2. #include "tier1/commandbuffer.h"
  3. #include "tier1/utlbuffer.h"
  4. #include "tier1/strtools.h"
  5. #if defined( UNIT_TESTS_ENABLED ) && defined( _PS3 )
  6. extern "C" bool _tier1_unit_tests(void)
  7. {
  8. for( int i = 0; i < UnitTestCount(); i++ )
  9. {
  10. ITestCase* pThisTest = GetUnitTest( i );
  11. Assert( pThisTest );
  12. if( pThisTest )
  13. pThisTest->RunTest();
  14. }
  15. return true;
  16. }
  17. DEFINE_TESTSUITE( CommandBufferTestSuite )
  18. DEFINE_TESTCASE( CommandBufferTestSimple, CommandBufferTestSuite )
  19. {
  20. Msg( "Simple command buffer test...\n" );
  21. CCommandBuffer buffer;
  22. buffer.AddText( "test_command test_arg1 test_arg2" );
  23. buffer.AddText( "test_command2 test_arg3; test_command3 test_arg4" );
  24. buffer.AddText( "test_command4\ntest_command5" );
  25. buffer.AddText( "test_command6 // Comment; test_command7" );
  26. buffer.AddText( "test_command8 // Comment; test_command9\ntest_command10" );
  27. buffer.AddText( "test_command11 \"test_arg5 test_arg6\"" );
  28. buffer.AddText( "test_command12 \"\"" );
  29. buffer.AddText( "// Comment\ntest_command13\t\t\"test_arg7\"" );
  30. buffer.AddText( "test_command14\"test_arg8\"test_arg9" );
  31. buffer.AddText( "test_command15 test_arg10" );
  32. buffer.AddText( "test_command16 test_arg11:test_arg12" );
  33. CCommand command;
  34. buffer.BeginProcessingCommands( 1 );
  35. Verify( buffer.DequeueNextCommand( &command ) );
  36. Shipping_Assert( command.ArgC() == 3 );
  37. Shipping_Assert( !Q_stricmp( command[0], "test_command" ) );
  38. Shipping_Assert( !Q_stricmp( command[1], "test_arg1" ) );
  39. Shipping_Assert( !Q_stricmp( command[2], "test_arg2" ) );
  40. Shipping_Assert( !Q_stricmp( command.ArgS(), "test_arg1 test_arg2" ) );
  41. Verify( buffer.DequeueNextCommand( &command ) );
  42. Shipping_Assert( command.ArgC() == 2 );
  43. Shipping_Assert( !Q_stricmp( command[0], "test_command2" ) );
  44. Shipping_Assert( !Q_stricmp( command[1], "test_arg3" ) );
  45. Shipping_Assert( !Q_stricmp( command.ArgS(), "test_arg3" ) );
  46. Verify( buffer.DequeueNextCommand( &command ) );
  47. Shipping_Assert( command.ArgC() == 2 );
  48. Shipping_Assert( !Q_stricmp( command[0], "test_command3" ) );
  49. Shipping_Assert( !Q_stricmp( command[1], "test_arg4" ) );
  50. Shipping_Assert( !Q_stricmp( command.ArgS(), "test_arg4" ) );
  51. Verify( buffer.DequeueNextCommand( &command ) );
  52. Shipping_Assert( command.ArgC() == 1 );
  53. Shipping_Assert( !Q_stricmp( command[0], "test_command4" ) );
  54. Shipping_Assert( !Q_stricmp( command.ArgS(), "" ) );
  55. Verify( buffer.DequeueNextCommand( &command ) );
  56. Shipping_Assert( command.ArgC() == 1 );
  57. Shipping_Assert( !Q_stricmp( command[0], "test_command5" ) );
  58. Shipping_Assert( !Q_stricmp( command.ArgS(), "" ) );
  59. Verify( buffer.DequeueNextCommand( &command ) );
  60. Shipping_Assert( command.ArgC() == 1 );
  61. Shipping_Assert( !Q_stricmp( command[0], "test_command6" ) );
  62. Shipping_Assert( !Q_stricmp( command.ArgS(), "" ) );
  63. Verify( buffer.DequeueNextCommand( &command ) );
  64. Shipping_Assert( command.ArgC() == 1 );
  65. Shipping_Assert( !Q_stricmp( command[0], "test_command8" ) );
  66. Shipping_Assert( !Q_stricmp( command.ArgS(), "" ) );
  67. Verify( buffer.DequeueNextCommand( &command ) );
  68. Shipping_Assert( command.ArgC() == 1 );
  69. Shipping_Assert( !Q_stricmp( command[0], "test_command10" ) );
  70. Shipping_Assert( !Q_stricmp( command.ArgS(), "" ) );
  71. Verify( buffer.DequeueNextCommand( &command ) );
  72. Shipping_Assert( command.ArgC() == 2 );
  73. Shipping_Assert( !Q_stricmp( command[0], "test_command11" ) );
  74. Shipping_Assert( !Q_stricmp( command[1], "test_arg5 test_arg6" ) );
  75. Shipping_Assert( !Q_stricmp( command.ArgS(), "\"test_arg5 test_arg6\"" ) );
  76. Verify( buffer.DequeueNextCommand( &command ) );
  77. Shipping_Assert( command.ArgC() == 2 );
  78. Shipping_Assert( !Q_stricmp( command[0], "test_command12" ) );
  79. Shipping_Assert( !Q_stricmp( command[1], "" ) );
  80. Shipping_Assert( !Q_stricmp( command.ArgS(), "\"\"" ) );
  81. Verify( buffer.DequeueNextCommand( &command ) );
  82. Shipping_Assert( command.ArgC() == 2 );
  83. Shipping_Assert( !Q_stricmp( command[0], "test_command13" ) );
  84. Shipping_Assert( !Q_stricmp( command[1], "test_arg7" ) );
  85. Shipping_Assert( !Q_stricmp( command.ArgS(), "\"test_arg7\"" ) );
  86. Verify( buffer.DequeueNextCommand( &command ) );
  87. Shipping_Assert( command.ArgC() == 3 );
  88. Shipping_Assert( !Q_stricmp( command[0], "test_command14" ) );
  89. Shipping_Assert( !Q_stricmp( command[1], "test_arg8" ) );
  90. Shipping_Assert( !Q_stricmp( command[2], "test_arg9" ) );
  91. Shipping_Assert( !Q_stricmp( command.ArgS(), "\"test_arg8\"test_arg9" ) );
  92. Verify( buffer.DequeueNextCommand( &command ) );
  93. Shipping_Assert( command.ArgC() == 2 );
  94. Shipping_Assert( !Q_stricmp( command[0], "test_command15" ) );
  95. Shipping_Assert( !Q_stricmp( command[1], "test_arg10" ) );
  96. Shipping_Assert( !Q_stricmp( command.ArgS(), "test_arg10" ) );
  97. Verify( buffer.DequeueNextCommand( &command ) );
  98. Shipping_Assert( command.ArgC() == 4 );
  99. Shipping_Assert( !Q_stricmp( command[0], "test_command16" ) );
  100. Shipping_Assert( !Q_stricmp( command[1], "test_arg11" ) );
  101. Shipping_Assert( !Q_stricmp( command[2], ":" ) );
  102. Shipping_Assert( !Q_stricmp( command[3], "test_arg12" ) );
  103. Shipping_Assert( !Q_stricmp( command.ArgS(), "test_arg11:test_arg12" ) );
  104. Verify( !buffer.DequeueNextCommand( &command ) );
  105. Shipping_Assert( command.ArgC() == 0 );
  106. buffer.EndProcessingCommands( );
  107. }
  108. DEFINE_TESTCASE( CommandBufferTestTiming, CommandBufferTestSuite )
  109. {
  110. Msg( "Delayed command buffer test...\n" );
  111. CCommandBuffer buffer;
  112. buffer.AddText( "test_command test_arg1 test_arg2" );
  113. buffer.AddText( "test_command2 test_arg1 test_arg2 test_arg3", kCommandSrcUserInput, 1 );
  114. buffer.AddText( "test_command3;wait;test_command4;wait 2;test_command5" );
  115. CCommand command;
  116. {
  117. buffer.BeginProcessingCommands( 1 );
  118. Verify( buffer.DequeueNextCommand( &command ) );
  119. Shipping_Assert( command.ArgC() == 3 );
  120. Shipping_Assert( !Q_stricmp( command[0], "test_command" ) );
  121. Shipping_Assert( !Q_stricmp( command[1], "test_arg1" ) );
  122. Shipping_Assert( !Q_stricmp( command[2], "test_arg2" ) );
  123. Verify( buffer.DequeueNextCommand( &command ) );
  124. Shipping_Assert( command.ArgC() == 1 );
  125. Shipping_Assert( !Q_stricmp( command[0], "test_command3" ) );
  126. Verify( !buffer.DequeueNextCommand( &command ) );
  127. Shipping_Assert( command.ArgC() == 0 );
  128. buffer.EndProcessingCommands( );
  129. }
  130. {
  131. buffer.BeginProcessingCommands( 1 );
  132. Verify( buffer.DequeueNextCommand( &command ) );
  133. Shipping_Assert( command.ArgC() == 4 );
  134. Shipping_Assert( !Q_stricmp( command[0], "test_command2" ) );
  135. Shipping_Assert( !Q_stricmp( command[1], "test_arg1" ) );
  136. Shipping_Assert( !Q_stricmp( command[2], "test_arg2" ) );
  137. Shipping_Assert( !Q_stricmp( command[3], "test_arg3" ) );
  138. Verify( buffer.DequeueNextCommand( &command ) );
  139. Shipping_Assert( command.ArgC() == 1 );
  140. Shipping_Assert( !Q_stricmp( command[0], "test_command4" ) );
  141. Verify( !buffer.DequeueNextCommand( &command ) );
  142. Shipping_Assert( command.ArgC() == 0 );
  143. buffer.EndProcessingCommands( );
  144. }
  145. {
  146. buffer.BeginProcessingCommands( 1 );
  147. Verify( !buffer.DequeueNextCommand( &command ) );
  148. Shipping_Assert( command.ArgC() == 0 );
  149. buffer.EndProcessingCommands( );
  150. }
  151. {
  152. buffer.BeginProcessingCommands( 1 );
  153. Verify( buffer.DequeueNextCommand( &command ) );
  154. Shipping_Assert( command.ArgC() == 1 );
  155. Shipping_Assert( !Q_stricmp( command[0], "test_command5" ) );
  156. Verify( !buffer.DequeueNextCommand( &command ) );
  157. Shipping_Assert( command.ArgC() == 0 );
  158. buffer.EndProcessingCommands( );
  159. }
  160. }
  161. DEFINE_TESTCASE( CommandBufferTestNested, CommandBufferTestSuite )
  162. {
  163. Msg( "Nested command buffer test...\n" );
  164. CCommandBuffer buffer;
  165. buffer.AddText( "test_command test_arg1 test_arg2" );
  166. buffer.AddText( "test_command2 test_arg3 test_arg4 test_arg5", 2 );
  167. CCommand command;
  168. {
  169. buffer.BeginProcessingCommands( 2 );
  170. Verify( buffer.DequeueNextCommand( &command ) );
  171. Shipping_Assert( command.ArgC() == 3 );
  172. Shipping_Assert( !Q_stricmp( command[0], "test_command" ) );
  173. Shipping_Assert( !Q_stricmp( command[1], "test_arg1" ) );
  174. Shipping_Assert( !Q_stricmp( command[2], "test_arg2" ) );
  175. Verify( !buffer.DequeueNextCommand( &command ) );
  176. Shipping_Assert( command.ArgC() == 0 );
  177. buffer.AddText( "test_command3;test_command4", 1 );
  178. Verify( buffer.DequeueNextCommand( &command ) );
  179. Shipping_Assert( command.ArgC() == 1 );
  180. Shipping_Assert( !Q_stricmp( command[0], "test_command3" ) );
  181. Verify( buffer.DequeueNextCommand( &command ) );
  182. Shipping_Assert( command.ArgC() == 1 );
  183. Shipping_Assert( !Q_stricmp( command[0], "test_command4" ) );
  184. Verify( !buffer.DequeueNextCommand( &command ) );
  185. Shipping_Assert( command.ArgC() == 0 );
  186. buffer.EndProcessingCommands( );
  187. }
  188. {
  189. buffer.BeginProcessingCommands( 1 );
  190. Verify( buffer.DequeueNextCommand( &command ) );
  191. Shipping_Assert( command.ArgC() == 4 );
  192. Shipping_Assert( !Q_stricmp( command[0], "test_command2" ) );
  193. Shipping_Assert( !Q_stricmp( command[1], "test_arg3" ) );
  194. Shipping_Assert( !Q_stricmp( command[2], "test_arg4" ) );
  195. Shipping_Assert( !Q_stricmp( command[3], "test_arg5" ) );
  196. Verify( !buffer.DequeueNextCommand( &command ) );
  197. Shipping_Assert( command.ArgC() == 0 );
  198. buffer.EndProcessingCommands( );
  199. }
  200. }
  201. DEFINE_TESTCASE( CommandBufferTestOverflow, CommandBufferTestSuite )
  202. {
  203. Msg( "Command buffer overflow test...\n" );
  204. CCommandBuffer buffer;
  205. buffer.LimitArgumentBufferSize( 40 );
  206. bool bOk = buffer.AddText( "test_command test_arg1 test_arg2" ); // 32 chars
  207. Shipping_Assert( bOk );
  208. bOk = buffer.AddText( "test_command2 test_arg3 test_arg4 test_arg5", 2 ); // 43 chars
  209. Shipping_Assert( !bOk );
  210. CCommand command;
  211. {
  212. buffer.BeginProcessingCommands( 1 );
  213. Verify( buffer.DequeueNextCommand( &command ) );
  214. Shipping_Assert( command.ArgC() == 3 );
  215. Shipping_Assert( !Q_stricmp( command[0], "test_command" ) );
  216. Shipping_Assert( !Q_stricmp( command[1], "test_arg1" ) );
  217. Shipping_Assert( !Q_stricmp( command[2], "test_arg2" ) );
  218. bOk = buffer.AddText( "test_command3 test_arg6;wait;test_command4" );
  219. Shipping_Assert( bOk );
  220. // This makes sure that AddText doesn't cause argv to become bogus after
  221. // compacting memory
  222. Shipping_Assert( !Q_stricmp( command[0], "test_command" ) );
  223. Shipping_Assert( !Q_stricmp( command[1], "test_arg1" ) );
  224. Shipping_Assert( !Q_stricmp( command[2], "test_arg2" ) );
  225. Verify( buffer.DequeueNextCommand( &command ) );
  226. Shipping_Assert( command.ArgC() == 2 );
  227. Shipping_Assert( !Q_stricmp( command[0], "test_command3" ) );
  228. Shipping_Assert( !Q_stricmp( command[1], "test_arg6" ) );
  229. Verify( !buffer.DequeueNextCommand( &command ) );
  230. Shipping_Assert( command.ArgC() == 0 );
  231. buffer.EndProcessingCommands( );
  232. }
  233. {
  234. buffer.BeginProcessingCommands( 1 );
  235. Verify( buffer.DequeueNextCommand( &command ) );
  236. Shipping_Assert( command.ArgC() == 1 );
  237. Shipping_Assert( !Q_stricmp( command[0], "test_command4" ) );
  238. Verify( !buffer.DequeueNextCommand( &command ) );
  239. Shipping_Assert( command.ArgC() == 0 );
  240. buffer.EndProcessingCommands( );
  241. }
  242. }
  243. template < class A >
  244. bool TestValueAndGutters( A atest[3], const A &a, const char *mtest )
  245. {
  246. bool bSuccess0 = V_memcmp( &atest[ 0 ], mtest, sizeof( atest[ 0 ] ) ) == 0;
  247. bool bSuccess1 = atest[ 1 ] == a;
  248. bool bSuccess2 = V_memcmp( &atest[ 2 ], mtest, sizeof( atest[ 2 ] ) ) == 0;
  249. Shipping_Assert( bSuccess0 && bSuccess1 && bSuccess2 );
  250. return bSuccess0 && bSuccess1 && bSuccess2;
  251. }
  252. bool TestString( CUtlBuffer &buf, const char *pString )
  253. {
  254. char strtest[ 1023 ];
  255. int nLen = buf.GetUpTo( strtest, sizeof( strtest ) );
  256. strtest[ nLen ] = '\0';
  257. bool bSuccessStr = V_strcmp( pString, strtest ) == 0;
  258. Shipping_Assert( bSuccessStr );
  259. return bSuccessStr;
  260. }
  261. template < class A >
  262. void TestScanfAndPrintf( const char *pString, const A &a )
  263. {
  264. char mtest[] = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"; // 0x555555...
  265. A atest[3]; V_memset( atest, mtest[0], sizeof( atest ) );
  266. CUtlBuffer strbuf( pString, V_strlen( pString ) + 1, CUtlBuffer::READ_ONLY | CUtlBuffer::TEXT_BUFFER );
  267. const char *pScanFmt = GetFmtStr<A>();
  268. strbuf.Scanf( pScanFmt, &atest[1] );
  269. bool bSuccessA = TestValueAndGutters( atest, a, mtest );
  270. if ( !bSuccessA )
  271. {
  272. Msg( "CUtlBuffer::Scanf '%s' FAILED!\n", pString );
  273. return;
  274. }
  275. CUtlBuffer valbuf( 0, 1024, CUtlBuffer::TEXT_BUFFER );
  276. const char *pPrintFmt = GetFmtStr<A>();
  277. valbuf.Printf( pPrintFmt, atest[1] ); // we know that a == atest[1] from before
  278. if ( !TestString( valbuf, pString ) )
  279. {
  280. Msg( "CUtlBuffer::Printf '%s' FAILED!\n", pString );
  281. }
  282. }
  283. template < class A, class B >
  284. void TestScanfAndPrintf( const char *pString, const A &a, const B &b )
  285. {
  286. char mtest[] = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"; // 0x555555...
  287. A atest[3]; V_memset( atest, mtest[0], sizeof( atest ) );
  288. B btest[3]; V_memset( btest, mtest[0], sizeof( btest ) );
  289. CUtlBuffer strbuf( pString, V_strlen( pString ) + 1, CUtlBuffer::READ_ONLY | CUtlBuffer::TEXT_BUFFER );
  290. char scanfmt[ 256 ];
  291. V_snprintf( scanfmt, sizeof( scanfmt ), "%s %s", GetFmtStr<A>( 10, false ), GetFmtStr<B>( 10, false ) );
  292. strbuf.Scanf( scanfmt, &atest[1], &btest[1] );
  293. bool bSuccessA = TestValueAndGutters( atest, a, mtest );
  294. bool bSuccessB = TestValueAndGutters( btest, b, mtest );
  295. if ( !bSuccessA || !bSuccessB )
  296. {
  297. Msg( "CUtlBuffer::Scanf '%s' FAILED!\n", pString );
  298. return;
  299. }
  300. CUtlBuffer valbuf( 0, 1024, CUtlBuffer::TEXT_BUFFER );
  301. char printfmt[ 256 ];
  302. V_snprintf( printfmt, sizeof( printfmt ), "%s %s", GetFmtStr<A>(), GetFmtStr<B>() );
  303. valbuf.Printf( printfmt, atest[1], btest[1] ); // we know that a == atest[1] and b == btest[1] from before
  304. if ( !TestString( valbuf, pString ) )
  305. {
  306. Msg( "CUtlBuffer::Printf '%s' FAILED!\n", pString );
  307. }
  308. }
  309. template < class A, class B, class C >
  310. void TestScanfAndPrintf( const char *pString, const A &a, const B &b, const C &c )
  311. {
  312. const char mtest[] = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"; // 0x555555...
  313. A atest[3]; V_memset( atest, mtest[0], sizeof( atest ) );
  314. B btest[3]; V_memset( btest, mtest[0], sizeof( btest ) );
  315. C ctest[3]; V_memset( ctest, mtest[0], sizeof( ctest ) );
  316. CUtlBuffer strbuf( pString, V_strlen( pString ) + 1, CUtlBuffer::READ_ONLY | CUtlBuffer::TEXT_BUFFER );
  317. char scanfmt[ 256 ];
  318. V_snprintf( scanfmt, sizeof( scanfmt ), "%s %s %s", GetFmtStr<A>( 10, false ), GetFmtStr<B>( 10, false ), GetFmtStr<C>( 10, false ) );
  319. strbuf.Scanf( scanfmt, &atest[1], &btest[1], &ctest[1] );
  320. bool bSuccessA = TestValueAndGutters( atest, a, mtest );
  321. bool bSuccessB = TestValueAndGutters( btest, b, mtest );
  322. bool bSuccessC = TestValueAndGutters( ctest, c, mtest );
  323. if ( !bSuccessA || !bSuccessB || !bSuccessC )
  324. {
  325. Msg( "CUtlBuffer::Scanf '%s' FAILED!\n", pString );
  326. return;
  327. }
  328. CUtlBuffer valbuf( 0, 1024, CUtlBuffer::TEXT_BUFFER );
  329. char printfmt[ 256 ];
  330. V_snprintf( printfmt, sizeof( printfmt ), "%s %s %s", GetFmtStr<A>(), GetFmtStr<B>(), GetFmtStr<C>() );
  331. valbuf.Printf( printfmt, atest[1], btest[1], ctest[1] ); // we know that a == atest[1] and b == btest[1] and c == ctest[1] from before
  332. if ( !TestString( valbuf, pString ) )
  333. {
  334. Msg( "CUtlBuffer::Printf '%s' FAILED!\n", pString );
  335. }
  336. }
  337. template < class T >
  338. void TestGetPut( T ( CUtlBuffer::*getfunc )(), void ( CUtlBuffer::*putfunc )( T ), const char *pString, const T &value )
  339. {
  340. {
  341. CUtlBuffer valbuf( 0, 1024, CUtlBuffer::TEXT_BUFFER );
  342. char mtest[] = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"; // 0x555555...
  343. T valtest[3];
  344. V_memset( valtest, mtest[0], sizeof( valtest ) );
  345. valtest[1] = value;
  346. ( valbuf.*putfunc )( valtest[1] );
  347. if ( !TestValueAndGutters( valtest, value, mtest ) )
  348. {
  349. Msg( "CUtlBuffer::PutXXX FAILED!\n" );
  350. }
  351. if ( !TestString( valbuf, pString ) )
  352. {
  353. Msg( "CUtlBuffer::PutXXX FAILED!\n" );
  354. }
  355. }
  356. {
  357. CUtlBuffer strbuf( pString, V_strlen( pString ) + 1, CUtlBuffer::READ_ONLY | CUtlBuffer::TEXT_BUFFER );
  358. char mtest[] = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"; // 0x555555...
  359. T valtest[3];
  360. V_memset( valtest, mtest[0], sizeof( valtest ) );
  361. valtest[1] = (strbuf.*getfunc)();
  362. if ( !TestValueAndGutters( valtest, value, mtest ) )
  363. {
  364. Msg( "CUtlBuffer::GetXXX FAILED!\n" );
  365. }
  366. }
  367. // {
  368. // CUtlBuffer strbuf( pString, V_strlen( pString ) + 1, CUtlBuffer::READ_ONLY | CUtlBuffer::TEXT_BUFFER );
  369. //
  370. // char mtest[] = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU"; // 0x555555...
  371. // T valtest[3];
  372. // V_memset( valtest, mtest[0], sizeof( valtest ) );
  373. //
  374. // char fmt[ 256 ];
  375. // V_snprintf( fmt, sizeof( fmt ), "%s", GetFmtStr<T>() );
  376. //
  377. // strbuf.GetType( valtest[1], fmt );
  378. //
  379. // if ( !TestValueAndGutters( valtest, value, mtest ) )
  380. // {
  381. // Msg( "CUtlBuffer::GetType FAILED!\n" );
  382. // }
  383. // }
  384. }
  385. DEFINE_TESTSUITE( UtlBufferTestSuite )
  386. DEFINE_TESTCASE( UtlBufferTestScanf, UtlBufferTestSuite )
  387. {
  388. Msg( "CUtlBuffer::Scanf test...\n" );
  389. TestScanfAndPrintf( "-1234567890 12345 0.123456789012345", -1234567890, 12345u, 0.123456789012345 );
  390. TestScanfAndPrintf( "-12345 0.123456", -12345, 0.123456f );
  391. TestScanfAndPrintf( "1234567890", 1234567890u );
  392. TestScanfAndPrintf( "1234567890123456789", 1234567890123456789ll );
  393. }
  394. typedef unsigned char uchar;
  395. DEFINE_TESTCASE( UtlBufferTestGetPut, UtlBufferTestSuite )
  396. {
  397. Msg( "CUtlBuffer Get/Put test...\n" );
  398. // TestGetPut< char >( &CUtlBuffer::GetChar, &CUtlBuffer::PutChar, "-123", -123i8 ); // GetChar()/PutChar() always read/write a single byte, even in text mode
  399. TestGetPut< uchar >( &CUtlBuffer::GetUnsignedChar, &CUtlBuffer::PutUnsignedChar, "123", 123 );
  400. TestGetPut< short >( &CUtlBuffer::GetShort, &CUtlBuffer::PutShort, "-12345", -12345 );
  401. TestGetPut< ushort >( &CUtlBuffer::GetUnsignedShort, &CUtlBuffer::PutUnsignedShort, "12345", 12345u );
  402. TestGetPut< int >( &CUtlBuffer::GetInt, &CUtlBuffer::PutInt, "-1234567890", -1234567890 );
  403. TestGetPut< uint >( &CUtlBuffer::GetUnsignedInt, &CUtlBuffer::PutUnsignedInt, "1234567890", 1234567890u );
  404. // TestGetPut< int >( &CUtlBuffer::GetIntHex, &CUtlBuffer::PutIntHex, "123", 123i8 ); // there is no PutIntHex()
  405. TestGetPut< int64 >( &CUtlBuffer::GetInt64, &CUtlBuffer::PutInt64, "1234567890123456789", 1234567890123456789ll );
  406. TestGetPut< float >( &CUtlBuffer::GetFloat, &CUtlBuffer::PutFloat, "0.123456", 0.123456f );
  407. TestGetPut< double >( &CUtlBuffer::GetDouble, &CUtlBuffer::PutDouble, "0.123456789012345", 0.123456789012345 );
  408. }
  409. #endif // _DEBUG