From 54d9da19dfede361119a086b559bdda9208ad550 Mon Sep 17 00:00:00 2001
From: Verena Reimund <reimund@ill.eu>
Date: Wed, 9 May 2018 09:38:46 +0200
Subject: [PATCH] Tests of corresponding error messages for current changes

- Doxygen updated (throws)
- Templated storeWS

Running ConjoinXRunsTest for testTableInputWorkspaceInGroupThrows:
ConjoinXRuns-[Warning] Invalid value for InputWorkspaces: Workspace table is not a MatrixWorkspace

showing the need to check !ws and + input + works (ll 128,130 in ConjoinXRuns.cpp)

Refs #22383
---
 .../RunCombinationHelper.cpp                  |  1 +
 Framework/Algorithms/test/ConjoinXRunsTest.h  | 20 +++++++++++++++++++
 .../test/RunCombinationHelperTest.h           | 13 ++++++++----
 .../WorkspaceCreationHelper.h                 | 10 ++++++++--
 .../src/WorkspaceCreationHelper.cpp           |  8 --------
 5 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/Framework/Algorithms/src/RunCombinationHelpers/RunCombinationHelper.cpp b/Framework/Algorithms/src/RunCombinationHelpers/RunCombinationHelper.cpp
index d474ab26019..d0fcf9fed41 100644
--- a/Framework/Algorithms/src/RunCombinationHelpers/RunCombinationHelper.cpp
+++ b/Framework/Algorithms/src/RunCombinationHelpers/RunCombinationHelper.cpp
@@ -21,6 +21,7 @@ using namespace Kernel;
 * @param inputs : input workspaces vector [including] group workspaces (all must
 * be on ADS)
 * @return : the flat vector of the input workspaces
+* @throw : std::runtime_error if the input workspaces are neither groups nor MatrixWorkspaces
 */
 std::vector<std::string>
 RunCombinationHelper::unWrapGroups(const std::vector<std::string> &inputs) {
diff --git a/Framework/Algorithms/test/ConjoinXRunsTest.h b/Framework/Algorithms/test/ConjoinXRunsTest.h
index fd1e397fdc0..7097b4eea0b 100644
--- a/Framework/Algorithms/test/ConjoinXRunsTest.h
+++ b/Framework/Algorithms/test/ConjoinXRunsTest.h
@@ -5,9 +5,11 @@
 
 #include "MantidAPI/Axis.h"
 #include "MantidAPI/MatrixWorkspace.h"
+#include "MantidAPI/WorkspaceFactory.h"
 #include "MantidAlgorithms/AddSampleLog.h"
 #include "MantidAlgorithms/AddTimeSeriesLog.h"
 #include "MantidAlgorithms/ConjoinXRuns.h"
+#include "MantidAlgorithms/GroupWorkspaces.h"
 #include "MantidHistogramData/Counts.h"
 #include "MantidHistogramData/HistogramDx.h"
 #include "MantidHistogramData/HistogramE.h"
@@ -20,6 +22,7 @@
 using Mantid::Algorithms::ConjoinXRuns;
 using Mantid::Algorithms::AddSampleLog;
 using Mantid::Algorithms::AddTimeSeriesLog;
+using Mantid::Algorithms::GroupWorkspaces;
 using Mantid::HistogramData::Counts;
 using Mantid::HistogramData::HistogramDx;
 using Mantid::HistogramData::HistogramE;
@@ -96,6 +99,23 @@ public:
     TSM_ASSERT_EQUALS("Dx and y values are the same", out->dx(0).rawData(), y);
   }
 
