From 433e11f3d7eae524c148a7af1a253a8f77d5b037 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 30 Apr 2024 00:56:36 +1200 Subject: [PATCH 1/5] Some minor cleaning up. --- src/api/libopencor/file.h | 8 ++++---- src/api/libopencor/logger.h | 16 ++++++++-------- src/api/libopencor/seddocument.h | 12 ++++++------ src/api/libopencor/types.h | 20 ++++++++++---------- src/bindings/javascript/file.cpp | 2 +- src/bindings/javascript/main.cpp | 18 +++++++++--------- src/file/file.cpp | 8 ++++---- src/file/file_p.h | 6 +++--- src/file/filemanager.h | 2 +- src/logger/logger.cpp | 8 ++++---- src/logger/logger_p.h | 8 ++++---- src/misc/compiler.cpp | 12 ++++++------ src/misc/utils.cpp | 6 +++--- src/misc/utils.h | 8 ++++---- src/sed/seddocument.cpp | 6 +++--- src/sed/seddocument_p.h | 14 +++++++------- src/sed/sedinstance_p.h | 2 +- src/solver/solverkinsol.cpp | 28 ++++++++++++++-------------- tests/api/file/basictests.cpp | 12 ++++++------ tests/api/file/typetests.cpp | 6 +++--- tests/api/sed/serialisetests.cpp | 4 ++-- tests/utils.cpp | 2 +- tests/utils.h.in | 2 +- 23 files changed, 105 insertions(+), 105 deletions(-) diff --git a/src/api/libopencor/file.h b/src/api/libopencor/file.h index c75024106..18e5b0c35 100644 --- a/src/api/libopencor/file.h +++ b/src/api/libopencor/file.h @@ -145,20 +145,20 @@ class LIBOPENCOR_EXPORT File: public Logger * * Return the contents of this file. * - * @return The contents, as an @ref UnsignedCharVector, of this file. + * @return The contents, as an @ref UnsignedChars, of this file. */ - UnsignedCharVector contents(); + UnsignedChars contents(); /** * @brief Set the contents of this file. * * Set the contents of this file. * - * @param pContents The contents, as an @ref UnsignedCharVector, of this file. + * @param pContents The contents, as an @ref UnsignedChars, of this file. */ - void setContents(const UnsignedCharVector &pContents); + void setContents(const UnsignedChars &pContents); private: class Impl; /**< Forward declaration of the implementation class, @private. */ diff --git a/src/api/libopencor/logger.h b/src/api/libopencor/logger.h index 447bc7389..e48387541 100644 --- a/src/api/libopencor/logger.h +++ b/src/api/libopencor/logger.h @@ -60,10 +60,10 @@ class LIBOPENCOR_EXPORT Logger * * Return the issues. * - * @return The issues, as an @ref IssuePtrVector. + * @return The issues, as an @ref IssuePtrs. */ - IssuePtrVector issues() const; + IssuePtrs issues() const; /** * @brief Return whether there are some errors. @@ -80,10 +80,10 @@ class LIBOPENCOR_EXPORT Logger * * Return the errors. * - * @return The errors, as a @ref IssuePtrVector of type @ref Issue::Type::ERROR. + * @return The errors, as a @ref IssuePtrs of type @ref Issue::Type::ERROR. */ - IssuePtrVector errors() const; + IssuePtrs errors() const; /** * @brief Return whether there are some warnings. @@ -100,10 +100,10 @@ class LIBOPENCOR_EXPORT Logger * * Return the warnings. * - * @return The warnings, as a @ref IssuePtrVector of type @ref Issue::Type::WARNING. + * @return The warnings, as a @ref IssuePtrs of type @ref Issue::Type::WARNING. */ - IssuePtrVector warnings() const; + IssuePtrs warnings() const; /** * @brief Return whether there are some messages. @@ -120,10 +120,10 @@ class LIBOPENCOR_EXPORT Logger * * Return the messages. * - * @return The messages, as a @ref IssuePtrVector of type @ref Issue::Type::MESSAGE. + * @return The messages, as a @ref IssuePtrs of type @ref Issue::Type::MESSAGE. */ - IssuePtrVector messages() const; + IssuePtrs messages() const; protected: class Impl; /**< Forward declaration of the implementation class, @private. */ diff --git a/src/api/libopencor/seddocument.h b/src/api/libopencor/seddocument.h index 9bdc816f8..157c5d6f5 100644 --- a/src/api/libopencor/seddocument.h +++ b/src/api/libopencor/seddocument.h @@ -104,10 +104,10 @@ class LIBOPENCOR_EXPORT SedDocument: public Logger * * Return the models. * - * @return The models, as a @ref SedModelPtrVector. + * @return The models, as a @ref SedModelPtrs. */ - SedModelPtrVector models() const; + SedModelPtrs models() const; /** * @brief Add the model to this simulation experiment description. @@ -148,10 +148,10 @@ class LIBOPENCOR_EXPORT SedDocument: public Logger * * Return the simulations. * - * @return The simulations, as a @ref SedSimulationPtrVector. + * @return The simulations, as a @ref SedSimulationPtrs. */ - SedSimulationPtrVector simulations() const; + SedSimulationPtrs simulations() const; /** * @brief Add the simulation to this simulation experiment description. @@ -192,10 +192,10 @@ class LIBOPENCOR_EXPORT SedDocument: public Logger * * Return the tasks. * - * @return The tasks, as a @ref SedAbstractTaskPtrVector. + * @return The tasks, as a @ref SedAbstractTaskPtrs. */ - SedAbstractTaskPtrVector tasks() const; + SedAbstractTaskPtrs tasks() const; /** * @brief Add the task to this simulation experiment description. diff --git a/src/api/libopencor/types.h b/src/api/libopencor/types.h index 9cc3ffe0b..065cf9a52 100644 --- a/src/api/libopencor/types.h +++ b/src/api/libopencor/types.h @@ -114,15 +114,15 @@ using SolverSecondOrderRungeKuttaPtr = std::shared_ptr; /**< Type definition for a vector of @ref Issue pointers. */ -using SedAbstractTaskPtrVector = std::vector; /**< Type definition for a vector of @ref SedAbstractTask pointers. */ -using SedDataDescriptionPtrVector = std::vector; /**< Type definition for a vector of @ref SedDataDescription pointers. */ -using SedDataGeneratorPtrVector = std::vector; /**< Type definition for a vector of @ref SedDataGenerator pointers. */ -using SedInstanceTaskPtrVector = std::vector; /**< Type definition for a vector of @ref SedInstanceTask pointers. */ -using SedModelPtrVector = std::vector; /**< Type definition for a vector of @ref SedModel pointers. */ -using SedOutputPtrVector = std::vector; /**< Type definition for a vector of @ref SedOutput pointers. */ -using SedSimulationPtrVector = std::vector; /**< Type definition for a vector of @ref SedSimulation pointers. */ -using SedStylePtrVector = std::vector; /**< Type definition for a vector of @ref SedStyle pointers. */ -using UnsignedCharVector = std::vector; /**< Type definition for a vector of unsigned characters. */ +using IssuePtrs = std::vector; /**< Type definition for a vector of @ref Issue pointers. */ +using SedAbstractTaskPtrs = std::vector; /**< Type definition for a vector of @ref SedAbstractTask pointers. */ +using SedDataDescriptionPtrs = std::vector; /**< Type definition for a vector of @ref SedDataDescription pointers. */ +using SedDataGeneratorPtrs = std::vector; /**< Type definition for a vector of @ref SedDataGenerator pointers. */ +using SedInstanceTaskPtrs = std::vector; /**< Type definition for a vector of @ref SedInstanceTask pointers. */ +using SedModelPtrs = std::vector; /**< Type definition for a vector of @ref SedModel pointers. */ +using SedOutputPtrs = std::vector; /**< Type definition for a vector of @ref SedOutput pointers. */ +using SedSimulationPtrs = std::vector; /**< Type definition for a vector of @ref SedSimulation pointers. */ +using SedStylePtrs = std::vector; /**< Type definition for a vector of @ref SedStyle pointers. */ +using UnsignedChars = std::vector; /**< Type definition for a vector of unsigned characters. */ } // namespace libOpenCOR diff --git a/src/bindings/javascript/file.cpp b/src/bindings/javascript/file.cpp index 2c7524828..46c216c5f 100644 --- a/src/bindings/javascript/file.cpp +++ b/src/bindings/javascript/file.cpp @@ -44,7 +44,7 @@ void fileApi() .function("setContents", emscripten::optional_override([](libOpenCOR::FilePtr &pThis, uintptr_t pContents, size_t pSize) { auto contents = reinterpret_cast(pContents); - pThis->setContents(libOpenCOR::UnsignedCharVector(contents, contents + pSize)); + pThis->setContents(libOpenCOR::UnsignedChars(contents, contents + pSize)); })); EM_ASM({ diff --git a/src/bindings/javascript/main.cpp b/src/bindings/javascript/main.cpp index 0bfebee8c..925734c55 100644 --- a/src/bindings/javascript/main.cpp +++ b/src/bindings/javascript/main.cpp @@ -26,15 +26,15 @@ EMSCRIPTEN_BINDINGS(libOpenCOR) { // Vectors. - emscripten::register_vector("IssuePtrVector"); - emscripten::register_vector("SedAbstractTaskPtrVector"); - emscripten::register_vector("SedDataDescriptionPtrVector"); - emscripten::register_vector("SedDataGeneratorPtrVector"); - emscripten::register_vector("SedInstanceTaskPtrVector"); - emscripten::register_vector("SedModelPtrVector"); - emscripten::register_vector("SedOutputPtrVector"); - emscripten::register_vector("SedSimulationPtrVector"); - emscripten::register_vector("SedStylePtrVector"); + emscripten::register_vector("IssuePtrs"); + emscripten::register_vector("SedAbstractTaskPtrs"); + emscripten::register_vector("SedDataDescriptionPtrs"); + emscripten::register_vector("SedDataGeneratorPtrs"); + emscripten::register_vector("SedInstanceTaskPtrs"); + emscripten::register_vector("SedModelPtrs"); + emscripten::register_vector("SedOutputPtrs"); + emscripten::register_vector("SedSimulationPtrs"); + emscripten::register_vector("SedStylePtrs"); // APIs. diff --git a/src/file/file.cpp b/src/file/file.cpp index cf9bf3e31..7c26bf5f8 100644 --- a/src/file/file.cpp +++ b/src/file/file.cpp @@ -127,14 +127,14 @@ void File::Impl::retrieveContents() } #endif -void File::Impl::setContents(const UnsignedCharVector &pContents) +void File::Impl::setContents(const UnsignedChars &pContents) { mContents = pContents; mContentsRetrieved = true; } -UnsignedCharVector File::Impl::contents() +UnsignedChars File::Impl::contents() { #ifndef __EMSCRIPTEN__ retrieveContents(); @@ -207,12 +207,12 @@ std::string File::path() const return pimpl()->path(); } -UnsignedCharVector File::contents() +UnsignedChars File::contents() { return pimpl()->contents(); } -void File::setContents(const UnsignedCharVector &pContents) +void File::setContents(const UnsignedChars &pContents) { pimpl()->setContents(pContents); diff --git a/src/file/file_p.h b/src/file/file_p.h index 5d4afaf5c..f41d6ac6f 100644 --- a/src/file/file_p.h +++ b/src/file/file_p.h @@ -36,7 +36,7 @@ class File::Impl: public Logger::Impl std::string mUrl; bool mContentsRetrieved = false; - UnsignedCharVector mContents; + UnsignedChars mContents; CellmlFilePtr mCellmlFile; SedmlFilePtr mSedmlFile; @@ -53,8 +53,8 @@ class File::Impl: public Logger::Impl void retrieveContents(); #endif - UnsignedCharVector contents(); - void setContents(const UnsignedCharVector &pContents); + UnsignedChars contents(); + void setContents(const UnsignedChars &pContents); }; } // namespace libOpenCOR diff --git a/src/file/filemanager.h b/src/file/filemanager.h index 1db07e907..0bc0f2f67 100644 --- a/src/file/filemanager.h +++ b/src/file/filemanager.h @@ -35,7 +35,7 @@ class FileManager FilePtr file(const std::string &pFileNameOrUrl) const; private: - FileVector mFiles; + Files mFiles; }; } // namespace libOpenCOR diff --git a/src/logger/logger.cpp b/src/logger/logger.cpp index a59068435..3ddf4cc79 100644 --- a/src/logger/logger.cpp +++ b/src/logger/logger.cpp @@ -136,7 +136,7 @@ bool Logger::hasIssues() const return pimpl()->hasIssues(); } -IssuePtrVector Logger::issues() const +IssuePtrs Logger::issues() const { return pimpl()->mIssues; } @@ -146,7 +146,7 @@ bool Logger::hasErrors() const return pimpl()->hasErrors(); } -IssuePtrVector Logger::errors() const +IssuePtrs Logger::errors() const { return pimpl()->mErrors; } @@ -156,7 +156,7 @@ bool Logger::hasWarnings() const return pimpl()->hasWarnings(); } -IssuePtrVector Logger::warnings() const +IssuePtrs Logger::warnings() const { return pimpl()->mWarnings; } @@ -166,7 +166,7 @@ bool Logger::hasMessages() const return pimpl()->hasMessages(); } -IssuePtrVector Logger::messages() const +IssuePtrs Logger::messages() const { return pimpl()->mMessages; } diff --git a/src/logger/logger_p.h b/src/logger/logger_p.h index 4d92ceae1..154dbb66d 100644 --- a/src/logger/logger_p.h +++ b/src/logger/logger_p.h @@ -27,11 +27,11 @@ namespace libOpenCOR { class Logger::Impl { public: - IssuePtrVector mIssues; + IssuePtrs mIssues; - IssuePtrVector mErrors; - IssuePtrVector mWarnings; - IssuePtrVector mMessages; + IssuePtrs mErrors; + IssuePtrs mWarnings; + IssuePtrs mMessages; bool hasIssues() const; bool hasErrors() const; diff --git a/src/misc/compiler.cpp b/src/misc/compiler.cpp index a5e238a57..5bd6186d6 100644 --- a/src/misc/compiler.cpp +++ b/src/misc/compiler.cpp @@ -67,15 +67,15 @@ bool Compiler::Impl::compile(const std::string &pCode) // Get a compilation object to which we pass some arguments. static constexpr auto DUMMY_FILE_NAME = "dummy.c"; - static const ConstCharPtrVector COMPILATION_ARGUMENTS = {"clang", "-fsyntax-only", + static const ConstCharPtrs COMPILATION_ARGUMENTS = {"clang", "-fsyntax-only", #ifdef NDEBUG - "-O3", + "-O3", #else - "-g", "-O0", + "-g", "-O0", #endif - "-fno-math-errno", - "-fno-stack-protector", - DUMMY_FILE_NAME}; + "-fno-math-errno", + "-fno-stack-protector", + DUMMY_FILE_NAME}; std::unique_ptr compilation(driver.BuildCompilation(COMPILATION_ARGUMENTS)); diff --git a/src/misc/utils.cpp b/src/misc/utils.cpp index 467c01705..7c962525e 100644 --- a/src/misc/utils.cpp +++ b/src/misc/utils.cpp @@ -356,7 +356,7 @@ std::tuple downloadFile(const std::string &pUrl) #endif #ifndef __EMSCRIPTEN__ -UnsignedCharVector fileContents(const std::filesystem::path &pFilePath) +UnsignedChars fileContents(const std::filesystem::path &pFilePath) { // Retrieve and return the contents of the given file. @@ -367,7 +367,7 @@ UnsignedCharVector fileContents(const std::filesystem::path &pFilePath) } const auto fileSize = std::filesystem::file_size(pFilePath); - UnsignedCharVector contents(fileSize); + UnsignedChars contents(fileSize); file.read(reinterpret_cast(&contents[0]), static_cast(fileSize)); // NOLINT @@ -419,7 +419,7 @@ std::string toString(double pNumber) return res.str(); } -std::string toString(const UnsignedCharVector &pBytes) +std::string toString(const UnsignedChars &pBytes) { return {reinterpret_cast(pBytes.data()), pBytes.size()}; } diff --git a/src/misc/utils.h b/src/misc/utils.h index 42c916edc..409ea9349 100644 --- a/src/misc/utils.h +++ b/src/misc/utils.h @@ -35,8 +35,8 @@ namespace libOpenCOR { static const std::string LIBOPENCOR_NAMESPACE = "https://opencor.ws/libopencor"; -using ConstCharPtrVector = std::vector; -using FileVector = std::vector; +using ConstCharPtrs = std::vector; +using Files = std::vector; using StringStringMap = std::map; @@ -85,7 +85,7 @@ std::string urlPath(const std::string &pPath); #ifndef __EMSCRIPTEN__ std::tuple downloadFile(const std::string &pUrl); -UnsignedCharVector LIBOPENCOR_UNIT_TESTING_EXPORT fileContents(const std::filesystem::path &pFilePath); +UnsignedChars LIBOPENCOR_UNIT_TESTING_EXPORT fileContents(const std::filesystem::path &pFilePath); #endif char LIBOPENCOR_UNIT_TESTING_EXPORT *nlaSolverAddress(SolverNla *pNlaSolver); @@ -93,7 +93,7 @@ char LIBOPENCOR_UNIT_TESTING_EXPORT *nlaSolverAddress(SolverNla *pNlaSolver); std::string toString(int pNumber); std::string toString(size_t pNumber); std::string toString(double pNumber); -std::string LIBOPENCOR_UNIT_TESTING_EXPORT toString(const UnsignedCharVector &pBytes); +std::string LIBOPENCOR_UNIT_TESTING_EXPORT toString(const UnsignedChars &pBytes); const xmlChar *toConstXmlCharPtr(const std::string &pString); diff --git a/src/sed/seddocument.cpp b/src/sed/seddocument.cpp index 6df963b38..562ec6da9 100644 --- a/src/sed/seddocument.cpp +++ b/src/sed/seddocument.cpp @@ -435,7 +435,7 @@ bool SedDocument::hasModels() const return pimpl()->hasModels(); } -SedModelPtrVector SedDocument::models() const +SedModelPtrs SedDocument::models() const { return pimpl()->mModels; } @@ -455,7 +455,7 @@ bool SedDocument::hasSimulations() const return pimpl()->hasSimulations(); } -SedSimulationPtrVector SedDocument::simulations() const +SedSimulationPtrs SedDocument::simulations() const { return pimpl()->mSimulations; } @@ -475,7 +475,7 @@ bool SedDocument::hasTasks() const return pimpl()->hasTasks(); } -SedAbstractTaskPtrVector SedDocument::tasks() const +SedAbstractTaskPtrs SedDocument::tasks() const { return pimpl()->mTasks; } diff --git a/src/sed/seddocument_p.h b/src/sed/seddocument_p.h index 196d16992..d53f22a1d 100644 --- a/src/sed/seddocument_p.h +++ b/src/sed/seddocument_p.h @@ -33,13 +33,13 @@ class SedDocument::Impl: public Logger::Impl std::unordered_set mIds; - SedDataDescriptionPtrVector mDataDescriptions; - SedModelPtrVector mModels; - SedSimulationPtrVector mSimulations; - SedAbstractTaskPtrVector mTasks; - SedDataGeneratorPtrVector mDataGenerators; - SedOutputPtrVector mOutputs; - SedStylePtrVector mStyles; + SedDataDescriptionPtrs mDataDescriptions; + SedModelPtrs mModels; + SedSimulationPtrs mSimulations; + SedAbstractTaskPtrs mTasks; + SedDataGeneratorPtrs mDataGenerators; + SedOutputPtrs mOutputs; + SedStylePtrs mStyles; std::string uniqueId(const std::string &pPrefix); diff --git a/src/sed/sedinstance_p.h b/src/sed/sedinstance_p.h index 7b07b121c..95adb5873 100644 --- a/src/sed/sedinstance_p.h +++ b/src/sed/sedinstance_p.h @@ -27,7 +27,7 @@ class SedInstance::Impl: public Logger::Impl public: static SedInstancePtr create(const SedDocumentPtr &pDocument); - SedInstanceTaskPtrVector mTasks; + SedInstanceTaskPtrs mTasks; explicit Impl(const SedDocumentPtr &pDocument); diff --git a/src/solver/solverkinsol.cpp b/src/solver/solverkinsol.cpp index 88e94a85b..1086d962f 100644 --- a/src/solver/solverkinsol.cpp +++ b/src/solver/solverkinsol.cpp @@ -155,15 +155,15 @@ bool SolverKinsol::Impl::solve(ComputeSystem pComputeSystem, double *pU, size_t // Initialise our KINSOL solver. - auto *uVector = N_VMake_Serial(static_cast(pN), pU, context); - auto *onesVector = N_VNew_Serial(static_cast(pN), context); + auto *u = N_VMake_Serial(static_cast(pN), pU, context); + auto *ones = N_VNew_Serial(static_cast(pN), context); - ASSERT_NE(uVector, nullptr); - ASSERT_NE(onesVector, nullptr); + ASSERT_NE(u, nullptr); + ASSERT_NE(ones, nullptr); - N_VConst(1.0, onesVector); + N_VConst(1.0, ones); - ASSERT_EQ(KINInit(solver, computeSystem, uVector), KIN_SUCCESS); + ASSERT_EQ(KINInit(solver, computeSystem, u), KIN_SUCCESS); // Set our linear solver. @@ -175,7 +175,7 @@ bool SolverKinsol::Impl::solve(ComputeSystem pComputeSystem, double *pU, size_t ASSERT_NE(sunMatrix, nullptr); - sunLinearSolver = SUNLinSol_Dense(uVector, sunMatrix, context); + sunLinearSolver = SUNLinSol_Dense(u, sunMatrix, context); } else if (mLinearSolver == LinearSolver::BANDED) { sunMatrix = SUNBandMatrix(static_cast(pN), static_cast(mUpperHalfBandwidth), static_cast(mLowerHalfBandwidth), @@ -183,16 +183,16 @@ bool SolverKinsol::Impl::solve(ComputeSystem pComputeSystem, double *pU, size_t ASSERT_NE(sunMatrix, nullptr); - sunLinearSolver = SUNLinSol_Band(uVector, sunMatrix, context); + sunLinearSolver = SUNLinSol_Band(u, sunMatrix, context); } else { sunMatrix = nullptr; if (mLinearSolver == LinearSolver::GMRES) { - sunLinearSolver = SUNLinSol_SPGMR(uVector, PREC_NONE, 0, context); + sunLinearSolver = SUNLinSol_SPGMR(u, PREC_NONE, 0, context); } else if (mLinearSolver == LinearSolver::BICGSTAB) { - sunLinearSolver = SUNLinSol_SPBCGS(uVector, PREC_NONE, 0, context); + sunLinearSolver = SUNLinSol_SPBCGS(u, PREC_NONE, 0, context); } else { - sunLinearSolver = SUNLinSol_SPTFQMR(uVector, PREC_NONE, 0, context); + sunLinearSolver = SUNLinSol_SPTFQMR(u, PREC_NONE, 0, context); } } @@ -218,12 +218,12 @@ bool SolverKinsol::Impl::solve(ComputeSystem pComputeSystem, double *pU, size_t #ifndef CODE_COVERAGE_ENABLED auto res = #endif - KINSol(solver, uVector, KIN_LINESEARCH, onesVector, onesVector); + KINSol(solver, u, KIN_LINESEARCH, ones, ones); // Release some memory. - N_VDestroy_Serial(uVector); - N_VDestroy_Serial(onesVector); + N_VDestroy_Serial(u); + N_VDestroy_Serial(ones); SUNMatDestroy(sunMatrix); SUNLinSolFree(sunLinearSolver); diff --git a/tests/api/file/basictests.cpp b/tests/api/file/basictests.cpp index 5115456f4..8bedf3479 100644 --- a/tests/api/file/basictests.cpp +++ b/tests/api/file/basictests.cpp @@ -102,12 +102,12 @@ TEST(BasicFileTest, localVirtualFile) EXPECT_TRUE(file->contents().empty()); EXPECT_EQ_ISSUES(file, EXPECTED_NON_EXISTING_FILE_ISSUES); - auto someUnknownContentsVector = libOpenCOR::charArrayToVector(libOpenCOR::SOME_UNKNOWN_CONTENTS); + auto someUnknownContents = libOpenCOR::charArrayToUnsignedChars(libOpenCOR::SOME_UNKNOWN_CONTENTS); - file->setContents(someUnknownContentsVector); + file->setContents(someUnknownContents); EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); - EXPECT_EQ(file->contents(), someUnknownContentsVector); + EXPECT_EQ(file->contents(), someUnknownContents); EXPECT_EQ_ISSUES(file, EXPECTED_UNKNOWN_FILE_ISSUES); } @@ -122,11 +122,11 @@ TEST(BasicFileTest, remoteVirtualFile) EXPECT_TRUE(file->contents().empty()); EXPECT_EQ_ISSUES(file, EXPECTED_NON_DOWNLOADABLE_FILE_ISSUES); - auto someUnknownContentsVector = libOpenCOR::charArrayToVector(libOpenCOR::SOME_UNKNOWN_CONTENTS); + auto someUnknownContents = libOpenCOR::charArrayToUnsignedChars(libOpenCOR::SOME_UNKNOWN_CONTENTS); - file->setContents(someUnknownContentsVector); + file->setContents(someUnknownContents); EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); - EXPECT_EQ(file->contents(), someUnknownContentsVector); + EXPECT_EQ(file->contents(), someUnknownContents); EXPECT_EQ_ISSUES(file, EXPECTED_UNKNOWN_FILE_ISSUES); } diff --git a/tests/api/file/typetests.cpp b/tests/api/file/typetests.cpp index 0e5b5f408..7b62572c0 100644 --- a/tests/api/file/typetests.cpp +++ b/tests/api/file/typetests.cpp @@ -103,7 +103,7 @@ TEST(TypeFileTest, unknownVirtualFile) { auto file = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); - file->setContents(libOpenCOR::charArrayToVector(libOpenCOR::SOME_UNKNOWN_CONTENTS)); + file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::SOME_UNKNOWN_CONTENTS)); EXPECT_EQ(file->type(), libOpenCOR::File::Type::UNKNOWN_FILE); EXPECT_EQ_ISSUES(file, EXPECTED_UNKNOWN_FILE_ISSUES); @@ -113,7 +113,7 @@ TEST(TypeFileTest, cellmlVirtualFile) { auto file = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); - file->setContents(libOpenCOR::charArrayToVector(libOpenCOR::SOME_CELLML_CONTENTS)); + file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::SOME_CELLML_CONTENTS)); EXPECT_EQ(file->type(), libOpenCOR::File::Type::CELLML_FILE); } @@ -122,7 +122,7 @@ TEST(TypeFileTest, sedmlVirtualFile) { auto file = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); - file->setContents(libOpenCOR::charArrayToVector(libOpenCOR::SOME_SEDML_CONTENTS)); + file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::SOME_SEDML_CONTENTS)); EXPECT_EQ(file->type(), libOpenCOR::File::Type::SEDML_FILE); } diff --git a/tests/api/sed/serialisetests.cpp b/tests/api/sed/serialisetests.cpp index 1a38159d3..60b575e2d 100644 --- a/tests/api/sed/serialisetests.cpp +++ b/tests/api/sed/serialisetests.cpp @@ -126,7 +126,7 @@ TEST(SerialiseSedTest, localCellmlFileWithoutBasePath) { auto file = libOpenCOR::File::create(libOpenCOR::LOCAL_FILE); - file->setContents(libOpenCOR::charArrayToVector(libOpenCOR::SOME_CELLML_CONTENTS)); + file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::SOME_CELLML_CONTENTS)); auto sed = libOpenCOR::SedDocument::create(file); @@ -149,7 +149,7 @@ TEST(SerialiseSedTest, relativeLocalCellmlFileWithoutBasePath) { auto file = libOpenCOR::File::create(libOpenCOR::CELLML_2_FILE); - file->setContents(libOpenCOR::charArrayToVector(libOpenCOR::SOME_CELLML_CONTENTS)); + file->setContents(libOpenCOR::charArrayToUnsignedChars(libOpenCOR::SOME_CELLML_CONTENTS)); auto sed = libOpenCOR::SedDocument::create(file); diff --git a/tests/utils.cpp b/tests/utils.cpp index 0e3f06904..58dcf7636 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -76,7 +76,7 @@ std::string textFileContents(const std::string &pFileName) return regex_replace(res, CR_LF, "\n"); } -UnsignedCharVector charArrayToVector(const char *pContents) +UnsignedChars charArrayToUnsignedChars(const char *pContents) { return {pContents, pContents + strlen(pContents)}; // NOLINT } diff --git a/tests/utils.h.in b/tests/utils.h.in index 4b39a086e..bdc549292 100644 --- a/tests/utils.h.in +++ b/tests/utils.h.in @@ -91,6 +91,6 @@ void expectEqualDoubles(double *pDoubles, const Doubles &pExpectedDoubles, const std::string resourcePath(const std::string &pResourceRelativePath = {}); std::string textFileContents(const std::string &pFileName); -UnsignedCharVector charArrayToVector(const char *pContents); +UnsignedChars charArrayToUnsignedChars(const char *pContents); } // namespace libOpenCOR From f15b95e08f81014aa7bdc710f497f13efb976215 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 30 Apr 2024 01:03:42 +1200 Subject: [PATCH 2/5] Issue: swapped the order of the type and description of an issue. --- src/api/libopencor/issue.h | 2 +- src/logger/issue.cpp | 6 +++--- src/logger/issue_p.h | 2 +- src/logger/logger.cpp | 24 ++++++++++++------------ src/logger/logger_p.h | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/api/libopencor/issue.h b/src/api/libopencor/issue.h index f6e3f5a74..b32a78de9 100644 --- a/src/api/libopencor/issue.h +++ b/src/api/libopencor/issue.h @@ -85,7 +85,7 @@ class LIBOPENCOR_EXPORT Issue Impl *mPimpl; - explicit Issue(const std::string &pDescription, Type pType); /**< Constructor, @private. */ + explicit Issue(Type pType, const std::string &pDescription); /**< Constructor, @private. */ }; } // namespace libOpenCOR diff --git a/src/logger/issue.cpp b/src/logger/issue.cpp index 57820ee49..7edd52174 100644 --- a/src/logger/issue.cpp +++ b/src/logger/issue.cpp @@ -18,14 +18,14 @@ limitations under the License. namespace libOpenCOR { -Issue::Impl::Impl(std::string pDescription, Type pType) +Issue::Impl::Impl(Type pType, const std::string &pDescription) : mType(pType) , mDescription(std::move(pDescription)) { } -Issue::Issue(const std::string &pDescription, Type pType) - : mPimpl(new Impl {pDescription, pType}) +Issue::Issue(Type pType, const std::string &pDescription) + : mPimpl(new Impl {pType, pDescription}) { } diff --git a/src/logger/issue_p.h b/src/logger/issue_p.h index f924012e4..0a5dd9258 100644 --- a/src/logger/issue_p.h +++ b/src/logger/issue_p.h @@ -26,7 +26,7 @@ class Issue::Impl Type mType; std::string mDescription; - explicit Impl(std::string pDescription, Type pType); + explicit Impl(Type pType, const std::string &pDescription); ~Impl() = default; }; diff --git a/src/logger/logger.cpp b/src/logger/logger.cpp index 3ddf4cc79..271d7bb9c 100644 --- a/src/logger/logger.cpp +++ b/src/logger/logger.cpp @@ -42,7 +42,7 @@ bool Logger::Impl::hasMessages() const void Logger::Impl::addIssues(const LoggerPtr &pLogger) { for (const auto &issue : pLogger->issues()) { - addIssue(issue->description(), issue->type()); + addIssue(issue->type(), issue->description()); } } @@ -52,21 +52,21 @@ void Logger::Impl::addIssues(const libcellml::LoggerPtr &pLogger) auto issue = pLogger->issue(i); #ifdef CODE_COVERAGE_ENABLED //---GRY--- SHOULD BE REMOVED AT SOME POINT. - addIssue(issue->description(), - (issue->level() == libcellml::Issue::Level::ERROR) ? Issue::Type::ERROR : - Issue::Type::WARNING); + addIssue((issue->level() == libcellml::Issue::Level::ERROR) ? Issue::Type::ERROR : + Issue::Type::WARNING, + issue->description()); #else - addIssue(issue->description(), - (issue->level() == libcellml::Issue::Level::ERROR) ? Issue::Type::ERROR : + addIssue((issue->level() == libcellml::Issue::Level::ERROR) ? Issue::Type::ERROR : (issue->level() == libcellml::Issue::Level::WARNING) ? Issue::Type::WARNING : - Issue::Type::MESSAGE); + Issue::Type::MESSAGE, + issue->description()); #endif } } -void Logger::Impl::addIssue(const std::string &pDescription, Issue::Type pType) +void Logger::Impl::addIssue(Issue::Type pType, const std::string &pDescription) { - auto issue = IssuePtr {new Issue {pDescription, pType}}; + auto issue = IssuePtr {new Issue {pType, pDescription}}; mIssues.push_back(issue); #ifdef CODE_COVERAGE_ENABLED //---GRY--- SHOULD BE REMOVED AT SOME POINT. @@ -92,19 +92,19 @@ void Logger::Impl::addIssue(const std::string &pDescription, Issue::Type pType) void Logger::Impl::addError(const std::string &pDescription) { - addIssue(pDescription, Issue::Type::ERROR); + addIssue(Issue::Type::ERROR, pDescription); } /*---GRY--- void Logger::Impl::addWarning(const std::string &pDescription) { - addIssue(pDescription, Issue::Type::WARNING); + addIssue(Issue::Type::WARNING, pDescription); } */ void Logger::Impl::addMessage(const std::string &pDescription) { - addIssue(pDescription, Issue::Type::MESSAGE); + addIssue(Issue::Type::MESSAGE, pDescription); } void Logger::Impl::removeAllIssues() diff --git a/src/logger/logger_p.h b/src/logger/logger_p.h index 154dbb66d..9372c3a70 100644 --- a/src/logger/logger_p.h +++ b/src/logger/logger_p.h @@ -41,7 +41,7 @@ class Logger::Impl void addIssues(const LoggerPtr &pLogger); void addIssues(const libcellml::LoggerPtr &pLogger); - void addIssue(const std::string &pDescription, Issue::Type pType); + void addIssue(Issue::Type pType, const std::string &pDescription); void addError(const std::string &pDescription); void addWarning(const std::string &pDescription); From 003cc1b83a127c1e24551dc4620f8a8cd3342f3b Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 30 Apr 2024 01:07:20 +1200 Subject: [PATCH 3/5] Address code analysis issue. --- src/logger/issue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logger/issue.cpp b/src/logger/issue.cpp index 7edd52174..58b3cf773 100644 --- a/src/logger/issue.cpp +++ b/src/logger/issue.cpp @@ -20,7 +20,7 @@ namespace libOpenCOR { Issue::Impl::Impl(Type pType, const std::string &pDescription) : mType(pType) - , mDescription(std::move(pDescription)) + , mDescription(pDescription) { } From 1c562ed67b013aad6ee60fa99e5afd83e2c82698 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 30 Apr 2024 01:20:16 +1200 Subject: [PATCH 4/5] CI: updated the location of LLVM for our coverage tests on macOS. --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7af8097b8..35387679d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -234,7 +234,7 @@ jobs: python_unit_testing: OFF shared_libs: ON unit_testing: ON - context: PATH=/usr/local/opt/llvm/bin:$PATH CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++ + context: PATH=/opt/homebrew/opt/llvm/bin:$PATH CC=/opt/homebrew/opt/llvm/bin/clang CXX=/opt/homebrew/opt/llvm/bin/clang++ target: code_coverage - name: 'Memory checks' os: ubuntu-latest @@ -285,7 +285,9 @@ jobs: uses: ilammy/msvc-dev-cmd@v1 - name: Install LLVM if: ${{ matrix.target == 'code_coverage' }} - run: brew install --overwrite llvm + run: | + brew install --overwrite llvm + brew info llvm - name: Install Clang if: ${{ matrix.name == 'Code analysis' }} run: | From 046fad523a5e36def26a1795f46e15d535d67f3e Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 30 Apr 2024 01:33:39 +1200 Subject: [PATCH 5/5] CI: addressed issue for our macOS Python bindings test. --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35387679d..943ca7686 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -274,6 +274,10 @@ jobs: steps: - name: Check out libOpenCOR uses: actions/checkout@v3 + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' - name: Install CMake and Ninja uses: lukka/get-cmake@latest - name: Install buildcache