LONGBOW_TEST_CASE(Local, _cpiAddressList_FreeAddress) { CPIAddress *address = cpiAddress_CreateFromInterface(1); _cpiAddressList_FreeAddress((void **) &address); assertTrue(parcMemory_Outstanding() == 0, "Got memory imbalance: %u", parcMemory_Outstanding()); }
/** * Ensure that the scheduler is using parc memory inside libevent */ LONGBOW_TEST_CASE(Global, parc_EventScheduler_Memory) { PARCEventScheduler *parcEventScheduler = parcEventScheduler_Create(); assertNotNull(parcEventScheduler, "parcEventScheduler_Create returned a null reference"); size_t baseline = parcMemory_Outstanding(); struct event *testEvent = event_new(parcEventScheduler_GetEvBase(parcEventScheduler), -1, 0, _test_memory_event, NULL); assertTrue(parcMemory_Outstanding() > baseline, "event_new() did not increase parcMemory_Outstanding: baseline %zu now %u", baseline, parcMemory_Outstanding()); event_free(testEvent); assertTrue(parcMemory_Outstanding() == baseline, "event_free() did reduce to baseline: baseline %zu now %u", baseline, parcMemory_Outstanding()); parcEventScheduler_Destroy(&parcEventScheduler); assertTrue(parcSafeMemory_ReportAllocation(STDOUT_FILENO) == 0, "Memory imbalance on create/destroy: %u", parcMemory_Outstanding()); }
LONGBOW_TEST_CASE(Global, cpiAddress_BuildString) { CPIAddress *address = cpiAddress_CreateFromInterface(1); uint32_t beforeBalance = parcMemory_Outstanding(); PARCBufferComposer *composer = cpiAddress_BuildString(address, parcBufferComposer_Create()); parcBufferComposer_Release(&composer); uint32_t afterBalance = parcMemory_Outstanding(); cpiAddress_Destroy(&address); assertTrue(beforeBalance == afterBalance, "Memory leak off by %d allocations", (int) (afterBalance - beforeBalance)); }
LONGBOW_TEST_CASE(Global, rtaApiConnection_Create_Destroy) { TestData *data = longBowTestCase_GetClipBoardData(testCase); uint32_t beforeBalance = parcMemory_Outstanding(); RtaApiConnection *apiConnection = rtaApiConnection_Create(data->connection); assertNotNull(apiConnection, "Got null API connection"); rtaApiConnection_Destroy(&apiConnection); assertNull(apiConnection, "Destroy did not null apiConnection"); uint32_t afterBalance = parcMemory_Outstanding(); assertTrue(beforeBalance == afterBalance, "Memory imbalance: %d", (int) (afterBalance - beforeBalance)); }
LONGBOW_TEST_CASE(Global, metisFibEntry_Create_Destroy) { CCNxName *ccnxName = ccnxName_CreateFromURI("lci:/foo/bar"); MetisTlvName *tlvName = metisTlvName_CreateFromCCNxName(ccnxName); size_t beforeMemory = parcMemory_Outstanding(); MetisFibEntry *fibEntry = metisFibEntry_Create(tlvName); metisFibEntry_Release(&fibEntry); size_t afterMemory = parcMemory_Outstanding(); metisTlvName_Release(&tlvName); ccnxName_Release(&ccnxName); assertTrue(beforeMemory == afterMemory, "Memory imbalance on create/destroy: expected %zu got %zu", beforeMemory, afterMemory); }
LONGBOW_TEST_CASE(Global, metisMessage_Copy) { char message_str[] = "\x00Once upon a time, in a stack far away, a dangling pointer found its way to the top of the heap."; PARCEventBuffer *buff = parcEventBuffer_Create(); parcEventBuffer_Append(buff, message_str, sizeof(message_str)); PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *message = metisMessage_CreateFromBuffer(1, 2, buff, logger); metisLogger_Release(&logger); assertNotNull(message, "Got null from metisMessage_CreateFromBuffer"); assertTrue(message->refcount == 1, "Incorrect refcount, expected %u got %u", 1, message->refcount); MetisMessage *copy = metisMessage_Acquire(message); assertTrue(message->refcount == 2, "Incorrect refcount, expected %u got %u", 2, message->refcount); metisMessage_Release(&message); assertTrue(copy->refcount == 1, "Incorrect refcount, expected %u got %u", 1, message->refcount); metisMessage_Release(©); assertTrue(parcMemory_Outstanding() == 0, "Memory balance should be zero after destroying last copy, got %u", parcMemory_Outstanding()); }
LONGBOW_TEST_CASE(Global, cpiAddressList_ToString) { CPIAddressList *truth_list = cpiAddressList_Create(); int loops = 2; for (int i = 0; i < loops; i++) { cpiAddressList_Append(truth_list, cpiAddress_CreateFromInterface(i)); } uint32_t beforeMemory = parcMemory_Outstanding(); char *string = cpiAddressList_ToString(truth_list); assertNotNull(string, "Got null string from ToString"); parcMemory_Deallocate((void **) &string); uint32_t afterMemory = parcMemory_Outstanding(); cpiAddressList_Destroy(&truth_list); assertTrue(beforeMemory == afterMemory, "Memory leak from ToString by %d allocations", (int) (afterMemory - beforeMemory)); }
LONGBOW_TEST_CASE(Global, cpiAddressList_Create_Destroy) { CPIAddressList *list = cpiAddressList_Create(); cpiAddressList_Destroy(&list); assertTrue(parcMemory_Outstanding() == 0, "Got memory imbalance: %u", parcMemory_Outstanding()); }