UnitTest.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. GWEN
  3. Copyright (c) 2010 Facepunch Studios
  4. See license in Gwen.h
  5. */
  6. #include "UnitTest.h"
  7. #include "Gwen/Platform.h"
  8. #include "Gwen/Controls/TreeControl.h"
  9. using namespace Gwen;
  10. #define ADD_UNIT_TEST( name )\
  11. GUnit* RegisterUnitTest_##name( Gwen::Controls::TabControl* tab );\
  12. RegisterUnitTest_##name( m_TabControl )->SetUnitTest( this );
  13. GWEN_CONTROL_CONSTRUCTOR( UnitTest )
  14. {
  15. SetTitle( L"GWEN Unit Test" );
  16. SetSize( 600, 450 );
  17. m_TabControl = new Controls::TabControl( this );
  18. m_TabControl->Dock( Pos::Fill );
  19. m_TabControl->SetMargin( Margin( 2, 2, 2, 2 ) );
  20. m_TextOutput = new Controls::ListBox( this );
  21. m_TextOutput->Dock( Pos::Bottom );
  22. m_TextOutput->SetHeight( 100 );
  23. ADD_UNIT_TEST( ImagePanel );
  24. //ADD_UNIT_TEST( MenuStrip );
  25. Gwen::UnicodeString str1(L"testje");
  26. Gwen::Controls::TabButton* tab = m_TabControl->AddPage(str1);
  27. Gwen::Controls::TreeControl* ctrl=0;
  28. {
  29. ctrl = new Gwen::Controls::TreeControl(tab->GetPage());
  30. ctrl->SetKeyboardInputEnabled(true);
  31. ctrl->AddNode( L"Node One" );
  32. {
  33. Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
  34. pNode->AddNode( L"Node Two Inside" );
  35. pNode->AddNode( L"Eyes" );
  36. }
  37. {
  38. Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
  39. pNode->AddNode( L"Node Two Inside" );
  40. pNode->AddNode( L"Eyes" );
  41. }
  42. {
  43. Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
  44. pNode->AddNode( L"Node Two Inside" );
  45. pNode->AddNode( L"Eyes" );
  46. }
  47. {
  48. Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
  49. pNode->AddNode( L"Node Two Inside" );
  50. pNode->AddNode( L"Eyes" );
  51. }
  52. {
  53. Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
  54. pNode->AddNode( L"Node Two Inside" );
  55. pNode->AddNode( L"Eyes" );
  56. }
  57. {
  58. Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
  59. pNode->AddNode( L"Node Two Inside" );
  60. pNode->AddNode( L"Eyes" );
  61. pNode->SetSelected(true);
  62. pNode->AddNode( L"Brown" )->AddNode( L"Node Two Inside" )->AddNode( L"Eyes" )->AddNode( L"Brown" );
  63. }
  64. ctrl->AddNode( L"Node Three" );
  65. ctrl->Focus();
  66. ctrl->SetKeyboardInputEnabled(true);
  67. ctrl->SetBounds( 30, 30, 200, 30+16*10 );
  68. //ctrl->ExpandAll();
  69. ctrl->ForceUpdateScrollBars();
  70. ctrl->OnKeyDown(true);
  71. }
  72. //GUnit* u = new TreeControl2(m_TabControl);..Gwen::Controls::TreeControl2( m_TabControl );
  73. //GUnit* RegisterUnitTest_TreeControl2( Gwen::Controls::TabControl* tab );\
  74. //RegisterUnitTest_TreeControl2( m_TabControl )->SetUnitTest( this );
  75. //#define DEFINE_UNIT_TEST( name, displayname )
  76. //GUnit* RegisterUnitTest_TreeControl2( Gwen::Controls::TabControl* tab )
  77. //{
  78. // GUnit* u = new TreeControl2( tab );
  79. // tab->AddPage( displayname, u );
  80. // return u;
  81. //}
  82. //ADD_UNIT_TEST( TreeControl2 );
  83. ADD_UNIT_TEST( Properties2 );
  84. ADD_UNIT_TEST( TabControl2 );
  85. ADD_UNIT_TEST( ScrollControl );
  86. ADD_UNIT_TEST( MenuStrip );
  87. ADD_UNIT_TEST( Numeric );
  88. ADD_UNIT_TEST( ComboBox );
  89. ADD_UNIT_TEST( TextBox );
  90. ADD_UNIT_TEST( ListBox );
  91. ADD_UNIT_TEST( Slider );
  92. ADD_UNIT_TEST( ProgressBar );
  93. ADD_UNIT_TEST( RadioButton2 );
  94. ADD_UNIT_TEST( Label );
  95. ADD_UNIT_TEST( Checkbox );
  96. ADD_UNIT_TEST( Button );
  97. ADD_UNIT_TEST( CrossSplitter );
  98. ADD_UNIT_TEST( PanelListPanel );
  99. ADD_UNIT_TEST( GroupBox2 );
  100. ADD_UNIT_TEST( StatusBar );
  101. ctrl->Focus();
  102. PrintText( L"Unit Test Started.\n" );
  103. m_fLastSecond = Gwen::Platform::GetTimeInSeconds();
  104. m_iFrames = 0;
  105. }
  106. void UnitTest::PrintText( const Gwen::UnicodeString& str )
  107. {
  108. m_TextOutput->AddItem( str );
  109. m_TextOutput->Scroller()->ScrollToBottom();
  110. }
  111. void UnitTest::Render( Gwen::Skin::Base* skin )
  112. {
  113. m_iFrames++;
  114. if ( m_fLastSecond < Gwen::Platform::GetTimeInSeconds() )
  115. {
  116. SetTitle( Gwen::Utility::Format( L"GWEN Unit Test - %i fps", m_iFrames ) );
  117. m_fLastSecond = Gwen::Platform::GetTimeInSeconds() + 1.0f;
  118. m_iFrames = 0;
  119. }
  120. BaseClass::Render( skin );
  121. }
  122. void GUnit::UnitPrint( const Gwen::UnicodeString& str )
  123. {
  124. m_pUnitTest->PrintText( str );
  125. }
  126. void GUnit::UnitPrint( const Gwen::String& str )
  127. {
  128. UnitPrint( Utility::StringToUnicode( str ) );
  129. }