From 3e928e20f0fc1f322ce59368befab2fd466880ee Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Wed, 6 May 2020 11:26:02 +1200 Subject: [PATCH 01/29] Test showing printer missing equivalent variables --- tests/printer/printer.cpp | 15 +++++++++++++++ tests/resources/importedModel.cellml | 6 ++++++ tests/resources/importingModel.cellml | 12 ++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 tests/resources/importedModel.cellml create mode 100644 tests/resources/importingModel.cellml diff --git a/tests/printer/printer.cpp b/tests/printer/printer.cpp index 8433d2da5..59e51919b 100644 --- a/tests/printer/printer.cpp +++ b/tests/printer/printer.cpp @@ -252,3 +252,18 @@ TEST(Printer, printModelWithStandardUnitsAdded) libcellml::PrinterPtr printer = libcellml::Printer::create(); EXPECT_EQ(e, printer->printModel(model)); } + +TEST(Printer, printModelWithEquivVariables) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("importingModel.cellml")); + + auto validator = libcellml::Validator::create(); + validator->validateModel(model); + EXPECT_EQ(size_t(0), validator->issueCount()); + + auto printer = libcellml::Printer::create(); + auto serialisedModel = printer->printModel(model); + + EXPECT_EQ(serialisedModel, fileContents("importingModel.cellml")); +} diff --git a/tests/resources/importedModel.cellml b/tests/resources/importedModel.cellml new file mode 100644 index 000000000..6716b0a4e --- /dev/null +++ b/tests/resources/importedModel.cellml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/resources/importingModel.cellml b/tests/resources/importingModel.cellml new file mode 100644 index 000000000..b9c40f0f2 --- /dev/null +++ b/tests/resources/importingModel.cellml @@ -0,0 +1,12 @@ + + + + + + + + + + + + From 9c701e0a752c1b9fc4e77eda3670d9b5601a2492 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Wed, 6 May 2020 11:40:04 +1200 Subject: [PATCH 02/29] Second test to show what I'd want to be able to do ... --- tests/variable/variable.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/variable/variable.cpp b/tests/variable/variable.cpp index 5cd6de034..271beb518 100644 --- a/tests/variable/variable.cpp +++ b/tests/variable/variable.cpp @@ -1699,3 +1699,38 @@ TEST(Variable, variableInterfaceDontDowngrade) EXPECT_EQ("", v3->interfaceType()); EXPECT_EQ("public", v4->interfaceType()); } + +TEST(Variable, addEquivalenceToImportedVariable) +{ + // This won't work ... but it's what I'd want to be able to do ... + auto model = libcellml::Model::create("importing_model"); + + // Set up the local component + auto localComponent = libcellml::Component::create("localComponent"); + auto x = libcellml::Variable::create("x"); + x->setUnits("dimensionless"); + x->setInterfaceType("public_and_private"); + + // Set up the imported component + auto importedComponent = libcellml::Component::create("importedComponent"); + model->addComponent(importedComponent); + + auto importer = libcellml::ImportSource::create(); + importer->setUrl("importedModel.cellml"); + importedComponent->setImportSource(importer); + importedComponent->setImportReference("importMe"); + + // Create equivalent variables: THIS BIT I DON'T KNOW HOW TO DO! + // The importedComponent is not instantiated, so can't point to any of its variables... + // libcellml::Variable::addEquivalence(x, importedComponent->variable("x")); + libcellml::Variable::addEquivalence(localComponent, "x", importedComponent, "x"); + + auto validator = libcellml::Validator::create(); + validator->validateModel(model); + + auto printer = libcellml::Printer::create(); + auto serialisedModel = printer->printModel(model); + + EXPECT_EQ(serialisedModel, fileContents("importingModel.cellml")); + +} From 56274ba05609c071295f8a769f8b7d28c50321d3 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Wed, 27 May 2020 17:40:24 +1200 Subject: [PATCH 03/29] Revert "Second test to show what I'd want to be able to do ..." This reverts commit 9c701e0a752c1b9fc4e77eda3670d9b5601a2492. --- tests/variable/variable.cpp | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/tests/variable/variable.cpp b/tests/variable/variable.cpp index 271beb518..5cd6de034 100644 --- a/tests/variable/variable.cpp +++ b/tests/variable/variable.cpp @@ -1699,38 +1699,3 @@ TEST(Variable, variableInterfaceDontDowngrade) EXPECT_EQ("", v3->interfaceType()); EXPECT_EQ("public", v4->interfaceType()); } - -TEST(Variable, addEquivalenceToImportedVariable) -{ - // This won't work ... but it's what I'd want to be able to do ... - auto model = libcellml::Model::create("importing_model"); - - // Set up the local component - auto localComponent = libcellml::Component::create("localComponent"); - auto x = libcellml::Variable::create("x"); - x->setUnits("dimensionless"); - x->setInterfaceType("public_and_private"); - - // Set up the imported component - auto importedComponent = libcellml::Component::create("importedComponent"); - model->addComponent(importedComponent); - - auto importer = libcellml::ImportSource::create(); - importer->setUrl("importedModel.cellml"); - importedComponent->setImportSource(importer); - importedComponent->setImportReference("importMe"); - - // Create equivalent variables: THIS BIT I DON'T KNOW HOW TO DO! - // The importedComponent is not instantiated, so can't point to any of its variables... - // libcellml::Variable::addEquivalence(x, importedComponent->variable("x")); - libcellml::Variable::addEquivalence(localComponent, "x", importedComponent, "x"); - - auto validator = libcellml::Validator::create(); - validator->validateModel(model); - - auto printer = libcellml::Printer::create(); - auto serialisedModel = printer->printModel(model); - - EXPECT_EQ(serialisedModel, fileContents("importingModel.cellml")); - -} From b0d28e2f8de1629e253f51a05b3731efe838c639 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Thu, 28 May 2020 09:13:30 +1200 Subject: [PATCH 04/29] Added more tests to show encapsulations with imports not parsed --- tests/parser/file_parser.cpp | 54 +++++++++ tests/printer/printer.cpp | 15 --- .../importedModelWithCustomUnits.cellml | 9 ++ .../importedModelWithCustomUnits1.cellml | 9 ++ .../importedModelWithCustomUnits2.cellml | 9 ++ tests/resources/importedModelWithMaps.cellml | 21 ++++ ...portedModelWithMapsOfDifferentUnits.cellml | 27 +++++ .../importingModelChildComponent.cellml | 14 +++ .../importingModelParentComponent.cellml | 14 +++ tests/test_utils.cpp | 114 ++++++++++-------- tests/test_utils.h | 8 +- tests/variable/variable.cpp | 109 +++++++++++++++++ 12 files changed, 339 insertions(+), 64 deletions(-) create mode 100644 tests/resources/importedModelWithCustomUnits.cellml create mode 100644 tests/resources/importedModelWithCustomUnits1.cellml create mode 100644 tests/resources/importedModelWithCustomUnits2.cellml create mode 100644 tests/resources/importedModelWithMaps.cellml create mode 100644 tests/resources/importedModelWithMapsOfDifferentUnits.cellml create mode 100644 tests/resources/importingModelChildComponent.cellml create mode 100644 tests/resources/importingModelParentComponent.cellml diff --git a/tests/parser/file_parser.cpp b/tests/parser/file_parser.cpp index 377ce6b21..ad5798ebb 100644 --- a/tests/parser/file_parser.cpp +++ b/tests/parser/file_parser.cpp @@ -155,3 +155,57 @@ TEST(Parser, simpleGeneratorModel) std::string a = model->component("my_component")->math(); EXPECT_EQ(e, a); } + +TEST(Parser, parseModelWithImportedEquivVariables) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("importingModel.cellml")); + + printModelToTerminal(model); + printIssues(parser); + + auto validator = libcellml::Validator::create(); + validator->validateModel(model); + EXPECT_EQ(size_t(0), validator->issueCount()); + + auto printer = libcellml::Printer::create(); + auto serialisedModel = printer->printModel(model); + + EXPECT_EQ(serialisedModel, fileContents("importingModel.cellml")); +} + +TEST(Parser, parseModelImportingModelParentComponent) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("importingModelParentComponent.cellml")); + + printModelToTerminal(model); + printIssues(parser); + + auto validator = libcellml::Validator::create(); + validator->validateModel(model); + EXPECT_EQ(size_t(0), validator->issueCount()); + + auto printer = libcellml::Printer::create(); + auto serialisedModel = printer->printModel(model); + + EXPECT_EQ(serialisedModel, fileContents("importingModelParentComponent.cellml")); +} + +TEST(Parser, parseModelWithImportedEncapsulation2) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("importingModelChildComponent.cellml")); + + printModelToTerminal(model); + printIssues(parser); + + auto validator = libcellml::Validator::create(); + validator->validateModel(model); + EXPECT_EQ(size_t(0), validator->issueCount()); + + auto printer = libcellml::Printer::create(); + auto serialisedModel = printer->printModel(model); + + EXPECT_EQ(serialisedModel, fileContents("importingModelChildComponent.cellml")); +} diff --git a/tests/printer/printer.cpp b/tests/printer/printer.cpp index fd01d0626..d074e1798 100644 --- a/tests/printer/printer.cpp +++ b/tests/printer/printer.cpp @@ -254,18 +254,3 @@ TEST(Printer, printModelWithStandardUnitsAdded) libcellml::PrinterPtr printer = libcellml::Printer::create(); EXPECT_EQ(e, printer->printModel(model)); } - -TEST(Printer, printModelWithEquivVariables) -{ - auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("importingModel.cellml")); - - auto validator = libcellml::Validator::create(); - validator->validateModel(model); - EXPECT_EQ(size_t(0), validator->issueCount()); - - auto printer = libcellml::Printer::create(); - auto serialisedModel = printer->printModel(model); - - EXPECT_EQ(serialisedModel, fileContents("importingModel.cellml")); -} diff --git a/tests/resources/importedModelWithCustomUnits.cellml b/tests/resources/importedModelWithCustomUnits.cellml new file mode 100644 index 000000000..22d5c96b6 --- /dev/null +++ b/tests/resources/importedModelWithCustomUnits.cellml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/resources/importedModelWithCustomUnits1.cellml b/tests/resources/importedModelWithCustomUnits1.cellml new file mode 100644 index 000000000..705ca2e69 --- /dev/null +++ b/tests/resources/importedModelWithCustomUnits1.cellml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/resources/importedModelWithCustomUnits2.cellml b/tests/resources/importedModelWithCustomUnits2.cellml new file mode 100644 index 000000000..18d43564a --- /dev/null +++ b/tests/resources/importedModelWithCustomUnits2.cellml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/resources/importedModelWithMaps.cellml b/tests/resources/importedModelWithMaps.cellml new file mode 100644 index 000000000..6dbce72f8 --- /dev/null +++ b/tests/resources/importedModelWithMaps.cellml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/resources/importedModelWithMapsOfDifferentUnits.cellml b/tests/resources/importedModelWithMapsOfDifferentUnits.cellml new file mode 100644 index 000000000..d7ce2b834 --- /dev/null +++ b/tests/resources/importedModelWithMapsOfDifferentUnits.cellml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/resources/importingModelChildComponent.cellml b/tests/resources/importingModelChildComponent.cellml new file mode 100644 index 000000000..765840271 --- /dev/null +++ b/tests/resources/importingModelChildComponent.cellml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/tests/resources/importingModelParentComponent.cellml b/tests/resources/importingModelParentComponent.cellml new file mode 100644 index 000000000..2ccd0cb99 --- /dev/null +++ b/tests/resources/importingModelParentComponent.cellml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index 686c4b341..4c3143647 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -58,83 +58,103 @@ void printIssues(const libcellml::LoggerPtr &l, bool headings, bool causes, bool } } -void printModel(const libcellml::ModelPtr &model) +void printModelToTerminal(libcellml::ModelPtr &model) { - std::cout << "The model name is: '" << model->name() << "'" << std::endl; + printModelToTerminal(model, true); +} + +void printModelToTerminal(libcellml::ModelPtr &model, bool includeMaths) +{ + std::string spacer = " "; + + std::cout << " MODEL: '" << model->name() << "'"; if (model->id() != "") { - std::cout << "The model id is: '" << model->id() << "'" << std::endl; + std::cout << ", id: '" << model->id() << "'"; } + std::cout << std::endl; - // 2.a Print any custom units of the model - std::cout << "The model defines " << model->unitsCount() - << " custom units:" << std::endl; + std::cout << spacer << "UNITS: " << model->unitsCount() << " custom units" << std::endl; for (size_t u = 0; u < model->unitsCount(); ++u) { - std::cout << " Units[" << u << "] is '" << model->units(u)->name() << "'" - << std::endl; + std::cout << spacer << spacer << "[" << u << "]: " << model->units(u)->name() << std::endl; } - // 2.b Print the components of the model - std::cout << "The model has " << model->componentCount() - << " components:" << std::endl; + std::cout << spacer << "COMPONENTS: " << model->componentCount() << " components" << std::endl; for (size_t c = 0; c < model->componentCount(); ++c) { - // 2.c Printing the attributes of the component auto component = model->component(c); - std::string spacer = " "; - printComponent(component, c, spacer); + printComponentToTerminal(component, c, spacer + spacer, includeMaths); } } -void printComponent(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer) +void printComponentToTerminal(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer) +{ + printComponentToTerminal(component, c, spacer, true); +} + +void printComponentToTerminal(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer, bool includeMaths) { - std::cout << spacer << "Component[" << c << "] has name: '" - << component->name() << "'" << std::endl; + std::string local = " "; + + std::cout << spacer << "[" << c << "]: " << component->name(); if (component->id() != "") { - std::cout << spacer << "Component[" << c << "] has id: '" - << component->id() << "'" << std::endl; + std::cout << " id: " << component->id(); } + std::cout << std::endl; - std::cout << spacer << "Component[" << c << "] has " - << component->variableCount() - << " variables:" << std::endl; - - // Printing the variables within the component - for (size_t vIndex = 0; vIndex < component->variableCount(); vIndex++) { - auto v = component->variable(vIndex); - std::cout << spacer << " Variable[" << vIndex << "] has name: '" - << v->name() << "'" << std::endl; - if (v->initialValue() != "") { - std::cout << spacer << " Variable[" << vIndex << "] has initial_value: '" - << v->initialValue() << "'" - << std::endl; - } - if (v->units() != nullptr) { - std::cout << spacer << " Variable[" << vIndex << "] has units: '" - << v->units()->name() << "'" << std::endl; + std::cout << spacer << local << "VARIABLES: " << component->variableCount() << " variables" << std::endl; + + // Printing the variables within the component. + for (size_t v = 0; v < component->variableCount(); v++) { + std::cout << spacer << local << local; + std::cout << "[" << v << "]: " << component->variable(v)->name(); + if (component->variable(v)->units() != nullptr) { + std::cout << " [" << component->variable(v)->units()->name() << "]"; } - std::cout << spacer << " Variable[" << vIndex << "] has " << v->equivalentVariableCount() << " equivalent variable(s): "; - for (size_t eIndex = 0; eIndex < v->equivalentVariableCount(); ++eIndex) { - auto equivVariable = v->equivalentVariable(eIndex); - std::cout << equivVariable->name() << ", "; + if (component->variable(v)->initialValue() != "") { + std::cout << ", initial = " << component->variable(v)->initialValue(); } std::cout << std::endl; + if (component->variable(v)->equivalentVariableCount() > 0) { + std::cout << spacer << local << local << local; + std::string con = " └──> "; + for (size_t e = 0; e < component->variable(v)->equivalentVariableCount(); ++e) { + auto ev = component->variable(v)->equivalentVariable(e); + if (ev == nullptr) { + std::cout << "WHOOPS! Null equivalent variable!"; + continue; + } + libcellml::ComponentPtr ev_parent = std::dynamic_pointer_cast(ev->parent()); + if (ev_parent == nullptr) { + std::cout << "WHOOPS! Null parent component for equivalent variable!"; + continue; + } + std::cout << con << ev_parent->name() << ":" << ev->name(); + if (ev->units() != nullptr) { + std::cout << " [" << ev->units()->name() << "]"; + } + con = ", "; + } + std::cout << std::endl; + } } - // Print the maths within the component - if (component->math() != "") { - std::cout << spacer << " Maths in the component is:" << std::endl; - std::cout << component->math() << std::endl; + // Print the maths within the component. + if (includeMaths) { + if (component->math() != "") { + std::cout << spacer << " Maths in the component is:" << std::endl; + std::cout << component->math() << std::endl; + } } // Print the encapsulated components if (component->componentCount() > 0) { - std::cout << spacer << "Component[" << c << "] has " + std::cout << spacer << local << "COMPONENT " << component->name() << " has " << component->componentCount() << " child components:" << std::endl; for (size_t c2 = 0; c2 < component->componentCount(); c2++) { auto child = component->component(c2); - std::string oneMoreSpacer = spacer + " "; - printComponent(child, c2, oneMoreSpacer); + std::string oneMoreSpacer = spacer + local + local; + printComponentToTerminal(child, c2, oneMoreSpacer, includeMaths); } } } diff --git a/tests/test_utils.h b/tests/test_utils.h index 64ec9f64a..c0b78e622 100644 --- a/tests/test_utils.h +++ b/tests/test_utils.h @@ -76,8 +76,12 @@ struct Debug std::string TEST_EXPORT resourcePath(const std::string &resourceRelativePath = ""); std::string TEST_EXPORT fileContents(const std::string &fileName); void TEST_EXPORT printIssues(const libcellml::LoggerPtr &l, bool headings = false, bool causes = false, bool rule = false); -void TEST_EXPORT printComponent(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer); -void TEST_EXPORT printModel(const libcellml::ModelPtr &model); + +void TEST_EXPORT printModelToTerminal(libcellml::ModelPtr &model); +void TEST_EXPORT printModelToTerminal(libcellml::ModelPtr &model, bool includeMaths); +void TEST_EXPORT printComponentToTerminal(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer); +void TEST_EXPORT printComponentToTerminal(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer, bool includeMaths); + void TEST_EXPORT expectEqualIssues(const std::vector &issues, const libcellml::LoggerPtr &logger); void TEST_EXPORT expectEqualIssuesSpecificationHeadings(const std::vector &issues, const std::vector &specificationHeadings, diff --git a/tests/variable/variable.cpp b/tests/variable/variable.cpp index 5cd6de034..36e3f4ead 100644 --- a/tests/variable/variable.cpp +++ b/tests/variable/variable.cpp @@ -1699,3 +1699,112 @@ TEST(Variable, variableInterfaceDontDowngrade) EXPECT_EQ("", v3->interfaceType()); EXPECT_EQ("public", v4->interfaceType()); } + +TEST(Variable, connectionsPersistAfterImporting) +{ + auto model = libcellml::Model::create("model"); + auto importedComponent = libcellml::Component::create("importedComponent"); + model->addComponent(importedComponent); + + auto importer = libcellml::ImportSource::create(); + importer->setUrl("importedModelWithMaps.cellml"); + importedComponent->setImportSource(importer); + importedComponent->setImportReference("importMe"); + + EXPECT_TRUE(model->hasUnresolvedImports()); + model->resolveImports(resourcePath("")); + EXPECT_FALSE(model->hasUnresolvedImports()); + + model->flatten(); + EXPECT_NE(nullptr, model->component("importedComponent")); + EXPECT_NE(nullptr, model->component("importedComponent")->component("child1")); + EXPECT_NE(nullptr, model->component("importedComponent")->component("child2")); + EXPECT_NE(nullptr, model->component("importedComponent")->component("child1")->variable("x")); + EXPECT_NE(nullptr, model->component("importedComponent")->component("child2")->variable("x")); + + auto x1 = model->component("importedComponent")->component("child1")->variable("x"); + auto x2 = model->component("importedComponent")->component("child2")->variable("x"); + EXPECT_EQ(size_t(1), x1->equivalentVariableCount()); + EXPECT_EQ(size_t(1), x2->equivalentVariableCount()); + EXPECT_EQ(x1, x2->equivalentVariable(0)); + EXPECT_EQ(x2, x1->equivalentVariable(0)); +} + +TEST(Variable, connectionsAsymmetricWithRepeatedUnits) +{ + auto model = libcellml::Model::create("model"); + auto c1 = libcellml::Component::create("c1"); + auto c2 = libcellml::Component::create("c2"); + + model->addComponent(c1); + model->addComponent(c2); + + auto importer = libcellml::ImportSource::create(); + importer->setUrl("importedModelWithCustomUnits1.cellml"); + + c1->setImportSource(importer); + c1->setImportReference("importMe"); + + c2->setImportSource(importer); + c2->setImportReference("importMe"); + + EXPECT_TRUE(model->hasUnresolvedImports()); + model->resolveImports(resourcePath("")); + EXPECT_FALSE(model->hasUnresolvedImports()); + + model->flatten(); + + EXPECT_NE(nullptr, model->component("c1")); + EXPECT_NE(nullptr, model->component("c1")->variable("x")); + EXPECT_NE(nullptr, model->component("c2")->variable("x")); + + EXPECT_TRUE(libcellml::Variable::addEquivalence(model->component("c1")->variable("x"), model->component("c2")->variable("x"))); + + auto x1 = model->component("c1")->variable("x"); + auto x2 = model->component("c2")->variable("x"); + EXPECT_EQ(size_t(1), x1->equivalentVariableCount()); + EXPECT_EQ(size_t(1), x2->equivalentVariableCount()); + EXPECT_EQ(x1, x2->equivalentVariable(0)); + EXPECT_EQ(x2, x1->equivalentVariable(0)); +} + +TEST(Variable, connectionsSymmetricWithMismatchedUnits) +{ + auto model = libcellml::Model::create("model"); + auto c1 = libcellml::Component::create("c1"); + auto c2 = libcellml::Component::create("c2"); + + model->addComponent(c1); + model->addComponent(c2); + + auto importer1 = libcellml::ImportSource::create(); + importer1->setUrl("importedModelWithCustomUnits1.cellml"); + + c1->setImportSource(importer1); + c1->setImportReference("importMe"); + + auto importer2 = libcellml::ImportSource::create(); + importer2->setUrl("importedModelWithCustomUnits2.cellml"); + + c2->setImportSource(importer2); + c2->setImportReference("importMe"); + + EXPECT_TRUE(model->hasUnresolvedImports()); + model->resolveImports(resourcePath("")); + EXPECT_FALSE(model->hasUnresolvedImports()); + + model->flatten(); + + EXPECT_NE(nullptr, model->component("c1")); + EXPECT_NE(nullptr, model->component("c1")->variable("x")); + EXPECT_NE(nullptr, model->component("c2")->variable("x")); + + EXPECT_TRUE(libcellml::Variable::addEquivalence(model->component("c1")->variable("x"), model->component("c2")->variable("x"))); + + auto x1 = model->component("c1")->variable("x"); + auto x2 = model->component("c2")->variable("x"); + EXPECT_EQ(size_t(1), x1->equivalentVariableCount()); + EXPECT_EQ(size_t(1), x2->equivalentVariableCount()); + EXPECT_EQ(x1, x2->equivalentVariable(0)); + EXPECT_EQ(x2, x1->equivalentVariable(0)); +} From f1ceaa42f5f630a3be4268f8a0f62db27d029709 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Tue, 2 Jun 2020 09:52:12 +1200 Subject: [PATCH 05/29] bug in test resources --- tests/resources/importingModelChildComponent.cellml | 2 +- tests/resources/importingModelParentComponent.cellml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/resources/importingModelChildComponent.cellml b/tests/resources/importingModelChildComponent.cellml index 765840271..f7db5302b 100644 --- a/tests/resources/importingModelChildComponent.cellml +++ b/tests/resources/importingModelChildComponent.cellml @@ -1,7 +1,7 @@ - + diff --git a/tests/resources/importingModelParentComponent.cellml b/tests/resources/importingModelParentComponent.cellml index 2ccd0cb99..7df1b4bea 100644 --- a/tests/resources/importingModelParentComponent.cellml +++ b/tests/resources/importingModelParentComponent.cellml @@ -1,7 +1,7 @@ - + From 0257594937cd28e9fe1f66537a5b084ae7134725 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Tue, 2 Jun 2020 09:55:54 +1200 Subject: [PATCH 06/29] and again ... --- tests/resources/importingModelChildComponent.cellml | 4 ++-- tests/resources/importingModelParentComponent.cellml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/resources/importingModelChildComponent.cellml b/tests/resources/importingModelChildComponent.cellml index f7db5302b..cf0163b3f 100644 --- a/tests/resources/importingModelChildComponent.cellml +++ b/tests/resources/importingModelChildComponent.cellml @@ -1,14 +1,14 @@ - + - + diff --git a/tests/resources/importingModelParentComponent.cellml b/tests/resources/importingModelParentComponent.cellml index 7df1b4bea..bf641e742 100644 --- a/tests/resources/importingModelParentComponent.cellml +++ b/tests/resources/importingModelParentComponent.cellml @@ -8,7 +8,7 @@ - + From 9e3a719c30bbd45effe0cb0f9ae267bb8c3412af Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Tue, 2 Jun 2020 10:07:59 +1200 Subject: [PATCH 07/29] Update file_parser.cpp --- tests/parser/file_parser.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/parser/file_parser.cpp b/tests/parser/file_parser.cpp index ad5798ebb..6a230107c 100644 --- a/tests/parser/file_parser.cpp +++ b/tests/parser/file_parser.cpp @@ -178,9 +178,7 @@ TEST(Parser, parseModelImportingModelParentComponent) { auto parser = libcellml::Parser::create(); auto model = parser->parseModel(fileContents("importingModelParentComponent.cellml")); - - printModelToTerminal(model); - printIssues(parser); + EXPECT_EQ(size_t(0), parser->errorCount()); auto validator = libcellml::Validator::create(); validator->validateModel(model); @@ -192,7 +190,7 @@ TEST(Parser, parseModelImportingModelParentComponent) EXPECT_EQ(serialisedModel, fileContents("importingModelParentComponent.cellml")); } -TEST(Parser, parseModelWithImportedEncapsulation2) +TEST(Parser, parseModelImportingModelChildComponent) { auto parser = libcellml::Parser::create(); auto model = parser->parseModel(fileContents("importingModelChildComponent.cellml")); @@ -202,10 +200,12 @@ TEST(Parser, parseModelWithImportedEncapsulation2) auto validator = libcellml::Validator::create(); validator->validateModel(model); + printIssues(validator); EXPECT_EQ(size_t(0), validator->issueCount()); auto printer = libcellml::Printer::create(); auto serialisedModel = printer->printModel(model); + printIssues(printer); EXPECT_EQ(serialisedModel, fileContents("importingModelChildComponent.cellml")); } From 5bbf09d33bb865a37c9420ab572f5a8dfb565b22 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Tue, 2 Jun 2020 10:09:18 +1200 Subject: [PATCH 08/29] moved test to printer as that's where the trouble is ... --- tests/parser/file_parser.cpp | 36 ------------------------------------ tests/printer/printer.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/tests/parser/file_parser.cpp b/tests/parser/file_parser.cpp index 6a230107c..1d268870a 100644 --- a/tests/parser/file_parser.cpp +++ b/tests/parser/file_parser.cpp @@ -173,39 +173,3 @@ TEST(Parser, parseModelWithImportedEquivVariables) EXPECT_EQ(serialisedModel, fileContents("importingModel.cellml")); } - -TEST(Parser, parseModelImportingModelParentComponent) -{ - auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("importingModelParentComponent.cellml")); - EXPECT_EQ(size_t(0), parser->errorCount()); - - auto validator = libcellml::Validator::create(); - validator->validateModel(model); - EXPECT_EQ(size_t(0), validator->issueCount()); - - auto printer = libcellml::Printer::create(); - auto serialisedModel = printer->printModel(model); - - EXPECT_EQ(serialisedModel, fileContents("importingModelParentComponent.cellml")); -} - -TEST(Parser, parseModelImportingModelChildComponent) -{ - auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("importingModelChildComponent.cellml")); - - printModelToTerminal(model); - printIssues(parser); - - auto validator = libcellml::Validator::create(); - validator->validateModel(model); - printIssues(validator); - EXPECT_EQ(size_t(0), validator->issueCount()); - - auto printer = libcellml::Printer::create(); - auto serialisedModel = printer->printModel(model); - printIssues(printer); - - EXPECT_EQ(serialisedModel, fileContents("importingModelChildComponent.cellml")); -} diff --git a/tests/printer/printer.cpp b/tests/printer/printer.cpp index d074e1798..542ccf86b 100644 --- a/tests/printer/printer.cpp +++ b/tests/printer/printer.cpp @@ -254,3 +254,38 @@ TEST(Printer, printModelWithStandardUnitsAdded) libcellml::PrinterPtr printer = libcellml::Printer::create(); EXPECT_EQ(e, printer->printModel(model)); } +TEST(Parser, printModelImportingModelParentComponent) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("importingModelParentComponent.cellml")); + EXPECT_EQ(size_t(0), parser->errorCount()); + + auto validator = libcellml::Validator::create(); + validator->validateModel(model); + EXPECT_EQ(size_t(0), validator->issueCount()); + + auto printer = libcellml::Printer::create(); + auto serialisedModel = printer->printModel(model); + + EXPECT_EQ(serialisedModel, fileContents("importingModelParentComponent.cellml")); +} + +TEST(Parser, printModelImportingModelChildComponent) +{ + auto parser = libcellml::Parser::create(); + auto model = parser->parseModel(fileContents("importingModelChildComponent.cellml")); + + printModelToTerminal(model); + printIssues(parser); + + auto validator = libcellml::Validator::create(); + validator->validateModel(model); + printIssues(validator); + EXPECT_EQ(size_t(0), validator->issueCount()); + + auto printer = libcellml::Printer::create(); + auto serialisedModel = printer->printModel(model); + printIssues(printer); + + EXPECT_EQ(serialisedModel, fileContents("importingModelChildComponent.cellml")); +} From f9dc58345064e79f056929be29b486a1a0d5e49b Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Tue, 2 Jun 2020 10:19:16 +1200 Subject: [PATCH 09/29] fixed order of components in resources file --- tests/parser/file_parser.cpp | 3 --- tests/printer/printer.cpp | 4 ++-- tests/resources/importingModel.cellml | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/parser/file_parser.cpp b/tests/parser/file_parser.cpp index 1d268870a..6462fe061 100644 --- a/tests/parser/file_parser.cpp +++ b/tests/parser/file_parser.cpp @@ -161,9 +161,6 @@ TEST(Parser, parseModelWithImportedEquivVariables) auto parser = libcellml::Parser::create(); auto model = parser->parseModel(fileContents("importingModel.cellml")); - printModelToTerminal(model); - printIssues(parser); - auto validator = libcellml::Validator::create(); validator->validateModel(model); EXPECT_EQ(size_t(0), validator->issueCount()); diff --git a/tests/printer/printer.cpp b/tests/printer/printer.cpp index 542ccf86b..e7e0618e2 100644 --- a/tests/printer/printer.cpp +++ b/tests/printer/printer.cpp @@ -254,7 +254,7 @@ TEST(Printer, printModelWithStandardUnitsAdded) libcellml::PrinterPtr printer = libcellml::Printer::create(); EXPECT_EQ(e, printer->printModel(model)); } -TEST(Parser, printModelImportingModelParentComponent) +TEST(Printer, printModelImportingModelParentComponent) { auto parser = libcellml::Parser::create(); auto model = parser->parseModel(fileContents("importingModelParentComponent.cellml")); @@ -270,7 +270,7 @@ TEST(Parser, printModelImportingModelParentComponent) EXPECT_EQ(serialisedModel, fileContents("importingModelParentComponent.cellml")); } -TEST(Parser, printModelImportingModelChildComponent) +TEST(Printer, printModelImportingModelChildComponent) { auto parser = libcellml::Parser::create(); auto model = parser->parseModel(fileContents("importingModelChildComponent.cellml")); diff --git a/tests/resources/importingModel.cellml b/tests/resources/importingModel.cellml index b9c40f0f2..e617a8e0d 100644 --- a/tests/resources/importingModel.cellml +++ b/tests/resources/importingModel.cellml @@ -1,12 +1,12 @@ - + - + From 7193a65dc9a9aaa1bd9def48e19f25549684c428 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Tue, 2 Jun 2020 10:26:51 +1200 Subject: [PATCH 10/29] Removed validation check from parser test (bug there addressed in #605) --- tests/parser/file_parser.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/parser/file_parser.cpp b/tests/parser/file_parser.cpp index 6462fe061..d9cf712da 100644 --- a/tests/parser/file_parser.cpp +++ b/tests/parser/file_parser.cpp @@ -161,10 +161,6 @@ TEST(Parser, parseModelWithImportedEquivVariables) auto parser = libcellml::Parser::create(); auto model = parser->parseModel(fileContents("importingModel.cellml")); - auto validator = libcellml::Validator::create(); - validator->validateModel(model); - EXPECT_EQ(size_t(0), validator->issueCount()); - auto printer = libcellml::Printer::create(); auto serialisedModel = printer->printModel(model); From 57cfb32a234d1887f00ec186a182337871616a9b Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Tue, 2 Jun 2020 10:51:16 +1200 Subject: [PATCH 11/29] Fixed bug in printer --- src/printer.cpp | 69 +++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/printer.cpp b/src/printer.cpp index 919736e21..bdac0ec67 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -237,37 +237,37 @@ std::string Printer::PrinterImpl::printUnits(const UnitsPtr &units) const std::string Printer::PrinterImpl::printComponent(const ComponentPtr &component) const { std::string repr; - if (component->isImport()) { - return repr; - } - repr += "name(); - if (!componentName.empty()) { - repr += " name=\"" + componentName + "\""; - } - if (!component->id().empty()) { - repr += " id=\"" + component->id() + "\""; - } - size_t variableCount = component->variableCount(); - size_t resetCount = component->resetCount(); - bool hasChildren = false; - if (variableCount > 0 || resetCount > 0 || !component->math().empty()) { - hasChildren = true; - } - if (hasChildren) { - repr += ">"; - for (size_t i = 0; i < variableCount; ++i) { - repr += printVariable(component->variable(i)); + + if (!component->isImport()) { + repr += "name(); + if (!componentName.empty()) { + repr += " name=\"" + componentName + "\""; } - for (size_t i = 0; i < resetCount; ++i) { - repr += printReset(component->reset(i)); + if (!component->id().empty()) { + repr += " id=\"" + component->id() + "\""; } - if (!component->math().empty()) { - repr += printMath(component->math()); + size_t variableCount = component->variableCount(); + size_t resetCount = component->resetCount(); + bool hasChildren = false; + if (variableCount > 0 || resetCount > 0 || !component->math().empty()) { + hasChildren = true; + } + if (hasChildren) { + repr += ">"; + for (size_t i = 0; i < variableCount; ++i) { + repr += printVariable(component->variable(i)); + } + for (size_t i = 0; i < resetCount; ++i) { + repr += printReset(component->reset(i)); + } + if (!component->math().empty()) { + repr += printMath(component->math()); + } + repr += ""; + } else { + repr += "/>"; } - repr += ""; - } else { - repr += "/>"; } // Traverse through children of this component and add them to the representation. for (size_t i = 0; i < component->componentCount(); ++i) { @@ -438,12 +438,12 @@ std::string Printer::printModel(const ModelPtr &model) const importOrder.push_back(importSource); } importMap[importSource].push_back(pair); - } else { - for (size_t j = 0; j < comp->componentCount(); ++j) { - auto childComponent = comp->component(j); - componentStack.push_back(childComponent); - } + } // else { // KRM check this? Local children of imported components should be checked too? + for (size_t j = 0; j < comp->componentCount(); ++j) { + auto childComponent = comp->component(j); + componentStack.push_back(childComponent); } + //} if (componentStack.empty()) { comp = nullptr; @@ -492,7 +492,8 @@ std::string Printer::printModel(const ModelPtr &model) const } std::string componentEncapsulation; - // Serialise components of the model, imported components have already been dealt with at this point. + // Serialise components of the model, imported components have already been dealt with at this point, + // ... but their locally-defined children have not. for (size_t i = 0; i < model->componentCount(); ++i) { ComponentPtr component = model->component(i); repr += mPimpl->printComponent(component); From 1788381dd2ae870b6c99fc5824b394da98c675fb Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Thu, 4 Jun 2020 08:53:38 +1200 Subject: [PATCH 12/29] Removed debug statements --- tests/printer/printer.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/printer/printer.cpp b/tests/printer/printer.cpp index e7e0618e2..2da63183d 100644 --- a/tests/printer/printer.cpp +++ b/tests/printer/printer.cpp @@ -275,17 +275,13 @@ TEST(Printer, printModelImportingModelChildComponent) auto parser = libcellml::Parser::create(); auto model = parser->parseModel(fileContents("importingModelChildComponent.cellml")); - printModelToTerminal(model); - printIssues(parser); - auto validator = libcellml::Validator::create(); validator->validateModel(model); - printIssues(validator); + EXPECT_EQ(size_t(0), validator->issueCount()); auto printer = libcellml::Printer::create(); auto serialisedModel = printer->printModel(model); - printIssues(printer); EXPECT_EQ(serialisedModel, fileContents("importingModelChildComponent.cellml")); } From d105d835e32fe0d3622e3d94d25311b0e440b7e5 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Thu, 4 Jun 2020 08:55:21 +1200 Subject: [PATCH 13/29] Removed comments --- src/printer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/printer.cpp b/src/printer.cpp index bdac0ec67..62ffabe81 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -438,12 +438,11 @@ std::string Printer::printModel(const ModelPtr &model) const importOrder.push_back(importSource); } importMap[importSource].push_back(pair); - } // else { // KRM check this? Local children of imported components should be checked too? + } for (size_t j = 0; j < comp->componentCount(); ++j) { auto childComponent = comp->component(j); componentStack.push_back(childComponent); } - //} if (componentStack.empty()) { comp = nullptr; From 087e3a39e75de1961cd13406ee088b27a575d52a Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Thu, 11 Jun 2020 10:45:24 +1200 Subject: [PATCH 14/29] removed overloads in test utils printing functions --- tests/test_utils.cpp | 10 ---------- tests/test_utils.h | 6 ++---- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index 4c3143647..7333dc409 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -58,11 +58,6 @@ void printIssues(const libcellml::LoggerPtr &l, bool headings, bool causes, bool } } -void printModelToTerminal(libcellml::ModelPtr &model) -{ - printModelToTerminal(model, true); -} - void printModelToTerminal(libcellml::ModelPtr &model, bool includeMaths) { std::string spacer = " "; @@ -85,11 +80,6 @@ void printModelToTerminal(libcellml::ModelPtr &model, bool includeMaths) } } -void printComponentToTerminal(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer) -{ - printComponentToTerminal(component, c, spacer, true); -} - void printComponentToTerminal(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer, bool includeMaths) { std::string local = " "; diff --git a/tests/test_utils.h b/tests/test_utils.h index c0b78e622..529ba44a3 100644 --- a/tests/test_utils.h +++ b/tests/test_utils.h @@ -77,10 +77,8 @@ std::string TEST_EXPORT resourcePath(const std::string &resourceRelativePath = " std::string TEST_EXPORT fileContents(const std::string &fileName); void TEST_EXPORT printIssues(const libcellml::LoggerPtr &l, bool headings = false, bool causes = false, bool rule = false); -void TEST_EXPORT printModelToTerminal(libcellml::ModelPtr &model); -void TEST_EXPORT printModelToTerminal(libcellml::ModelPtr &model, bool includeMaths); -void TEST_EXPORT printComponentToTerminal(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer); -void TEST_EXPORT printComponentToTerminal(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer, bool includeMaths); +void TEST_EXPORT printModelToTerminal(libcellml::ModelPtr &model, bool includeMaths = true); +void TEST_EXPORT printComponentToTerminal(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer, bool includeMaths = true); void TEST_EXPORT expectEqualIssues(const std::vector &issues, const libcellml::LoggerPtr &logger); void TEST_EXPORT expectEqualIssuesSpecificationHeadings(const std::vector &issues, From 6fa87e134c6c82a71bebfd957afa61f27c78fa59 Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Wed, 1 Jul 2020 12:03:48 +1200 Subject: [PATCH 15/29] Change name of print model and compnent test utility functions. --- tests/test_utils.cpp | 8 ++++---- tests/test_utils.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index 9dbebbb56..8d29e2117 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -60,7 +60,7 @@ void printIssues(const libcellml::LoggerPtr &l, bool headings, bool causes, bool } } -void printModelToTerminal(libcellml::ModelPtr &model, bool includeMaths) +void prettyPrintModelToStdout(libcellml::ModelPtr &model, bool includeMaths) { std::string spacer = " "; @@ -78,11 +78,11 @@ void printModelToTerminal(libcellml::ModelPtr &model, bool includeMaths) std::cout << spacer << "COMPONENTS: " << model->componentCount() << " components" << std::endl; for (size_t c = 0; c < model->componentCount(); ++c) { auto component = model->component(c); - printComponentToTerminal(component, c, spacer + spacer, includeMaths); + prettyPrintComponentToStdout(component, c, spacer + spacer, includeMaths); } } -void printComponentToTerminal(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer, bool includeMaths) +void prettyPrintComponentToStdout(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer, bool includeMaths) { std::string local = " "; @@ -146,7 +146,7 @@ void printComponentToTerminal(const libcellml::ComponentPtr &component, size_t c for (size_t c2 = 0; c2 < component->componentCount(); c2++) { auto child = component->component(c2); std::string oneMoreSpacer = spacer + local + local; - printComponentToTerminal(child, c2, oneMoreSpacer, includeMaths); + prettyPrintComponentToStdout(child, c2, oneMoreSpacer, includeMaths); } } } diff --git a/tests/test_utils.h b/tests/test_utils.h index 4dad578ca..b0c60f259 100644 --- a/tests/test_utils.h +++ b/tests/test_utils.h @@ -77,8 +77,8 @@ std::string TEST_EXPORT resourcePath(const std::string &resourceRelativePath = " std::string TEST_EXPORT fileContents(const std::string &fileName); void TEST_EXPORT printIssues(const libcellml::LoggerPtr &l, bool headings = false, bool causes = false, bool rule = false); -void TEST_EXPORT printModelToTerminal(libcellml::ModelPtr &model, bool includeMaths = true); -void TEST_EXPORT printComponentToTerminal(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer, bool includeMaths = true); +void TEST_EXPORT prettyPrintModelToStdout(libcellml::ModelPtr &model, bool includeMaths = true); +void TEST_EXPORT prettyPrintComponentToStdout(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer, bool includeMaths = true); void TEST_EXPORT expectEqualIssues(const std::vector &issues, const libcellml::LoggerPtr &logger); void TEST_EXPORT expectEqualIssuesSpecificationHeadings(const std::vector &issues, From f3870c70f86d1f5318f62980413b3dd9bb70facc Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 2 Jul 2020 10:03:12 +1200 Subject: [PATCH 16/29] Test utils: reworked the methods for pretty printing a model/component. --- tests/test_utils.cpp | 83 ++++++++++++++++++++++++-------------------- tests/test_utils.h | 4 +-- 2 files changed, 47 insertions(+), 40 deletions(-) diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index 8d29e2117..d787e986a 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -60,44 +60,27 @@ void printIssues(const libcellml::LoggerPtr &l, bool headings, bool causes, bool } } -void prettyPrintModelToStdout(libcellml::ModelPtr &model, bool includeMaths) -{ - std::string spacer = " "; - - std::cout << " MODEL: '" << model->name() << "'"; - if (model->id() != "") { - std::cout << ", id: '" << model->id() << "'"; - } - std::cout << std::endl; - - std::cout << spacer << "UNITS: " << model->unitsCount() << " custom units" << std::endl; - for (size_t u = 0; u < model->unitsCount(); ++u) { - std::cout << spacer << spacer << "[" << u << "]: " << model->units(u)->name() << std::endl; - } +static const std::string INDENT = " "; - std::cout << spacer << "COMPONENTS: " << model->componentCount() << " components" << std::endl; - for (size_t c = 0; c < model->componentCount(); ++c) { - auto component = model->component(c); - prettyPrintComponentToStdout(component, c, spacer + spacer, includeMaths); - } -} - -void prettyPrintComponentToStdout(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer, bool includeMaths) +void printComponent(const libcellml::ComponentPtr &component, size_t c, const std::string &indent, bool includeMaths) { - std::string local = " "; + if (c == -1) { + std::cout << "COMPONENT: '" << component->name() << "'"; + } else { + std::cout << indent << "[" << c + 1 << "]: " << component->name(); + } - std::cout << spacer << "[" << c << "]: " << component->name(); if (component->id() != "") { - std::cout << " id: " << component->id(); + std::cout << ", id: " << component->id(); } - std::cout << std::endl; - std::cout << spacer << local << "VARIABLES: " << component->variableCount() << " variables" << std::endl; + std::cout << std::endl; + std::cout << indent << INDENT << "VARIABLES: " << component->variableCount() << " variables" << std::endl; // Printing the variables within the component. - for (size_t v = 0; v < component->variableCount(); v++) { - std::cout << spacer << local << local; - std::cout << "[" << v << "]: " << component->variable(v)->name(); + for (size_t v = 0; v < component->variableCount(); ++v) { + std::cout << indent << INDENT << INDENT; + std::cout << "[" << v + 1 << "]: " << component->variable(v)->name(); if (component->variable(v)->units() != nullptr) { std::cout << " [" << component->variable(v)->units()->name() << "]"; } @@ -106,7 +89,7 @@ void prettyPrintComponentToStdout(const libcellml::ComponentPtr &component, size } std::cout << std::endl; if (component->variable(v)->equivalentVariableCount() > 0) { - std::cout << spacer << local << local << local; + std::cout << indent << INDENT << INDENT << INDENT; std::string con = " └──> "; for (size_t e = 0; e < component->variable(v)->equivalentVariableCount(); ++e) { auto ev = component->variable(v)->equivalentVariable(e); @@ -132,25 +115,49 @@ void prettyPrintComponentToStdout(const libcellml::ComponentPtr &component, size // Print the maths within the component. if (includeMaths) { if (component->math() != "") { - std::cout << spacer << " Maths in the component is:" << std::endl; + std::cout << indent << " Maths in the component is:" << std::endl; std::cout << component->math() << std::endl; } } // Print the encapsulated components if (component->componentCount() > 0) { - std::cout << spacer << local << "COMPONENT " << component->name() << " has " - << component->componentCount() - << " child components:" << std::endl; + std::cout << indent << INDENT << "CHILD COMPONENTS: " << component->componentCount() + << " child components" << std::endl; + std::string newIndent = indent + INDENT + INDENT; - for (size_t c2 = 0; c2 < component->componentCount(); c2++) { + for (size_t c2 = 0; c2 < component->componentCount(); ++c2) { auto child = component->component(c2); - std::string oneMoreSpacer = spacer + local + local; - prettyPrintComponentToStdout(child, c2, oneMoreSpacer, includeMaths); + printComponent(child, c2, newIndent, includeMaths); } } } +void printComponent(const libcellml::ComponentPtr &component, bool includeMaths) +{ + printComponent(component, -1, {}, includeMaths); +} + +void printModel(const libcellml::ModelPtr &model, bool includeMaths) +{ + std::cout << "MODEL: '" << model->name() << "'"; + if (model->id() != "") { + std::cout << ", id: '" << model->id() << "'"; + } + std::cout << std::endl; + + std::cout << INDENT << "UNITS: " << model->unitsCount() << " custom units" << std::endl; + for (size_t u = 0; u < model->unitsCount(); ++u) { + std::cout << INDENT << INDENT << "[" << u + 1 << "]: " << model->units(u)->name() << std::endl; + } + + std::cout << INDENT << "COMPONENTS: " << model->componentCount() << " components" << std::endl; + for (size_t c = 0; c < model->componentCount(); ++c) { + auto component = model->component(c); + printComponent(component, c, INDENT + INDENT, includeMaths); + } +} + void expectEqualIssues(const std::vector &issues, const libcellml::LoggerPtr &logger) { diff --git a/tests/test_utils.h b/tests/test_utils.h index b0c60f259..55152a076 100644 --- a/tests/test_utils.h +++ b/tests/test_utils.h @@ -77,8 +77,8 @@ std::string TEST_EXPORT resourcePath(const std::string &resourceRelativePath = " std::string TEST_EXPORT fileContents(const std::string &fileName); void TEST_EXPORT printIssues(const libcellml::LoggerPtr &l, bool headings = false, bool causes = false, bool rule = false); -void TEST_EXPORT prettyPrintModelToStdout(libcellml::ModelPtr &model, bool includeMaths = true); -void TEST_EXPORT prettyPrintComponentToStdout(const libcellml::ComponentPtr &component, size_t const c, std::string const spacer, bool includeMaths = true); +void TEST_EXPORT printModel(const libcellml::ModelPtr &model, bool includeMaths = true); +void TEST_EXPORT printComponent(const libcellml::ComponentPtr &component, bool includeMaths = true); void TEST_EXPORT expectEqualIssues(const std::vector &issues, const libcellml::LoggerPtr &logger); void TEST_EXPORT expectEqualIssuesSpecificationHeadings(const std::vector &issues, From cecbafc5849f84095999234f4cbac625f4e8b477 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 2 Jul 2020 10:11:34 +1200 Subject: [PATCH 17/29] Printer: slight improvement to the code. --- src/printer.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/printer.cpp b/src/printer.cpp index 2fb960075..71f997aa2 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -249,11 +249,7 @@ std::string Printer::PrinterImpl::printComponent(const ComponentPtr &component) } size_t variableCount = component->variableCount(); size_t resetCount = component->resetCount(); - bool hasChildren = false; - if (variableCount > 0 || resetCount > 0 || !component->math().empty()) { - hasChildren = true; - } - if (hasChildren) { + if ((variableCount > 0) || (resetCount > 0) || !component->math().empty()) { repr += ">"; for (size_t i = 0; i < variableCount; ++i) { repr += printVariable(component->variable(i)); From 471a2bbdb1d9df4708a5eb2b0f71b5aa4ffdcbac Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 2 Jul 2020 10:12:08 +1200 Subject: [PATCH 18/29] Tests: slight speed improvements. --- tests/parser/file_parser.cpp | 5 +++-- tests/printer/printer.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/parser/file_parser.cpp b/tests/parser/file_parser.cpp index d9cf712da..4f519f5f1 100644 --- a/tests/parser/file_parser.cpp +++ b/tests/parser/file_parser.cpp @@ -159,10 +159,11 @@ TEST(Parser, simpleGeneratorModel) TEST(Parser, parseModelWithImportedEquivVariables) { auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("importingModel.cellml")); + auto modelContents = fileContents("importingModel.cellml"); + auto model = parser->parseModel(modelContents); auto printer = libcellml::Printer::create(); auto serialisedModel = printer->printModel(model); - EXPECT_EQ(serialisedModel, fileContents("importingModel.cellml")); + EXPECT_EQ(serialisedModel, modelContents); } diff --git a/tests/printer/printer.cpp b/tests/printer/printer.cpp index 54bec8cb9..e9d8c1191 100644 --- a/tests/printer/printer.cpp +++ b/tests/printer/printer.cpp @@ -298,7 +298,8 @@ TEST(Printer, printModelWithStandardUnitsAdded) TEST(Printer, printModelImportingModelParentComponent) { auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("importingModelParentComponent.cellml")); + auto modelContents = fileContents("importingModelParentComponent.cellml"); + auto model = parser->parseModel(modelContents); EXPECT_EQ(size_t(0), parser->errorCount()); auto validator = libcellml::Validator::create(); @@ -308,13 +309,14 @@ TEST(Printer, printModelImportingModelParentComponent) auto printer = libcellml::Printer::create(); auto serialisedModel = printer->printModel(model); - EXPECT_EQ(serialisedModel, fileContents("importingModelParentComponent.cellml")); + EXPECT_EQ(serialisedModel, modelContents); } TEST(Printer, printModelImportingModelChildComponent) { auto parser = libcellml::Parser::create(); - auto model = parser->parseModel(fileContents("importingModelChildComponent.cellml")); + auto modelContents = fileContents("importingModelChildComponent.cellml"); + auto model = parser->parseModel(modelContents); auto validator = libcellml::Validator::create(); validator->validateModel(model); @@ -324,5 +326,5 @@ TEST(Printer, printModelImportingModelChildComponent) auto printer = libcellml::Printer::create(); auto serialisedModel = printer->printModel(model); - EXPECT_EQ(serialisedModel, fileContents("importingModelChildComponent.cellml")); + EXPECT_EQ(serialisedModel, modelContents); } From 26f78d8e5d9664f3ea8a2470140c5341ccf9aed3 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 2 Jul 2020 10:20:01 +1200 Subject: [PATCH 19/29] Removed unneded test CellML files. --- tests/resources/importedModel.cellml | 6 ----- .../importedModelWithCustomUnits.cellml | 9 ------- ...portedModelWithMapsOfDifferentUnits.cellml | 27 ------------------- 3 files changed, 42 deletions(-) delete mode 100644 tests/resources/importedModel.cellml delete mode 100644 tests/resources/importedModelWithCustomUnits.cellml delete mode 100644 tests/resources/importedModelWithMapsOfDifferentUnits.cellml diff --git a/tests/resources/importedModel.cellml b/tests/resources/importedModel.cellml deleted file mode 100644 index 6716b0a4e..000000000 --- a/tests/resources/importedModel.cellml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/tests/resources/importedModelWithCustomUnits.cellml b/tests/resources/importedModelWithCustomUnits.cellml deleted file mode 100644 index 22d5c96b6..000000000 --- a/tests/resources/importedModelWithCustomUnits.cellml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/tests/resources/importedModelWithMapsOfDifferentUnits.cellml b/tests/resources/importedModelWithMapsOfDifferentUnits.cellml deleted file mode 100644 index d7ce2b834..000000000 --- a/tests/resources/importedModelWithMapsOfDifferentUnits.cellml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - From 8d8b28f765d4b63bfb1a804950dfab029dadf0cf Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 2 Jul 2020 10:26:32 +1200 Subject: [PATCH 20/29] Some minor cleaning up. --- tests/variable/variable.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/variable/variable.cpp b/tests/variable/variable.cpp index f3d304fd5..0dbf18f95 100644 --- a/tests/variable/variable.cpp +++ b/tests/variable/variable.cpp @@ -1712,7 +1712,7 @@ TEST(Variable, connectionsPersistAfterImporting) importedComponent->setImportReference("importMe"); EXPECT_TRUE(model->hasUnresolvedImports()); - model->resolveImports(resourcePath("")); + model->resolveImports(resourcePath()); EXPECT_FALSE(model->hasUnresolvedImports()); model->flatten(); @@ -1749,7 +1749,7 @@ TEST(Variable, connectionsAsymmetricWithRepeatedUnits) c2->setImportReference("importMe"); EXPECT_TRUE(model->hasUnresolvedImports()); - model->resolveImports(resourcePath("")); + model->resolveImports(resourcePath()); EXPECT_FALSE(model->hasUnresolvedImports()); model->flatten(); @@ -1790,7 +1790,7 @@ TEST(Variable, connectionsSymmetricWithMismatchedUnits) c2->setImportReference("importMe"); EXPECT_TRUE(model->hasUnresolvedImports()); - model->resolveImports(resourcePath("")); + model->resolveImports(resourcePath()); EXPECT_FALSE(model->hasUnresolvedImports()); model->flatten(); From 2af7803c1408938d704412504b8f51ef0fde471a Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 2 Jul 2020 11:41:09 +1200 Subject: [PATCH 21/29] Tests: put the expected/actual bit in the right order. --- tests/parser/file_parser.cpp | 2 +- tests/printer/printer.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/parser/file_parser.cpp b/tests/parser/file_parser.cpp index 4f519f5f1..8d501e44c 100644 --- a/tests/parser/file_parser.cpp +++ b/tests/parser/file_parser.cpp @@ -165,5 +165,5 @@ TEST(Parser, parseModelWithImportedEquivVariables) auto printer = libcellml::Printer::create(); auto serialisedModel = printer->printModel(model); - EXPECT_EQ(serialisedModel, modelContents); + EXPECT_EQ(modelContents, serialisedModel); } diff --git a/tests/printer/printer.cpp b/tests/printer/printer.cpp index e9d8c1191..24cea3ae2 100644 --- a/tests/printer/printer.cpp +++ b/tests/printer/printer.cpp @@ -309,7 +309,7 @@ TEST(Printer, printModelImportingModelParentComponent) auto printer = libcellml::Printer::create(); auto serialisedModel = printer->printModel(model); - EXPECT_EQ(serialisedModel, modelContents); + EXPECT_EQ(modelContents, serialisedModel); } TEST(Printer, printModelImportingModelChildComponent) @@ -326,5 +326,5 @@ TEST(Printer, printModelImportingModelChildComponent) auto printer = libcellml::Printer::create(); auto serialisedModel = printer->printModel(model); - EXPECT_EQ(serialisedModel, modelContents); + EXPECT_EQ(modelContents, serialisedModel); } From 083787b3517e4946aca6dc5a03ad1aa4020f89a8 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Wed, 8 Jul 2020 15:53:52 +1200 Subject: [PATCH 22/29] Still a bug here ... see new tests. Need recursion in forming the import lists. --- tests/printer/printer.cpp | 34 +++++++++++++++++++ .../importingModelGrandchildComponent.cellml | 19 +++++++++++ .../importingModelGrandparentComponent.cellml | 19 +++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/resources/importingModelGrandchildComponent.cellml create mode 100644 tests/resources/importingModelGrandparentComponent.cellml diff --git a/tests/printer/printer.cpp b/tests/printer/printer.cpp index 24cea3ae2..626f635b6 100644 --- a/tests/printer/printer.cpp +++ b/tests/printer/printer.cpp @@ -328,3 +328,37 @@ TEST(Printer, printModelImportingModelChildComponent) EXPECT_EQ(modelContents, serialisedModel); } + +TEST(Printer, printModelImportingModelGrandparentComponent) +{ + auto parser = libcellml::Parser::create(); + auto modelContents = fileContents("importingModelGrandparentComponent.cellml"); + auto model = parser->parseModel(modelContents); + EXPECT_EQ(size_t(0), parser->errorCount()); + + auto validator = libcellml::Validator::create(); + validator->validateModel(model); + EXPECT_EQ(size_t(0), validator->issueCount()); + + auto printer = libcellml::Printer::create(); + auto serialisedModel = printer->printModel(model); + + EXPECT_EQ(modelContents, serialisedModel); +} + +TEST(Printer, printModelImportingModelGrandchildComponent) +{ + auto parser = libcellml::Parser::create(); + auto modelContents = fileContents("importingModelGrandchildComponent.cellml"); + auto model = parser->parseModel(modelContents); + + auto validator = libcellml::Validator::create(); + validator->validateModel(model); + + EXPECT_EQ(size_t(0), validator->issueCount()); + + auto printer = libcellml::Printer::create(); + auto serialisedModel = printer->printModel(model); + + EXPECT_EQ(modelContents, serialisedModel); +} diff --git a/tests/resources/importingModelGrandchildComponent.cellml b/tests/resources/importingModelGrandchildComponent.cellml new file mode 100644 index 000000000..0c9d610e8 --- /dev/null +++ b/tests/resources/importingModelGrandchildComponent.cellml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/tests/resources/importingModelGrandparentComponent.cellml b/tests/resources/importingModelGrandparentComponent.cellml new file mode 100644 index 000000000..9d0a0fef2 --- /dev/null +++ b/tests/resources/importingModelGrandparentComponent.cellml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + From 5db08a3e7aa61080d22589cb7480613ffd064cda Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Wed, 8 Jul 2020 16:00:46 +1200 Subject: [PATCH 23/29] Revert "Still a bug here ... see new tests. Need recursion in forming the import lists." This reverts commit 083787b3517e4946aca6dc5a03ad1aa4020f89a8. --- tests/printer/printer.cpp | 34 ------------------- .../importingModelGrandchildComponent.cellml | 19 ----------- .../importingModelGrandparentComponent.cellml | 19 ----------- 3 files changed, 72 deletions(-) delete mode 100644 tests/resources/importingModelGrandchildComponent.cellml delete mode 100644 tests/resources/importingModelGrandparentComponent.cellml diff --git a/tests/printer/printer.cpp b/tests/printer/printer.cpp index 626f635b6..24cea3ae2 100644 --- a/tests/printer/printer.cpp +++ b/tests/printer/printer.cpp @@ -328,37 +328,3 @@ TEST(Printer, printModelImportingModelChildComponent) EXPECT_EQ(modelContents, serialisedModel); } - -TEST(Printer, printModelImportingModelGrandparentComponent) -{ - auto parser = libcellml::Parser::create(); - auto modelContents = fileContents("importingModelGrandparentComponent.cellml"); - auto model = parser->parseModel(modelContents); - EXPECT_EQ(size_t(0), parser->errorCount()); - - auto validator = libcellml::Validator::create(); - validator->validateModel(model); - EXPECT_EQ(size_t(0), validator->issueCount()); - - auto printer = libcellml::Printer::create(); - auto serialisedModel = printer->printModel(model); - - EXPECT_EQ(modelContents, serialisedModel); -} - -TEST(Printer, printModelImportingModelGrandchildComponent) -{ - auto parser = libcellml::Parser::create(); - auto modelContents = fileContents("importingModelGrandchildComponent.cellml"); - auto model = parser->parseModel(modelContents); - - auto validator = libcellml::Validator::create(); - validator->validateModel(model); - - EXPECT_EQ(size_t(0), validator->issueCount()); - - auto printer = libcellml::Printer::create(); - auto serialisedModel = printer->printModel(model); - - EXPECT_EQ(modelContents, serialisedModel); -} diff --git a/tests/resources/importingModelGrandchildComponent.cellml b/tests/resources/importingModelGrandchildComponent.cellml deleted file mode 100644 index 0c9d610e8..000000000 --- a/tests/resources/importingModelGrandchildComponent.cellml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/tests/resources/importingModelGrandparentComponent.cellml b/tests/resources/importingModelGrandparentComponent.cellml deleted file mode 100644 index 9d0a0fef2..000000000 --- a/tests/resources/importingModelGrandparentComponent.cellml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - From e92429f909a581552fbb97d2b16b6c94b743f225 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Mon, 13 Jul 2020 11:38:23 +1200 Subject: [PATCH 24/29] trigger new build --- tests/model/model.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/model/model.cpp b/tests/model/model.cpp index 46fc52c13..75a846bdd 100644 --- a/tests/model/model.cpp +++ b/tests/model/model.cpp @@ -784,11 +784,11 @@ TEST(Model, removeComponentInsensitiveToOrder) // If the order of operations is switched the behaviour is the same: - // Get a pointer to the second componet in the parsed model + // Get a pointer to the second component in the parsed model. auto c2Parsed = modelParsed->component("c2"); - // Remove it from the parsed model + // Remove it from the parsed model. modelParsed->removeComponent(c2Parsed); - // Add it to the api model + // Add it to the api model. modelApi->addComponent(c2Parsed); EXPECT_EQ(size_t(0), modelParsed->componentCount()); From 2fb347de1709ff20228cad97539c96a382b6f031 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Thu, 23 Jul 2020 10:37:16 +1200 Subject: [PATCH 25/29] Fix merge conflicts --- src/printer.cpp | 63 ++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/src/printer.cpp b/src/printer.cpp index 1797228cf..2ee757535 100644 --- a/src/printer.cpp +++ b/src/printer.cpp @@ -249,42 +249,41 @@ std::string Printer::PrinterImpl::printUnits(const UnitsPtr &units, IdList &idLi std::string Printer::PrinterImpl::printComponent(const ComponentPtr &component, IdList &idList, bool autoIds) { std::string repr; - if (component->isImport()) { - return repr; - } - repr += "name(); - if (!componentName.empty()) { - repr += " name=\"" + componentName + "\""; - } - if (!component->id().empty()) { - repr += " id=\"" + component->id() + "\""; - } else if (autoIds) { - repr += " id=\"" + makeUniqueId(idList) + "\""; - } - size_t variableCount = component->variableCount(); - size_t resetCount = component->resetCount(); - bool hasChildren = false; - if (variableCount > 0 || resetCount > 0 || !component->math().empty()) { - hasChildren = true; - } - if (hasChildren) { - repr += ">"; - for (size_t i = 0; i < variableCount; ++i) { - repr += printVariable(component->variable(i), idList, autoIds); + if (!component->isImport()) { + repr += "name(); + if (!componentName.empty()) { + repr += " name=\"" + componentName + "\""; + } + if (!component->id().empty()) { + repr += " id=\"" + component->id() + "\""; + } else if (autoIds) { + repr += " id=\"" + makeUniqueId(idList) + "\""; } - for (size_t i = 0; i < resetCount; ++i) { - repr += printReset(component->reset(i), idList, autoIds); + size_t variableCount = component->variableCount(); + size_t resetCount = component->resetCount(); + bool hasChildren = false; + if (variableCount > 0 || resetCount > 0 || !component->math().empty()) { + hasChildren = true; } - if (!component->math().empty()) { - repr += printMath(component->math()); + if (hasChildren) { + repr += ">"; + for (size_t i = 0; i < variableCount; ++i) { + repr += printVariable(component->variable(i), idList, autoIds); + } + for (size_t i = 0; i < resetCount; ++i) { + repr += printReset(component->reset(i), idList, autoIds); + } + if (!component->math().empty()) { + repr += printMath(component->math()); + } + + repr += ""; + } else { + repr += "/>"; } - - repr += ""; - } else { - repr += "/>"; } - + // Traverse through children of this component and add them to the representation. for (size_t i = 0; i < component->componentCount(); ++i) { repr += printComponent(component->component(i), idList, autoIds); From f0f249dcf4e0fcae06745785411277add2139e2c Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Thu, 13 Aug 2020 13:06:11 +1200 Subject: [PATCH 26/29] renamed INDENT to FIXED_INDENT --- tests/test_utils.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index 6b6004d28..b5bacc590 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -60,7 +60,7 @@ void printIssues(const libcellml::LoggerPtr &l, bool headings, bool causes, bool } } -static const std::string INDENT = " "; +static const std::string FIXED_INDENT = " "; void printComponent(const libcellml::ComponentPtr &component, size_t c, const std::string &indent, bool includeMaths) { @@ -75,11 +75,11 @@ void printComponent(const libcellml::ComponentPtr &component, size_t c, const st } std::cout << std::endl; - std::cout << indent << INDENT << "VARIABLES: " << component->variableCount() << " variables" << std::endl; + std::cout << indent << FIXED_INDENT << "VARIABLES: " << component->variableCount() << " variables" << std::endl; // Printing the variables within the component. for (size_t v = 0; v < component->variableCount(); ++v) { - std::cout << indent << INDENT << INDENT; + std::cout << indent << FIXED_INDENT << FIXED_INDENT; std::cout << "[" << v + 1 << "]: " << component->variable(v)->name(); if (component->variable(v)->units() != nullptr) { std::cout << " [" << component->variable(v)->units()->name() << "]"; @@ -89,7 +89,7 @@ void printComponent(const libcellml::ComponentPtr &component, size_t c, const st } std::cout << std::endl; if (component->variable(v)->equivalentVariableCount() > 0) { - std::cout << indent << INDENT << INDENT << INDENT; + std::cout << indent << FIXED_INDENT << FIXED_INDENT << FIXED_INDENT; std::string con = " └──> "; for (size_t e = 0; e < component->variable(v)->equivalentVariableCount(); ++e) { auto ev = component->variable(v)->equivalentVariable(e); @@ -122,9 +122,9 @@ void printComponent(const libcellml::ComponentPtr &component, size_t c, const st // Print the encapsulated components if (component->componentCount() > 0) { - std::cout << indent << INDENT << "CHILD COMPONENTS: " << component->componentCount() + std::cout << indent << FIXED_INDENT << "CHILD COMPONENTS: " << component->componentCount() << " child components" << std::endl; - std::string newIndent = indent + INDENT + INDENT; + std::string newIndent = indent + FIXED_INDENT + FIXED_INDENT; for (size_t c2 = 0; c2 < component->componentCount(); ++c2) { auto child = component->component(c2); @@ -146,15 +146,15 @@ void printModel(const libcellml::ModelPtr &model, bool includeMaths) } std::cout << std::endl; - std::cout << INDENT << "UNITS: " << model->unitsCount() << " custom units" << std::endl; + std::cout << FIXED_INDENT << "UNITS: " << model->unitsCount() << " custom units" << std::endl; for (size_t u = 0; u < model->unitsCount(); ++u) { - std::cout << INDENT << INDENT << "[" << u + 1 << "]: " << model->units(u)->name() << std::endl; + std::cout << FIXED_INDENT << FIXED_INDENT << "[" << u + 1 << "]: " << model->units(u)->name() << std::endl; } - std::cout << INDENT << "COMPONENTS: " << model->componentCount() << " components" << std::endl; + std::cout << FIXED_INDENT << "COMPONENTS: " << model->componentCount() << " components" << std::endl; for (size_t c = 0; c < model->componentCount(); ++c) { auto component = model->component(c); - printComponent(component, c, INDENT + INDENT, includeMaths); + printComponent(component, c, FIXED_INDENT + FIXED_INDENT, includeMaths); } } From 8114ded107929e45856596d876d1156b07b6358f Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Thu, 13 Aug 2020 13:20:43 +1200 Subject: [PATCH 27/29] deleted tests ... --- tests/variable/variable.cpp | 79 ------------------------------------- 1 file changed, 79 deletions(-) diff --git a/tests/variable/variable.cpp b/tests/variable/variable.cpp index 0dbf18f95..a6adfcd84 100644 --- a/tests/variable/variable.cpp +++ b/tests/variable/variable.cpp @@ -1730,85 +1730,6 @@ TEST(Variable, connectionsPersistAfterImporting) EXPECT_EQ(x2, x1->equivalentVariable(0)); } -TEST(Variable, connectionsAsymmetricWithRepeatedUnits) -{ - auto model = libcellml::Model::create("model"); - auto c1 = libcellml::Component::create("c1"); - auto c2 = libcellml::Component::create("c2"); - - model->addComponent(c1); - model->addComponent(c2); - - auto importer = libcellml::ImportSource::create(); - importer->setUrl("importedModelWithCustomUnits1.cellml"); - - c1->setImportSource(importer); - c1->setImportReference("importMe"); - - c2->setImportSource(importer); - c2->setImportReference("importMe"); - - EXPECT_TRUE(model->hasUnresolvedImports()); - model->resolveImports(resourcePath()); - EXPECT_FALSE(model->hasUnresolvedImports()); - - model->flatten(); - - EXPECT_NE(nullptr, model->component("c1")); - EXPECT_NE(nullptr, model->component("c1")->variable("x")); - EXPECT_NE(nullptr, model->component("c2")->variable("x")); - - EXPECT_TRUE(libcellml::Variable::addEquivalence(model->component("c1")->variable("x"), model->component("c2")->variable("x"))); - - auto x1 = model->component("c1")->variable("x"); - auto x2 = model->component("c2")->variable("x"); - EXPECT_EQ(size_t(1), x1->equivalentVariableCount()); - EXPECT_EQ(size_t(1), x2->equivalentVariableCount()); - EXPECT_EQ(x1, x2->equivalentVariable(0)); - EXPECT_EQ(x2, x1->equivalentVariable(0)); -} - -TEST(Variable, connectionsSymmetricWithMismatchedUnits) -{ - auto model = libcellml::Model::create("model"); - auto c1 = libcellml::Component::create("c1"); - auto c2 = libcellml::Component::create("c2"); - - model->addComponent(c1); - model->addComponent(c2); - - auto importer1 = libcellml::ImportSource::create(); - importer1->setUrl("importedModelWithCustomUnits1.cellml"); - - c1->setImportSource(importer1); - c1->setImportReference("importMe"); - - auto importer2 = libcellml::ImportSource::create(); - importer2->setUrl("importedModelWithCustomUnits2.cellml"); - - c2->setImportSource(importer2); - c2->setImportReference("importMe"); - - EXPECT_TRUE(model->hasUnresolvedImports()); - model->resolveImports(resourcePath()); - EXPECT_FALSE(model->hasUnresolvedImports()); - - model->flatten(); - - EXPECT_NE(nullptr, model->component("c1")); - EXPECT_NE(nullptr, model->component("c1")->variable("x")); - EXPECT_NE(nullptr, model->component("c2")->variable("x")); - - EXPECT_TRUE(libcellml::Variable::addEquivalence(model->component("c1")->variable("x"), model->component("c2")->variable("x"))); - - auto x1 = model->component("c1")->variable("x"); - auto x2 = model->component("c2")->variable("x"); - EXPECT_EQ(size_t(1), x1->equivalentVariableCount()); - EXPECT_EQ(size_t(1), x2->equivalentVariableCount()); - EXPECT_EQ(x1, x2->equivalentVariable(0)); - EXPECT_EQ(x2, x1->equivalentVariable(0)); -} - TEST(Variable, addVariableDuplicates) { auto model = libcellml::Model::create("model"); From 6ab2e6044aa7e8dfbf5ad1e597200b318704fd94 Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Thu, 13 Aug 2020 16:24:20 +1200 Subject: [PATCH 28/29] Fix connectionsPersistAfterImporting text in tests/variable/variable.cpp. --- tests/variable/variable.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/variable/variable.cpp b/tests/variable/variable.cpp index a6adfcd84..447d10605 100644 --- a/tests/variable/variable.cpp +++ b/tests/variable/variable.cpp @@ -1703,19 +1703,22 @@ TEST(Variable, variableInterfaceDontDowngrade) TEST(Variable, connectionsPersistAfterImporting) { auto model = libcellml::Model::create("model"); + auto importer = libcellml::Importer::create(); + auto importedComponent = libcellml::Component::create("importedComponent"); model->addComponent(importedComponent); - auto importer = libcellml::ImportSource::create(); - importer->setUrl("importedModelWithMaps.cellml"); - importedComponent->setImportSource(importer); + auto importSource = libcellml::ImportSource::create(); + importSource->setUrl("importedModelWithMaps.cellml"); + importedComponent->setImportSource(importSource); importedComponent->setImportReference("importMe"); EXPECT_TRUE(model->hasUnresolvedImports()); - model->resolveImports(resourcePath()); + importer->resolveImports(model, resourcePath()); EXPECT_FALSE(model->hasUnresolvedImports()); - model->flatten(); + model = importer->flattenModel(model); + EXPECT_NE(nullptr, model->component("importedComponent")); EXPECT_NE(nullptr, model->component("importedComponent")->component("child1")); EXPECT_NE(nullptr, model->component("importedComponent")->component("child2")); From 47e287cd0f4118c3d256fa15dd480fa410083336 Mon Sep 17 00:00:00 2001 From: Keri Moyle Date: Thu, 13 Aug 2020 18:57:50 +1200 Subject: [PATCH 29/29] deleted unused test files --- tests/resources/importedModelWithCustomUnits1.cellml | 9 --------- tests/resources/importedModelWithCustomUnits2.cellml | 9 --------- 2 files changed, 18 deletions(-) delete mode 100644 tests/resources/importedModelWithCustomUnits1.cellml delete mode 100644 tests/resources/importedModelWithCustomUnits2.cellml diff --git a/tests/resources/importedModelWithCustomUnits1.cellml b/tests/resources/importedModelWithCustomUnits1.cellml deleted file mode 100644 index 705ca2e69..000000000 --- a/tests/resources/importedModelWithCustomUnits1.cellml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/tests/resources/importedModelWithCustomUnits2.cellml b/tests/resources/importedModelWithCustomUnits2.cellml deleted file mode 100644 index 18d43564a..000000000 --- a/tests/resources/importedModelWithCustomUnits2.cellml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - -