Преглед изворни кода

adds a starting point for the export test results functionality

Signed-off-by: jromnoa <[email protected]>
jromnoa пре 4 година
родитељ
комит
0c9276a32a

+ 42 - 0
Gem/Code/Source/Automation/ScriptReporter.cpp

@@ -15,6 +15,9 @@
 #include <AzFramework/IO/LocalFileIO.h>
 #include <AzFramework/IO/LocalFileIO.h>
 #include <AzCore/IO/SystemFile.h>
 #include <AzCore/IO/SystemFile.h>
 #include <AzCore/Utils/Utils.h>
 #include <AzCore/Utils/Utils.h>
+#include <iostream>
+#include <fstream>
+#include <string>
 
 
 namespace AtomSampleViewer
 namespace AtomSampleViewer
 {
 {
@@ -436,6 +439,16 @@ namespace AtomSampleViewer
                         UpdateAllLocalBaselineImages();
                         UpdateAllLocalBaselineImages();
                     });
                     });
             }
             }
+            if (ImGui::Button("Export Test Results"))
+            {
+                m_messageBox.OpenPopupConfirmation(
+                    "Export Test Results",
+                    "All test results will be exported \n"
+                    "Proceed?",
+                    [this]() {
+                        ExportTestResults();
+                    });
+            }
 
 
             int displayOption = m_displayOption;
             int displayOption = m_displayOption;
             ImGui::Combo("Display", &displayOption, DiplayOptions, AZ_ARRAY_SIZE(DiplayOptions));
             ImGui::Combo("Display", &displayOption, DiplayOptions, AZ_ARRAY_SIZE(DiplayOptions));
@@ -1081,4 +1094,33 @@ namespace AtomSampleViewer
         }
         }
 
 
     }
     }
+
+    void ScriptReporter::ExportTestResults()
+    {
+        uint32_t totalAssertCount = 0;
+        uint32_t totalErrorCount = 0;
+        uint32_t totalWarningCount = 0;
+        uint32_t totalScreenshotErrorCount = 0;
+        uint32_t totalScreenshotWarningCount = 0;
+        
+        for (ScriptReport& scriptReport : m_scriptReports)
+        {
+            totalAssertCount += scriptReport.m_assertCount;
+            totalErrorCount += scriptReport.m_generalErrorCount;
+            totalWarningCount += scriptReport.m_generalWarningCount;
+            totalScreenshotErrorCount += scriptReport.m_screenshotErrorCount;
+            totalScreenshotWarningCount += scriptReport.m_screenshotWarningCount;
+        }
+
+        std::ofstream exportResultsFile;
+        exportResultsFile.open("exported_results.txt");  // This will save to the default bin you built with.
+        exportResultsFile << AZStd::string::format("Asserts: %s \n", std::to_string(totalAssertCount).c_str()).c_str();
+        exportResultsFile << AZStd::string::format("Errors: %s \n", std::to_string(totalErrorCount).c_str()).c_str();
+        exportResultsFile << AZStd::string::format("Warnings: %s \n", std::to_string(totalWarningCount).c_str()).c_str();
+        exportResultsFile << AZStd::string::format("Screenshot errors: %s \n", std::to_string(totalScreenshotErrorCount).c_str()).c_str();
+        exportResultsFile << AZStd::string::format("Screenshot warnings: %s \n", std::to_string(totalScreenshotWarningCount).c_str()).c_str();
+        exportResultsFile.close();
+        
+        m_messageBox.OpenPopupMessage("Exported test results", "Check your build/bin folder containing AtomSampleViewerStandalone and find the file named 'exported_results.txt' to view the results.");
+    }
 } // namespace AtomSampleViewer
 } // namespace AtomSampleViewer

+ 4 - 0
Gem/Code/Source/Automation/ScriptReporter.h

@@ -38,6 +38,7 @@ namespace AtomSampleViewer
 
 
         //! Returns the path to the official baseline image that corresponds to @forScreenshotFile
         //! Returns the path to the official baseline image that corresponds to @forScreenshotFile
         AZStd::string GetOfficialBaseline(const AZStd::string& forScreenshotFile);
         AZStd::string GetOfficialBaseline(const AZStd::string& forScreenshotFile);
+
     }
     }
 
 
     //! Collects data about each script run by the ScriptManager.
     //! Collects data about each script run by the ScriptManager.
@@ -226,6 +227,9 @@ namespace AtomSampleViewer
         // Show a message box to let the user know the results of updating local baseline images
         // Show a message box to let the user know the results of updating local baseline images
         void ShowUpdateLocalBaselineResult(int successCount, int failureCount);
         void ShowUpdateLocalBaselineResult(int successCount, int failureCount);
 
 
+        // For exporting test results
+        void ExportTestResults();
+
         const ImageComparisonToleranceLevel* FindBestToleranceLevel(float diffScore, bool filterImperceptibleDiffs) const;
         const ImageComparisonToleranceLevel* FindBestToleranceLevel(float diffScore, bool filterImperceptibleDiffs) const;
 
 
         void ShowReportDialog();
         void ShowReportDialog();