+  void testTableInputWorkspaceInGroup() {
+    auto table = WorkspaceFactory::Instance().createTable("TableWorkspace");
+    storeWS("table", table);
+
+    GroupWorkspaces group;
+    group.initialize();
+    group.setProperty("InputWorkspaces",
+                      std::vector<std::string>{"table", "ws1"});
+    group.setProperty("OutputWorkspace", "group");
+    group.execute();
+    m_testee.setProperty("InputWorkspaces", "group");
+    m_testee.setProperty("OutputWorkspace", "out");
+    TS_ASSERT_THROWS_EQUALS(m_testee.execute(), const std::runtime_error &e,
+                            std::string(e.what()),
+                            "Some invalid Properties found");
+  }
+
   void testWSWithoutDxValues() {
     // Workspaces have 5 spectra must be point data
     MatrixWorkspace_sptr ws0 = create2DWorkspace123(5, 3); // 3 points
diff --git a/Framework/Algorithms/test/RunCombinationHelperTest.h b/Framework/Algorithms/test/RunCombinationHelperTest.h
index 30f1b381d97..90b94d80718 100644
--- a/Framework/Algorithms/test/RunCombinationHelperTest.h
+++ b/Framework/Algorithms/test/RunCombinationHelperTest.h
@@ -7,7 +7,9 @@
 #include "MantidAPI/FrameworkManager.h"
 
 #include "MantidAPI/Axis.h"
+#include "MantidAPI/ITableWorkspace.h"
 #include "MantidAPI/MatrixWorkspace.h"
+#include "MantidAPI/WorkspaceFactory.h"
 #include "MantidGeometry/Instrument/DetectorInfo.h"
 #include "MantidHistogramData/HistogramDx.h"
 #include "MantidAlgorithms/CreateSampleWorkspace.h"
@@ -20,10 +22,12 @@ using Mantid::Algorithms::RunCombinationHelper;
 using Mantid::Algorithms::GroupWorkspaces;
 using Mantid::Algorithms::CreateSampleWorkspace;
 using namespace Mantid::API;
+using namespace Mantid::DataObjects;
 using namespace Mantid::HistogramData;
 using namespace Mantid::Kernel;
 using namespace WorkspaceCreationHelper;
 
+
 class RunCombinationHelperTest : public CxxTest::TestSuite {
 public:
   // This pair of boilerplate methods prevent the suite being created statically
@@ -42,14 +46,15 @@ public:
 
   void testUnwraping_throws() {
 
-    MatrixWorkspace_sptr ws1 = create2DWorkspace(2, 3);
+    auto ws1 = create2DWorkspace(2, 3);
     storeWS("ws1", ws1);
+    auto table = WorkspaceFactory::Instance().createTable("TableWorkspace");
+    storeWS("table", table);
 
     TS_ASSERT_THROWS_EQUALS(
-        m_testee.unWrapGroups(std::vector<std::string>{"ws1", "ws?"}),
+        m_testee.unWrapGroups(std::vector<std::string>{"ws1", "table"}),
         const std::runtime_error &e, std::string(e.what()),
-        "Unable to find workspace type with name 'ws?': data service  search "
-        "object ws?");
+        "The input table is neither a WorkspaceGroup nor a MatrixWorkspace");
 
     removeWS("ws1");
   }
diff --git a/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h b/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h
index b809b285196..9db2c01f27a 100644
--- a/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h
+++ b/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h
@@ -106,8 +106,14 @@ struct EPPTableRow {
   FitStatus fitStatus = FitStatus::SUCCESS;
 };
 
-/// Adds a workspace to the ADS
-void storeWS(const std::string &name, Mantid::API::Workspace_sptr ws);
+/**
+ * Adds a workspace to the ADS
+ * @param name :: The name of the workspace
+ * @param ws :: The workspace object
+ */
+template <typename WSType> void storeWS(const std::string &name, WSType &ws) {
+  Mantid::API::AnalysisDataService::Instance().add(name, ws);
+}
 /// Deletes a workspace
 void removeWS(const std::string &name);
 /// Returns a workspace of a given type
diff --git a/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp b/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp
index f90803a4cd5..5a8efb136bc 100644
--- a/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp
+++ b/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp
@@ -72,14 +72,6 @@ EPPTableRow::EPPTableRow(const int index, const double peakCentre_,
     : workspaceIndex(index), peakCentre(peakCentre_), sigma(sigma_),
       height(height_), fitStatus(fitStatus_) {}
 
-/**
- * @param name :: The name of the workspace
- * @param ws :: The workspace object
- */
-void storeWS(const std::string &name, Mantid::API::Workspace_sptr ws) {
-  Mantid::API::AnalysisDataService::Instance().add(name, ws);
-}
-
 /**
  * Deletes a workspace
  * @param name :: The name of the workspace
-- 
GitLab