IMPLEMENT_TEST(MsaImporterExporterUnitTests, importExportAlignment) {
    const U2DbiRef& dbiRef = MsaImporterExporterTestData::getDbiRef();

    U2OpStatusImpl os;

    // Init an alignment
    QString alignmentName = "Test alignment";
    DNAAlphabetRegistry* alphabetRegistry = AppContext::getDNAAlphabetRegistry();
    const DNAAlphabet* alphabet = alphabetRegistry->findById(BaseDNAAlphabetIds::NUCL_DNA_DEFAULT());

    QByteArray firstSequence("---AG-T");
    QByteArray secondSequence("AG-CT-TAA");

    MultipleSequenceAlignment al(alignmentName, alphabet);

    al->addRow("First row", firstSequence);
    al->addRow("Second row", secondSequence);

    // Import the alignment
    QScopedPointer<MultipleSequenceAlignmentObject> msaObj(MultipleSequenceAlignmentImporter::createAlignment(dbiRef, al, os));
    CHECK_NO_ERROR(os);

    // Export the alignment
    MultipleSequenceAlignmentExporter alExporter;
    MultipleSequenceAlignment alActual = alExporter.getAlignment(dbiRef, msaObj->getEntityRef().entityId, os);
    CHECK_NO_ERROR(os);

    bool alsEqual = (*al == *alActual);
    CHECK_TRUE(alsEqual, "Actual alignment doesn't equal to the original!");
    CHECK_EQUAL(alignmentName, alActual->getName(), "alignment name");
}
Ejemplo n.º 2
0
IMPLEMENT_TEST(MsaUtilsUnitTests, all_names_with_spaces){
    U2OpStatusImpl os;

    // Prepare input data
    const DNAAlphabet* alphabet = U2AlphabetUtils::getById(BaseDNAAlphabetIds::NUCL_DNA_DEFAULT());
    MAlignment ma1("nigguz1_all_names_with_spaces", alphabet);
    ma1.addRow("diss 1", "AAAA--AAA", -1, os);
    CHECK_NO_ERROR(os);
    ma1.addRow("fiss 2", "C--CCCCCC", -1, os);
    CHECK_NO_ERROR(os);
    ma1.addRow("ziss 3", "GG-GGGG-G", -1, os);
    CHECK_NO_ERROR(os);
    ma1.addRow("riss 4", "TTT-TTTT", -1, os);
    CHECK_NO_ERROR(os);

    MAlignment ma2("nigguz2_two_all_names_with_spaces", alphabet);
    ma2.addRow("diss_1", "AAAA--AAA", -1, os);
    CHECK_NO_ERROR(os);
    ma2.addRow("fiss_2", "C--CCCCCC", -1, os);
    CHECK_NO_ERROR(os);
    ma2.addRow("ziss_3", "GG-GGGG-G", -1, os);
    CHECK_NO_ERROR(os);
    ma2.addRow("riss_4", "TTT-TTTT", -1, os);
    CHECK_NO_ERROR(os);

    MSAUtils::compareRowsAfterAlignment(ma1, ma2, os);
    CHECK_NO_ERROR(os);
}
Ejemplo n.º 3
0
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, commonUndoRedo_actionUndoActionUndo2) {
    U2OpStatusImpl os;
    U2ObjectDbi *objDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();
    SQLiteDbi *sqliteDbi = SQLiteObjectDbiTestData::getSQLiteDbi();

    // Create test msa
    U2DataId msaId = SQLiteObjectDbiTestData::createTestMsa(true, os);
    CHECK_NO_ERROR(os);

    // Get msa version
    qint64 msaVersion = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);

    // Do an action
    SQLiteObjectDbiTestData::addTestRow(msaId, os);

    // Undo
    objDbi->undo(msaId, os);
    CHECK_NO_ERROR(os);

    // Do an action
    SQLiteObjectDbiTestData::addTestRow(msaId, os);

    // Check there is no obsolete steps
    SQLiteReadQuery qUser("SELECT COUNT(*) FROM UserModStep WHERE object = ?1", sqliteDbi->getDbRef(), os);
    qUser.bindDataId(1, msaId);
    if (qUser.step()) {
        CHECK_EQUAL(1, qUser.getInt64(0), "number of user steps");
    }
    else {
        CHECK_TRUE(false, "Unexpected error!");
    }
    CHECK_NO_ERROR(os);

    SQLiteReadQuery qSingle("SELECT COUNT(*) FROM SingleModStep WHERE object = ?1", sqliteDbi->getDbRef(), os);
    qSingle.bindDataId(1, msaId);
    if (qSingle.step()) {
        CHECK_EQUAL(1, qSingle.getInt64(0), "number of single steps");
    }
    else {
        CHECK_TRUE(false, "Unexpected error!");
    }
    CHECK_NO_ERROR(os);

    // Undo
    objDbi->undo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify msa version
    qint64 msaVersionAfter = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersion, msaVersionAfter, "msa version after action, undo, action, undo");

    // Verify canUndo/canRedo
    bool undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    bool redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_FALSE(undoState, "undo state after undo, action and undo/redo");
    CHECK_TRUE(redoState, "redo state after undo, action and undo/redo");
}
Ejemplo n.º 4
0
IMPLEMENT_TEST(TextObjectUnitTests, remove) {
    U2OpStatusImpl os;
    QScopedPointer<TextObject> object(TextObject::createInstance("some text", "object", TextObjectTestData::getDbiRef(), os));
    CHECK_NO_ERROR(os);
    U2DataId objId = object->getEntityRef().entityId;

    TextObjectTestData::getObjDbi()->removeObject(objId, os);
    CHECK_NO_ERROR(os);

    QList<UdrRecord> records = TextObjectTestData::getUdrDbi()->getObjectRecords(RawDataUdrSchema::ID, objId, os);
    CHECK_NO_ERROR(os);
    CHECK_TRUE(records.isEmpty(), "records");
}
Ejemplo n.º 5
0
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, canUndoRedo_noAction) {
    U2OpStatusImpl os;
    U2ObjectDbi* objDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();

    // Create test msa
    U2DataId msaId = SQLiteObjectDbiTestData::createTestMsa(true, os);
    CHECK_NO_ERROR(os);

    // Verify canUndo/canRedo
    bool undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    bool redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_FALSE(undoState, "undo state");
    CHECK_FALSE(redoState, "redo state");
}
Ejemplo n.º 6
0
IMPLEMENT_TEST(TextObjectUnitTests, createInstance) {
    U2OpStatusImpl os;
    QScopedPointer<TextObject> object(TextObject::createInstance("some text", "object", TextObjectTestData::getDbiRef(), os));
    CHECK_NO_ERROR(os);

    CHECK_TRUE("some text" == object->getText(), "text");
}
Ejemplo n.º 7
0
IMPLEMENT_TEST(AnnotationGroupUnitTest, groupHierarchy) {
    const U2DbiRef dbiRef(getDbiRef());
    SharedAnnotationData anData = createTestAnnotationData();
    const QString groupName1 = "subgroup1";
    const QString groupName2 = "subgroup1/subgroup11";
    const QString groupName3 = "subgroup2/subgroup21";

    AnnotationTableObject ft("aname_table", dbiRef);
    ft.addAnnotations(QList<SharedAnnotationData>() << anData, groupName1);
    ft.addAnnotations(QList<SharedAnnotationData>() << anData, groupName2);
    ft.addAnnotations(QList<SharedAnnotationData>() << anData, groupName3);

    AnnotationGroup *rootGroup = ft.getRootGroup();
    CHECK_FALSE(rootGroup->isTopLevelGroup(), "Unexpected top level group");
    CHECK_EQUAL(1, rootGroup->getGroupDepth(), "Root group's depth");
    CHECK_EQUAL(QString(), rootGroup->getGroupPath(), "Root group's path");

    const QList<AnnotationGroup *> subgroups = rootGroup->getSubgroups();
    CHECK_EQUAL(2, subgroups.size(), "Count of subgroups");

    QBitArray groupMatches(2, false);
    foreach (AnnotationGroup *subgroup, subgroups) {
        CHECK_TRUE(subgroup->isTopLevelGroup(), "Unexpected top level group");
        CHECK_TRUE(rootGroup->isParentOf(subgroup), "Unexpected parent group");
        CHECK_EQUAL(2, subgroup->getGroupDepth(), "Subgroup's depth");

        U2OpStatusImpl os;
        const U2Feature f = U2FeatureUtils::getFeatureById(subgroup->id, dbiRef, os);
        CHECK_NO_ERROR(os);
        AnnotationGroup *secondLevelSubgroup = subgroup;
        if ("subgroup1" == f.name) {
            groupMatches.setBit(0, true);
            CHECK_EQUAL("subgroup1", subgroup->getGroupPath(), "Subgroup's path");

            const QList<AnnotationGroup *> secondLevelSubgroups = subgroup->getSubgroups();
            CHECK_EQUAL(1, secondLevelSubgroups.size(), "Count of 2nd level subgroups");

            secondLevelSubgroup = secondLevelSubgroups.first();
            CHECK_EQUAL("subgroup1/subgroup11", secondLevelSubgroup->getGroupPath(), "Subgroup's path");
        } else if ("subgroup2" == f.name) {
            groupMatches.setBit(1, true);
            CHECK_EQUAL("subgroup2", subgroup->getGroupPath(), "Subgroup's path");

            const QList<AnnotationGroup *> secondLevelSubgroups = subgroup->getSubgroups();
            CHECK_EQUAL(1, secondLevelSubgroups.size(), "Count of 2nd level subgroups");

            secondLevelSubgroup = secondLevelSubgroups.first();
            CHECK_EQUAL("subgroup2/subgroup21", secondLevelSubgroup->getGroupPath(), "Subgroup's path");
        }
        CHECK_FALSE(secondLevelSubgroup->isTopLevelGroup(), "Unexpected top level group");
        CHECK_TRUE(subgroup->isParentOf(secondLevelSubgroup), "Unexpected parent group");
        CHECK_EQUAL(3, secondLevelSubgroup->getGroupDepth(), "Subgroup's depth");
    }
Ejemplo n.º 8
0
IMPLEMENT_TEST(TextObjectUnitTests, clone) {
    TextObject object("object", TextObjectTestData::getObjRef());

    U2OpStatusImpl os;
    GObject *clonedGObj = object.clone(TextObjectTestData::getDbiRef(), os);
    QScopedPointer<TextObject> cloned(dynamic_cast<TextObject*>(clonedGObj));
    CHECK_NO_ERROR(os);

    cloned->setText("cloned text");

    CHECK_TRUE("text" == object.getText(), "text");
    CHECK_TRUE("cloned text" == cloned->getText(), "cloned text");
}
Ejemplo n.º 9
0
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, setTrackModType) {
    U2OpStatusImpl os;
    U2MsaDbi *msaDbi = SQLiteObjectDbiTestData::getMsaDbi();
    SQLiteObjectDbi *objectDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();

    // Create alignment 1
    U2DataId msaId1 = msaDbi->createMsaObject("", "Test name 1", BaseDNAAlphabetIds::NUCL_DNA_DEFAULT(), os);
    CHECK_NO_ERROR(os);
    Utils::addRow(msaDbi->getRootDbi(), msaId1, "1", "ACGTACGT", QList<U2MsaGap>(), os);
    CHECK_NO_ERROR(os);
    QList<U2MsaRow> rows1 = msaDbi->getRows(msaId1, os);
    CHECK_NO_ERROR(os);

    // Create alignment 2
    U2DataId msaId2 = msaDbi->createMsaObject("", "Test name 2", BaseDNAAlphabetIds::NUCL_DNA_DEFAULT(), os);
    CHECK_NO_ERROR(os);
    Utils::addRow(msaDbi->getRootDbi(), msaId2, "2", "CCCCCCC", QList<U2MsaGap>(), os);
    CHECK_NO_ERROR(os);
    QList<U2MsaRow> rows2 = msaDbi->getRows(msaId2, os);
    CHECK_NO_ERROR(os);

    // Change mod track 1
    objectDbi->setTrackModType(msaId1, TrackOnUpdate, os);
    CHECK_NO_ERROR(os);

    U2TrackModType newType1_1 = objectDbi->getTrackModType(rows1[0].sequenceId, os);
    CHECK_EQUAL(TrackOnUpdate, newType1_1, "new mod track type 1_1");

    U2TrackModType newType1_2 = objectDbi->getTrackModType(rows2[0].sequenceId, os);
    CHECK_EQUAL(NoTrack, newType1_2, "new mod track type 1_2");

    // Change mod track 2
    objectDbi->setTrackModType(msaId1, NoTrack, os);
    CHECK_NO_ERROR(os);
    objectDbi->setTrackModType(msaId2, TrackOnUpdate, os);
    CHECK_NO_ERROR(os);

    U2TrackModType newType2_1 = objectDbi->getTrackModType(rows1[0].sequenceId, os);
    CHECK_EQUAL(NoTrack, newType2_1, "new mod track type 2_1");

    U2TrackModType newType2_2 = objectDbi->getTrackModType(rows2[0].sequenceId, os);
    CHECK_EQUAL(TrackOnUpdate, newType2_2, "new mod track type 2_2");
}
Ejemplo n.º 10
0
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, canUndoRedo_oneUserStep) {
    U2OpStatusImpl os;
    U2ObjectDbi* objDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();

    // Create test msa
    U2DataId msaId = SQLiteObjectDbiTestData::createTestMsa(true, os);
    CHECK_NO_ERROR(os);

    // Do action twice inside one UserStep
    {
        U2UseCommonUserModStep userStep(objDbi->getRootDbi(), msaId, os);
        CHECK_NO_ERROR(os);
        Q_UNUSED(userStep);

        SQLiteObjectDbiTestData::addTestRow(msaId, os);
        CHECK_NO_ERROR(os);
        SQLiteObjectDbiTestData::addTestRow(msaId, os);
        CHECK_NO_ERROR(os);
    }

    // Verify canUndo/canRedo
    bool undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    bool redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_TRUE(undoState, "undo state before undo");
    CHECK_FALSE(redoState, "redo state before undo");

    // Undo UserStep
    objDbi->undo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify canUndo/canRedo
    undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_FALSE(undoState, "undo state after undo");
    CHECK_TRUE(redoState, "redo state after undo");
}
Ejemplo n.º 11
0
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, canUndoRedo_midState) {
    U2OpStatusImpl os;
    U2ObjectDbi* objDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();

    // Create test msa
    U2DataId msaId = SQLiteObjectDbiTestData::createTestMsa(true, os);
    CHECK_NO_ERROR(os);

    // Do action twice, undo
    SQLiteObjectDbiTestData::addTestRow(msaId, os);
    CHECK_NO_ERROR(os);
    SQLiteObjectDbiTestData::addTestRow(msaId, os);
    CHECK_NO_ERROR(os);

    objDbi->undo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify canUndo/canRedo
    bool undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    bool redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_TRUE(undoState, "undo state");
    CHECK_TRUE(redoState, "redo state");
}
int
aagAppendGroupKeyForRsn(tAniPacket *packet)
{
#if 0
    tAniPacket *groupKey = NULL;
#else
    tANI_U8 groupKey[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                          0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15};
#endif
    tANI_U8 *groupKeyBytes = NULL;
    tANI_U8 *lenPtr = NULL;
    tANI_U8 *endPtr = NULL;
    int groupKeyLen;
    int retVal;

#if 0
    groupKey = AAG_GROUP_KEY(radioId);
    if (groupKey == NULL) {
        ANI_AAG_LOG_E("Group key is not yet set on radio %d, id %d!",
                      radioId, AAG_GROUP_KEY_ID(radioId));
        assert(0 && "Group key is still NULL!");
        return ANI_E_FAILED;
    }

    groupKeyLen = aniAsfPacketGetBytes(groupKey, &groupKeyBytes);
    CHECK_NO_ERROR(groupKeyLen);

    if (aagConfig.logLevel >= LOG_INFO) {
        ANI_AAG_LOG_D("Will encapsulate group key bytes %s",
                      aniAsfHexStr(groupKeyBytes, groupKeyLen));
    }
#else
    groupKeyBytes = groupKey;

    groupKeyLen = STATIC_WEP_KEY_LEN;
#endif

    /*
     * Add the key data encapsulation needed for RSN/WPA2
     */

    // The IE ID
    retVal = aniAsfPacketAppend8(packet, ANI_SSM_IE_RSN_KEY_DATA_ENCAPS_ID);
    //CHECK_NO_ERROR(retVal);

    // Obtain the position for the length
    aniAsfPacketGetBytesFromTail(packet, &lenPtr);

    // Write out a dummy length - we'll fill this in later. It will be 
    // 6 bytes more than the length of the GTK
    retVal = aniAsfPacketAppend8(packet, 0);
    //CHECK_NO_ERROR(retVal);

    // Copy the RSN OUI
    retVal = aniAsfPacketAppendBuffer(packet, aniSsmIeRsnOui, sizeof(aniSsmIeRsnOui));
    //CHECK_NO_ERROR(retVal);

    // Indicate that the key type is group key
    retVal = aniAsfPacketAppend8(packet, ANI_SSM_IE_RSN_GROUP_KEY_DATA_ENCAPS_ID);
    //CHECK_NO_ERROR(retVal);
 
    // Copy the key-id to the first two bits of the next byte
    // Copy the Tx bit the third bit of the same byte
    // (Here, I assume the Group Key is to be used for both STA Tx and Rx)
    retVal = aniAsfPacketAppend8(
            packet,
            GROUP_KEY_ID );
            //AAG_GROUP_KEY_ID(radioId) );
    //CHECK_NO_ERROR(retVal);

    retVal = aniAsfPacketMoveRight(packet, 1); // Reserved bits (1 byte)
    //CHECK_NO_ERROR(retVal);

    // Copy the real key bytes
    retVal = aniAsfPacketAppendBuffer(packet, groupKeyBytes, groupKeyLen);
    //CHECK_NO_ERROR(retVal);
    
    // Calculate and enter the length of the entire encoding
    aniAsfPacketGetBytesFromTail(packet, &endPtr);
    *lenPtr = endPtr - (lenPtr + 1) ; // subtract one to avoid tail

    return retVal;
}
Ejemplo n.º 13
0
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, commonUndoRedo_user3Single6) {
    U2OpStatusImpl os;
    U2ObjectDbi *objDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();
    SQLiteDbi *sqliteDbi = SQLiteObjectDbiTestData::getSQLiteDbi();

    // Create test msa
    U2DataId msaId = SQLiteObjectDbiTestData::createTestMsa(true, os);
    CHECK_NO_ERROR(os);

    // Get msa version
    qint64 msaVersion = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);

    // User step 1
    {
        U2UseCommonUserModStep userStep(objDbi->getRootDbi(), msaId, os);
        CHECK_NO_ERROR(os);
        Q_UNUSED(userStep);

        SQLiteObjectDbiTestData::addTestRow(msaId, os); // multi/single step 1
        CHECK_NO_ERROR(os);

        SQLiteObjectDbiTestData::addTestRow(msaId, os); // multi/single step 2
        CHECK_NO_ERROR(os);
    }

    // User step 2
    SQLiteObjectDbiTestData::addTestRow(msaId, os); // multi/single step 3

    // Verify version
    qint64 msaVersionAfterUser1 = msaVersion + 2; // verified in another test
    qint64 msaVersionAfterUser2 = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersionAfterUser1 + 1, msaVersionAfterUser2, "msa version after user step 2");

    // Verify canUndo/canRedo
    bool undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    bool redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_TRUE(undoState, "undo state after user step 2");
    CHECK_FALSE(redoState, "redo state after user step 2");

    // User step 3
    U2Sequence seq;
    seq.alphabet = BaseDNAAlphabetIds::NUCL_DNA_DEFAULT();
    seq.circular = false;
    seq.trackModType = NoTrack;
    seq.visualName = "Test sequence";
    sqliteDbi->getSQLiteSequenceDbi()->createSequenceObject(seq, "", os, U2DbiObjectRank_TopLevel);
    CHECK_NO_ERROR(os);

    U2MsaRow row;
    row.sequenceId = seq.id;
    row.gstart = 0;
    row.gend = 0;
    row.length = 0;

    {
        U2UseCommonUserModStep userStep(objDbi->getRootDbi(), msaId, os);
        CHECK_NO_ERROR(os);
        Q_UNUSED(userStep);

        sqliteDbi->getMsaDbi()->addRow(msaId, -1, row, os); // multi/single step 4
        CHECK_NO_ERROR(os);

        sqliteDbi->getMsaDbi()->updateRowContent(msaId, row.rowId, "ACGT", QList<U2MsaGap>(), os); // multi step 5, single steps 5-6
        CHECK_NO_ERROR(os);
    }

    // Verify version
    qint64 msaVersionAfterUser3 = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersionAfterUser2 + 2, msaVersionAfterUser3, "msa version after user step 3");

    // Verify canUndo/canRedo
    undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_TRUE(undoState, "undo state after user step 3");
    CHECK_FALSE(redoState, "redo state after user step 3");

    // Undo 1 (to user step 2)
    objDbi->undo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify version
    qint64 msaVersionAfterUndo1 = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersionAfterUser2, msaVersionAfterUndo1, "msa version after undo 1");

    // Verify canUndo/canRedo
    undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_TRUE(undoState, "undo state after undo 1");
    CHECK_TRUE(redoState, "redo state after undo 1");

    // Undo 2 (to user step 1)
    objDbi->undo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify version
    qint64 msaVersionAfterUndo2 = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersionAfterUser1, msaVersionAfterUndo2, "msa version after undo 2");

    // Verify canUndo/canRedo
    undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_TRUE(undoState, "undo state after undo 2");
    CHECK_TRUE(redoState, "redo state after undo 2");

    // Undo 3 (to original)
    objDbi->undo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify version
    qint64 msaVersionAfterUndo3 = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersion, msaVersionAfterUndo3, "msa version after undo 3");

    // Verify canUndo/canRedo
    undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_FALSE(undoState, "undo state after undo 3");
    CHECK_TRUE(redoState, "redo state after undo 3");

    // Redo 1 (to user step 1)
    objDbi->redo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify version
    qint64 msaVersionAfterRedo1 = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersionAfterUser1, msaVersionAfterRedo1, "msa version after redo 1");

    // Verify canUndo/canRedo
    undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_TRUE(undoState, "undo state after redo 1");
    CHECK_TRUE(redoState, "redo state after redo 1");

    // Redo 2 (to user step 2)
    objDbi->redo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify version
    qint64 msaVersionAfterRedo2 = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersionAfterUser2, msaVersionAfterRedo2, "msa version after redo 2");

    // Verify canUndo/canRedo
    undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_TRUE(undoState, "undo state after redo 2");
    CHECK_TRUE(redoState, "redo state after redo 2");

    // Redo 3 (to user step 3)
    objDbi->redo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify version
    qint64 msaVersionAfterRedo3 = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersionAfterUser3, msaVersionAfterRedo3, "msa version after redo 3");

    // Verify canUndo/canRedo
    undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_TRUE(undoState, "undo state after redo 3");
    CHECK_FALSE(redoState, "redo state after redo 3");
}
Ejemplo n.º 14
0
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, commonUndoRedo_user3Multi) {
    U2OpStatusImpl os;
    U2ObjectDbi *objDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();
    SQLiteDbi *sqliteDbi = SQLiteObjectDbiTestData::getSQLiteDbi();

    // Create test msa
    U2DataId msaId = SQLiteObjectDbiTestData::createTestMsa(true, os);
    CHECK_NO_ERROR(os);

    // Get msa version
    qint64 msaVersion = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);

    // Do 3 actions
    {
        U2UseCommonUserModStep userStep(objDbi->getRootDbi(), msaId, os);
        CHECK_NO_ERROR(os);
        Q_UNUSED(userStep);

        SQLiteObjectDbiTestData::addTestRow(msaId, os);
        CHECK_NO_ERROR(os);

        SQLiteObjectDbiTestData::addTestRow(msaId, os);
        CHECK_NO_ERROR(os);

        SQLiteObjectDbiTestData::addTestRow(msaId, os);
        CHECK_NO_ERROR(os);
    }

    // Verify version in the userModStep
    SQLiteReadQuery qVersion("SELECT version FROM UserModStep WHERE object = ?1", sqliteDbi->getDbRef(), os);
    qVersion.bindDataId(1, msaId);
    if (qVersion.step()) {
        qint64 userStepVersion = qVersion.getInt64(0);
        CHECK_EQUAL(msaVersion, userStepVersion, "version in user step");
    }
    else {
        CHECK_TRUE(false, "Failed to get userModStep version!");
    }
    CHECK_NO_ERROR(os);

    // Verify msa version
    qint64 msaVersionAftAct = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersion + 3, msaVersionAftAct, "msa version after 3 actions");

    // Verify canUndo/canRedo
    bool undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    bool redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_TRUE(undoState, "undo state before undo");
    CHECK_FALSE(redoState, "redo state before undo");

    // Undo
    objDbi->undo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify msa version
    qint64 msaVersionAftUndo = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersion, msaVersionAftUndo, "msa version after undo");

    // Verify canUndo/canRedo
    undoState = objDbi->canUndo(msaId, os);
    CHECK_NO_ERROR(os);
    redoState = objDbi->canRedo(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_FALSE(undoState, "undo state after undo");
    CHECK_TRUE(redoState, "redo state after undo");

    // Redo
    objDbi->redo(msaId, os);
    CHECK_NO_ERROR(os);

    // Verify msa version
    qint64 msaVersionAftRedo = objDbi->getObjectVersion(msaId, os);
    CHECK_NO_ERROR(os);
    CHECK_EQUAL(msaVersion + 3, msaVersionAftRedo, "msa version after redo");

    // Verify canUndo/canRedo
    undoState = objDbi->canUndo(msaId, os); CHECK_NO_ERROR(os);
    redoState = objDbi->canRedo(msaId, os); CHECK_NO_ERROR(os);
    CHECK_TRUE(undoState, "undo state after redo");
    CHECK_FALSE(redoState, "redo state after redo");
}
Ejemplo n.º 15
0
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, removeMsaObject) {
    U2OpStatusImpl os;
    U2MsaDbi* msaDbi = SQLiteObjectDbiTestData::getMsaDbi();

    // FIRST ALIGNMENT
    // Create an alignment
    U2DataId msaId = msaDbi->createMsaObject("", "Test name", BaseDNAAlphabetIds::NUCL_DNA_DEFAULT(), os);
    CHECK_NO_ERROR(os);

    // Add alignment info
    U2StringAttribute attr(msaId, "MSA1 info key", "MSA1 info value");
    U2AttributeDbi* attrDbi = SQLiteObjectDbiTestData::getAttributeDbi();
    attrDbi->createStringAttribute(attr, os);
    CHECK_NO_ERROR(os);

    // Create sequences
    U2SequenceDbi* sequenceDbi = SQLiteObjectDbiTestData::getSequenceDbi();
    U2Sequence seq1;
    U2Sequence seq2;
    sequenceDbi->createSequenceObject(seq1, "", os);
    CHECK_NO_ERROR(os);
    sequenceDbi->createSequenceObject(seq2, "", os);
    CHECK_NO_ERROR(os);

    // Add rows
    U2MsaRow row1;
    row1.rowId = 0;
    row1.sequenceId = seq1.id;
    row1.gstart = 0;
    row1.gend = 5;

    U2MsaGap row1gap1(0, 2);
    U2MsaGap row1gap2(3, 1);
    QList<U2MsaGap> row1gaps;
    row1gaps << row1gap1 << row1gap2;

    row1.gaps = row1gaps;

    U2MsaRow row2;
    row2.rowId = 1;
    row2.sequenceId = seq2.id;
    row2.gstart = 2;
    row2.gend = 4;

    U2MsaGap row2gap(1, 2);
    QList<U2MsaGap> row2gaps;
    row2gaps << row2gap;

    row2.gaps = row2gaps;

    QList<U2MsaRow> rows;
    rows << row1 << row2;

    msaDbi->addRows(msaId, rows, os);
    CHECK_NO_ERROR(os);

    // SECOND ALIGNMENT
    // Create an alignment
    U2DataId msaId2 = msaDbi->createMsaObject("", "Test name 2", BaseDNAAlphabetIds::AMINO_DEFAULT(), os);
    CHECK_NO_ERROR(os);

    // Add alignment info
    U2StringAttribute attr2(msaId2, "MSA2 info key", "MSA2 info value");
    attrDbi->createStringAttribute(attr2, os);
    CHECK_NO_ERROR(os);

    // Create sequences
    U2Sequence al2Seq;
    sequenceDbi->createSequenceObject(al2Seq, "", os);
    CHECK_NO_ERROR(os);

    // Add rows
    U2MsaRow al2Row;
    al2Row.rowId = 0;
    al2Row.sequenceId = al2Seq.id;
    al2Row.gstart = 0;
    al2Row.gend = 15;

    U2MsaGap al2RowGap(1, 12);
    QList<U2MsaGap> al2RowGaps;
    al2RowGaps << al2RowGap;

    al2Row.gaps = al2RowGaps;

    QList<U2MsaRow> al2Rows;
    al2Rows << al2Row;

    msaDbi->addRows(msaId2, al2Rows, os);
    CHECK_NO_ERROR(os);

    // REMOVE THE FIRST ALIGNMENT OBJECT
    SQLiteObjectDbi* sqliteObjectDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();
    sqliteObjectDbi->removeObject(msaId, os);

    // VERIFY THAT THERE IS ONLY THE SECOND ALIGNMENT'S RECORDS LEFT IN TABLES
    SQLiteDbi* sqliteDbi = SQLiteObjectDbiTestData::getSQLiteDbi();

    // "Attribute"
    SQLiteReadQuery qAttr("SELECT COUNT(*) FROM Attribute WHERE name = ?1", sqliteDbi->getDbRef(), os);
    qAttr.bindString(1, "MSA1 info key");
    qint64 msa1AttrNum = qAttr.selectInt64();
    CHECK_EQUAL(0, msa1AttrNum, "MSA1 attributes number");

    qAttr.reset(true);
    qAttr.bindString(1, "MSA2 info key");
    qint64 msa2AttrNum = qAttr.selectInt64();
    CHECK_EQUAL(1, msa2AttrNum, "MSA2 attributes number");

    // "StringAttribute"
    SQLiteReadQuery qStringAttr("SELECT COUNT(*) FROM StringAttribute WHERE value = ?1", sqliteDbi->getDbRef(), os);
    qStringAttr.bindString(1, "MSA1 info value");
    qint64 msa1StrAttrNum = qStringAttr.selectInt64();
    CHECK_EQUAL(0, msa1StrAttrNum, "MSA1 string attributes number");

    qStringAttr.reset(true);
    qStringAttr.bindString(1, "MSA2 info value");
    qint64 msa2StrAttrNum = qStringAttr.selectInt64();
    CHECK_EQUAL(1, msa2StrAttrNum, "MSA2 string attributes number");

    // "MsaRow"
    SQLiteReadQuery qMsaRow("SELECT COUNT(*) FROM MsaRow WHERE msa = ?1", sqliteDbi->getDbRef(), os);
    qMsaRow.bindDataId(1, msaId);
    qint64 msa1Rows = qMsaRow.selectInt64();
    CHECK_EQUAL(0, msa1Rows, "number of rows in MSA1");

    qMsaRow.reset(true);
    qMsaRow.bindDataId(1, msaId2);
    qint64 msa2Rows = qMsaRow.selectInt64();
    CHECK_EQUAL(1, msa2Rows, "number of rows in MSA2");

    // "MsaRowGap"
    SQLiteReadQuery qMsaRowGap("SELECT COUNT(*) FROM MsaRowGap WHERE msa = ?1", sqliteDbi->getDbRef(), os);
    qMsaRowGap.bindDataId(1, msaId);
    qint64 msa1Gaps = qMsaRowGap.selectInt64();
    CHECK_EQUAL(0, msa1Gaps, "number of gaps in MSA1 rows");

    qMsaRowGap.reset(true);
    qMsaRowGap.bindDataId(1, msaId2);
    qint64 msa2Gaps = qMsaRowGap.selectInt64();
    CHECK_EQUAL(1, msa2Gaps, "number of gaps in MSA2 rows");

    // "Sequence"
    SQLiteReadQuery qSeq("SELECT COUNT(*) FROM Sequence WHERE object = ?1", sqliteDbi->getDbRef(), os);
    qSeq.bindDataId(1, seq1.id);
    qint64 msa1seq1 = qSeq.selectInt64();
    CHECK_EQUAL(0, msa1seq1, "seq1 of msa1");

    qSeq.reset(true);
    qSeq.bindDataId(1, seq2.id);
    qint64 msa1seq2 = qSeq.selectInt64();
    CHECK_EQUAL(0, msa1seq2, "seq2 of msa1");

    qSeq.reset(true);
    qSeq.bindDataId(1, al2Seq.id);
    qint64 msa2seq = qSeq.selectInt64();
    CHECK_EQUAL(1, msa2seq, "seq of msa2");

    // "Msa"
    SQLiteReadQuery qMsa("SELECT COUNT(*) FROM Msa WHERE object = ?1", sqliteDbi->getDbRef(), os);
    qMsa.bindDataId(1, msaId);
    qint64 msa1records = qMsa.selectInt64();
    CHECK_EQUAL(0, msa1records, "number of MSA1 records");

    qMsa.reset(true);
    qMsa.bindDataId(1, msaId2);
    qint64 msa2records = qMsa.selectInt64();
    CHECK_EQUAL(1, msa2records, "number of MSA2 records");

    // "Object"
    SQLiteReadQuery qObj("SELECT COUNT(*) FROM Object WHERE id = ?1", sqliteDbi->getDbRef(), os);
    qObj.bindDataId(1, msaId);
    qint64 msa1objects = qObj.selectInt64();
    CHECK_EQUAL(0, msa1objects, "number of MSA1 objects");

    qObj.reset(true);
    qObj.bindDataId(1, msaId2);
    qint64 msa2objects = qObj.selectInt64();
    CHECK_EQUAL(1, msa2objects, "number of MSA2 objects");

    // Remove the second alignment
    sqliteObjectDbi->removeObject(msaId2, os);
}