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(); }
void testEventTree_serialisation(CuTest* testCase) { cactusEventTreeTestSetup(); int64_t i; void *vA = binaryRepresentation_makeBinaryRepresentation(eventTree, (void (*)(void *, void (*)(const void *, size_t, size_t)))eventTree_writeBinaryRepresentation, &i); CuAssertTrue(testCase, i > 0); eventTree_destruct(eventTree); void *vA2 = vA; eventTree = eventTree_loadFromBinaryRepresentation(&vA2, flower); rootEvent = eventTree_getRootEvent(eventTree); internalEvent = event_getChild(rootEvent, 0); leafEvent1 = event_getChild(internalEvent, 0); leafEvent2 = event_getChild(internalEvent, 1); free(vA); nestedTest = 1; testEventTree_copyConstruct(testCase); testEventTree_getRootEvent(testCase); testEventTree_getEvent(testCase); testEventTree_getCommonAncestor(testCase); testEventTree_getFlower(testCase); testEventTree_getEventNumber(testCase); testEventTree_getFirst(testCase); testEventTree_makeNewickString(testCase); testEventTree_iterator(testCase); testEventTree_addSiblingUnaryEvent(testCase); nestedTest = 0; cactusEventTreeTestTeardown(); }
void testEvent_serialisation(CuTest* testCase) { cactusEventTestSetup(); int64_t i; void *vA = binaryRepresentation_makeBinaryRepresentation(leafEvent1, (void (*)(void *, void (*)(const void *, size_t, size_t)))event_writeBinaryRepresentation, &i); CuAssertTrue(testCase, i > 0); event_destruct(leafEvent1); void *vA2 = vA; leafEvent1 = event_loadFromBinaryRepresentation(&vA2, eventTree); free(vA); nestedTest = 1; testEvent_getParent(testCase); testEvent_getName(testCase); testEvent_getHeader(testCase); testEvent_getBranchLength(testCase); testEvent_getSubTreeBranchLength(testCase); testEvent_getSubTreeEventNumber(testCase); testEvent_getChildNumber(testCase); //testEvent_getChild(testCase); -- won't work as doesn't preserve order of leaves, which is okay -- here's a replacement. CuAssertTrue(testCase, event_getChild(rootEvent, 0) == internalEvent); CuAssertTrue(testCase, event_getChild(internalEvent, 0) == leafEvent2); CuAssertTrue(testCase, event_getChild(internalEvent, 1) == leafEvent1); testEvent_getEventTree(testCase); testEvent_isAncestor(testCase); testEvent_isDescendant(testCase); testEvent_isSibling(testCase); testEvent_isOutgroup(testCase); nestedTest = 0; cactusEventTestTeardown(); }
void testMetaSequence_serialisation(CuTest* testCase) { cactusMetaSequenceTestSetup(); int64_t i; Name name = metaSequence_getName(metaSequence); CuAssertTrue(testCase, cactusDisk_getMetaSequence(cactusDisk, name) == metaSequence); void *vA = binaryRepresentation_makeBinaryRepresentation(metaSequence, (void (*)(void *, void (*)(const void *, size_t, size_t)))metaSequence_writeBinaryRepresentation, &i); CuAssertTrue(testCase, i > 0); metaSequence_destruct(metaSequence); CuAssertTrue(testCase, cactusDisk_getMetaSequence(cactusDisk, name) == NULL); void *vA2 = vA; metaSequence = metaSequence_loadFromBinaryRepresentation(&vA2, cactusDisk); CuAssertTrue(testCase, name == metaSequence_getName(metaSequence)); CuAssertStrEquals(testCase, headerString, metaSequence_getHeader(metaSequence)); CuAssertTrue(testCase, cactusDisk_getMetaSequence(cactusDisk, name) == metaSequence); cactusDisk_write(cactusDisk); metaSequence_destruct(metaSequence); CuAssertTrue(testCase, cactusDisk_getMetaSequence(cactusDisk, name) != NULL); metaSequence = cactusDisk_getMetaSequence(cactusDisk, name); nestedTest = 1; testMetaSequence_getName(testCase); testMetaSequence_getStart(testCase); testMetaSequence_getLength(testCase); testMetaSequence_getEventName(testCase); testMetaSequence_getString(testCase); testMetaSequence_getHeader(testCase); testMetaSequence_isTrivialSequence(testCase); nestedTest = 0; cactusMetaSequenceTestTeardown(); }
void testBinaryRepresentation_makeBinaryRepresentation(CuTest* testCase) { cactusSerialisationTestSetup(); int64_t i, j; i = 14314; void *vA = binaryRepresentation_makeBinaryRepresentation(&i, testBinaryRepresentation_fn, &j); void *vA2 = vA; CuAssertTrue(testCase, j == sizeof(int64_t)); CuAssertIntEquals(testCase, binaryRepresentation_getInteger(&vA2), i); free(vA); cactusSerialisationTestTeardown(); }
void testEnd_serialisation(CuTest* testCase) { cactusEndTestSetup(); Name rootInstanceName = cap_getName(rootCap); Name leaf1InstanceName = cap_getName(leaf1Cap); Name leaf2InstanceName = cap_getName(leaf2Cap); Name leaf3InstanceName = cap_getName(leaf3Cap); int64_t i; void *vA = binaryRepresentation_makeBinaryRepresentation(end, (void(*)(void *, void(*)(const void *, size_t, size_t))) end_writeBinaryRepresentation, &i); CuAssertTrue(testCase, i > 0); end_destruct(end); void *vA2 = vA; end = end_loadFromBinaryRepresentation(&vA2, flower); rootCap = cap_getReverse(end_getInstance(end, rootInstanceName)); leaf1Cap = cap_getReverse(end_getInstance(end, leaf1InstanceName)); leaf2Cap = end_getInstance(end, leaf2InstanceName); leaf3Cap = cap_getReverse(end_getInstance(end, leaf3InstanceName)); CuAssertTrue(testCase, leaf3Cap != NULL); free(vA); nestedTest = 1; testEnd_copyConstruct(testCase); testEnd_getName(testCase); testEnd_getOrientation(testCase); testEnd_getReverse(testCase); testEnd_getSide(testCase); testEnd_getFlower(testCase); testEnd_getBlock(testCase); testEnd_getOtherBlockEnd(testCase); testEnd_getGroup(testCase); testEnd_setGroup(testCase); testEnd_getInstanceNumber(testCase); testEnd_getInstance(testCase); testEnd_getFirst(testCase); testEnd_getSetRootInstance(testCase); testEnd_instanceIterator(testCase); testEnd_isBlockOrStubEnd(testCase); testEnd_isAttachedOrFree(testCase); testEnd_getCapForEvent(testCase); nestedTest = 0; cactusEndTestTeardown(); }
void testBlock_serialisation(CuTest* testCase) { cactusBlockTestSetup(); Name rootInstanceName = segment_getName(rootSegment); Name leaf1InstanceName = segment_getName(leaf1Segment); Name leaf2InstanceName = segment_getName(leaf2Segment); int64_t i; void *vA = binaryRepresentation_makeBinaryRepresentation(block, (void(*)(void *, void(*)(const void *, size_t, size_t))) block_writeBinaryRepresentation, &i); CuAssertTrue(testCase, i > 0); block_destruct(block); void *vA2 = vA; block = block_loadFromBinaryRepresentation(&vA2, flower); rootSegment = segment_getReverse(block_getInstance(block, rootInstanceName)); leaf1Segment = block_getInstance(block, leaf1InstanceName); leaf2Segment = segment_getReverse(block_getInstance(block, leaf2InstanceName)); free(vA); nestedTest = 1; testBlock_getName(testCase); testBlock_getOrientation(testCase); testBlock_getReverse(testCase); testBlock_getLength(testCase); testBlock_getFlower(testCase); testBlock_getLeftEnd(testCase); testBlock_getRightEnd(testCase); testBlock_getSetRootInstance(testCase); testBlock_getInstanceNumber(testCase); testBlock_getInstance(testCase); testBlock_getFirst(testCase); testBlock_instanceIterator(testCase); testBlock_makeNewickString(testCase); testBlock_getChain(testCase); testBlock_getSegmentForEvent(testCase); nestedTest = 0; cactusBlockTestTeardown(); }
void cactusDisk_addUpdateRequest(CactusDisk *cactusDisk, Flower *flower) { int64_t recordSize; void *vA = binaryRepresentation_makeBinaryRepresentation(flower, (void (*)(void *, void (*)(const void * ptr, size_t size, size_t count))) flower_writeBinaryRepresentation, &recordSize); //Compression vA = compress(vA, &recordSize); if (containsRecord(cactusDisk, flower_getName(flower))) { int64_t recordSize2; void *vA2 = stCache_getRecord(cactusDisk->cache, flower_getName(flower), 0, INT64_MAX, &recordSize2); if (!stCache_recordsIdentical(vA, recordSize, vA2, recordSize2)) { //Only rewrite if we actually did something stList_append(cactusDisk->updateRequests, stKVDatabaseBulkRequest_constructUpdateRequest(flower_getName(flower), vA, recordSize)); } free(vA2); } else { stList_append(cactusDisk->updateRequests, stKVDatabaseBulkRequest_constructInsertRequest(flower_getName(flower), vA, recordSize)); } free(vA); }
void testCap_serialisation(CuTest* testCase) { cactusCapTestSetup(); int64_t i; void *vA = binaryRepresentation_makeBinaryRepresentation(leaf2Cap, (void(*)(void *, void(*)(const void *, size_t, size_t))) cap_writeBinaryRepresentation, &i); CuAssertTrue(testCase, i > 0); cap_destruct(leaf2Cap); void *vA2 = vA; leaf2Cap = cap_loadFromBinaryRepresentation(&vA2, end); free(vA); nestedTest = 1; testCap_getName(testCase); testCap_getOrientation(testCase); testCap_getReverse(testCase); testCap_getEvent(testCase); testCap_getEnd(testCase); testCap_getSegment(testCase); testCap_getOtherSegmentCap(testCase); testCap_segmentCoordinates(testCase); testCap_segmentCoordinatesReverseStrand(testCase); testCap_getCoordinate(testCase); testCap_setCoordinate(testCase); testCap_getStrand(testCase); testCap_getSide(testCase); testCap_getSequence(testCase); testCap_adjacent(testCase); testCap_getTopCap(testCase); testCap_getTopFace(testCase); testCap_getBottomAndTopFaceEnd(testCase); testCap_getParent(testCase); testCap_getChildNumber(testCase); testCap_getChild(testCase); testCap_isInternal(testCase); nestedTest = 0; cactusCapTestTeardown(); }
void cactusDisk_write(CactusDisk *cactusDisk) { Flower *flower; int64_t recordSize; stList *removeRequests = stList_construct3(0, (void (*)(void *)) stIntTuple_destruct); st_logDebug("Starting to write the cactus to disk\n"); stSortedSetIterator *it = stSortedSet_getIterator(cactusDisk->flowers); //Sort flowers to update. while ((flower = stSortedSet_getNext(it)) != NULL) { cactusDisk_addUpdateRequest(cactusDisk, flower); } stSortedSet_destructIterator(it); st_logDebug("Got the flowers to update\n"); //Remove nets that are marked for deletion.. it = stSortedSet_getIterator(cactusDisk->flowerNamesMarkedForDeletion); char *nameString; while ((nameString = stSortedSet_getNext(it)) != NULL) { Name name = cactusMisc_stringToName(nameString); if (containsRecord(cactusDisk, name)) { stList_append(cactusDisk->updateRequests, stKVDatabaseBulkRequest_constructUpdateRequest(name, &name, 0)); //We set it to null in the first atomic operation. stList_append(removeRequests, stIntTuple_construct1(name)); } } stSortedSet_destructIterator(it); st_logDebug("Avoided updating nets marked for deletion\n"); // Insert and/or update meta-sequences. it = stSortedSet_getIterator(cactusDisk->metaSequences); MetaSequence *metaSequence; while ((metaSequence = stSortedSet_getNext(it)) != NULL) { void *vA = binaryRepresentation_makeBinaryRepresentation(metaSequence, (void (*)(void *, void (*)(const void * ptr, size_t size, size_t count))) metaSequence_writeBinaryRepresentation, &recordSize); //Compression vA = compress(vA, &recordSize); if (!containsRecord(cactusDisk, metaSequence_getName(metaSequence))) { stList_append(cactusDisk->updateRequests, stKVDatabaseBulkRequest_constructInsertRequest(metaSequence_getName(metaSequence), vA, recordSize)); } else { stList_append(cactusDisk->updateRequests, stKVDatabaseBulkRequest_constructUpdateRequest(metaSequence_getName(metaSequence), vA, recordSize)); } free(vA); } stSortedSet_destructIterator(it); st_logDebug("Got the sequences we are going to add to the database.\n"); if (!containsRecord(cactusDisk, CACTUS_DISK_PARAMETER_KEY)) { //We only write the parameters once. //Finally the database info. void *cactusDiskParameters = binaryRepresentation_makeBinaryRepresentation(cactusDisk, (void (*)(void *, void (*)(const void * ptr, size_t size, size_t count))) cactusDisk_writeBinaryRepresentation, &recordSize); //Compression cactusDiskParameters = compress(cactusDiskParameters, &recordSize); stList_append(cactusDisk->updateRequests, stKVDatabaseBulkRequest_constructInsertRequest(CACTUS_DISK_PARAMETER_KEY, cactusDiskParameters, recordSize)); free(cactusDiskParameters); } st_logDebug("Checked if need to write the initial parameters\n"); if (stList_length(cactusDisk->updateRequests) > 0) { st_logDebug("Going to write %" PRIi64 " updates\n", stList_length(cactusDisk->updateRequests)); stTry { st_logDebug("Writing %" PRIi64 " updates\n", stList_length(cactusDisk->updateRequests)); assert(stList_length(cactusDisk->updateRequests) > 0); stKVDatabase_bulkSetRecords(cactusDisk->database, cactusDisk->updateRequests); } stCatch(except) { stThrowNewCause(except, ST_KV_DATABASE_EXCEPTION_ID, "Failed when trying to set records in updating the cactus disk"); }stTryEnd ; }