Team Fortress 2 Source Code as on 22/4/2020
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.

104 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Unit test program for DMX testing (testing the single-value operations)
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "unitlib/unitlib.h"
  8. #include "datamodel/dmelement.h"
  9. #include "datamodel/idatamodel.h"
  10. #include "tier1/utlbuffer.h"
  11. #include "filesystem.h"
  12. #include "datamodel/dmehandle.h"
  13. #include "tier2/tier2.h"
  14. #include "movieobjects/dmeshape.h"
  15. DEFINE_TESTCASE_NOSUITE( DmxValueTest )
  16. {
  17. Msg( "Running dmx single value tests...\n" );
  18. CDisableUndoScopeGuard sg;
  19. DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( "<RunValueTests>" );
  20. CDmElement *pElement = CreateElement< CDmElement >( "root", fileid );
  21. CDmElement *pElement2 = CreateElement<CDmElement>( "element1", fileid );
  22. Assert( pElement2 );
  23. CDmElement *pElement3 = CreateElement<CDmElement>( "element2", fileid );
  24. Assert( pElement3 );
  25. CDmeShape *pElement4 = CreateElement<CDmeShape>( "shape", fileid );
  26. Assert( pElement4 );
  27. CDmAttribute *pIntAttribute = pElement->SetValue( "int_test", 5 );
  28. CDmAttribute *pFloatAttribute = pElement->SetValue( "float_test", 4.5f );
  29. CDmAttribute *pBoolAttribute = pElement->SetValue( "bool_test", true );
  30. CDmAttribute *pAttribute = pElement->AddAttribute( "int_convert_test", AT_INT );
  31. // Type conversion set test
  32. pAttribute->SetValue( 5 );
  33. Shipping_Assert( pAttribute->GetValue<int>() == 5 );
  34. pAttribute->SetValue( 4.5f );
  35. Shipping_Assert( pAttribute->GetValue<int>() == 4 );
  36. pAttribute->SetValue( true );
  37. Shipping_Assert( pAttribute->GetValue<int>() == 1 );
  38. pAttribute->SetValue( pIntAttribute );
  39. Shipping_Assert( pAttribute->GetValue<int>() == 5 );
  40. pAttribute->SetValue( pFloatAttribute );
  41. Shipping_Assert( pAttribute->GetValue<int>() == 4 );
  42. pAttribute->SetValue( pBoolAttribute );
  43. Shipping_Assert( pAttribute->GetValue<int>() == 1 );
  44. pAttribute = pElement->AddAttribute( "bool_convert_test", AT_BOOL );
  45. // Type conversion set test
  46. pAttribute->SetValue( 5 );
  47. Shipping_Assert( pAttribute->GetValue<bool>() == true );
  48. pAttribute->SetValue( 4.5f );
  49. Shipping_Assert( pAttribute->GetValue<bool>() == true );
  50. pAttribute->SetValue( false );
  51. Shipping_Assert( pAttribute->GetValue<bool>() == false );
  52. pAttribute->SetValue( pIntAttribute );
  53. Shipping_Assert( pAttribute->GetValue<bool>() == true );
  54. pAttribute->SetValue( pFloatAttribute );
  55. Shipping_Assert( pAttribute->GetValue<bool>() == true );
  56. pAttribute->SetValue( pBoolAttribute );
  57. Shipping_Assert( pAttribute->GetValue<bool>() == true );
  58. pAttribute = pElement->AddAttribute( "float_convert_test", AT_FLOAT );
  59. // Type conversion set test
  60. pAttribute->SetValue( 5 );
  61. Shipping_Assert( pAttribute->GetValue<float>() == 5.0f );
  62. pAttribute->SetValue( 4.5f );
  63. Shipping_Assert( pAttribute->GetValue<float>() == 4.5f );
  64. pAttribute->SetValue( true );
  65. Shipping_Assert( pAttribute->GetValue<float>() == 1.0f );
  66. pAttribute->SetValue( pIntAttribute );
  67. Shipping_Assert( pAttribute->GetValue<float>() == 5.0f );
  68. pAttribute->SetValue( pFloatAttribute );
  69. Shipping_Assert( pAttribute->GetValue<float>() == 4.5f );
  70. pAttribute->SetValue( pBoolAttribute );
  71. Shipping_Assert( pAttribute->GetValue<float>() == 1.0f );
  72. // Type conversion set test
  73. QAngle angles( 90, 0, 0 );
  74. Quaternion quat;
  75. AngleQuaternion( angles, quat );
  76. pAttribute = pElement->AddAttribute( "qangle_convert_test", AT_QANGLE );
  77. pAttribute->SetValue( angles );
  78. Shipping_Assert( pAttribute->GetValue<QAngle>() == angles );
  79. pAttribute->SetValue( quat );
  80. Shipping_Assert( pAttribute->GetValue<QAngle>() == angles );
  81. pAttribute = pElement->AddAttribute( "quat_convert_test", AT_QUATERNION );
  82. pAttribute->SetValue( angles );
  83. Shipping_Assert( pAttribute->GetValue<Quaternion>() == quat );
  84. pAttribute->SetValue( quat );
  85. Shipping_Assert( pAttribute->GetValue<Quaternion>() == quat );
  86. g_pDataModel->RemoveFileId( fileid );
  87. }