Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

202 строки
6.9 KiB

  1. #include "TestReport.h"
  2. #include <QDateTime>
  3. #include <QFile>
  4. #include <QTextStream>
  5. #include <QMessageBox>
  6. #include <QTextCodec>
  7. #include "TestBenchSettings.h"
  8. CTestReport::CTestReport()
  9. {
  10. mSoftwareVersion = QString(TEST_BENCH_VERSION);
  11. CreateNewTestReport();
  12. mReportFileDirectory = "./Rapports/";
  13. QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
  14. }
  15. CVisualInspectionResult * CTestReport::GetInspectionResult()
  16. {
  17. return &mVisualInspectionResultReport;
  18. }
  19. CCableParametersData *CTestReport::GetReportCableParameters()
  20. {
  21. return &mCableParameters;
  22. }
  23. int CTestReport::CreateNewTestReport()
  24. {
  25. mVisualInspectionResultReport.ClearResults();
  26. mCableParameters.ResetData();
  27. mAutomatedTestReport.ClearAutomatedTestReport();
  28. mTestLog.clear();
  29. mLastReportName.clear();
  30. return RET_OK;
  31. }
  32. int CTestReport::AddLogEntry(QString NewEntry, bool IncludeTime, bool Propagate)
  33. {
  34. if(NewEntry.isEmpty())
  35. {
  36. return RET_ERROR;
  37. }
  38. if(IncludeTime)
  39. {
  40. QString Time = QDateTime::currentDateTime().toString("hh:mm:ss.zzz - ");
  41. NewEntry.prepend(Time);
  42. }
  43. qDebug(NewEntry.toAscii().data());
  44. if(NewEntry.endsWith(QChar('\n')) == false)
  45. {
  46. NewEntry.append(QChar('\n'));
  47. }
  48. if(Propagate)
  49. {
  50. emit NewTestLogEntry(NewEntry);
  51. }
  52. mTestLog.append(NewEntry);
  53. return RET_OK;
  54. }
  55. CAutomatedTestReport *CTestReport::GetAutomatedTestReport()
  56. {
  57. return &mAutomatedTestReport;
  58. }
  59. int CTestReport::SaveReportToFile(CTestBenchSettings *BenchSettings)
  60. {
  61. QFile *ReportFile;
  62. //QTextStream ReportStream;
  63. QString Filename = QDateTime::currentDateTime().toString("yyMMdd_hhmmss_");
  64. Filename.append(mCableParameters.mStationCodeName);
  65. Filename.append(mCableParameters.mCableIdentification);
  66. Filename.append(".txt");
  67. Filename.prepend(mReportFileDirectory);
  68. ReportFile = new QFile(Filename);
  69. if (!ReportFile->open(QIODevice::ReadWrite |QIODevice::Truncate | QIODevice::Text))
  70. {
  71. AddLogEntry(QString("Impossible de sauvegarder le rapport %1").arg(Filename),false);
  72. QMessageBox::critical(NULL,"Erreur de sauvegarde",QString("Impossible de sauvegarder le fichier rapport \n%1").arg(Filename));
  73. return RET_ERROR;
  74. }
  75. mLastReportName = Filename;
  76. QTextStream ReportStream(ReportFile);
  77. ReportStream.setCodec(QTextCodec::codecForName("UTF-8"));
  78. ReportStream << QString("Rapport de test - Câble SEI\n");
  79. ReportStream << QString("Date de l'essai: ") << QDateTime::currentDateTime().toString("yyyy-MM-dd") << "\n";
  80. ReportStream << "Version du logiciel de test: " << mSoftwareVersion << "\n\n";
  81. ReportStream << "-----------------------------------------\n";
  82. ReportStream << QString("Paramètres du test: \n");
  83. ReportStream << QString("Temps de maintien des contacts: %1ms\n").arg(BenchSettings->mPinHoldTime);
  84. if(BenchSettings->mIgnoreVisualInspection)
  85. {
  86. ReportStream << QString("Ignorer inspection visuelle: OUI\n");
  87. }
  88. else
  89. {
  90. ReportStream << QString("Ignorer inspection visuelle: NON\n");
  91. }
  92. if(BenchSettings->mExecSecondPass)
  93. {
  94. ReportStream << QString("2è test exécuté: OUI\n");
  95. }
  96. else
  97. {
  98. ReportStream << QString("2è test exécuté: NON\n");
  99. }
  100. ReportStream << QString("Adresse IP des modules d'I/O : %1\n\n").arg(BenchSettings->mIOModuleIPAddress);
  101. ReportStream << "-----------------------------------------\n";
  102. ReportStream << QString("Paramètres du câble: \n");
  103. ReportStream << QString("Identification du câble: ") << mCableParameters.mCableIdentification << "\n";
  104. ReportStream << "Station: " << mCableParameters.mStationCodeName << " - "<< mCableParameters.mStationName << "\n";
  105. ReportStream << "Type: " << mCableParameters.mCableType << "\n";
  106. ReportStream << QString("Opérateur du test: ") << mCableParameters.mTestOperatorName << "\n";
  107. ReportStream << QString("Connecteur d'entrée: ") << mCableParameters.mInputConnectorType << "\n";
  108. ReportStream << "Connecteur de sortie: " << mCableParameters.mOutputConnectorType << "\n\n";
  109. ReportStream << "-----------------------------------------\n";
  110. ReportStream << QString("Résultats de l'inspection visuelle:\n");
  111. ReportStream << QString("Section 5.2 exécutée: ") << mVisualInspectionResultReport.mVerif52ExecResultText << "\n";
  112. ReportStream << QString("Section 5.3 exécutée: ") << mVisualInspectionResultReport.mVerif53ExecResultText << "\n";
  113. ReportStream << QString("Section 5.4 exécutée: ") << mVisualInspectionResultReport.mVerif54ExecResultText << "\n";
  114. ReportStream << QString("Section 5.5 exécutée: ") << mVisualInspectionResultReport.mVerif55ExecResultText << "\n";
  115. ReportStream << QString("Section 5.6 exécutée: ") << mVisualInspectionResultReport.mVerif56ExecResultText << "\n\n";
  116. ReportStream << "Notes d'inspection:\n\n";
  117. ReportStream << mVisualInspectionResultReport.mVerifNotesText << "\n\n";
  118. ReportStream << "-----------------------------------------\n";
  119. ReportStream << QString("Résultats du test automatique du câble:\n");
  120. ReportStream << QString("Pré-test des modules d'I/O: ") << mAutomatedTestReport.GetPretestResult() << "\n";
  121. ReportStream << QString("Lorsqu'applicable, les valeurs entre crochets [] correspondent aux contacts en défaut.\n\n");
  122. ReportStream.setFieldWidth(15);
  123. ReportStream.setFieldAlignment(QTextStream::AlignCenter);
  124. ReportStream << "No. Contact" << QString("Continuité") << "Isolation" << "Assignation" << QString("2è test") << qSetFieldWidth(0) << "\n";
  125. for(int pin = 1; pin <= mAutomatedTestReport.mPinCount; pin++)
  126. {
  127. ReportStream.setFieldWidth(15);
  128. ReportStream.setFieldAlignment(QTextStream::AlignCenter);
  129. ReportStream << QString("%1").arg(pin) <<
  130. mAutomatedTestReport.GetPinContinuityResult(pin) <<
  131. mAutomatedTestReport.GetPinIsolationResult(pin) <<
  132. mAutomatedTestReport.GetPinConcordanceResult(pin) <<
  133. mAutomatedTestReport.GetPinSecondTestResult(pin) << qSetFieldWidth(0) <<
  134. " \n";
  135. }
  136. ReportStream << QString("\n\n\n Signature de l'opérateur de test: _________________________________________\n\n");
  137. ReportStream << QString(" Date: _________________________________________\n\n");
  138. ReportStream << "-----------------------------------------\n";
  139. if(BenchSettings->mIncludeLogInReport)
  140. {
  141. ReportStream << "Log du test:\n";
  142. ReportStream << mTestLog;
  143. }
  144. ReportFile->close();
  145. delete ReportFile;
  146. return RET_OK;
  147. }
  148. bool CTestReport::IsAutoTestReportReady()
  149. {
  150. if(mAutomatedTestReport.GetPinCount() == 0)
  151. {
  152. return false;
  153. }
  154. return true;
  155. }
  156. bool CTestReport::GetGlobalAutoTestResult()
  157. {
  158. return mAutomatedTestReport.IsAutomatedTestSuccess();
  159. }
  160. QString CTestReport::GetLastReportFileName()
  161. {
  162. return mLastReportName;
  163. }