Example #1
0
void Tests::basicTests()
{
    // Some very basic tests to make sure that we have access to the CellML API

    // Get a bootstrap object and its model loader

    ObjRef<iface::cellml_api::CellMLBootstrap> cellmlBootstrap = CreateCellMLBootstrap();
    ObjRef<iface::cellml_api::DOMModelLoader> modelLoader = cellmlBootstrap->modelLoader();

    QVERIFY(cellmlBootstrap);
    QVERIFY(modelLoader);

    // Create a CellML 1.0 model

    ObjRef<iface::cellml_api::Model> cellml10Model = cellmlBootstrap->createModel(L"1.0");

    QVERIFY(cellml10Model);

    // Create a CellML 1.1 model

    ObjRef<iface::cellml_api::Model> cellml11Model = cellmlBootstrap->createModel(L"1.1");

    QVERIFY(cellml11Model);

    // Create an invalid CellML model

    ObjRef<iface::cellml_api::Model> invalidCellmlModel;

    try {
        invalidCellmlModel = cellmlBootstrap->createModel(L"xxx");
    } catch (...) {
        QVERIFY(!invalidCellmlModel);
    }

    // Load an existing model

    ObjRef<iface::cellml_api::Model> existingModel = modelLoader->loadFromURL(QUrl::fromPercentEncoding(QUrl::fromLocalFile(QFileInfo(OpenCOR::fileName("models/noble_model_1962.cellml")).canonicalFilePath()).toEncoded()).toStdWString());

    QVERIFY(existingModel);

    QCOMPARE(QString::fromStdWString(existingModel->name()), QString("noble_model_1962"));
    QCOMPARE(QString::fromStdWString(existingModel->cellmlVersion()), QString("1.0"));

    // Load a non-existing model

    ObjRef<iface::cellml_api::Model> nonExistingModel;

    try {
        nonExistingModel = modelLoader->loadFromURL(L"xxx");
    } catch (...) {
        QVERIFY(!nonExistingModel);
    }
}