Source code of Windows XP (NT5)
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.

211 lines
4.1 KiB

  1. /*
  2. * A command line based tool to run tests.
  3. * TestRunner expects as its only argument the name of a TestCase class.
  4. * TestRunner prints out a trace as the tests are executed followed by a
  5. * summary at the end.
  6. *
  7. * You can add to the tests that the TestRunner knows about by
  8. * making additional calls to "addTest (...)" in main.
  9. *
  10. * Here is the synopsis:
  11. *
  12. * TestRunner [-wait] ExampleTestCase
  13. *
  14. */
  15. #include <iostream>
  16. #include <vector>
  17. #include "TestRunner.h"
  18. #include "MulticasterTest.h"
  19. #include "CHStringtest.h"
  20. #include "autoptrtest.h"
  21. #include <WQLParserTest.h>
  22. #include <wbemcomn\testlib\maintest.h>
  23. #include <maintest.h>
  24. #include <windows.h>
  25. TestAllocator::TestAllocator():size_(0),mem_(HeapCreate(0,0,0)),freze_(false){} ;
  26. TestAllocator::~TestAllocator(){ HeapDestroy(mem_);} ;
  27. TestAllocator * TestAllocator::instance()
  28. {
  29. static TestAllocator tmp;
  30. return &tmp;
  31. }
  32. void * TestAllocator::allocate(size_t n){
  33. if (freze_ && size_< n )
  34. return 0;
  35. void * p = HeapAlloc(mem_,0,n);
  36. if (p!=0)
  37. size_+=n;
  38. return p;
  39. };
  40. void TestAllocator::deallocate(void *p){
  41. if (p == 0)
  42. {
  43. return;
  44. }
  45. size_-=HeapSize(mem_,0,p);
  46. HeapFree(mem_,0,p);
  47. }
  48. /*
  49. void* __cdecl operator new(size_t n)
  50. {
  51. return TestAllocator::instance()->allocate(n);
  52. }
  53. void* __cdecl operator new(size_t n, std::nothrow_t&)
  54. {
  55. return TestAllocator::instance()->allocate(n);
  56. }
  57. void __cdecl operator delete(void *p)
  58. {
  59. return TestAllocator::instance()->deallocate(p);
  60. }
  61. void __cdecl operator delete(void *p, std::nothrow_t&)
  62. {
  63. return TestAllocator::instance()->deallocate(p);
  64. }
  65. void* __cdecl operator new[](size_t n)
  66. {
  67. return TestAllocator::instance()->allocate(n);
  68. }
  69. void* __cdecl operator new[](size_t n, std::nothrow_t&)
  70. {
  71. return TestAllocator::instance()->allocate(n);
  72. }
  73. void __cdecl operator delete[](void *p)
  74. {
  75. return TestAllocator::instance()->deallocate(p);
  76. }
  77. void __cdecl operator delete[](void *p, std::nothrow_t&)
  78. {
  79. return TestAllocator::instance()->deallocate(p);
  80. }
  81. */
  82. TestRunner::TestRunner ():allocator(TestAllocator::instance()),m_wait (false)
  83. {
  84. }
  85. void TestRunner::printBanner ()
  86. {
  87. cout << "Usage: driver [ -wait ] testName, where name is the name of a test case class" << endl;
  88. }
  89. void TestRunner::run (int ac, char **av)
  90. {
  91. string testCase;
  92. int numberOfTests = 0;
  93. for (int i = 1; i < ac; i++) {
  94. if (string (av [i]) == "-wait") {
  95. m_wait = true;
  96. continue;
  97. }
  98. testCase = av [i];
  99. Test *testToRun = NULL;
  100. if (testCase == "*") {
  101. for (mappings::iterator it = m_mappings.begin ();
  102. it != m_mappings.end ();
  103. ++it) {
  104. testToRun = (*it).second;
  105. run (testToRun);
  106. }
  107. return;
  108. }
  109. if (testCase == "/?" || testCase == "-?" ) {
  110. printBanner ();
  111. return;
  112. }
  113. for (mappings::iterator it = m_mappings.begin ();
  114. it != m_mappings.end ();
  115. ++it) {
  116. if ((*it).first == testCase) {
  117. testToRun = (*it).second;
  118. run (testToRun);
  119. }
  120. }
  121. numberOfTests++;
  122. if (!testToRun) {
  123. cout << "Test " << testCase << " not found." << endl;
  124. return;
  125. }
  126. }
  127. if (numberOfTests == 0) {
  128. printBanner ();
  129. return;
  130. }
  131. if (m_wait) {
  132. cout << "<RETURN> to continue" << endl;
  133. cin.get ();
  134. }
  135. }
  136. TestRunner::~TestRunner ()
  137. {
  138. for (mappings::iterator it = m_mappings.begin ();
  139. it != m_mappings.end ();
  140. ++it)
  141. it->second->Delete();
  142. }
  143. void TestRunner::run (Test *test)
  144. {
  145. TextTestResult result;
  146. if (test)
  147. test->run (&result);
  148. cout << result << endl;
  149. }
  150. void
  151. populateRunner(TestRunner& runner)
  152. {
  153. runner.addTest ("MulticasterTest", MulticasterTest::suite ());
  154. runner.addTest ("CHStringTest", CHStringTestCase::suite ());
  155. runner.addTest ("AutoBuffer", autobufferTest::suite());
  156. runner.addTest ("WQLParserTest", WQLParserTest::suite());
  157. runner.addTest ("CoreDllTest", CoreTest::suite());
  158. runner.addTest ("WBEMCommonTest", WBEMCommonTest::suite());
  159. }