unittests.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #include "platform.h"
  15. #include "jlib.hpp"
  16. #include "jlog.hpp"
  17. #include "jmisc.hpp"
  18. #include <cppunit/extensions/TestFactoryRegistry.h>
  19. #include <cppunit/ui/text/TestRunner.h>
  20. #include <cppunit/extensions/HelperMacros.h>
  21. #define ASSERT(a) { if (!(a)) CPPUNIT_ASSERT(a); }
  22. /*
  23. * This is the main unittest driver for HPCC. From here,
  24. * all unit tests, be they internal or external (API),
  25. * will run.
  26. *
  27. * All internal unit tests, written on the same source
  28. * files as the implementation they're testing, can be
  29. * dynamically linked via the helper class below.
  30. *
  31. * All external unit tests (API tests, test-driven
  32. * development, interface documentation and general
  33. * usability tests) should be implemented as source
  34. * files within the same directory as this file, and
  35. * statically linked together.
  36. *
  37. * CPPUnit will automatically recognise and run them all.
  38. */
  39. /*
  40. * Helper class to unload libraries at the end
  41. * and make sure the SharedObject gets deleted
  42. * correctly.
  43. *
  44. * This is important to run valgrind tests and not
  45. * having to care about which memory leaks are "good"
  46. * and which are not.
  47. */
  48. class LoadedObject : public IInterface, CInterface {
  49. SharedObject *so;
  50. public:
  51. IMPLEMENT_IINTERFACE;
  52. LoadedObject(const char * name)
  53. {
  54. so = new SharedObject;
  55. so->load(name, true);
  56. }
  57. ~LoadedObject()
  58. {
  59. so->unload();
  60. delete so;
  61. }
  62. };
  63. int main(int argc, char* argv[])
  64. {
  65. InitModuleObjects();
  66. // These are the internal unit tests covered by other modules and libraries
  67. Array objects;
  68. objects.append(*(new LoadedObject ("jhtree")));
  69. objects.append(*(new LoadedObject ("roxiemem")));
  70. objects.append(*(new LoadedObject ("thorhelper")));
  71. queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_time);
  72. CppUnit::TextUi::TestRunner runner;
  73. if (argc==1)
  74. {
  75. CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
  76. runner.addTest( registry.makeTest() );
  77. }
  78. else
  79. {
  80. for (int name = 1; name < argc; name++)
  81. {
  82. CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(argv[name]);
  83. runner.addTest( registry.makeTest() );
  84. }
  85. }
  86. bool wasSucessful = runner.run( "", false );
  87. ExitModuleObjects();
  88. releaseAtoms();
  89. return wasSucessful;
  90. }