Move HTML collector to separate files 93/28693/5
authorMarcin Niesluchowski <m.niesluchow@samsung.com>
Mon, 13 Oct 2014 13:05:27 +0000 (15:05 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Tue, 21 Oct 2014 09:53:14 +0000 (11:53 +0200)
Change-Id: I9e3d507cbde42bced1daac0eae351c55b925a63c

tests/framework/config.cmake
tests/framework/include/dpl/test/test_results_collector_html.h [new file with mode: 0644]
tests/framework/src/test_results_collector.cpp
tests/framework/src/test_results_collector_html.cpp [new file with mode: 0644]

index 14b2cd4..2335298 100644 (file)
@@ -35,6 +35,7 @@ SET(DPL_FRAMEWORK_TEST_SOURCES
     ${PROJECT_SOURCE_DIR}/tests/framework/src/test_results_collector.cpp
     ${PROJECT_SOURCE_DIR}/tests/framework/src/test_results_collector_commons.cpp
     ${PROJECT_SOURCE_DIR}/tests/framework/src/test_results_collector_console.cpp
+    ${PROJECT_SOURCE_DIR}/tests/framework/src/test_results_collector_html.cpp
     ${PROJECT_SOURCE_DIR}/tests/framework/src/test_results_collector_xml.cpp
     ${PROJECT_SOURCE_DIR}/tests/framework/src/test_runner_child.cpp
     ${PROJECT_SOURCE_DIR}/tests/framework/src/test_runner.cpp
diff --git a/tests/framework/include/dpl/test/test_results_collector_html.h b/tests/framework/include/dpl/test/test_results_collector_html.h
new file mode 100644 (file)
index 0000000..5bc1c9f
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        test_results_collector_html.h
+ * @author      Marcin Niesluchowski (m.niesluchow@samsung.com)
+ * @version     1.0
+ * @brief       Header file containing HtmlCollector class declaration
+ */
+
+#ifndef DPL_TEST_RESULTS_COLLECTOR_HTML_H
+#define DPL_TEST_RESULTS_COLLECTOR_HTML_H
+
+#include <map>
+
+#include <dpl/scoped_fclose.h>
+#include <dpl/test/statistic.h>
+#include <dpl/test/test_results_collector.h>
+
+namespace DPL {
+namespace Test {
+
+class HtmlCollector :
+    public TestResultsCollectorBase
+{
+public:
+    static TestResultsCollectorBase* Constructor();
+
+private:
+    HtmlCollector();
+
+    virtual std::string CollectorSpecificHelp() const;
+    virtual bool ParseCollectorSpecificArg(const std::string& arg);
+    virtual bool Configure();
+    virtual void Start();
+    virtual void CollectCurrentTestGroupName(const std::string& name);
+    virtual void CollectResult(const std::string& id,
+                               const std::string& /*description*/,
+                               const FailStatus::Type status = FailStatus::NONE,
+                               const std::string& reason = "",
+                               const bool& isPerformanceTest = false,
+                               const std::chrono::system_clock::duration& performanceTime
+                                   = std::chrono::microseconds::zero(),
+                               const std::chrono::system_clock::duration& performanceMaxTime
+                                   = std::chrono::microseconds::zero());
+    virtual void Finish();
+
+    void PrintfErrorMessage(const char* type,
+                            const std::string& message,
+                            bool verbosity);
+    void PrintfIgnoredMessage(const char* type,
+                              const std::string& message,
+                              bool verbosity);
+    void PrintStats(const std::string& name, const Statistic& stats);
+
+    std::string m_filename;
+    ScopedFClose m_fp;
+    Statistic m_stats;
+    std::string m_currentGroup;
+    std::map<std::string, Statistic> m_groupsStats;
+};
+
+} // namespace Test
+} // namespace DPL
+
+#endif // DPL_TEST_RESULTS_COLLECTOR_HTML_H
index 6267b1c..48cc93b 100644 (file)
  */
 #include <dpl/test/statistic.h>
 #include <dpl/test/test_results_collector.h>
-#include <dpl/test/test_results_collector_commons.h>
 #include <dpl/test/test_results_collector_console.h>
+#include <dpl/test/test_results_collector_html.h>
 #include <dpl/test/test_results_collector_xml.h>
-#include <dpl/colors.h>
-#include <dpl/assert.h>
-#include <dpl/scoped_fclose.h>
-
-#include <string>
-#include <cstdio>
 
 namespace DPL {
 namespace Test {
-namespace {
-const char *DEFAULT_HTML_FILE_NAME = "index.html";
-
-class HtmlCollector :
-    public TestResultsCollectorBase
-{
-  public:
-    static TestResultsCollectorBase* Constructor();
-
-  private:
-    HtmlCollector() : m_filename(DEFAULT_HTML_FILE_NAME) {}
-
-    virtual void CollectCurrentTestGroupName(const std::string& name)
-    {
-        fprintf(m_fp.Get(), "<b>Starting group %s", name.c_str());
-        m_currentGroup = name;
-    }
-
-    virtual bool Configure()
-    {
-        m_fp.Reset(fopen(m_filename.c_str(), "w"));
-        if (!m_fp) {
-            LogPedantic("Could not open file " << m_filename << " for writing");
-            return false;
-        }
-        return true;
-    }
-    virtual std::string CollectorSpecificHelp() const
-    {
-        return "--file=<filename> - name of file for output\n"
-               "                    default - index.html\n";
-    }
-
-    virtual void Start()
-    {
-        Assert(!!m_fp && "File handle must not be null");
-        fprintf(m_fp.Get(),
-                "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0"
-                "Transitional//EN\" "
-                "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\""
-                ">\n");
-        fprintf(m_fp.Get(),
-                "<html xmlns=\"http://www.w3.org/1999/xhtml\" "
-                "lang=\"en\" dir=\"ltr\">\n");
-        fprintf(m_fp.Get(), "<body style=\"background-color: black;\">\n");
-        fprintf(m_fp.Get(), "<pre>\n");
-        fprintf(m_fp.Get(), "<font color=\"white\">\n");
-    }
-
-    virtual void Finish()
-    {
-        using namespace DPL::Colors::Html;
-        // Show result
-        for (auto &group : m_groupsStats) {
-            PrintStats(group.first, group.second);
-        }
-        PrintStats("All tests together", m_stats);
-        fprintf(m_fp.Get(), "</font>\n");
-        fprintf(m_fp.Get(), "</pre>\n");
-        fprintf(m_fp.Get(), "</body>\n");
-        fprintf(m_fp.Get(), "</html>\n");
-    }
-
-    virtual bool ParseCollectorSpecificArg(const std::string& arg)
-    {
-        return ParseCollectorFileArg(arg, m_filename);
-    }
-
-    virtual void CollectResult(const std::string& id,
-                               const std::string& /*description*/,
-                               const FailStatus::Type status = FailStatus::NONE,
-                               const std::string& reason = "",
-                               const bool& isPerformanceTest = false,
-                               const std::chrono::system_clock::duration& performanceTime = std::chrono::microseconds::zero(),
-                               const std::chrono::system_clock::duration& performanceMaxTime = std::chrono::microseconds::zero())
-    {
-        using namespace DPL::Colors::Html;
-        std::string tmp = "'" + id + "' ...";
-
-        fprintf(m_fp.Get(), "Running test case %-100s", tmp.c_str());
-        switch (status) {
-        case TestResultsCollectorBase::FailStatus::NONE:
-            if (isPerformanceTest) {
-                if (performanceMaxTime <= std::chrono::microseconds::zero()) {
-                    fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME,
-                            get_milliseconds(performanceTime));
-                    break;
-                } else {
-                    if (performanceTime > performanceMaxTime)
-                        fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME_TOO_LONG(
-                                get_milliseconds(performanceTime),
-                                get_milliseconds(performanceMaxTime)));
-                    else
-                        fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME_MAX(
-                                get_milliseconds(performanceTime),
-                                get_milliseconds(performanceMaxTime)));
-                    break;
-                }
-            }
-            fprintf(m_fp.Get(), GREEN_RESULT_OK);
-            break;
-        case TestResultsCollectorBase::FailStatus::FAILED:
-            PrintfErrorMessage(" FAILED ", reason, true);
-            break;
-        case TestResultsCollectorBase::FailStatus::IGNORED:
-            PrintfIgnoredMessage("Ignored ", reason, true);
-            break;
-        case TestResultsCollectorBase::FailStatus::INTERNAL:
-            PrintfErrorMessage("INTERNAL", reason, true);
-            break;
-        default:
-            Assert(false && "Bad status");
-        }
-        m_groupsStats[m_currentGroup].AddTest(status);
-        m_stats.AddTest(status);
-    }
-
-    void PrintfErrorMessage(const char* type,
-                            const std::string& message,
-                            bool verbosity)
-    {
-        using namespace DPL::Colors::Html;
-        if (verbosity) {
-            fprintf(m_fp.Get(),
-                    "[%s%s%s] %s%s%s\n",
-                    BOLD_RED_BEGIN,
-                    type,
-                    BOLD_RED_END,
-                    BOLD_YELLOW_BEGIN,
-                    message.c_str(),
-                    BOLD_YELLOW_END);
-        } else {
-            fprintf(m_fp.Get(),
-                    "[%s%s%s]\n",
-                    BOLD_RED_BEGIN,
-                    type,
-                    BOLD_RED_END);
-        }
-    }
-
-    void PrintfIgnoredMessage(const char* type,
-                              const std::string& message,
-                              bool verbosity)
-    {
-        using namespace DPL::Colors::Html;
-
-        if (verbosity) {
-            fprintf(m_fp.Get(),
-                    "[%s%s%s] %s%s%s\n",
-                    CYAN_BEGIN,
-                    type,
-                    CYAN_END,
-                    BOLD_GOLD_BEGIN,
-                    message.c_str(),
-                    BOLD_GOLD_END);
-        } else {
-            fprintf(m_fp.Get(),
-                    "[%s%s%s]\n",
-                    CYAN_BEGIN,
-                    type,
-                    CYAN_END);
-        }
-    }
-
-    void PrintStats(const std::string& name, const Statistic& stats)
-    {
-        using namespace DPL::Colors::Html;
-        fprintf(
-            m_fp.Get(), "\n%sResults [%s]:%s\n", BOLD_GREEN_BEGIN,
-            name.c_str(), BOLD_GREEN_END);
-        fprintf(
-            m_fp.Get(), "%s%s%3zu%s\n", CYAN_BEGIN,
-            "Total tests:            ", stats.GetTotal(), CYAN_END);
-        fprintf(
-            m_fp.Get(), "  %s%s%3zu%s\n", CYAN_BEGIN,
-            "Succeeded:            ", stats.GetPassed(), CYAN_END);
-        fprintf(
-            m_fp.Get(), "  %s%s%3zu%s\n", CYAN_BEGIN,
-            "Failed:               ", stats.GetFailed(), CYAN_END);
-        fprintf(
-            m_fp.Get(), "  %s%s%3zu%s\n", CYAN_BEGIN,
-            "Ignored:              ", stats.GetIgnored(), CYAN_END);
-    }
-
-    std::string m_filename;
-    ScopedFClose m_fp;
-    Statistic m_stats;
-    std::string m_currentGroup;
-    std::map<std::string, Statistic> m_groupsStats;
-};
-
-TestResultsCollectorBase* HtmlCollector::Constructor()
-{
-    return new HtmlCollector();
-}
-
-}
 
 void TestResultsCollectorBase::RegisterCollectorConstructor(
     const std::string& name,
diff --git a/tests/framework/src/test_results_collector_html.cpp b/tests/framework/src/test_results_collector_html.cpp
new file mode 100644 (file)
index 0000000..324eb97
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/*
+ * @file        test_results_collector_html.cpp
+ * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
+ * @author      Marcin Niesluchowski (m.niesluchow@samsung.com)
+ * @version     1.0
+ * @brief       Source file containing HtmlCollector class definition
+ */
+
+#include <cstdio>
+
+#include <dpl/assert.h>
+#include <dpl/colors.h>
+#include <dpl/test/test_results_collector_commons.h>
+
+#include "dpl/test/test_results_collector_html.h"
+
+namespace DPL {
+namespace Test {
+
+namespace {
+
+const char *DEFAULT_HTML_FILE_NAME = "index.html";
+
+}
+
+HtmlCollector::HtmlCollector()
+    : m_filename(DEFAULT_HTML_FILE_NAME)
+{
+}
+
+TestResultsCollectorBase* HtmlCollector::Constructor()
+{
+    return new HtmlCollector();
+}
+
+void HtmlCollector::CollectCurrentTestGroupName(const std::string& name)
+{
+    fprintf(m_fp.Get(), "<b>Starting group %s", name.c_str());
+    m_currentGroup = name;
+}
+
+bool HtmlCollector::Configure()
+{
+    m_fp.Reset(fopen(m_filename.c_str(), "w"));
+    if (!m_fp) {
+        LogPedantic("Could not open file " << m_filename << " for writing");
+        return false;
+    }
+    return true;
+}
+
+std::string HtmlCollector::CollectorSpecificHelp() const
+{
+    return "--file=<filename> - name of file for output\n"
+           "                    default - index.html\n";
+}
+
+void HtmlCollector::Start()
+{
+    Assert(!!m_fp && "File handle must not be null");
+    fprintf(m_fp.Get(),
+            "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0"
+            "Transitional//EN\" "
+            "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\""
+            ">\n");
+    fprintf(m_fp.Get(),
+            "<html xmlns=\"http://www.w3.org/1999/xhtml\" "
+            "lang=\"en\" dir=\"ltr\">\n");
+    fprintf(m_fp.Get(), "<body style=\"background-color: black;\">\n");
+    fprintf(m_fp.Get(), "<pre>\n");
+    fprintf(m_fp.Get(), "<font color=\"white\">\n");
+}
+
+void HtmlCollector::Finish()
+{
+    using namespace DPL::Colors::Html;
+    // Show result
+    for (auto &group : m_groupsStats) {
+        PrintStats(group.first, group.second);
+    }
+    PrintStats("All tests together", m_stats);
+    fprintf(m_fp.Get(), "</font>\n");
+    fprintf(m_fp.Get(), "</pre>\n");
+    fprintf(m_fp.Get(), "</body>\n");
+    fprintf(m_fp.Get(), "</html>\n");
+}
+
+bool HtmlCollector::ParseCollectorSpecificArg(const std::string& arg)
+{
+    return ParseCollectorFileArg(arg, m_filename);
+}
+
+void HtmlCollector::CollectResult(const std::string& id,
+                                  const std::string& /*description*/,
+                                  const FailStatus::Type status,
+                                  const std::string& reason,
+                                  const bool& isPerformanceTest,
+                                  const std::chrono::system_clock::duration& performanceTime,
+                                  const std::chrono::system_clock::duration& performanceMaxTime)
+{
+    using namespace DPL::Colors::Html;
+    std::string tmp = "'" + id + "' ...";
+
+    fprintf(m_fp.Get(), "Running test case %-100s", tmp.c_str());
+    switch (status) {
+    case TestResultsCollectorBase::FailStatus::NONE:
+        if (isPerformanceTest) {
+            if (performanceMaxTime <= std::chrono::microseconds::zero()) {
+                fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME,
+                        get_milliseconds(performanceTime));
+                break;
+            } else {
+                if (performanceTime > performanceMaxTime)
+                    fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME_TOO_LONG(
+                            get_milliseconds(performanceTime),
+                            get_milliseconds(performanceMaxTime)));
+                else
+                    fprintf(m_fp.Get(), GREEN_RESULT_OK_TIME_MAX(
+                            get_milliseconds(performanceTime),
+                            get_milliseconds(performanceMaxTime)));
+                break;
+            }
+        }
+        fprintf(m_fp.Get(), GREEN_RESULT_OK);
+        break;
+    case TestResultsCollectorBase::FailStatus::FAILED:
+        PrintfErrorMessage(" FAILED ", reason, true);
+        break;
+    case TestResultsCollectorBase::FailStatus::IGNORED:
+        PrintfIgnoredMessage("Ignored ", reason, true);
+        break;
+    case TestResultsCollectorBase::FailStatus::INTERNAL:
+        PrintfErrorMessage("INTERNAL", reason, true);
+        break;
+    default:
+        Assert(false && "Bad status");
+    }
+    m_groupsStats[m_currentGroup].AddTest(status);
+    m_stats.AddTest(status);
+}
+
+void HtmlCollector::PrintfErrorMessage(const char* type,
+                                       const std::string& message,
+                                       bool verbosity)
+{
+    using namespace DPL::Colors::Html;
+    if (verbosity) {
+        fprintf(m_fp.Get(),
+                "[%s%s%s] %s%s%s\n",
+                BOLD_RED_BEGIN,
+                type,
+                BOLD_RED_END,
+                BOLD_YELLOW_BEGIN,
+                message.c_str(),
+                BOLD_YELLOW_END);
+    } else {
+        fprintf(m_fp.Get(),
+                "[%s%s%s]\n",
+                BOLD_RED_BEGIN,
+                type,
+                BOLD_RED_END);
+    }
+}
+
+void HtmlCollector::PrintfIgnoredMessage(const char* type,
+                                         const std::string& message,
+                                         bool verbosity)
+{
+    using namespace DPL::Colors::Html;
+
+    if (verbosity) {
+        fprintf(m_fp.Get(),
+                "[%s%s%s] %s%s%s\n",
+                CYAN_BEGIN,
+                type,
+                CYAN_END,
+                BOLD_GOLD_BEGIN,
+                message.c_str(),
+                BOLD_GOLD_END);
+    } else {
+        fprintf(m_fp.Get(),
+                "[%s%s%s]\n",
+                CYAN_BEGIN,
+                type,
+                CYAN_END);
+    }
+}
+
+void HtmlCollector::PrintStats(const std::string& name, const Statistic& stats)
+{
+    using namespace DPL::Colors::Html;
+    fprintf(
+        m_fp.Get(), "\n%sResults [%s]:%s\n", BOLD_GREEN_BEGIN,
+        name.c_str(), BOLD_GREEN_END);
+    fprintf(
+        m_fp.Get(), "%s%s%3zu%s\n", CYAN_BEGIN,
+        "Total tests:            ", stats.GetTotal(), CYAN_END);
+    fprintf(
+        m_fp.Get(), "  %s%s%3zu%s\n", CYAN_BEGIN,
+        "Succeeded:            ", stats.GetPassed(), CYAN_END);
+    fprintf(
+        m_fp.Get(), "  %s%s%3zu%s\n", CYAN_BEGIN,
+        "Failed:               ", stats.GetFailed(), CYAN_END);
+    fprintf(
+        m_fp.Get(), "  %s%s%3zu%s\n", CYAN_BEGIN,
+        "Ignored:              ", stats.GetIgnored(), CYAN_END);
+}
+
+} // namespace Test
+} // namespace DPL