daunittest.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include "platform.h"
  2. #include "jlib.hpp"
  3. #include "jmisc.hpp"
  4. #include "mpbase.hpp"/*##############################################################################
  5. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  6. Licensed under the Apache License, Version 2.0 (the "License");
  7. you may not use this file except in compliance with the License.
  8. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. ############################################################################## */
  16. #include "mpcomm.hpp"
  17. #include "daclient.hpp"
  18. #include "dadfs.hpp"
  19. #include "dafdesc.hpp"
  20. #include "dasds.hpp"
  21. #include "danqs.hpp"
  22. #include "dautils.hpp"
  23. #include "mplog.hpp"
  24. #include <cppunit/ui/text/TestRunner.h>
  25. #include <cppunit/extensions/HelperMacros.h>
  26. #include <cppunit/extensions/TestFactoryRegistry.h>
  27. #include <cppunit/TestResult.h>
  28. #include <cppunit/TestFailure.h>
  29. #include <cppunit/BriefTestProgressListener.h>
  30. #include <cppunit/TestResultCollector.h>
  31. static void usage(const char *error=NULL)
  32. {
  33. if (error)
  34. printf("ERROR: %s\n", error);
  35. printf("usage: daunittest <dali-ip>");
  36. }
  37. class DfsTestProgressListener : public CPPUNIT_NS::TestListener
  38. {
  39. public:
  40. DfsTestProgressListener() : m_lastTestFailed( false ) {}
  41. virtual ~DfsTestProgressListener() {}
  42. void startTest( CPPUNIT_NS::Test *test )
  43. {
  44. PROGLOG("TEST(%s): START",test->getName().c_str());
  45. m_lastTestFailed = false;
  46. }
  47. void addFailure( const CPPUNIT_NS::TestFailure &failure )
  48. {
  49. StringBuffer s;
  50. s.appendf("TEST(%s): %s File: %s Ln:%d",failure.failedTestName().c_str(),failure.isError()?"":"ASSERT ",(const char *)failure.sourceLine().fileName().c_str(),(unsigned)failure.sourceLine().lineNumber());
  51. CPPUNIT_NS::Exception *e = failure.thrownException();
  52. if (e)
  53. s.appendf(" %s %s",e->message().shortDescription().c_str(),e->message().details().c_str());
  54. UERRLOG("%s",s.str());
  55. m_lastTestFailed = true;
  56. }
  57. void endTest( CPPUNIT_NS::Test *test )
  58. {
  59. PROGLOG("TEST(%s): END%s",test->getName().c_str(),m_lastTestFailed?"":" OK");
  60. }
  61. private:
  62. /// Prevents the use of the copy constructor.
  63. DfsTestProgressListener( const DfsTestProgressListener &copy );
  64. /// Prevents the use of the copy operator.
  65. void operator =( const DfsTestProgressListener &copy );
  66. private:
  67. bool m_lastTestFailed;
  68. };
  69. int main( int argc, char **argv )
  70. {
  71. enableMemLeakChecking(true);
  72. struct ReleaseAtomBlock { ~ReleaseAtomBlock() { releaseAtoms(); } } rABlock;
  73. InitModuleObjects();
  74. EnableSEHtoExceptionMapping();
  75. int ret=1;
  76. try {
  77. StringBuffer cmd;
  78. splitFilename(argv[0], NULL, NULL, &cmd, NULL);
  79. StringBuffer lf;
  80. openLogFile(lf, cmd.toLowerCase().append(".log").str());
  81. if (argc<2) {
  82. usage();
  83. return 1;
  84. }
  85. SocketEndpoint ep;
  86. ep.set(argv[1],DALI_SERVER_PORT);
  87. if (ep.isNull()) {
  88. usage("could not resolve dali server IP");
  89. return 1;
  90. }
  91. SocketEndpointArray epa;
  92. epa.append(ep);
  93. Owned<IGroup> group = createIGroup(epa);
  94. initClientProcess(group, DCR_Testing);
  95. // Create the event manager and test controller
  96. CPPUNIT_NS::TestResult controller;
  97. // Add a listener that colllects test result
  98. CPPUNIT_NS::TestResultCollector result;
  99. controller.addListener( &result );
  100. // Add a listener that print dots as test run.
  101. //CPPUNIT_NS::BriefTestProgressListener progress;
  102. DfsTestProgressListener progress;
  103. controller.addListener( &progress );
  104. // Add the top suite to the test runner
  105. CPPUNIT_NS::TestRunner runner;
  106. runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
  107. runner.run( controller );
  108. ret = result.wasSuccessful() ? 0 : 1;
  109. closedownClientProcess();
  110. setNodeCaching(false);
  111. }
  112. catch (IException *e) {
  113. EXCLOG(e,"daunittest Exception");
  114. }
  115. return ret;
  116. }