diff --git a/src/debug.h b/src/debug.h
index 0c6f861ad4..f476b5fcb3 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -93,6 +93,7 @@ struct Debug
bool mNewLine;
};
+void listModelsUnits(const ModelPtr &model);
void printAnalyserModelEquations(const AnalyserModelPtr &model);
void printAnalyserModelVariables(const AnalyserModelPtr &model);
void printAstAsTree(const AnalyserEquationAstPtr &ast);
@@ -101,16 +102,15 @@ void printComponentMap(const ComponentMap &map);
void printConnectionMap(const ConnectionMap &map);
void printEquivalenceMap(const EquivalenceMap &map);
void printEquivalenceMapWithModelInfo(const EquivalenceMap &map, const ModelPtr &model);
+void printEquivalences(const VariablePtr &variable);
void printHistory(const History &history);
void printHistoryEpoch(const HistoryEpochPtr &historyEpoch);
void printImportLibrary(const ImportLibrary &importlibrary);
+void printNamedPath(const ParentedEntityPtr &parented);
void printStack(const IndexStack &stack);
void printStackWithModelInfo(const IndexStack &stack, const ModelPtr &model);
void printStringStringMap(const StringStringMap &map);
-void printVariableMap(const VariableMap &map);
void printUnits(const UnitsPtr &units);
-void listModelsUnits(const ModelPtr &model);
-void printNamedPath(const ParentedEntityPtr &parented);
-void printEquivalences(const VariablePtr &variable);
+void printVariableMap(const VariableMap &map);
} // namespace libcellml
diff --git a/src/importer.cpp b/src/importer.cpp
index 7e74657fa5..dcd4726207 100644
--- a/src/importer.cpp
+++ b/src/importer.cpp
@@ -909,7 +909,7 @@ ComponentPtr flattenComponent(const ComponentEntityPtr &parent, ComponentPtr &co
}
}
- auto replacementUnits = (flattenedUnits != nullptr) ? flattenedUnits->clone() : units;
+ auto replacementUnits = (flattenedUnits != nullptr) ? flattenedUnits : units;
for (size_t unitIndex = 0; unitIndex < replacementUnits->unitCount(); ++unitIndex) {
const std::string ref = replacementUnits->unitAttributeReference(unitIndex);
diff --git a/tests/importer/model_flattening.cpp b/tests/importer/model_flattening.cpp
index 80c218df3f..8cf7935a7c 100644
--- a/tests/importer/model_flattening.cpp
+++ b/tests/importer/model_flattening.cpp
@@ -1918,3 +1918,28 @@ TEST(ModelFlattening, modelWithCnUnitsNotDefinedInImportedComponent)
EXPECT_EQ(size_t(1), importer->errorCount());
EXPECT_EQ("The model is not fully defined.", importer->error(0)->description());
}
+
+TEST(ModelFlattening, multiLayeredImportOfNonStandardUnits)
+{
+ auto parser = libcellml::Parser::create(false);
+ auto model = parser->parseModel(fileContents("importer/periodicstimulus/experiments/periodic-stimulus.xml"));
+
+ EXPECT_EQ(size_t(0), parser->errorCount());
+
+ auto validator = libcellml::Validator::create();
+
+ validator->validateModel(model);
+
+ EXPECT_EQ(size_t(0), validator->issueCount());
+ EXPECT_TRUE(model->hasUnresolvedImports());
+
+ auto importer = libcellml::Importer::create(false);
+
+ importer->resolveImports(model, resourcePath("importer/periodicstimulus/experiments"));
+
+ EXPECT_FALSE(model->hasUnresolvedImports());
+
+ auto flattenModel = importer->flattenModel(model);
+
+ EXPECT_NE(nullptr, flattenModel);
+}
diff --git a/tests/resources/importer/periodicstimulus/components/INa.xml b/tests/resources/importer/periodicstimulus/components/INa.xml
new file mode 100644
index 0000000000..39da14dc55
--- /dev/null
+++ b/tests/resources/importer/periodicstimulus/components/INa.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/tests/resources/importer/periodicstimulus/components/stimulated.xml b/tests/resources/importer/periodicstimulus/components/stimulated.xml
new file mode 100644
index 0000000000..4c045dec44
--- /dev/null
+++ b/tests/resources/importer/periodicstimulus/components/stimulated.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/resources/importer/periodicstimulus/components/units.xml b/tests/resources/importer/periodicstimulus/components/units.xml
new file mode 100644
index 0000000000..d0ec64903f
--- /dev/null
+++ b/tests/resources/importer/periodicstimulus/components/units.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/resources/importer/periodicstimulus/experiments/periodic-stimulus.xml b/tests/resources/importer/periodicstimulus/experiments/periodic-stimulus.xml
new file mode 100644
index 0000000000..e5a96f10fc
--- /dev/null
+++ b/tests/resources/importer/periodicstimulus/experiments/periodic-stimulus.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp
index 8aafe6088e..c4662caa96 100644
--- a/tests/test_utils.cpp
+++ b/tests/test_utils.cpp
@@ -91,7 +91,7 @@ static const std::string FIXED_INDENT = " ";
void printComponent(const libcellml::ComponentPtr &component, size_t c, const std::string &indent, bool includeMaths)
{
- if (c == -1) {
+ if (c == SIZE_MAX) {
std::cout << "COMPONENT: '" << component->name() << "'";
} else {
std::cout << indent << "[" << c + 1 << "]: " << component->name();
@@ -162,7 +162,7 @@ void printComponent(const libcellml::ComponentPtr &component, size_t c, const st
void printComponent(const libcellml::ComponentPtr &component, bool includeMaths)
{
- printComponent(component, -1, {}, includeMaths);
+ printComponent(component, SIZE_MAX, {}, includeMaths);
}
void printModel(const libcellml::ModelPtr &model, bool includeMaths)