cmCTestGenericHandler.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestGenericHandler.h"
  14. #include "cmCTest.h"
  15. //----------------------------------------------------------------------
  16. cmCTestGenericHandler::cmCTestGenericHandler()
  17. {
  18. this->HandlerVerbose = false;
  19. this->CTest = 0;
  20. this->SubmitIndex = 0;
  21. }
  22. //----------------------------------------------------------------------
  23. cmCTestGenericHandler::~cmCTestGenericHandler()
  24. {
  25. }
  26. //----------------------------------------------------------------------
  27. void cmCTestGenericHandler::SetOption(const char* op, const char* value)
  28. {
  29. if ( !op )
  30. {
  31. return;
  32. }
  33. if ( !value )
  34. {
  35. cmCTestGenericHandler::t_StringToString::iterator remit
  36. = this->Options.find(op);
  37. if ( remit != this->Options.end() )
  38. {
  39. this->Options.erase(remit);
  40. }
  41. return;
  42. }
  43. this->Options[op] = value;
  44. }
  45. //----------------------------------------------------------------------
  46. void cmCTestGenericHandler::SetPersistentOption(const char* op,
  47. const char* value)
  48. {
  49. this->SetOption(op, value);
  50. if ( !op )
  51. {
  52. return;
  53. }
  54. if ( !value )
  55. {
  56. cmCTestGenericHandler::t_StringToString::iterator remit
  57. = this->PersistentOptions.find(op);
  58. if ( remit != this->PersistentOptions.end() )
  59. {
  60. this->PersistentOptions.erase(remit);
  61. }
  62. return;
  63. }
  64. this->PersistentOptions[op] = value;
  65. }
  66. //----------------------------------------------------------------------
  67. void cmCTestGenericHandler::Initialize()
  68. {
  69. this->Options.clear();
  70. t_StringToString::iterator it;
  71. for ( it = this->PersistentOptions.begin();
  72. it != this->PersistentOptions.end();
  73. ++ it )
  74. {
  75. this->Options[it->first.c_str()] = it->second.c_str();
  76. }
  77. }
  78. //----------------------------------------------------------------------
  79. const char* cmCTestGenericHandler::GetOption(const char* op)
  80. {
  81. cmCTestGenericHandler::t_StringToString::iterator remit
  82. = this->Options.find(op);
  83. if ( remit == this->Options.end() )
  84. {
  85. return 0;
  86. }
  87. return remit->second.c_str();
  88. }
  89. //----------------------------------------------------------------------
  90. bool cmCTestGenericHandler::StartResultingXML(const char* name,
  91. cmGeneratedFileStream& xofs)
  92. {
  93. if ( !name )
  94. {
  95. cmCTestLog(this->CTest, ERROR_MESSAGE,
  96. "Cannot create resulting XML file without providing the name"
  97. << std::endl;);
  98. return false;
  99. }
  100. cmOStringStream ostr;
  101. ostr << name;
  102. if ( this->SubmitIndex > 0 )
  103. {
  104. ostr << "_" << this->SubmitIndex;
  105. }
  106. ostr << ".xml";
  107. if( !this->CTest->OpenOutputFile(this->CTest->GetCurrentTag(),
  108. ostr.str().c_str(), xofs, true) )
  109. {
  110. cmCTestLog(this->CTest, ERROR_MESSAGE,
  111. "Cannot create resulting XML file: " << ostr.str().c_str()
  112. << std::endl);
  113. return false;
  114. }
  115. this->CTest->AddSubmitFile(ostr.str().c_str());
  116. return true;
  117. }
  118. //----------------------------------------------------------------------
  119. bool cmCTestGenericHandler::StartLogFile(const char* name,
  120. cmGeneratedFileStream& xofs)
  121. {
  122. if ( !name )
  123. {
  124. cmCTestLog(this->CTest, ERROR_MESSAGE,
  125. "Cannot create log file without providing the name" << std::endl;);
  126. return false;
  127. }
  128. cmOStringStream ostr;
  129. ostr << "Last" << name;
  130. if ( this->SubmitIndex > 0 )
  131. {
  132. ostr << "_" << this->SubmitIndex;
  133. }
  134. if ( !this->CTest->GetCurrentTag().empty() )
  135. {
  136. ostr << "_" << this->CTest->GetCurrentTag();
  137. }
  138. ostr << ".log";
  139. if( !this->CTest->OpenOutputFile("Temporary", ostr.str().c_str(), xofs) )
  140. {
  141. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create log file: "
  142. << ostr.str().c_str() << std::endl);
  143. return false;
  144. }
  145. return true;
  146. }