From 8f723a402e21293757bcf43b44089c0a36a787af Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Tue, 13 Oct 2026 09:16:19 +1300 Subject: [PATCH 1/5] Add tests illustrating issue with parser parsing connections. --- tests/connection/connection.cpp | 52 +++++++++++++++++++ tests/resources/cellml1X/connections.cellml | 56 +++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 tests/resources/cellml1X/connections.cellml diff --git a/tests/connection/connection.cpp b/tests/connection/connection.cpp index 4789fe4b7f..cd7a9a695e 100644 --- a/tests/connection/connection.cpp +++ b/tests/connection/connection.cpp @@ -1535,3 +1535,55 @@ TEST(Connection, addEquivalenceConnectionIdClearedAfterDisconnect) libcellml::Variable::addEquivalence(v1, v2); EXPECT_EQ("", libcellml::Variable::equivalenceConnectionId(v1, v2)); } + +TEST(Connection, twoWayConnectionFromCellML1) +{ + auto p = libcellml::Parser::create(false); + auto m = p->parseModel(fileContents("cellml1X/connections.cellml")); + + EXPECT_EQ(size_t(0), p->errorCount()); +} + +TEST(Connection, sameNamedVariablesInDifferentComponents) +{ + auto m = libcellml::Model::create("m"); + auto c1 = libcellml::Component::create("c1"); + auto c2 = libcellml::Component::create("c2"); + auto v1c1 = libcellml::Variable::create("v1"); + auto v2c1 = libcellml::Variable::create("v2"); + auto v1c2 = libcellml::Variable::create("v1"); + auto v2c2 = libcellml::Variable::create("v2"); + + m->addComponent(c1); + m->addComponent(c2); + + c1->addVariable(v1c1); + c1->addVariable(v2c1); + c2->addVariable(v1c2); + c2->addVariable(v2c2); + + v1c1->setUnits("dimensionless"); + v2c1->setUnits("dimensionless"); + v1c2->setUnits("dimensionless"); + v2c2->setUnits("dimensionless"); + + libcellml::Variable::addEquivalence(v1c1, v2c2); + libcellml::Variable::addEquivalence(v2c1, v1c2); + + auto v = libcellml::Validator::create(); + v->validateModel(m); + + EXPECT_EQ(size_t(0), v->issueCount()); + + auto printer = libcellml::Printer::create(); + + auto modelString = printer->printModel(m); + + Debug() << modelString; + + auto p = libcellml::Parser::create(); + p->parseModel(modelString); + + printIssues(p); + EXPECT_EQ(size_t(0), p->issueCount()); +} diff --git a/tests/resources/cellml1X/connections.cellml b/tests/resources/cellml1X/connections.cellml new file mode 100644 index 0000000000..4c428e33be --- /dev/null +++ b/tests/resources/cellml1X/connections.cellml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 66d6bd3b59347d68086d4a7c3404fb592dc032bf Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Tue, 13 Oct 2026 11:47:04 +1300 Subject: [PATCH 2/5] Fix up sameNamedVariablesInDifferentComponents so it creates a validator valid model. --- tests/connection/connection.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/connection/connection.cpp b/tests/connection/connection.cpp index cd7a9a695e..76fda64dd6 100644 --- a/tests/connection/connection.cpp +++ b/tests/connection/connection.cpp @@ -1435,7 +1435,7 @@ TEST(Connection, repeatedMapVariables) const std::vector expectedIssues = { "Connection in model 'connection' between 'variable1' and 'variable2' is not unique.", - "Connection in model 'connection' between 'variable3' and 'variable6' is not unique.", + "Connection in model 'connection' between 'variable6' and 'variable3' is not unique.", }; EXPECT_EQ_ISSUES(expectedIssues, p); @@ -1563,9 +1563,13 @@ TEST(Connection, sameNamedVariablesInDifferentComponents) c2->addVariable(v2c2); v1c1->setUnits("dimensionless"); + v1c1->setInterfaceType("public"); v2c1->setUnits("dimensionless"); + v2c1->setInterfaceType("public"); v1c2->setUnits("dimensionless"); + v1c2->setInterfaceType("public"); v2c2->setUnits("dimensionless"); + v2c2->setInterfaceType("public"); libcellml::Variable::addEquivalence(v1c1, v2c2); libcellml::Variable::addEquivalence(v2c1, v1c2); @@ -1579,11 +1583,8 @@ TEST(Connection, sameNamedVariablesInDifferentComponents) auto modelString = printer->printModel(m); - Debug() << modelString; - auto p = libcellml::Parser::create(); p->parseModel(modelString); - printIssues(p); EXPECT_EQ(size_t(0), p->issueCount()); } From 9301fb62863b23864d8a4d3db6f14ef45e834a58 Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Tue, 13 Oct 2026 11:47:33 +1300 Subject: [PATCH 3/5] Don't canonaclise map variables in connection becuase the order is important. --- src/parser.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/parser.cpp b/src/parser.cpp index 7728f4ccd6..01e009edad 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1240,11 +1240,6 @@ void Parser::ParserImpl::loadConnection(const ModelPtr &model, const XmlNodePtr mapVariablesFound = true; if (!variable1Missing && !variable2Missing) { - if (variable1Name > variable2Name) { - std::string tmp = variable1Name; - variable1Name = variable2Name; - variable2Name = tmp; - } auto variableNamePair = std::make_pair(variable1Name, variable2Name); From 7b71eb37e5533e2ece83715e1bcb9e1aa82300eb Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Tue, 13 Oct 2026 11:48:14 +1300 Subject: [PATCH 4/5] Fix formatting in src/parser.cpp. --- src/parser.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/parser.cpp b/src/parser.cpp index 01e009edad..3060c83f98 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1240,7 +1240,6 @@ void Parser::ParserImpl::loadConnection(const ModelPtr &model, const XmlNodePtr mapVariablesFound = true; if (!variable1Missing && !variable2Missing) { - auto variableNamePair = std::make_pair(variable1Name, variable2Name); NamePairList::const_iterator it = std::find_if(usedMapVariables.begin(), usedMapVariables.end(), From 0bd1d0bda17682590154e1f884f0531fd78a6b19 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Tue, 13 Oct 2026 18:11:48 +1300 Subject: [PATCH 5/5] Some minor cleaning up. --- tests/resources/cellml1X/connections.cellml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/resources/cellml1X/connections.cellml b/tests/resources/cellml1X/connections.cellml index 4c428e33be..a8b5d2118f 100644 --- a/tests/resources/cellml1X/connections.cellml +++ b/tests/resources/cellml1X/connections.cellml @@ -39,7 +39,6 @@ - @@ -53,4 +52,4 @@ - \ No newline at end of file +