unittests.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 them internal or external (API).
  25. *
  26. * All internal unit tests, written on the same source
  27. * files as the implementation they're testing, can be
  28. * dynamically linked via the helper class below.
  29. *
  30. * All external unit tests (API tests, test-driven
  31. * development, interface documentation and general
  32. * usability tests) should be implemented as source
  33. * files within the same directory as this file, and
  34. * statically linked together.
  35. *
  36. * CPPUnit will automaticall recognise and run them all.
  37. */
  38. /*
  39. * Helper class to unload libraries at the end
  40. * and make sure the SharedObject gets deleted
  41. * correctly.
  42. *
  43. * This is important to run valgrind tests and not
  44. * having to care about which memory leaks are "good"
  45. * and which are not.
  46. */
  47. class LoadedObject : public IInterface, CInterface {
  48. SharedObject *so;
  49. public:
  50. IMPLEMENT_IINTERFACE;
  51. LoadedObject(const char * name)
  52. {
  53. so = new SharedObject;
  54. so->load(name, true);
  55. }
  56. ~LoadedObject()
  57. {
  58. so->unload();
  59. delete so;
  60. }
  61. };
  62. int main(int argc, char* argv[])
  63. {
  64. InitModuleObjects();
  65. // These are the internal unit tests covered by other modules and libraries
  66. Array objects;
  67. objects.append(*(new LoadedObject ("jhtree")));
  68. objects.append(*(new LoadedObject ("roxiemem")));
  69. objects.append(*(new LoadedObject ("thorhelper")));
  70. queryStderrLogMsgHandler()->setMessageFields(MSGFIELD_time);
  71. CppUnit::TextUi::TestRunner runner;
  72. if (argc==1)
  73. {
  74. CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();
  75. runner.addTest( registry.makeTest() );
  76. }
  77. else
  78. {
  79. for (int name = 1; name < argc; name++)
  80. {
  81. CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry(argv[name]);
  82. runner.addTest( registry.makeTest() );
  83. }
  84. }
  85. bool wasSucessful = runner.run( "", false );
  86. ExitModuleObjects();
  87. releaseAtoms();
  88. return wasSucessful;
  89. }