Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.20261016.1
1.20261019.0
19 changes: 15 additions & 4 deletions src/sed/sedmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ bool SedModel::Impl::isValid()

// Make sure that the CellML file is valid.

switch (mFile->pimpl()->mCellmlFile->type()) {
const auto &cellmlFile {mFile->pimpl()->mCellmlFile};

switch (cellmlFile->type()) {
case libcellml::AnalyserModel::Type::UNKNOWN:
// The model is unknown which either means that it doesn't contain any variables (i.e. it is empty as far as we
// are concerned) or its imports couldn't be resolved (in which case the CellML file's issues already tell us
// what is wrong).

if (!cellmlFile->hasErrors()) {
addError("The CellML file is empty.");
}

break;
case libcellml::AnalyserModel::Type::INVALID:
addError("The CellML file is invalid.");

Expand All @@ -64,15 +76,14 @@ bool SedModel::Impl::isValid()
addError("The CellML file is unsuitably constrained.");

break;
default: // libcellml::AnalyserModel::Type::UNKNOWN (we should never get this type),
// libcellml::AnalyserModel::Type::ALGEBRAIC,
default: // libcellml::AnalyserModel::Type::ALGEBRAIC,
// libcellml::AnalyserModel::Type::DAE,
// libcellml::AnalyserModel::Type::NLA, or
// libcellml::AnalyserModel::Type::ODE.
break;
}

addIssues(mFile->pimpl()->mCellmlFile, "CellML");
addIssues(cellmlFile, "CellML");

return !hasErrors();
}
Expand Down
26 changes: 26 additions & 0 deletions tests/api/sed/instancetests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ TEST(InstanceSedTest, noFile)
EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES);
}

TEST(InstanceSedTest, emptyModel)
{
static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{
{libOpenCOR::Issue::Type::ERROR, "Task | Model: the CellML file is empty."},
}};

auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("api/sed/empty.cellml"))};
auto document {libOpenCOR::SedDocument::create(file)};
auto instance {document->instantiate()};

EXPECT_EQ_ISSUES(instance, EXPECTED_ISSUES);
}

TEST(InstanceSedTest, cellmlFileWithInvalidImports)
{
static const std::string IMPORTER_ERROR_START {"Task | Model | CellML | Importer: "};

auto file {libOpenCOR::File::create(libOpenCOR::resourcePath("support/cellml/model_with_invalid_imports.cellml"))};
auto document {libOpenCOR::SedDocument::create(file)};
auto instance {document->instantiate()};

GTEST_ASSERT_EQ(instance->issueCount(), 1U);
EXPECT_EQ(instance->issue(0)->type(), libOpenCOR::Issue::Type::ERROR);
EXPECT_EQ(instance->issue(0)->description().substr(0, IMPORTER_ERROR_START.size()), IMPORTER_ERROR_START);
}

TEST(InstanceSedTest, invalidCellmlFile)
{
static const libOpenCOR::ExpectedIssues EXPECTED_ISSUES {{
Expand Down
26 changes: 26 additions & 0 deletions tests/bindings/javascript/sed.instance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ test.describe('Sed instance tests', () => {
]);
});

test('Empty model', () => {
const file = new loc.File(utils.resourcePath('api/sed/empty.cellml'));

file.setContents(utils.fileContents(file.path));

const document = new loc.SedDocument(file);
const instance = document.instantiate();

assertIssues(loc, instance, [[loc.Issue.Type.ERROR, 'Task | Model: the CellML file is empty.']]);
});

test('CellML file with invalid imports', () => {
const IMPORTER_ERROR_START = 'Task | Model | CellML | Importer: ';

const file = new loc.File(utils.resourcePath('support/cellml/model_with_invalid_imports.cellml'));

file.setContents(utils.fileContents(file.path));

const document = new loc.SedDocument(file);
const instance = document.instantiate();

assert.strictEqual(instance.issueCount, 1);
assert.strictEqual(instance.issue(0).type.value, loc.Issue.Type.ERROR.value);
assert.strictEqual(instance.issue(0).description.startsWith(IMPORTER_ERROR_START), true);
});

test('Invalid CellML file', () => {
const file = new loc.File(utils.resourcePath('error.cellml'));

Expand Down
29 changes: 29 additions & 0 deletions tests/bindings/python/test_sed_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,35 @@ def test_no_file():
assert_issues(instance, expected_issues)


def test_empty_model():
expected_issues = [
[
loc.Issue.Type.Error,
"Task | Model: the CellML file is empty.",
],
]

file = loc.File(utils.resource_path("api/sed/empty.cellml"))
document = loc.SedDocument(file)
instance = document.instantiate()

assert_issues(instance, expected_issues)


def test_cellml_file_with_invalid_imports():
importer_error_start = "Task | Model | CellML | Importer: "

file = loc.File(
utils.resource_path("support/cellml/model_with_invalid_imports.cellml")
)
document = loc.SedDocument(file)
instance = document.instantiate()

assert instance.issue_count == 1
assert instance.issues[0].type == loc.Issue.Type.Error
assert instance.issues[0].description.startswith(importer_error_start)


def test_invalid_cellml_file():
expected_issues = [
[
Expand Down
2 changes: 2 additions & 0 deletions tests/res/api/sed/empty.cellml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.cellml.org/cellml/2.0#" name="empty"/>
Loading