Пример #1
0
void testGroup_serialisation(CuTest* testCase) {
    cactusGroupTestSetup();
    int64_t i;
    Name name = group_getName(group);
    void
            *vA =
                    binaryRepresentation_makeBinaryRepresentation(group,
                            (void(*)(void *, void(*)(const void *, size_t,
                                    size_t))) group_writeBinaryRepresentation,
                            &i);
    CuAssertTrue(testCase, i > 0);
    group_destruct(group);
    void *vA2 = vA;
    group = group_loadFromBinaryRepresentation(&vA2, flower);
    free(vA);
    CuAssertTrue(testCase, group_getName(group) == name);
    CuAssertTrue(testCase, group_getFlower(group) == flower);
    CuAssertTrue(testCase, group_getNestedFlower(group) == nestedFlower);
    Group_EndIterator *iterator = group_getEndIterator(group);
    CuAssertTrue(testCase, group_getNextEnd(iterator) == end1);
    CuAssertTrue(testCase, group_getNextEnd(iterator) == end2);
    CuAssertTrue(testCase, group_getNextEnd(iterator) == NULL);
    group_destructEndIterator(iterator);

    cactusGroupTestTeardown();
}
Пример #2
0
bool flower_removeIfRedundant(Flower *flower) {
    if (!flower_isLeaf(flower) && flower_getParentGroup(flower) != NULL && flower_getBlockNumber(flower) == 0) { //We will remove this flower..
        Group *parentGroup = flower_getParentGroup(flower); //This group will be destructed
        //Deal with any parent chain..
        if (group_isLink(parentGroup)) {
            link_split(group_getLink(parentGroup));
        }
        Flower *parentFlower = group_getFlower(parentGroup); //We will add the groups in the flower to the parent

        /*
         * For each group in the flower we take its nested flower and attach it to the parent.
         */
        Group *group;
        Flower_GroupIterator *groupIt = flower_getGroupIterator(flower);
        while ((group = flower_getNextGroup(groupIt)) != NULL) {
            if (!group_isLeaf(group)) {
                //Copy the group into the parent..
                Flower *nestedFlower = group_getNestedFlower(group);
                assert(nestedFlower != NULL);
                Group *newParentGroup = group_construct(parentFlower, nestedFlower);
                flower_setParentGroup(nestedFlower, newParentGroup);
                group_constructChainForLink(newParentGroup);
            } else {
                Group *newParentGroup = group_construct2(parentFlower);
                End *end;
                Group_EndIterator *endIt = group_getEndIterator(group);
                while ((end = group_getNextEnd(endIt)) != NULL) {
                    End *parentEnd = flower_getEnd(parentFlower, end_getName(end));
                    assert(parentEnd != NULL);
                    end_setGroup(parentEnd, newParentGroup);
                }
                group_destructEndIterator(endIt);
                group_constructChainForLink(newParentGroup);
            }
        }
        flower_destructGroupIterator(groupIt);

        //The group attached to the flower should now be empty
        assert(group_getEndNumber(parentGroup) == 0);
        group_destruct(parentGroup);

        //Now wipe the flower out..
        cactusDisk_deleteFlowerFromDisk(flower_getCactusDisk(flower), flower);
        flower_destruct(flower, 0);
        return 1;
    }
    return 0;
}
Пример #3
0
void testGroup_endIterator(CuTest* testCase) {
    cactusGroupTestSetup();
    Group_EndIterator *iterator = group_getEndIterator(group);

    CuAssertTrue(testCase, group_getNextEnd(iterator) == end1);
    CuAssertTrue(testCase, group_getNextEnd(iterator) == end2);
    CuAssertTrue(testCase, group_getNextEnd(iterator) == NULL);

    Group_EndIterator *iterator2 = group_copyEndIterator(iterator);

    CuAssertTrue(testCase, group_getPreviousEnd(iterator) == end2);
    CuAssertTrue(testCase, group_getPreviousEnd(iterator) == end1);
    CuAssertTrue(testCase, group_getPreviousEnd(iterator) == NULL);

    group_destructEndIterator(iterator);

    CuAssertTrue(testCase, group_getPreviousEnd(iterator2) == end2);
    CuAssertTrue(testCase, group_getPreviousEnd(iterator2) == end1);
    CuAssertTrue(testCase, group_getPreviousEnd(iterator2) == NULL);

    group_destructEndIterator(iterator2);

    cactusGroupTestTeardown();
}