unittests.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifdef _USE_CPPUNIT
  14. #include "unittests.hpp"
  15. #include "jstats.h"
  16. /*
  17. * This is the main unittest driver for HPCC. From here,
  18. * all unit tests, be they internal or external (API),
  19. * will run.
  20. *
  21. * All internal unit tests, written on the same source
  22. * files as the implementation they're testing, can be
  23. * dynamically linked via the helper class below.
  24. *
  25. * All external unit tests (API tests, test-driven
  26. * development, interface documentation and general
  27. * usability tests) should be implemented as source
  28. * files within the same directory as this file, and
  29. * statically linked together.
  30. *
  31. * CPPUnit will automatically recognise and run them all.
  32. */
  33. int main(int argc, char* argv[])
  34. {
  35. InitModuleObjects();
  36. // These are the internal unit tests covered by other modules and libraries
  37. IArray objects;
  38. objects.append(*(new LoadedObject ("jhtree")));
  39. objects.append(*(new LoadedObject ("roxiemem")));
  40. objects.append(*(new LoadedObject ("thorhelper")));
  41. queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_time);
  42. CppUnit::TextUi::TestRunner runner;
  43. if (argc==1)
  44. {
  45. CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
  46. runner.addTest( registry.makeTest() );
  47. }
  48. else
  49. {
  50. for (int name = 1; name < argc; name++)
  51. {
  52. CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(argv[name]);
  53. runner.addTest( registry.makeTest() );
  54. }
  55. }
  56. bool wasSucessful = runner.run( "", false );
  57. ExitModuleObjects();
  58. releaseAtoms();
  59. return wasSucessful;
  60. }
  61. //MORE: This can't be included in jlib because of the dll dependency
  62. class InternalStatisticsTest : public CppUnit::TestFixture
  63. {
  64. CPPUNIT_TEST_SUITE( InternalStatisticsTest );
  65. CPPUNIT_TEST(testMappings);
  66. CPPUNIT_TEST_SUITE_END();
  67. void testMappings()
  68. {
  69. try
  70. {
  71. verifyStatisticFunctions();
  72. }
  73. catch (IException * e)
  74. {
  75. StringBuffer msg;
  76. fprintf(stderr, "Failure: %s", e->errorMessage(msg).str());
  77. e->Release();
  78. ASSERT(false);
  79. }
  80. }
  81. };
  82. CPPUNIT_TEST_SUITE_REGISTRATION( InternalStatisticsTest );
  83. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( InternalStatisticsTest, "StatisticsTest" );
  84. #endif // _USE_CPPUNIT