diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/EventNexusLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/EventNexusLoadingPresenter.h index b117f1e3b156574bdf2f83196279cb4ceadcdbff..0fdc65718b68499238c6e1faaef031c79f0e5493 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/EventNexusLoadingPresenter.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/EventNexusLoadingPresenter.h @@ -37,8 +37,11 @@ namespace Mantid class DLLExport EventNexusLoadingPresenter : public MDEWLoadingPresenter { public: - EventNexusLoadingPresenter(MDLoadingView* view, const std::string fileName); - virtual vtkDataSet* execute(vtkDataSetFactory* factory, ProgressAction& loadingProgressUpdate, ProgressAction& drawingProgressUpdate); + EventNexusLoadingPresenter(std::unique_ptr<MDLoadingView> view, + const std::string fileName); + virtual vtkDataSet *execute(vtkDataSetFactory *factory, + ProgressAction &loadingProgressUpdate, + ProgressAction &drawingProgressUpdate); virtual void executeLoadMetadata(); virtual bool hasTDimensionAvailable() const; virtual std::vector<double> getTimeStepValues() const; diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/MDEWEventNexusLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/MDEWEventNexusLoadingPresenter.h index 31ebc34dee814d96956d08deba85409735c38a0e..54f25d3e4facf73f4c86d8a2c807cfd02bc6e3e0 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/MDEWEventNexusLoadingPresenter.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/MDEWEventNexusLoadingPresenter.h @@ -38,8 +38,11 @@ namespace Mantid class DLLExport MDEWEventNexusLoadingPresenter : public MDEWLoadingPresenter { public: - MDEWEventNexusLoadingPresenter(MDLoadingView* view, const std::string fileName); - virtual vtkDataSet* execute(vtkDataSetFactory* factory, ProgressAction& rebinningProgressUpdate, ProgressAction& drawingProgressUpdate); + MDEWEventNexusLoadingPresenter(std::unique_ptr<MDLoadingView> view, + const std::string fileName); + virtual vtkDataSet *execute(vtkDataSetFactory *factory, + ProgressAction &rebinningProgressUpdate, + ProgressAction &drawingProgressUpdate); virtual void executeLoadMetadata(); virtual ~MDEWEventNexusLoadingPresenter(); virtual bool canReadFile() const; diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/MDEWInMemoryLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/MDEWInMemoryLoadingPresenter.h index 831690601406b3dfd2686be7c2d1614b2e2ec44c..f31f2f0187f5c63acba6079c84453a39f91b90ff 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/MDEWInMemoryLoadingPresenter.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/MDEWInMemoryLoadingPresenter.h @@ -44,7 +44,9 @@ namespace Mantid class DLLExport MDEWInMemoryLoadingPresenter : public MDEWLoadingPresenter { public: - MDEWInMemoryLoadingPresenter(MDLoadingView* view, WorkspaceProvider* repository, std::string wsName); + MDEWInMemoryLoadingPresenter(std::unique_ptr<MDLoadingView> view, + WorkspaceProvider *repository, + std::string wsName); virtual vtkDataSet* execute(vtkDataSetFactory* factory, ProgressAction& rebinningProgressUpdate, ProgressAction& drawingProgressUpdate); virtual void executeLoadMetadata(); virtual ~MDEWInMemoryLoadingPresenter(); diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/MDEWLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/MDEWLoadingPresenter.h index 618e7d938b2773147cc431bbe08a49cea52ae84e..03983bcc18134b13571f4bfd88defd6c92f77916 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/MDEWLoadingPresenter.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/MDEWLoadingPresenter.h @@ -46,8 +46,8 @@ namespace Mantid class DLLExport MDEWLoadingPresenter : public MDLoadingPresenter { public: - MDEWLoadingPresenter(MDLoadingView* view); - const std::string& getGeometryXML() const; + MDEWLoadingPresenter(std::unique_ptr<MDLoadingView> view); + const std::string &getGeometryXML() const; virtual bool hasTDimensionAvailable() const; virtual std::vector<double> getTimeStepValues() const; virtual std::string getTimeStepLabel() const; diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h index 892ee4a88158fcec943a9cfd67a25a82adee626f..857dcbcc7f3502633447b309008e428aea12c341 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/MDHWInMemoryLoadingPresenter.h @@ -46,7 +46,7 @@ class vtkDataSetFactory; class DLLExport MDHWInMemoryLoadingPresenter : public MDHWLoadingPresenter { public: - MDHWInMemoryLoadingPresenter(MDLoadingView *view, + MDHWInMemoryLoadingPresenter(std::unique_ptr<MDLoadingView> view, WorkspaceProvider *repository, std::string wsName); virtual vtkDataSet *execute(vtkDataSetFactory *factory, diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h index 5de80a7565d0e5b4acef86398aef4f2efd393b95..e8777a7b7bb184df9574c674e0b4dfebf52a4ccc 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/MDHWLoadingPresenter.h @@ -45,7 +45,7 @@ Code Documentation is available at: <http://doxygen.mantidproject.org> class MDLoadingView; class DLLExport MDHWLoadingPresenter : public MDLoadingPresenter { public: - MDHWLoadingPresenter(MDLoadingView *view); + MDHWLoadingPresenter(std::unique_ptr<MDLoadingView> view); const std::string &getGeometryXML() const; virtual bool hasTDimensionAvailable() const; virtual std::vector<double> getTimeStepValues() const; diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/MDHWNexusLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/MDHWNexusLoadingPresenter.h index ab67efc78e2fec669d34fb0f9c9ab8b261585e2e..53ebb4f5e8c45271024f6de76ca8219a2fef713d 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/MDHWNexusLoadingPresenter.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/MDHWNexusLoadingPresenter.h @@ -39,7 +39,7 @@ class MDLoadingView; class DLLExport MDHWNexusLoadingPresenter : public MDHWLoadingPresenter { public: - MDHWNexusLoadingPresenter(MDLoadingView* view, + MDHWNexusLoadingPresenter(std::unique_ptr<MDLoadingView> view, const std::string fileName); virtual vtkDataSet* execute(vtkDataSetFactory* factory, ProgressAction& rebinningProgressUpdate, diff --git a/Vates/VatesAPI/inc/MantidVatesAPI/SQWLoadingPresenter.h b/Vates/VatesAPI/inc/MantidVatesAPI/SQWLoadingPresenter.h index b60e758c9be8a117096b32cf8a30f3bd7f4bc1eb..ceb808dcc7f1680aba5385a74de1d6e791880594 100644 --- a/Vates/VatesAPI/inc/MantidVatesAPI/SQWLoadingPresenter.h +++ b/Vates/VatesAPI/inc/MantidVatesAPI/SQWLoadingPresenter.h @@ -37,7 +37,8 @@ namespace Mantid class DLLExport SQWLoadingPresenter : public MDEWLoadingPresenter { public: - SQWLoadingPresenter(MDLoadingView* view, const std::string fileName); + SQWLoadingPresenter(std::unique_ptr<MDLoadingView> view, + const std::string fileName); virtual vtkDataSet* execute(vtkDataSetFactory* factory, ProgressAction& rebinningProgressUpdate, ProgressAction& drawingProgressUpdate); virtual void extractMetadata(Mantid::API::IMDEventWorkspace_sptr eventWs); virtual void executeLoadMetadata(); diff --git a/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp b/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp index 18141371a9ca0d4ef268f4c1c921dffb2223bf31..65cbf6e2cec44cca944d74b9e2bb93a82ad0bda8 100644 --- a/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/EventNexusLoadingPresenter.cpp @@ -25,67 +25,59 @@ namespace Mantid @throw invalid_arument if view is null @throw logic_error if cannot use the reader-presenter for this filetype. */ - EventNexusLoadingPresenter::EventNexusLoadingPresenter(MDLoadingView* view, - const std::string filename) : - MDEWLoadingPresenter(view), m_filename(filename), m_wsTypeName("") - { - if (this->m_filename.empty()) - { - throw std::invalid_argument("File name is an empty string."); - } - if (nullptr == this->m_view) - { - throw std::invalid_argument("View is NULL."); - } + EventNexusLoadingPresenter::EventNexusLoadingPresenter( + std::unique_ptr<MDLoadingView> view, const std::string filename) + : MDEWLoadingPresenter(std::move(view)), m_filename(filename), + m_wsTypeName("") { + if (this->m_filename.empty()) { + throw std::invalid_argument("File name is an empty string."); + } + if (nullptr == this->m_view) { + throw std::invalid_argument("View is NULL."); } + } - /* - Indicates whether this presenter is capable of handling the type of file that is attempted to be loaded. - @return false if the file cannot be read. - */ - bool EventNexusLoadingPresenter::canReadFile() const - { - if (!canLoadFileBasedOnExtension(m_filename, ".nxs")) - { + /* + Indicates whether this presenter is capable of handling the type of file that + is attempted to be loaded. + @return false if the file cannot be read. + */ + bool EventNexusLoadingPresenter::canReadFile() const { + if (!canLoadFileBasedOnExtension(m_filename, ".nxs")) { + return 0; + } + + ::NeXus::File *file = NULL; + try { + file = new ::NeXus::File(this->m_filename); + // All SNS (event or histo) nxs files have an entry named "entry" + try { + file->openGroup("entry", "NXentry"); + } catch (::NeXus::Exception &) { + file->close(); return 0; } - - ::NeXus::File * file = NULL; - try - { - file = new ::NeXus::File(this->m_filename); - // All SNS (event or histo) nxs files have an entry named "entry" - try - { - file->openGroup("entry", "NXentry"); - } catch (::NeXus::Exception &) - { - file->close(); - return 0; - } - // But only eventNexus files have bank123_events as a group name - std::map<std::string, std::string> entries = file->getEntries(); - bool hasEvents = false; - std::map<std::string, std::string>::iterator it; - for (it = entries.begin(); it != entries.end(); ++it) - { - if (it->first.find("_events") != std::string::npos) - { - hasEvents = true; - break; - } + // But only eventNexus files have bank123_events as a group name + std::map<std::string, std::string> entries = file->getEntries(); + bool hasEvents = false; + std::map<std::string, std::string>::iterator it; + for (it = entries.begin(); it != entries.end(); ++it) { + if (it->first.find("_events") != std::string::npos) { + hasEvents = true; + break; } - file->close(); - return hasEvents ? 1 : 0; - } catch (std::exception & e) - { - std::cerr << "Could not open " << this->m_filename - << " as an EventNexus file because of exception: " << e.what() << std::endl; - // Clean up, if possible - if (file) - file->close(); } - return 0; + file->close(); + return hasEvents ? 1 : 0; + } catch (std::exception &e) { + std::cerr << "Could not open " << this->m_filename + << " as an EventNexus file because of exception: " << e.what() + << std::endl; + // Clean up, if possible + if (file) + file->close(); + } + return 0; } /* diff --git a/Vates/VatesAPI/src/MDEWEventNexusLoadingPresenter.cpp b/Vates/VatesAPI/src/MDEWEventNexusLoadingPresenter.cpp index b9e513cf9a657f5f632cc2fad36080ab85821287..df594657ddcd3cf400908dd195d8c120bcae40a6 100644 --- a/Vates/VatesAPI/src/MDEWEventNexusLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDEWEventNexusLoadingPresenter.cpp @@ -24,48 +24,44 @@ namespace Mantid @throw invalid_arument if view is null @throw logic_error if cannot use the reader-presenter for this filetype. */ - MDEWEventNexusLoadingPresenter::MDEWEventNexusLoadingPresenter(MDLoadingView* view, const std::string filename) : MDEWLoadingPresenter(view), m_filename(filename), m_wsTypeName("") - { - if(this->m_filename.empty()) - { - throw std::invalid_argument("File name is an empty string."); - } - if(nullptr == this->m_view) - { - throw std::invalid_argument("View is NULL."); - } + MDEWEventNexusLoadingPresenter::MDEWEventNexusLoadingPresenter( + std::unique_ptr<MDLoadingView> view, const std::string filename) + : MDEWLoadingPresenter(std::move(view)), m_filename(filename), + m_wsTypeName("") { + if (this->m_filename.empty()) { + throw std::invalid_argument("File name is an empty string."); } + if (nullptr == this->m_view) { + throw std::invalid_argument("View is NULL."); + } + } - /* - Indicates whether this presenter is capable of handling the type of file that is attempted to be loaded. - @return false if the file cannot be read. - */ - bool MDEWEventNexusLoadingPresenter::canReadFile() const - { - // Quick check based on extension. - if(!canLoadFileBasedOnExtension(m_filename, ".nxs")) - { - return 0; - } - - ::NeXus::File * file = NULL; + /* + Indicates whether this presenter is capable of handling the type of file that + is attempted to be loaded. + @return false if the file cannot be read. + */ + bool MDEWEventNexusLoadingPresenter::canReadFile() const { + // Quick check based on extension. + if (!canLoadFileBasedOnExtension(m_filename, ".nxs")) { + return 0; + } - file = new ::NeXus::File(this->m_filename); - // MDEventWorkspace file has a different name for the entry - try - { - file->openGroup("MDEventWorkspace", "NXentry"); - file->close(); - return 1; - } - catch(::NeXus::Exception &) - { - // If the entry name does not match, then it can't read the file. - file->close(); - return 0; - } + ::NeXus::File *file = NULL; + + file = new ::NeXus::File(this->m_filename); + // MDEventWorkspace file has a different name for the entry + try { + file->openGroup("MDEventWorkspace", "NXentry"); + file->close(); + return 1; + } catch (::NeXus::Exception &) { + // If the entry name does not match, then it can't read the file. + file->close(); return 0; } + return 0; + } /* Executes the underlying algorithm to create the MVP model. diff --git a/Vates/VatesAPI/src/MDEWInMemoryLoadingPresenter.cpp b/Vates/VatesAPI/src/MDEWInMemoryLoadingPresenter.cpp index 8ccdcee01eb4e08db17742e9c11a88706186cab3..b6ce105429c333121a02175b8cd29698a2ffc048 100644 --- a/Vates/VatesAPI/src/MDEWInMemoryLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDEWInMemoryLoadingPresenter.cpp @@ -22,46 +22,43 @@ namespace Mantid @throw invalid_argument if the repository is null @throw invalid_arument if view is null */ - MDEWInMemoryLoadingPresenter::MDEWInMemoryLoadingPresenter(MDLoadingView* view, WorkspaceProvider* repository, std::string wsName) : MDEWLoadingPresenter(view), - m_repository(repository), m_wsName(wsName), m_wsTypeName(""), m_specialCoords(-1) - { - if(m_wsName.empty()) - { - throw std::invalid_argument("The workspace name is empty."); - } - if(NULL == repository) - { - throw std::invalid_argument("The repository is NULL"); - } - if(nullptr == m_view) - { - throw std::invalid_argument("View is NULL."); - } + MDEWInMemoryLoadingPresenter::MDEWInMemoryLoadingPresenter( + std::unique_ptr<MDLoadingView> view, WorkspaceProvider *repository, + std::string wsName) + : MDEWLoadingPresenter(std::move(view)), m_repository(repository), + m_wsName(wsName), m_wsTypeName(""), m_specialCoords(-1) { + if (m_wsName.empty()) { + throw std::invalid_argument("The workspace name is empty."); + } + if (NULL == repository) { + throw std::invalid_argument("The repository is NULL"); } + if (nullptr == m_view) { + throw std::invalid_argument("View is NULL."); + } + } - /* - Indicates whether this presenter is capable of handling the type of file that is attempted to be loaded. - @return false if the file cannot be read. - */ - bool MDEWInMemoryLoadingPresenter::canReadFile() const - { - bool bCanReadIt = true; - if(!m_repository->canProvideWorkspace(m_wsName)) - { - //The workspace does not exist. - bCanReadIt = false; - } - else if(NULL == boost::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(m_repository->fetchWorkspace(m_wsName)).get()) - { - //The workspace can be found, but is not an IMDEventWorkspace. - bCanReadIt = false; - } - else - { - //The workspace is present, and is of the correct type. - bCanReadIt = true; - } - return bCanReadIt; + /* + Indicates whether this presenter is capable of handling the type of file that + is attempted to be loaded. + @return false if the file cannot be read. + */ + bool MDEWInMemoryLoadingPresenter::canReadFile() const { + bool bCanReadIt = true; + if (!m_repository->canProvideWorkspace(m_wsName)) { + // The workspace does not exist. + bCanReadIt = false; + } else if (NULL == + boost::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>( + m_repository->fetchWorkspace(m_wsName)) + .get()) { + // The workspace can be found, but is not an IMDEventWorkspace. + bCanReadIt = false; + } else { + // The workspace is present, and is of the correct type. + bCanReadIt = true; + } + return bCanReadIt; } /* diff --git a/Vates/VatesAPI/src/MDEWLoadingPresenter.cpp b/Vates/VatesAPI/src/MDEWLoadingPresenter.cpp index 7b34b4570c7f6e116ee53019793da62ce455b13c..6e8dd863192b78df0ba1c30780bbfc2ccc9730f2 100644 --- a/Vates/VatesAPI/src/MDEWLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDEWLoadingPresenter.cpp @@ -21,74 +21,66 @@ namespace Mantid { namespace VATES { - /// Constructor - MDEWLoadingPresenter::MDEWLoadingPresenter(MDLoadingView* view) : - m_view(view), - m_isSetup(false), - m_time(-1), - m_recursionDepth(0), - m_loadInMemory(false), - m_firstLoad(true), - m_metadataJsonManager(new MetadataJsonManager()), - m_metaDataExtractor(new MetaDataExtractorUtils()), - m_vatesConfigurations(new VatesConfigurations()) - { - Mantid::API::FrameworkManager::Instance(); - } + /// Constructor + MDEWLoadingPresenter::MDEWLoadingPresenter( + std::unique_ptr<MDLoadingView> view) + : m_view(std::move(view)), m_isSetup(false), m_time(-1), + m_recursionDepth(0), m_loadInMemory(false), m_firstLoad(true), + m_metadataJsonManager(new MetadataJsonManager()), + m_metaDataExtractor(new MetaDataExtractorUtils()), + m_vatesConfigurations(new VatesConfigurations()) { + Mantid::API::FrameworkManager::Instance(); + } - /// Destructor - MDEWLoadingPresenter::~MDEWLoadingPresenter() - { - } + /// Destructor + MDEWLoadingPresenter::~MDEWLoadingPresenter() {} - /* - Extract the geometry and function information - @param eventWs : event workspace to get the information from. - */ - void MDEWLoadingPresenter::extractMetadata(Mantid::API::IMDEventWorkspace_sptr eventWs) - { - using namespace Mantid::Geometry; - MDGeometryBuilderXML<NoDimensionPolicy> refresh; - xmlBuilder= refresh; //Reassign. - std::vector<MDDimensionExtents<coord_t> > ext = eventWs->getMinimumExtents(5); - std::vector<IMDDimension_sptr> dimensions; - size_t nDimensions = eventWs->getNumDims(); - for (size_t d=0; d<nDimensions; d++) - { - IMDDimension_const_sptr inDim = eventWs->getDimension(d); - coord_t min = ext[d].getMin(); - coord_t max = ext[d].getMax(); - if (min > max) - { - min = 0.0; - max = 1.0; - } - //std::cout << "dim " << d << min << " to " << max << std::endl; - axisLabels.push_back(makeAxisTitle(inDim)); - MDHistoDimension_sptr dim(new MDHistoDimension(inDim->getName(), inDim->getName(), inDim->getMDFrame(), min, max, inDim->getNBins())); - dimensions.push_back(dim); + /* + Extract the geometry and function information + @param eventWs : event workspace to get the information from. + */ + void MDEWLoadingPresenter::extractMetadata( + Mantid::API::IMDEventWorkspace_sptr eventWs) { + using namespace Mantid::Geometry; + MDGeometryBuilderXML<NoDimensionPolicy> refresh; + xmlBuilder = refresh; // Reassign. + std::vector<MDDimensionExtents<coord_t>> ext = + eventWs->getMinimumExtents(5); + std::vector<IMDDimension_sptr> dimensions; + size_t nDimensions = eventWs->getNumDims(); + for (size_t d = 0; d < nDimensions; d++) { + IMDDimension_const_sptr inDim = eventWs->getDimension(d); + coord_t min = ext[d].getMin(); + coord_t max = ext[d].getMax(); + if (min > max) { + min = 0.0; + max = 1.0; } + // std::cout << "dim " << d << min << " to " << max << std::endl; + axisLabels.push_back(makeAxisTitle(inDim)); + MDHistoDimension_sptr dim(new MDHistoDimension( + inDim->getName(), inDim->getName(), inDim->getMDFrame(), min, max, + inDim->getNBins())); + dimensions.push_back(dim); + } - //Configuring the geometry xml builder allows the object panel associated with this reader to later - //determine how to display all geometry related properties. - if(nDimensions > 0) - { - xmlBuilder.addXDimension( dimensions[0] ); - } - if(nDimensions > 1) - { - xmlBuilder.addYDimension( dimensions[1] ); - } - if(nDimensions > 2) - { - xmlBuilder.addZDimension( dimensions[2] ); - } - if(nDimensions > 3) - { - tDimension = dimensions[3]; - xmlBuilder.addTDimension(tDimension); - } - m_isSetup = true; + // Configuring the geometry xml builder allows the object panel associated + // with this reader to later + // determine how to display all geometry related properties. + if (nDimensions > 0) { + xmlBuilder.addXDimension(dimensions[0]); + } + if (nDimensions > 1) { + xmlBuilder.addYDimension(dimensions[1]); + } + if (nDimensions > 2) { + xmlBuilder.addZDimension(dimensions[2]); + } + if (nDimensions > 3) { + tDimension = dimensions[3]; + xmlBuilder.addTDimension(tDimension); + } + m_isSetup = true; } /** diff --git a/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp b/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp index f276e40e97c9fe24da17927987ffbddac33525a6..262247a4f6cbc405c1083303c7b534d087b65f1f 100644 --- a/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDHWInMemoryLoadingPresenter.cpp @@ -23,9 +23,10 @@ Constructor @throw invalid_arument if view is null */ MDHWInMemoryLoadingPresenter::MDHWInMemoryLoadingPresenter( - MDLoadingView *view, WorkspaceProvider *repository, std::string wsName) - : MDHWLoadingPresenter(view), m_repository(repository), m_wsName(wsName), - m_wsTypeName(""), m_specialCoords(-1) { + std::unique_ptr<MDLoadingView> view, WorkspaceProvider *repository, + std::string wsName) + : MDHWLoadingPresenter(std::move(view)), m_repository(repository), + m_wsName(wsName), m_wsTypeName(""), m_specialCoords(-1) { if (m_wsName.empty()) { throw std::invalid_argument("The workspace name is empty."); } diff --git a/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp b/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp index af492426350411be0321a2b86c335c066e5ecfe6..1e8bfbdd904c7fa5350b083f7fb851a8eb7b0f89 100644 --- a/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDHWLoadingPresenter.cpp @@ -91,9 +91,10 @@ void MDHWLoadingPresenter::transposeWs(Mantid::API::IMDHistoWorkspace_sptr &inHi } /// Constructor -MDHWLoadingPresenter::MDHWLoadingPresenter(MDLoadingView *view) - : m_view(view), m_isSetup(false), m_time(-1), m_loadInMemory(false), - m_firstLoad(true), m_metadataJsonManager(new MetadataJsonManager()), +MDHWLoadingPresenter::MDHWLoadingPresenter(std::unique_ptr<MDLoadingView> view) + : m_view(std::move(view)), m_isSetup(false), m_time(-1), + m_loadInMemory(false), m_firstLoad(true), + m_metadataJsonManager(new MetadataJsonManager()), m_metaDataExtractor(new MetaDataExtractorUtils()), m_vatesConfigurations(new VatesConfigurations()) { Mantid::API::FrameworkManager::Instance(); diff --git a/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp b/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp index 42fd16b2b8a23e90b0d48dff23e06ccb1519653d..ef26c667e829622d2af108ca61b07b431d616900 100644 --- a/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/MDHWNexusLoadingPresenter.cpp @@ -24,14 +24,14 @@ namespace VATES * @throw invalid_arument if view is null * @throw logic_error if cannot use the reader-presenter for this filetype. */ -MDHWNexusLoadingPresenter::MDHWNexusLoadingPresenter(MDLoadingView* view, const std::string filename) : MDHWLoadingPresenter(view), m_filename(filename), m_wsTypeName("") -{ - if(this->m_filename.empty()) - { +MDHWNexusLoadingPresenter::MDHWNexusLoadingPresenter( + std::unique_ptr<MDLoadingView> view, const std::string filename) + : MDHWLoadingPresenter(std::move(view)), m_filename(filename), + m_wsTypeName("") { + if (this->m_filename.empty()) { throw std::invalid_argument("File name is an empty string."); } - if(nullptr == this->m_view) - { + if (nullptr == this->m_view) { throw std::invalid_argument("View is NULL."); } } diff --git a/Vates/VatesAPI/src/SQWLoadingPresenter.cpp b/Vates/VatesAPI/src/SQWLoadingPresenter.cpp index d4483dce2b18d0131d3ea6a35f27e929565bff75..ef6f016128390fefe9cf1b50ce47ec3576999e1b 100644 --- a/Vates/VatesAPI/src/SQWLoadingPresenter.cpp +++ b/Vates/VatesAPI/src/SQWLoadingPresenter.cpp @@ -21,26 +21,28 @@ namespace Mantid @throw invalid_arument if view is null @throw logic_error if cannot use the reader-presenter for this filetype. */ - SQWLoadingPresenter::SQWLoadingPresenter(MDLoadingView* view, const std::string filename) : MDEWLoadingPresenter(view), m_filename(filename), m_wsTypeName("") - { - if(this->m_filename.empty()) - { - throw std::invalid_argument("File name is an empty string."); - } - if(nullptr == this->m_view) - { - throw std::invalid_argument("View is NULL."); - } + SQWLoadingPresenter::SQWLoadingPresenter(std::unique_ptr<MDLoadingView> view, + const std::string filename) + : MDEWLoadingPresenter(std::move(view)), m_filename(filename), + m_wsTypeName("") { + if (this->m_filename.empty()) { + throw std::invalid_argument("File name is an empty string."); } - - /* - Indicates whether this presenter is capable of handling the type of file that is attempted to be loaded. - @return false if the file cannot be read. - */ - bool SQWLoadingPresenter::canReadFile() const - { - boost::regex expression(".*sqw$", boost::regex_constants::icase); //check that the file ends with sqw. - return boost::regex_match(this->m_filename, expression); + if (nullptr == this->m_view) { + throw std::invalid_argument("View is NULL."); + } + } + + /* + Indicates whether this presenter is capable of handling the type of file that + is attempted to be loaded. + @return false if the file cannot be read. + */ + bool SQWLoadingPresenter::canReadFile() const { + boost::regex expression( + ".*sqw$", + boost::regex_constants::icase); // check that the file ends with sqw. + return boost::regex_match(this->m_filename, expression); } diff --git a/Vates/VatesAPI/test/EventNexusLoadingPresenterTest.h b/Vates/VatesAPI/test/EventNexusLoadingPresenterTest.h index af5f36011dda3822d4b2301e86b66ad9fb0181dd..d93f1cbcfad89790aed0d4a24d708ebfa6a3d06d 100644 --- a/Vates/VatesAPI/test/EventNexusLoadingPresenterTest.h +++ b/Vates/VatesAPI/test/EventNexusLoadingPresenterTest.h @@ -12,6 +12,7 @@ #include "MantidAPI/FileFinder.h" #include "MantidVatesAPI/EventNexusLoadingPresenter.h" #include "MantidVatesAPI/FilteringUpdateProgressAction.h" +#include "MantidKernel/make_unique.h" using namespace Mantid::VATES; using namespace testing; @@ -39,35 +40,44 @@ public: void testConstructWithEmptyFileThrows() { - TSM_ASSERT_THROWS("Should throw if an empty file string is given.", EventNexusLoadingPresenter(new MockMDLoadingView, ""), std::invalid_argument); + TSM_ASSERT_THROWS("Should throw if an empty file string is given.", + EventNexusLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), ""), + std::invalid_argument); } void testConstructWithNullViewThrows() { - MockMDLoadingView* pView = NULL; - - TSM_ASSERT_THROWS("Should throw if an empty file string is given.", EventNexusLoadingPresenter(pView, "some_file"), std::invalid_argument); + TSM_ASSERT_THROWS("Should throw if a null view is given.", + EventNexusLoadingPresenter(nullptr, "some_file"), + std::invalid_argument); } void testConstruct() { - TSM_ASSERT_THROWS_NOTHING("Object should be created without exception.", EventNexusLoadingPresenter(new MockMDLoadingView, getSuitableFile())); + TSM_ASSERT_THROWS_NOTHING( + "Object should be created without exception.", + EventNexusLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile())); } void testCanReadFile() { - EventNexusLoadingPresenter presenter(new MockMDLoadingView, getUnhandledFile()); - TSM_ASSERT("A file of this type cannot and should not be read by this presenter!.", !presenter.canReadFile()); + EventNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getUnhandledFile()); + TSM_ASSERT( + "A file of this type cannot and should not be read by this presenter!.", + !presenter.canReadFile()); } void testExecution() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; - EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(1)); - EXPECT_CALL(*view, getLoadInMemory()).Times(AtLeast(1)); - EXPECT_CALL(*view, getTime()).Times(AtLeast(1)); - EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); + MockMDLoadingView view; + EXPECT_CALL(view, getRecursionDepth()).Times(AtLeast(1)); + EXPECT_CALL(view, getLoadInMemory()).Times(AtLeast(1)); + EXPECT_CALL(view, getTime()).Times(AtLeast(1)); + EXPECT_CALL(view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); //Setup rendering factory MockvtkDataSetFactory factory; @@ -79,7 +89,8 @@ void testExecution() MockProgressAction mockDrawingProgressUpdate; //Create the presenter and runit! - EventNexusLoadingPresenter presenter(view, getSuitableFile()); + EventNexusLoadingPresenter presenter(std::unique_ptr<MDLoadingView>(&view), + getSuitableFile()); presenter.executeLoadMetadata(); vtkSmartPointer<vtkDataSet> product = presenter.execute(&factory, mockLoadingProgressUpdate, mockDrawingProgressUpdate); @@ -91,31 +102,38 @@ void testExecution() TS_ASSERT_THROWS_NOTHING(presenter.getGeometryXML()); TS_ASSERT(!presenter.getWorkspaceTypeName().empty()); - TS_ASSERT(Mock::VerifyAndClearExpectations(view)); + TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); } void testGetTDimension() { - EventNexusLoadingPresenter presenter(new MockMDLoadingView, getSuitableFile()); - TSM_ASSERT("EventNexus MDEW are created in fixed 3D.", !presenter.hasTDimensionAvailable()); + EventNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); + TSM_ASSERT("EventNexus MDEW are created in fixed 3D.", + !presenter.hasTDimensionAvailable()); } void testCallGetTDimensionValuesThrows() { - EventNexusLoadingPresenter presenter(new MockMDLoadingView, getSuitableFile()); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getTimeStepValues(), std::runtime_error); + EventNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.getTimeStepValues(), std::runtime_error); } void testCallGetGeometryThrows() { - EventNexusLoadingPresenter presenter(new MockMDLoadingView, getSuitableFile()); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getGeometryXML(), std::runtime_error); + EventNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.getGeometryXML(), std::runtime_error); } void testExecuteLoadMetadata() { - EventNexusLoadingPresenter presenter(new MockMDLoadingView, getSuitableFile()); + EventNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); presenter.executeLoadMetadata(); TSM_ASSERT_THROWS("Should always throw. Algorithm fixed to create 3 dimensions.", presenter.getTimeStepValues(), std::runtime_error); TSM_ASSERT_THROWS_NOTHING("Should throw. Execute not yet run.", presenter.hasTDimensionAvailable()); @@ -124,8 +142,10 @@ void testExecuteLoadMetadata() void testGetWorkspaceTypeName() { - EventNexusLoadingPresenter presenter(new MockMDLoadingView, getSuitableFile()); - TSM_ASSERT_EQUALS("Characterisation Test Failed", "", presenter.getWorkspaceTypeName()); + EventNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); + TSM_ASSERT_EQUALS("Characterisation Test Failed", "", + presenter.getWorkspaceTypeName()); } diff --git a/Vates/VatesAPI/test/MDEWEventNexusLoadingPresenterTest.h b/Vates/VatesAPI/test/MDEWEventNexusLoadingPresenterTest.h index e8dc8e90ae101ee5b4a3fa6a878258b96262dab0..a153bf0a7840d9055501923b030e327c936553f3 100644 --- a/Vates/VatesAPI/test/MDEWEventNexusLoadingPresenterTest.h +++ b/Vates/VatesAPI/test/MDEWEventNexusLoadingPresenterTest.h @@ -12,6 +12,7 @@ #include "MantidAPI/FileFinder.h" #include "MantidVatesAPI/MDEWEventNexusLoadingPresenter.h" #include "MantidVatesAPI/FilteringUpdateProgressAction.h" +#include "MantidKernel/make_unique.h" using namespace Mantid::VATES; using namespace testing; @@ -41,34 +42,45 @@ public: void testConstructWithEmptyFileThrows() { - TSM_ASSERT_THROWS("Should throw if an empty file string is given.", MDEWEventNexusLoadingPresenter(new MockMDLoadingView, ""), std::invalid_argument); + TSM_ASSERT_THROWS("Should throw if an empty file string is given.", + MDEWEventNexusLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), ""), + std::invalid_argument); } void testConstructWithNullViewThrows() { - MockMDLoadingView* pView = NULL; - - TSM_ASSERT_THROWS("Should throw if an empty file string is given.", MDEWEventNexusLoadingPresenter(pView, "some_file"), std::invalid_argument); + TSM_ASSERT_THROWS("Should throw if a null view is given.", + MDEWEventNexusLoadingPresenter(nullptr, "some_file"), + std::invalid_argument); } void testConstruct() { - TSM_ASSERT_THROWS_NOTHING("Object should be created without exception.", MDEWEventNexusLoadingPresenter(new MockMDLoadingView, getSuitableFile())); + TSM_ASSERT_THROWS_NOTHING( + "Object should be created without exception.", + MDEWEventNexusLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile())); } void testCanReadFile() { - MDEWEventNexusLoadingPresenter presenter(new MockMDLoadingView, getUnhandledFile()); - TSM_ASSERT("A file of this type cannot and should not be read by this presenter!.", !presenter.canReadFile()); + MDEWEventNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getUnhandledFile()); + TSM_ASSERT( + "A file of this type cannot and should not be read by this presenter!.", + !presenter.canReadFile()); } void testExecution() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; - EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(1)); - EXPECT_CALL(*view, getLoadInMemory()).Times(AtLeast(1)).WillRepeatedly(testing::Return(true)); - EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); + MockMDLoadingView view; + EXPECT_CALL(view, getRecursionDepth()).Times(AtLeast(1)); + EXPECT_CALL(view, getLoadInMemory()) + .Times(AtLeast(1)) + .WillRepeatedly(testing::Return(true)); + EXPECT_CALL(view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); //Setup rendering factory MockvtkDataSetFactory factory; @@ -83,7 +95,8 @@ void testExecution() MockProgressAction mockDrawingProgressAction; //Create the presenter and runit! - MDEWEventNexusLoadingPresenter presenter(view, getSuitableFile()); + MDEWEventNexusLoadingPresenter presenter( + std::unique_ptr<MDLoadingView>(&view), getSuitableFile()); presenter.executeLoadMetadata(); vtkSmartPointer<vtkDataSet> product = presenter.execute( &factory, mockLoadingProgressAction, mockDrawingProgressAction); @@ -96,41 +109,51 @@ void testExecution() TS_ASSERT_THROWS_NOTHING(presenter.getGeometryXML()); TS_ASSERT(!presenter.getWorkspaceTypeName().empty()); - TS_ASSERT(Mock::VerifyAndClearExpectations(view)); + TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); } void testCallHasTDimThrows() { - MDEWEventNexusLoadingPresenter presenter(new MockMDLoadingView, getSuitableFile()); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.hasTDimensionAvailable(), std::runtime_error); + MDEWEventNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.hasTDimensionAvailable(), std::runtime_error); } void testCallGetTDimensionValuesThrows() { - MDEWEventNexusLoadingPresenter presenter(new MockMDLoadingView, getSuitableFile()); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getTimeStepValues(), std::runtime_error); + MDEWEventNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.getTimeStepValues(), std::runtime_error); } void testCallGetGeometryThrows() { - MDEWEventNexusLoadingPresenter presenter(new MockMDLoadingView, getSuitableFile()); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getGeometryXML(), std::runtime_error); + MDEWEventNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.getGeometryXML(), std::runtime_error); } void testGetWorkspaceTypeName() { - MDEWEventNexusLoadingPresenter presenter(new MockMDLoadingView, getSuitableFile()); - TSM_ASSERT_EQUALS("Characterisation Test Failed", "", presenter.getWorkspaceTypeName()); + MDEWEventNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); + TSM_ASSERT_EQUALS("Characterisation Test Failed", "", + presenter.getWorkspaceTypeName()); } void testTimeLabel() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; - EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(1)); - EXPECT_CALL(*view, getLoadInMemory()).Times(AtLeast(1)).WillRepeatedly(testing::Return(true)); - EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); + MockMDLoadingView view; + EXPECT_CALL(view, getRecursionDepth()).Times(AtLeast(1)); + EXPECT_CALL(view, getLoadInMemory()) + .Times(AtLeast(1)) + .WillRepeatedly(testing::Return(true)); + EXPECT_CALL(view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); //Setup rendering factory MockvtkDataSetFactory factory; @@ -145,24 +168,27 @@ void testTimeLabel() MockProgressAction mockDrawingProgressAction; //Create the presenter and runit! - MDEWEventNexusLoadingPresenter presenter(view, getSuitableFile()); + MDEWEventNexusLoadingPresenter presenter(std::unique_ptr<MDLoadingView>(&view), + getSuitableFile()); presenter.executeLoadMetadata(); vtkSmartPointer<vtkDataSet> product = presenter.execute( &factory, mockLoadingProgressAction, mockDrawingProgressAction); TSM_ASSERT_EQUALS("Time label should be exact.", presenter.getTimeStepLabel(), "D (En)"); - TS_ASSERT(Mock::VerifyAndClearExpectations(view)); + TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); } void testAxisLabels() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; - EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(1)); - EXPECT_CALL(*view, getLoadInMemory()).Times(AtLeast(1)).WillRepeatedly(testing::Return(true)); - EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); + MockMDLoadingView view; + EXPECT_CALL(view, getRecursionDepth()).Times(AtLeast(1)); + EXPECT_CALL(view, getLoadInMemory()) + .Times(AtLeast(1)) + .WillRepeatedly(testing::Return(true)); + EXPECT_CALL(view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); //Setup rendering factory MockvtkDataSetFactory factory; @@ -177,7 +203,8 @@ void testAxisLabels() MockProgressAction mockDrawingProgressAction; //Create the presenter and runit! - MDEWEventNexusLoadingPresenter presenter(view, getSuitableFile()); + MDEWEventNexusLoadingPresenter presenter(std::unique_ptr<MDLoadingView>(&view), + getSuitableFile()); presenter.executeLoadMetadata(); vtkSmartPointer<vtkDataSet> product = presenter.execute( &factory, mockLoadingProgressAction, mockDrawingProgressAction); @@ -192,7 +219,7 @@ void testAxisLabels() getStringFieldDataValue(product, "AxisTitleForZ"), "C ($\\AA$)"); - TS_ASSERT(Mock::VerifyAndClearExpectations(view)); + TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); } diff --git a/Vates/VatesAPI/test/MDEWInMemoryLoadingPresenterTest.h b/Vates/VatesAPI/test/MDEWInMemoryLoadingPresenterTest.h index 3fe9b2ba91a8897240336c1ea8f4733b8e7d0e55..2e851773965526d3bb9e175a36c653b23a71fd7b 100644 --- a/Vates/VatesAPI/test/MDEWInMemoryLoadingPresenterTest.h +++ b/Vates/VatesAPI/test/MDEWInMemoryLoadingPresenterTest.h @@ -10,6 +10,7 @@ #include "MantidAPI/ITableWorkspace.h" #include "MantidVatesAPI/FilteringUpdateProgressAction.h" #include "MantidVatesAPI/MDEWInMemoryLoadingPresenter.h" +#include "MantidKernel/make_unique.h" #include <vtkUnstructuredGrid.h> #include <vtkSmartPointer.h> @@ -57,25 +58,36 @@ public: void testConstructWithNullViewThrows() { - MockMDLoadingView* pNullView = NULL; - TSM_ASSERT_THROWS("Should throw with empty Workspace name.", MDEWInMemoryLoadingPresenter(pNullView, new MockWorkspaceProvider, "_"), std::invalid_argument); + TSM_ASSERT_THROWS( + "Should throw with null view.", + MDEWInMemoryLoadingPresenter(nullptr, new MockWorkspaceProvider, "_"), + std::invalid_argument); } void testConstructWithNullRepositoryThrows() { - MockWorkspaceProvider* pNullRepository = NULL; - TSM_ASSERT_THROWS("Should throw with empty Workspace name.", MDEWInMemoryLoadingPresenter(new MockMDLoadingView, pNullRepository, "_"), std::invalid_argument); - } + TSM_ASSERT_THROWS( + "Should throw with null repository.", + MDEWInMemoryLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), nullptr, "_"), + std::invalid_argument); + } void testConstructWithEmptyWsNameThrows() { std::string emptyName = ""; - TSM_ASSERT_THROWS("Should throw with empty Workspace name.", MDEWInMemoryLoadingPresenter(new MockMDLoadingView, new MockWorkspaceProvider, emptyName), std::invalid_argument); + TSM_ASSERT_THROWS("Should throw with empty Workspace name.", + MDEWInMemoryLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, emptyName), + std::invalid_argument); } void testConstruction() { - TS_ASSERT_THROWS_NOTHING(MDEWInMemoryLoadingPresenter(new MockMDLoadingView, new MockWorkspaceProvider, "_")); + TS_ASSERT_THROWS_NOTHING(MDEWInMemoryLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_")); } void testCanLoadWithInvalidName() @@ -84,7 +96,8 @@ public: EXPECT_CALL(*repository, canProvideWorkspace(_)).WillOnce(Return(false)); //No matter what the argument, always returns false. //Give a dummy name corresponding to the workspace. - MDEWInMemoryLoadingPresenter presenter(new MockMDLoadingView, repository, "_"); + MDEWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), repository, "_"); TSM_ASSERT("Should indicate that the workspace cannot be read-out since the name is not in the Repository.", !presenter.canReadFile()); } @@ -97,7 +110,8 @@ public: EXPECT_CALL(*repository, fetchWorkspace(_)).WillOnce(Return(badWs)); //Give a dummy name corresponding to the workspace. - MDEWInMemoryLoadingPresenter presenter(new MockMDLoadingView, repository, "_"); + MDEWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), repository, "_"); TSM_ASSERT("Should indicate that the workspace cannot be read-out since it is not of the right type.", !presenter.canReadFile()); } @@ -110,7 +124,8 @@ public: EXPECT_CALL(*repository, fetchWorkspace(_)).WillOnce(Return(goodWs)); //Give a dummy name corresponding to the workspace. - MDEWInMemoryLoadingPresenter presenter(new MockMDLoadingView, repository, "_"); + MDEWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), repository, "_"); TSM_ASSERT("Should have worked! Workspace is of correct type and repository says ws is present.!", presenter.canReadFile()); } @@ -118,14 +133,15 @@ public: void testExtractMetadata() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; + MockMDLoadingView view; MockWorkspaceProvider* repository = new MockWorkspaceProvider; Mantid::API::Workspace_sptr ws = getReal4DWorkspace(); EXPECT_CALL(*repository, fetchWorkspace(_)).Times(1).WillRepeatedly(Return(ws)); - MDEWInMemoryLoadingPresenter presenter(view, repository, "_"); - + MDEWInMemoryLoadingPresenter presenter( + std::unique_ptr<MDLoadingView>(&view), repository, "_"); + //Test that it doesn't work when not setup. TSM_ASSERT_THROWS("::executeLoadMetadata is critical to setup, should throw if not run first.", presenter.getGeometryXML(), std::runtime_error); @@ -139,10 +155,11 @@ public: void testExecution() { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; - EXPECT_CALL(*view, getRecursionDepth()).Times(1); - EXPECT_CALL(*view, getLoadInMemory()).Times(0); //Not a question that needs asking for this presenter type. - EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); + MockMDLoadingView view; + EXPECT_CALL(view, getRecursionDepth()).Times(1); + EXPECT_CALL(view, getLoadInMemory()) + .Times(0); // Not a question that needs asking for this presenter type. + EXPECT_CALL(view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); //Setup rendering factory MockvtkDataSetFactory factory; @@ -159,7 +176,8 @@ public: MockProgressAction mockDrawingProgressAction; //Create the presenter and run it! - MDEWInMemoryLoadingPresenter presenter(view, repository, "_"); + MDEWInMemoryLoadingPresenter presenter( + std::unique_ptr<MDLoadingView>(&view), repository, "_"); presenter.executeLoadMetadata(); vtkSmartPointer<vtkDataSet> product = presenter.execute( &factory, mockLoadingProgressAction, mockDrawingProgressAction); @@ -172,38 +190,52 @@ public: TS_ASSERT_THROWS_NOTHING(presenter.getGeometryXML()); TS_ASSERT(!presenter.getWorkspaceTypeName().empty()); TSM_ASSERT("Special coordinate metadata failed.", -1 < presenter.getSpecialCoordinates()); - TS_ASSERT(Mock::VerifyAndClearExpectations(view)); + TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); } void testCallHasTDimThrows() { - MDEWInMemoryLoadingPresenter presenter(new MockMDLoadingView, new MockWorkspaceProvider, "_"); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.hasTDimensionAvailable(), std::runtime_error); + MDEWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_"); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.hasTDimensionAvailable(), std::runtime_error); } void testCallGetTDimensionValuesThrows() { - MDEWInMemoryLoadingPresenter presenter(new MockMDLoadingView, new MockWorkspaceProvider, "_"); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getTimeStepValues(), std::runtime_error); + MDEWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_"); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.getTimeStepValues(), std::runtime_error); } void testCallGetGeometryThrows() { - MDEWInMemoryLoadingPresenter presenter(new MockMDLoadingView, new MockWorkspaceProvider, "_"); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getGeometryXML(), std::runtime_error); + MDEWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_"); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.getGeometryXML(), std::runtime_error); } void testGetWorkspaceTypeName() { - MDEWInMemoryLoadingPresenter presenter(new MockMDLoadingView, new MockWorkspaceProvider, "_"); + MDEWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_"); TSM_ASSERT_EQUALS("Characterisation Test Failed", "", presenter.getWorkspaceTypeName()); } void testGetSpecialCoordinates() { - MDEWInMemoryLoadingPresenter presenter(new MockMDLoadingView, new MockWorkspaceProvider, "_"); - TSM_ASSERT_EQUALS("Characterisation Test Failed", -1, presenter.getSpecialCoordinates()); + MDEWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_"); + TSM_ASSERT_EQUALS("Characterisation Test Failed", -1, + presenter.getSpecialCoordinates()); } diff --git a/Vates/VatesAPI/test/MDEWLoadingPresenterTest.h b/Vates/VatesAPI/test/MDEWLoadingPresenterTest.h index 534d976234c0e1d2c492beec7c5324a7a269d0f0..6f1930276eed2084af845e13731d3fc88a27b4ba 100644 --- a/Vates/VatesAPI/test/MDEWLoadingPresenterTest.h +++ b/Vates/VatesAPI/test/MDEWLoadingPresenterTest.h @@ -42,10 +42,9 @@ private: { return MDEWLoadingPresenter::extractMetadata(eventWs); } - - ConcreteMDEWLoadingPresenter(MockMDLoadingView* view) : MDEWLoadingPresenter(view) - { - } + + ConcreteMDEWLoadingPresenter(MockMDLoadingView *view) + : MDEWLoadingPresenter(std::unique_ptr<MDLoadingView>(view)) {} virtual vtkDataSet* execute(vtkDataSetFactory*, ProgressAction&, ProgressAction&) { diff --git a/Vates/VatesAPI/test/MDHWInMemoryLoadingPresenterTest.h b/Vates/VatesAPI/test/MDHWInMemoryLoadingPresenterTest.h index 5c737379a6b5d3205a11fdf208e444d3f648e7af..531cae3d05012ab37001bb5e0d055be8141c6607 100644 --- a/Vates/VatesAPI/test/MDHWInMemoryLoadingPresenterTest.h +++ b/Vates/VatesAPI/test/MDHWInMemoryLoadingPresenterTest.h @@ -10,6 +10,7 @@ #include "MantidTestHelpers/MDEventsTestHelper.h" #include "MantidVatesAPI/FilteringUpdateProgressAction.h" #include "MantidVatesAPI/MDHWInMemoryLoadingPresenter.h" +#include "MantidKernel/make_unique.h" #include <vtkUnstructuredGrid.h> #include <vtkSmartPointer.h> @@ -50,25 +51,36 @@ public: void testConstructWithNullViewThrows() { - MockMDLoadingView* pNullView = NULL; - TSM_ASSERT_THROWS("Should throw with empty Workspace name.", MDHWInMemoryLoadingPresenter(pNullView, new MockWorkspaceProvider, "_"), std::invalid_argument); + TSM_ASSERT_THROWS( + "Should throw with null view.", + MDHWInMemoryLoadingPresenter(nullptr, new MockWorkspaceProvider, "_"), + std::invalid_argument); } void testConstructWithNullRepositoryThrows() { - MockWorkspaceProvider* pNullRepository = NULL; - TSM_ASSERT_THROWS("Should throw with empty Workspace name.", MDHWInMemoryLoadingPresenter(new MockMDLoadingView, pNullRepository, "_"), std::invalid_argument); - } + TSM_ASSERT_THROWS( + "Should throw with null repository.", + MDHWInMemoryLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), nullptr, "_"), + std::invalid_argument); + } void testConstructWithEmptyWsNameThrows() { std::string emptyName = ""; - TSM_ASSERT_THROWS("Should throw with empty Workspace name.", MDHWInMemoryLoadingPresenter(new MockMDLoadingView, new MockWorkspaceProvider, emptyName), std::invalid_argument); + TSM_ASSERT_THROWS("Should throw with empty Workspace name.", + MDHWInMemoryLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, emptyName), + std::invalid_argument); } void testConstruction() { - TS_ASSERT_THROWS_NOTHING(MDHWInMemoryLoadingPresenter(new MockMDLoadingView, new MockWorkspaceProvider, "_")); + TS_ASSERT_THROWS_NOTHING(MDHWInMemoryLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_")); } void testCanLoadWithInvalidName() @@ -77,7 +89,8 @@ public: EXPECT_CALL(*repository, canProvideWorkspace(_)).WillOnce(Return(false)); //No matter what the argument, always returns false. //Give a dummy name corresponding to the workspace. - MDHWInMemoryLoadingPresenter presenter(new MockMDLoadingView, repository, "_"); + MDHWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), repository, "_"); TSM_ASSERT("Should indicate that the workspace cannot be read-out since the name is not in the Repository.", !presenter.canReadFile()); } @@ -90,7 +103,8 @@ public: EXPECT_CALL(*repository, fetchWorkspace(_)).WillOnce(Return(badWs)); //Give a dummy name corresponding to the workspace. - MDHWInMemoryLoadingPresenter presenter(new MockMDLoadingView, repository, "_"); + MDHWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), repository, "_"); TSM_ASSERT("Should indicate that the workspace cannot be read-out since it is not of the right type.", !presenter.canReadFile()); } @@ -103,22 +117,21 @@ public: EXPECT_CALL(*repository, fetchWorkspace(_)).WillOnce(Return(goodWs)); //Give a dummy name corresponding to the workspace. - MDHWInMemoryLoadingPresenter presenter(new MockMDLoadingView, repository, "_"); + MDHWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), repository, "_"); TSM_ASSERT("Should have worked! Workspace is of correct type and repository says ws is present.!", presenter.canReadFile()); } void testExtractMetadata() { - //Setup view - MockMDLoadingView* view = new MockMDLoadingView; - MockWorkspaceProvider* repository = new MockWorkspaceProvider; Mantid::API::Workspace_sptr ws = getGoodWorkspace(); EXPECT_CALL(*repository, fetchWorkspace(_)).Times(1).WillRepeatedly(Return(ws)); - MDHWInMemoryLoadingPresenter presenter(view, repository, "_"); - + MDHWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), repository, "_"); + //Test that it doesn't work when not setup. TSM_ASSERT_THROWS("::executeLoadMetadata is critical to setup, should throw if not run first.", presenter.getGeometryXML(), std::runtime_error); @@ -136,10 +149,11 @@ public: { //Setup view - MockMDLoadingView* view = new MockMDLoadingView; - EXPECT_CALL(*view, getRecursionDepth()).Times(0); - EXPECT_CALL(*view, getLoadInMemory()).Times(0); //Not a question that needs asking for this presenter type. - EXPECT_CALL(*view, updateAlgorithmProgress(_,_)).Times(AnyNumber()); + MockMDLoadingView view; + EXPECT_CALL(view, getRecursionDepth()).Times(0); + EXPECT_CALL(view, getLoadInMemory()) + .Times(0); // Not a question that needs asking for this presenter type. + EXPECT_CALL(view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); //Setup rendering factory MockvtkDataSetFactory factory; @@ -155,7 +169,8 @@ public: MockProgressAction mockDrawingProgressAction; //Create the presenter and run it! - MDHWInMemoryLoadingPresenter presenter(view, repository, "_"); + MDHWInMemoryLoadingPresenter presenter( + std::unique_ptr<MDLoadingView>(&view), repository, "_"); presenter.executeLoadMetadata(); auto product = vtkSmartPointer<vtkDataSet>::Take(presenter.execute( &factory, mockLoadingProgressAction, mockDrawingProgressAction)); @@ -168,38 +183,53 @@ public: TS_ASSERT_THROWS_NOTHING(presenter.getGeometryXML()); TS_ASSERT(!presenter.getWorkspaceTypeName().empty()); TSM_ASSERT("Special coordinate metadata failed.", -1 < presenter.getSpecialCoordinates()); - TS_ASSERT(Mock::VerifyAndClearExpectations(view)); + TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); } void testCallHasTDimThrows() { - MDHWInMemoryLoadingPresenter presenter(new MockMDLoadingView, new MockWorkspaceProvider, "_"); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.hasTDimensionAvailable(), std::runtime_error); + MDHWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_"); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.hasTDimensionAvailable(), std::runtime_error); } void testCallGetTDimensionValuesThrows() { - MDHWInMemoryLoadingPresenter presenter(new MockMDLoadingView, new MockWorkspaceProvider, "_"); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getTimeStepValues(), std::runtime_error); + MDHWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_"); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.getTimeStepValues(), std::runtime_error); } void testCallGetGeometryThrows() { - MDHWInMemoryLoadingPresenter presenter(new MockMDLoadingView, new MockWorkspaceProvider, "_"); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getGeometryXML(), std::runtime_error); + MDHWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_"); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.getGeometryXML(), std::runtime_error); } void testGetWorkspaceTypeName() { - MDHWInMemoryLoadingPresenter presenter(new MockMDLoadingView, new MockWorkspaceProvider, "_"); - TSM_ASSERT_EQUALS("Characterisation Test Failed", "", presenter.getWorkspaceTypeName()); + MDHWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_"); + TSM_ASSERT_EQUALS("Characterisation Test Failed", "", + presenter.getWorkspaceTypeName()); } void testGetSpecialCoordinates() { - MDHWInMemoryLoadingPresenter presenter(new MockMDLoadingView, new MockWorkspaceProvider, "_"); - TSM_ASSERT_EQUALS("Characterisation Test Failed", -1, presenter.getSpecialCoordinates()); + MDHWInMemoryLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + new MockWorkspaceProvider, "_"); + TSM_ASSERT_EQUALS("Characterisation Test Failed", -1, + presenter.getSpecialCoordinates()); } }; diff --git a/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h b/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h index b8c96d2192390227c194c17703ca41322db022e5..cbaa0283cc2c2c3e8e0fdba8658ccf142978cd56 100644 --- a/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h +++ b/Vates/VatesAPI/test/MDHWLoadingPresenterTest.h @@ -35,9 +35,8 @@ private: private: typedef MDHWLoadingPresenter BaseClass; public: - ConcreteMDHWLoadingPresenter(MockMDLoadingView* view) : MDHWLoadingPresenter(view) - { - } + ConcreteMDHWLoadingPresenter(MockMDLoadingView *view) + : MDHWLoadingPresenter(std::unique_ptr<MDLoadingView>(view)) {} virtual void extractMetadata(Mantid::API::IMDHistoWorkspace_sptr histoWs) { diff --git a/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h b/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h index a975e443de2522c938b7924032640bc06114b5cd..c94676c05f757ff60b52114d9f48c1c088833352 100644 --- a/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h +++ b/Vates/VatesAPI/test/MDHWNexusLoadingPresenterTest.h @@ -22,6 +22,7 @@ #include "MantidAPI/FileFinder.h" #include "MantidVatesAPI/MDHWNexusLoadingPresenter.h" #include "MantidVatesAPI/FilteringUpdateProgressAction.h" +#include "MantidKernel/make_unique.h" #include <limits> @@ -51,13 +52,13 @@ private: vtkDataSet *doExecute(std::string filename, bool performAsserts = true) { // Setup view - MockMDLoadingView *view = new MockMDLoadingView; - EXPECT_CALL(*view, getTime()).WillRepeatedly(Return(0)); - EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(0)); - EXPECT_CALL(*view, getLoadInMemory()) + MockMDLoadingView view; + EXPECT_CALL(view, getTime()).WillRepeatedly(Return(0)); + EXPECT_CALL(view, getRecursionDepth()).Times(AtLeast(0)); + EXPECT_CALL(view, getLoadInMemory()) .Times(AtLeast(1)) .WillRepeatedly(testing::Return(true)); - EXPECT_CALL(*view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); + EXPECT_CALL(view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); // Setup rendering factory MockvtkDataSetFactory factory; @@ -70,7 +71,8 @@ private: MockProgressAction mockDrawingProgressAction; // Create the presenter and runit! - MDHWNexusLoadingPresenter presenter(view, filename); + MDHWNexusLoadingPresenter presenter(std::unique_ptr<MDLoadingView>(&view), + filename); presenter.executeLoadMetadata(); vtkDataSet *product = presenter.execute(&factory, mockLoadingProgressAction, mockDrawingProgressAction); @@ -87,7 +89,7 @@ private: TS_ASSERT_THROWS_NOTHING(presenter.getGeometryXML()); TS_ASSERT(!presenter.getWorkspaceTypeName().empty()); - TS_ASSERT(Mock::VerifyAndClearExpectations(view)); + TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); } return product; @@ -96,27 +98,28 @@ private: public: void testConstructWithEmptyFileThrows() { TSM_ASSERT_THROWS("Should throw if an empty file string is given.", - MDHWNexusLoadingPresenter(new MockMDLoadingView, ""), + MDHWNexusLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), ""), std::invalid_argument); } void testConstructWithNullViewThrows() { - MockMDLoadingView *pView = NULL; - TSM_ASSERT_THROWS("Should throw if an empty file string is given.", - MDHWNexusLoadingPresenter(pView, "some_file"), + MDHWNexusLoadingPresenter(nullptr, "some_file"), std::invalid_argument); } void testConstruct() { TSM_ASSERT_THROWS_NOTHING( "Object should be created without exception.", - MDHWNexusLoadingPresenter(new MockMDLoadingView, getSuitableFile())); + MDHWNexusLoadingPresenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + getSuitableFile())); } void testCanReadFile() { - MDHWNexusLoadingPresenter presenter(new MockMDLoadingView, - getUnhandledFile()); + MDHWNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getUnhandledFile()); TSM_ASSERT( "A file of this type cannot and should not be read by this presenter!.", !presenter.canReadFile()); @@ -141,7 +144,7 @@ public: NiceMock<MockProgressAction> mockDrawingProgressAction; // Setup view - MockMDLoadingView *view = new MockMDLoadingView; + auto view = Mantid::Kernel::make_unique<MockMDLoadingView>(); EXPECT_CALL(*view, getTime()).WillRepeatedly(Return(0)); EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(0)); EXPECT_CALL(*view, getLoadInMemory()) @@ -153,7 +156,7 @@ public: // Create the presenter as in the vtkMDHWSource auto normalizationOption = Mantid::VATES::VisualNormalization::AutoSelect; - MDHWNexusLoadingPresenter presenter(view, filename); + MDHWNexusLoadingPresenter presenter(std::move(view), filename); const double time = 0.0; vtkMD0DFactory *zeroDFactory = new vtkMD0DFactory; vtkMDHistoLineFactory *lineFactory = @@ -231,42 +234,42 @@ public: } void testCallHasTDimThrows() { - MDHWNexusLoadingPresenter presenter(new MockMDLoadingView, - getSuitableFile()); + MDHWNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.hasTDimensionAvailable(), std::runtime_error); } void testCallGetTDimensionValuesThrows() { - MDHWNexusLoadingPresenter presenter(new MockMDLoadingView, - getSuitableFile()); + MDHWNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getTimeStepValues(), std::runtime_error); } void testCallGetGeometryThrows() { - MDHWNexusLoadingPresenter presenter(new MockMDLoadingView, - getSuitableFile()); + MDHWNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getGeometryXML(), std::runtime_error); } void testGetWorkspaceTypeName() { - MDHWNexusLoadingPresenter presenter(new MockMDLoadingView, - getSuitableFile()); + MDHWNexusLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), getSuitableFile()); TSM_ASSERT_EQUALS("Characterisation Test Failed", "", presenter.getWorkspaceTypeName()); } void testTimeLabel() { // Setup view - MockMDLoadingView *view = new MockMDLoadingView; - EXPECT_CALL(*view, getTime()).WillRepeatedly(Return(0)); - EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(0)); - EXPECT_CALL(*view, getLoadInMemory()) + MockMDLoadingView view; + EXPECT_CALL(view, getTime()).WillRepeatedly(Return(0)); + EXPECT_CALL(view, getRecursionDepth()).Times(AtLeast(0)); + EXPECT_CALL(view, getLoadInMemory()) .Times(AtLeast(1)) .WillRepeatedly(testing::Return(true)); - EXPECT_CALL(*view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); + EXPECT_CALL(view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); // Setup rendering factory MockvtkDataSetFactory factory; @@ -279,26 +282,27 @@ public: MockProgressAction mockDrawingProgressAction; // Create the presenter and runit! - MDHWNexusLoadingPresenter presenter(view, getSuitableFile()); + MDHWNexusLoadingPresenter presenter(std::unique_ptr<MDLoadingView>(&view), + getSuitableFile()); presenter.executeLoadMetadata(); auto product = vtkSmartPointer<vtkDataSet>::Take(presenter.execute( &factory, mockLoadingProgressAction, mockDrawingProgressAction)); TSM_ASSERT_EQUALS("Time label should be exact.", presenter.getTimeStepLabel(), "DeltaE (DeltaE)"); - TS_ASSERT(Mock::VerifyAndClearExpectations(view)); + TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); } void testAxisLabels() { // Setup view - MockMDLoadingView *view = new MockMDLoadingView; - EXPECT_CALL(*view, getTime()).WillRepeatedly(Return(0)); - EXPECT_CALL(*view, getRecursionDepth()).Times(AtLeast(0)); - EXPECT_CALL(*view, getLoadInMemory()) + MockMDLoadingView view; + EXPECT_CALL(view, getTime()).WillRepeatedly(Return(0)); + EXPECT_CALL(view, getRecursionDepth()).Times(AtLeast(0)); + EXPECT_CALL(view, getLoadInMemory()) .Times(AtLeast(1)) .WillRepeatedly(testing::Return(true)); - EXPECT_CALL(*view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); + EXPECT_CALL(view, updateAlgorithmProgress(_, _)).Times(AnyNumber()); // Setup rendering factory MockvtkDataSetFactory factory; @@ -311,7 +315,8 @@ public: MockProgressAction mockDrawingProgressAction; // Create the presenter and runit! - MDHWNexusLoadingPresenter presenter(view, getSuitableFile()); + MDHWNexusLoadingPresenter presenter(std::unique_ptr<MDLoadingView>(&view), + getSuitableFile()); presenter.executeLoadMetadata(); auto product = vtkSmartPointer<vtkDataSet>::Take(presenter.execute( &factory, mockLoadingProgressAction, mockDrawingProgressAction)); @@ -327,7 +332,7 @@ public: getStringFieldDataValue(product, "AxisTitleForZ"), "[0,0,L] ($in$ $1.087$ $\\AA^{-1}$)"); - TS_ASSERT(Mock::VerifyAndClearExpectations(view)); + TS_ASSERT(Mock::VerifyAndClearExpectations(&view)); TS_ASSERT(Mock::VerifyAndClearExpectations(&factory)); } }; diff --git a/Vates/VatesAPI/test/SQWLoadingPresenterTest.h b/Vates/VatesAPI/test/SQWLoadingPresenterTest.h index 5157d169ef55bbf46aebd5243ed8d600eb531de9..abafe02dbb3cc0cbb25682c16688a42b4d976e96 100644 --- a/Vates/VatesAPI/test/SQWLoadingPresenterTest.h +++ b/Vates/VatesAPI/test/SQWLoadingPresenterTest.h @@ -13,6 +13,7 @@ #include "MantidAPI/FileFinder.h" #include "MantidVatesAPI/SQWLoadingPresenter.h" #include "MantidVatesAPI/FilteringUpdateProgressAction.h" +#include "MantidKernel/make_unique.h" using namespace Mantid::VATES; @@ -52,38 +53,51 @@ void setUp() void testConstructWithEmptyFileThrows() { - TSM_ASSERT_THROWS("Should throw if an empty file string is given.", SQWLoadingPresenter(new MockMDLoadingView, ""), std::invalid_argument); + std::unique_ptr<MDLoadingView> view = + Mantid::Kernel::make_unique<MockMDLoadingView>(); + TSM_ASSERT_THROWS("Should throw if an empty file string is given.", + SQWLoadingPresenter(std::move(view), ""), + std::invalid_argument); } void testConstructWithNullViewThrows() { - MockMDLoadingView* pView = NULL; - TSM_ASSERT_THROWS("Should throw if an empty file string is given.", SQWLoadingPresenter(pView, "some_file"), std::invalid_argument); + TSM_ASSERT_THROWS("Should throw if an empty file string is given.", + SQWLoadingPresenter(nullptr, "some_file"), + std::invalid_argument); } void testConstruct() { - TSM_ASSERT_THROWS_NOTHING("Object should be created without exception.", SQWLoadingPresenter(new MockMDLoadingView, getSuitableFileNamePath())); + std::unique_ptr<MDLoadingView> view = + Mantid::Kernel::make_unique<MockMDLoadingView>(); + TSM_ASSERT_THROWS_NOTHING( + "Object should be created without exception.", + SQWLoadingPresenter(std::move(view), getSuitableFileNamePath())); } void testCanReadFile() { - MockMDLoadingView view; - - SQWLoadingPresenter presenter(new MockMDLoadingView, getSuitableFileNamePath()); + std::unique_ptr<MDLoadingView> view = + Mantid::Kernel::make_unique<MockMDLoadingView>(); + SQWLoadingPresenter presenter(std::move(view), getSuitableFileNamePath()); TSM_ASSERT("Should be readable, valid SQW file.", presenter.canReadFile()); } void testCanReadFileWithDifferentCaseExtension() { - SQWLoadingPresenter presenter(new MockMDLoadingView, "other.Sqw"); - TSM_ASSERT("Should be readable, only different in case.", presenter.canReadFile()); + auto view = Mantid::Kernel::make_unique<MockMDLoadingView>(); + SQWLoadingPresenter presenter(std::move(view), "other.Sqw"); + TSM_ASSERT("Should be readable, only different in case.", + presenter.canReadFile()); } void testCannotReadFileWithWrongExtension() { - SQWLoadingPresenter presenter(new MockMDLoadingView, getUnhandledFileNamePath()); - TSM_ASSERT("Should NOT be readable, completely wrong file type.", !presenter.canReadFile()); + auto view = Mantid::Kernel::make_unique<MockMDLoadingView>(); + SQWLoadingPresenter presenter(std::move(view), getUnhandledFileNamePath()); + TSM_ASSERT("Should NOT be readable, completely wrong file type.", + !presenter.canReadFile()); } void testExecutionInMemory() @@ -111,7 +125,8 @@ void testExecutionInMemory() EXPECT_CALL(mockLoadingProgressAction, eventRaised(AllOf(Le(100),Ge(0)))).Times(AtLeast(1)); //Create the presenter and runit! - SQWLoadingPresenter presenter(view, getSuitableFileNamePath()); + SQWLoadingPresenter presenter(std::unique_ptr<MDLoadingView>(view), + getSuitableFileNamePath()); presenter.executeLoadMetadata(); auto product = vtkSmartPointer<vtkDataSet>::Take(presenter.execute( &factory, mockLoadingProgressAction, mockDrawingProgressAction)); @@ -136,25 +151,36 @@ void testExecutionInMemory() void testCallHasTDimThrows() { - SQWLoadingPresenter presenter(new MockMDLoadingView, getSuitableFileNamePath()); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.hasTDimensionAvailable(), std::runtime_error); + SQWLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + getSuitableFileNamePath()); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.hasTDimensionAvailable(), std::runtime_error); } void testCallGetTDimensionValuesThrows() { - SQWLoadingPresenter presenter(new MockMDLoadingView, getSuitableFileNamePath()); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getTimeStepValues(), std::runtime_error); + SQWLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + getSuitableFileNamePath()); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.getTimeStepValues(), std::runtime_error); } void testCallGetGeometryThrows() { - SQWLoadingPresenter presenter(new MockMDLoadingView, getSuitableFileNamePath()); - TSM_ASSERT_THROWS("Should throw. Execute not yet run.", presenter.getGeometryXML(), std::runtime_error); + SQWLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + getSuitableFileNamePath()); + TSM_ASSERT_THROWS("Should throw. Execute not yet run.", + presenter.getGeometryXML(), std::runtime_error); } void testExecuteLoadMetadata() { - SQWLoadingPresenter presenter(new MockMDLoadingView, getSuitableFileNamePath()); + SQWLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + getSuitableFileNamePath()); presenter.executeLoadMetadata(); TSM_ASSERT_THROWS_NOTHING("Should throw. Execute not yet run.", presenter.getTimeStepValues()); TSM_ASSERT_THROWS_NOTHING("Should throw. Execute not yet run.", presenter.hasTDimensionAvailable()); @@ -163,8 +189,11 @@ void testExecuteLoadMetadata() void testGetWorkspaceTypeName() { - SQWLoadingPresenter presenter(new MockMDLoadingView, getSuitableFileNamePath()); - TSM_ASSERT_EQUALS("Characterisation Test Failed", "", presenter.getWorkspaceTypeName()); + SQWLoadingPresenter presenter( + Mantid::Kernel::make_unique<MockMDLoadingView>(), + getSuitableFileNamePath()); + TSM_ASSERT_EQUALS("Characterisation Test Failed", "", + presenter.getWorkspaceTypeName()); } void testTimeLabel() @@ -192,7 +221,8 @@ void testTimeLabel() EXPECT_CALL(mockLoadingProgressAction, eventRaised(AllOf(Le(100),Ge(0)))).Times(AtLeast(1)); //Create the presenter and runit! - SQWLoadingPresenter presenter(view, getSuitableFileNamePath()); + SQWLoadingPresenter presenter(std::unique_ptr<MDLoadingView>(view), + getSuitableFileNamePath()); presenter.executeLoadMetadata(); auto product = vtkSmartPointer<vtkDataSet>::Take(presenter.execute( &factory, mockLoadingProgressAction, mockDrawingProgressAction)); @@ -230,7 +260,8 @@ void testAxisLabels() EXPECT_CALL(mockLoadingProgressAction, eventRaised(AllOf(Le(100),Ge(0)))).Times(AtLeast(1)); //Create the presenter and runit! - SQWLoadingPresenter presenter(view, getSuitableFileNamePath()); + SQWLoadingPresenter presenter(std::unique_ptr<MDLoadingView>(view), + getSuitableFileNamePath()); presenter.executeLoadMetadata(); auto product = vtkSmartPointer<vtkDataSet>::Take(presenter.execute( &factory, mockLoadingProgressAction, mockDrawingProgressAction));