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, metisMessage_ReadFromBuffer) { 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_ReadFromBuffer(1, 2, buff, sizeof(message_str), logger); metisLogger_Release(&logger); assertNotNull(message, "Got null from metisMessage_CreateFromBuffer"); assertTrue(parcEventBuffer_GetLength(message->messageBytes) == sizeof(message_str), "Length of internal buffer wrong, expected %zu got %zu", sizeof(message_str), parcEventBuffer_GetLength(message->messageBytes)); uint8_t *p = parcEventBuffer_Pullup(message->messageBytes, sizeof(message_str)); assertTrue(memcmp(p, message_str, sizeof(message_str)) == 0, "Internal buffer contents does not match test"); assertTrue(message->ingressConnectionId == 1, "IngressConnectionId wrong, expected %d got %u", 1, message->ingressConnectionId); assertTrue(message->receiveTime == 2, "receiveTime wrong, expected %u got %" PRIu64, 2, message->receiveTime); assertTrue(parcEventBuffer_GetLength(buff) == 0, "Origin buffer not drained, expected 0, got %zu", parcEventBuffer_GetLength(buff)); metisMessage_Release(&message); parcEventBuffer_Destroy(&buff); }
LONGBOW_TEST_CASE(Global, metisMessage_HasGetPublicKey) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *contentWithKey = metisMessage_CreateFromArray(metisTestDataV1_ContentObject_NameA_KeyId1_RsaSha256, sizeof(metisTestDataV1_ContentObject_NameA_KeyId1_RsaSha256), 1, 2, logger); MetisMessage *interestWithKeyIdRestriction = metisMessage_CreateFromArray(metisTestDataV1_Interest_NameAAndKeyId, sizeof(metisTestDataV1_Interest_NameAAndKeyId), 1, 2, logger); metisLogger_Release(&logger); assertTrue(metisMessage_HasPublicKey(contentWithKey), "Expected to see a public key"); assertFalse(metisMessage_HasPublicKey(interestWithKeyIdRestriction), "Expected to not see a public key"); PARCBuffer *key = metisMessage_GetPublicKey(contentWithKey); assertNotNull(key, "Expected to retrieve the public key"); metisMessage_Release(&contentWithKey); metisMessage_Release(&interestWithKeyIdRestriction); }
LONGBOW_TEST_CASE(Global, metisMessage_IsPublicKeyVerified_False) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *contentWithKey = metisMessage_CreateFromArray(metisTestDataV1_ContentObject_NameA_KeyId1_RsaSha256, sizeof(metisTestDataV1_ContentObject_NameA_KeyId1_RsaSha256), 1, 2, logger); MetisMessage *interestWithKeyIdRestriction = metisMessage_CreateFromArray(metisTestDataV1_Interest_NameAAndKeyId, sizeof(metisTestDataV1_Interest_NameAAndKeyId), 1, 2, logger); metisLogger_Release(&logger); assertFalse(metisMessage_IsKeyIdVerified(contentWithKey), "Expected key to not be verified."); // This is an interest. The keyId is actually a KeyId restriction, so will never be verified. assertFalse(metisMessage_IsKeyIdVerified(interestWithKeyIdRestriction), "Expected key to not be verified."); PARCBuffer *key = metisMessage_GetPublicKey(contentWithKey); assertNotNull(key, "Expected to retrieve the public key"); metisMessage_Release(&contentWithKey); metisMessage_Release(&interestWithKeyIdRestriction); }
static void _parcLogger_Destroy(PARCLog **loggerPtr) { PARCLog *logger = *loggerPtr; parcMemory_Deallocate((void **) &logger->hostName); parcMemory_Deallocate((void **) &logger->applicationName); parcMemory_Deallocate((void **) &logger->processId); parcLogReporter_Release(&logger->reporter); }
static PARCLog * _parc_logger_create(const char *name) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); PARCLog *log = parcLog_Create("localhost", "athenaTransportLinkModule", name, reporter); parcLogReporter_Release(&reporter); parcLog_SetLevel(log, PARCLogLevel_Info); return log; }
LONGBOW_TEST_CASE(Global, metisMessage_HasKeyId_False) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *message = metisMessage_CreateFromArray(metisTestDataV0_InterestWithName, sizeof(metisTestDataV0_InterestWithName), 1, 2, logger); metisLogger_Release(&logger); bool hasKeyId = metisMessage_HasKeyId(message); assertFalse(hasKeyId, "Message without a keyid says it does"); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_HasKeyId_True) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *message = metisMessage_CreateFromArray(metisTestDataV0_EncodedObject, sizeof(metisTestDataV0_EncodedObject), 1, 2, logger); metisLogger_Release(&logger); bool hasKeyId = metisMessage_HasKeyId(message); assertTrue(hasKeyId, "Message with a keyid says it does not"); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_HasContentObjectHash_False) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *message = metisMessage_CreateFromArray(metisTestDataV0_EncodedInterest, sizeof(metisTestDataV0_EncodedInterest), 1, 2, logger); metisLogger_Release(&logger); bool hasHash = metisMessage_HasContentObjectHash(message); assertTrue(hasHash, "Message without a content object hash says it does"); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_HasHopLimit_False) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *message = metisMessage_CreateFromArray(metisTestDataV0_EncodedInterest_no_hoplimit, sizeof(metisTestDataV0_EncodedInterest_no_hoplimit), 1, 2, logger); metisLogger_Release(&logger); bool hasHopLimit = metisMessage_HasHopLimit(message); assertFalse(hasHopLimit, "Message without a hop limit says it does."); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_GetHopLimit) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *message = metisMessage_CreateFromArray(metisTestDataV0_EncodedInterest, sizeof(metisTestDataV0_EncodedInterest), 1, 2, logger); metisLogger_Release(&logger); uint8_t hoplimit = metisMessage_GetHopLimit(message); assertTrue(hoplimit == 32, "Wrong hop limit, got %u expected %u.", hoplimit, 32); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_GetMessageType) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *message = metisMessage_CreateFromArray(metisTestDataV0_EncodedObject, sizeof(metisTestDataV0_EncodedObject), 1, 2, logger); metisLogger_Release(&logger); MetisMessagePacketType type = metisMessage_GetType(message); assertTrue(type == MetisMessagePacketType_ContentObject, "wrong type, expected %u got %u", MetisMessagePacketType_ContentObject, type); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_CreateFromArray_BadMessage) { // Invalid version char message_str[] = "\xFFOnce upon a time, in a stack far away, a dangling pointer found its way to the top of the heap."; printf("metisMessage_CreateFromArray_BadMessage attempting to process a bad message which should report an error:\n"); PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *message = metisMessage_CreateFromArray((uint8_t *) message_str, sizeof(message_str), 1, 2, logger); metisLogger_Release(&logger); assertNull(message, "Got null from metisMessage_CreateFromArray"); }
LONGBOW_TEST_CASE(Global, metisMessage_KeyIdEquals_DifferentValue) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *a = metisMessage_CreateFromArray(metisTestDataV0_EncodedObject, sizeof(metisTestDataV0_EncodedObject), 1, 2, logger); MetisMessage *b = metisMessage_CreateFromArray(metisTestDataV0_SecondInterest, sizeof(metisTestDataV0_SecondInterest), 1, 2, logger); metisLogger_Release(&logger); assertFalse(metisMessage_KeyIdEquals(a, b), "Messages with differnt keyids did compared equal"); metisMessage_Release(&a); metisMessage_Release(&b); }
LONGBOW_TEST_CASE(Global, metisMessage_ObjectHashEquals_IsEqual_Lazy) { // create messages from content objects, as those are lazy computed PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *a = metisMessage_CreateFromArray(metisTestDataV0_EncodedObject, sizeof(metisTestDataV0_EncodedObject), 1, 2, logger); MetisMessage *b = metisMessage_CreateFromArray(metisTestDataV0_EncodedObject, sizeof(metisTestDataV0_EncodedObject), 1, 2, logger); metisLogger_Release(&logger); assertTrue(metisMessage_ObjectHashEquals(a, b), "Messages with equal ContentObjectHash did not compare"); metisMessage_Release(&a); metisMessage_Release(&b); }
LONGBOW_TEST_CASE(Global, metisMessage_HasInterestLifetime) { PARCEventBuffer *buff = parcEventBuffer_Create(); parcEventBuffer_Append(buff, metisTestDataV1_Interest_AllFields, sizeof(metisTestDataV1_Interest_AllFields)); 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); assertTrue(metisMessage_HasInterestLifetime(message), "Should have returned true for interest lifetime"); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_ObjectHashEquals_IsNotEqual) { // create messages from different content objects PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *a = metisMessage_CreateFromArray(metisTestDataV0_EncodedObject, sizeof(metisTestDataV0_EncodedObject), 1, 2, logger); MetisMessage *b = metisMessage_CreateFromArray(metisTestDataV0_SecondObject, sizeof(metisTestDataV0_SecondObject), 1, 2, logger); metisLogger_Release(&logger); assertFalse(metisMessage_ObjectHashEquals(a, b), "Messages with unequal ContentObjectHash compared as equal"); metisMessage_Release(&a); metisMessage_Release(&b); }
LONGBOW_TEST_CASE(Global, metisMessage_CreateFromArray) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *message = metisMessage_CreateFromArray(metisTestDataV0_EncodedObject, sizeof(metisTestDataV0_EncodedObject), 1, 2, logger); metisLogger_Release(&logger); assertNotNull(message, "Got null from metisMessage_CreateFromArray"); assertTrue(message->ingressConnectionId == 1, "IngressConnectionId wrong, expected %d got %u", 1, message->ingressConnectionId); assertTrue(message->receiveTime == 2, "receiveTime wrong, expected %u got %" PRIu64, 2, message->receiveTime); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_GetName) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *message = metisMessage_CreateFromArray(metisTestDataV0_EncodedObject, sizeof(metisTestDataV0_EncodedObject), 1, 2, logger); metisLogger_Release(&logger); MetisTlvName *name = metisMessage_GetName(message); MetisTlvName *truth = metisTlvName_Create(&metisTestDataV0_EncodedObject[metisTestDataV0_EncodedObject_name.offset], metisTestDataV0_EncodedObject_name.length); assertTrue(metisTlvName_Equals(truth, name), "Did not get back the right name"); metisTlvName_Release(&truth); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_ObjectHashHashCode_Lazy) { // create messages from content object, as those are precomputed PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *a = metisMessage_CreateFromArray(metisTestDataV0_EncodedObject, sizeof(metisTestDataV0_EncodedObject), 1, 2, logger); metisLogger_Release(&logger); uint32_t hashcode; bool success = metisMessage_GetContentObjectHashHash(a, &hashcode); assertTrue(success, "Returned false trying to get hash of contentobject hash"); metisMessage_Release(&a); }
static PARCLog * _parc_logger_create(const char *name) { PARCFileOutputStream *fileOutput = parcFileOutputStream_Create(dup(STDOUT_FILENO)); PARCOutputStream *output = parcFileOutputStream_AsOutputStream(fileOutput); parcFileOutputStream_Release(&fileOutput); PARCLogReporter *reporter = parcLogReporterFile_Create(output); parcOutputStream_Release(&output); PARCLog *log = parcLog_Create("localhost", "athenaTransport", name, reporter); parcLogReporter_Release(&reporter); parcLog_SetLevel(log, PARCLogLevel_Info); return log; }
static PARCLog * _athena_logger_create(void) { PARCFileOutputStream *fileOutput = parcFileOutputStream_Create(dup(STDOUT_FILENO)); PARCOutputStream *output = parcFileOutputStream_AsOutputStream(fileOutput); parcFileOutputStream_Release(&fileOutput); PARCLogReporter *reporter = parcLogReporterFile_Create(output); parcOutputStream_Release(&output); PARCLog *log = parcLog_Create("localhost", "athena", NULL, reporter); parcLogReporter_Release(&reporter); parcLog_SetLevel(log, PARCLogLevel_Info); return log; }
LONGBOW_TEST_CASE(Global, metisMessage_Create_InterestV1) { PARCEventBuffer *buff = parcEventBuffer_Create(); parcEventBuffer_Append(buff, metisTestDataV1_Interest_AllFields, sizeof(metisTestDataV1_Interest_AllFields)); 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->ingressConnectionId == 1, "IngressConnectionId wrong, expected %d got %u", 1, message->ingressConnectionId); assertTrue(message->receiveTime == 2, "receiveTime wrong, expected %u got %" PRIu64, 2, message->receiveTime); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_SetGetRecommendedCacheTime) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); // Note: Assumes metisTestDataV0_EncodedObject doesn't have RCT. MetisMessage *message = metisMessage_CreateFromArray(metisTestDataV0_EncodedObject, sizeof(metisTestDataV0_EncodedObject), 1, 2, logger); metisLogger_Release(&logger); uint64_t time = 12345; metisMessage_SetRecommendedCacheTimeTicks(message, time); assertTrue(time == metisMessage_GetRecommendedCacheTimeTicks(message), "Retrieved unexpected RCT"); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_GetInterestLifetimeTicks) { PARCEventBuffer *buff = parcEventBuffer_Create(); parcEventBuffer_Append(buff, metisTestDataV1_Interest_AllFields, sizeof(metisTestDataV1_Interest_AllFields)); 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); // don't check actual value. It will vary based on METISHZ and rouding errors due to integer math MetisTicks ticks = metisMessage_GetInterestLifetimeTicks(message); assertTrue(ticks > 0, "Should have gotten positive value for interest lifetime ticks"); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(CreateDestroy, parcLog_Create) { PARCFileOutputStream *fileOutput = parcFileOutputStream_Create(dup(STDOUT_FILENO)); PARCOutputStream *output = parcFileOutputStream_AsOutputStream(fileOutput); parcFileOutputStream_Release(&fileOutput); PARCLogReporter *reporter = parcLogReporterFile_Create(output); parcOutputStream_Release(&output); PARCLog *log = parcLog_Create("localhost", "test_parc_Log", NULL, reporter); parcLogReporter_Release(&reporter); assertTrue(parcLogLevel_Equals(parcLog_GetLevel(log), PARCLogLevel_Off), "Expected initial log level to be OFF"); parcLog_Release(&log); }
static _CCNxPortalRTAContext * _ccnxPortalRTAContext_Create(RTATransport *rtaTransport, const CCNxTransportConfig *configuration, int fileId) { _CCNxPortalRTAContext *result = parcObject_CreateInstance(_CCNxPortalRTAContext); if (result != NULL) { result->rtaTransport = rtaTransport; result->configuration = configuration; result->fileId = fileId; PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); result->logger = parcLog_Create(NULL, "ccnxPortalRTA", NULL, reporter); parcLogReporter_Release(&reporter); parcLog_SetLevel(result->logger, PARCLogLevel_Debug); } return result; }
LONGBOW_TEST_CASE(Global, metisMessage_GetKeyIdHash) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); MetisMessage *message = metisMessage_CreateFromArray(metisTestDataV0_EncodedObject, sizeof(metisTestDataV0_EncodedObject), 1, 2, logger); metisLogger_Release(&logger); uint32_t truthhash = parcHash32_Data(&metisTestDataV0_EncodedObject[metisTestDataV0_EncodedObject_keyid.offset], metisTestDataV0_EncodedObject_keyid.length); uint32_t testhash; bool success = metisMessage_GetKeyIdHash(message, &testhash); assertTrue(success, "Failed metisMessage_GetKeyIdHash, returned false"); assertTrue(truthhash == testhash, "Hash compared wrong, expected %08X, got %08X", truthhash, testhash); metisMessage_Release(&message); }
LONGBOW_TEST_CASE(Global, metisMessage_Length) { 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"); size_t length = metisMessage_Length(message); assertTrue(length == sizeof(message_str), "Wrong length, expected %zu got %zu", sizeof(message_str), length); metisMessage_Release(&message); }
static MetisContentStoreInterface * _createLRUContentStore(size_t capacity) { PARCLogReporter *reporter = parcLogReporterTextStdout_Create(); MetisLogger *logger = metisLogger_Create(reporter, parcClock_Wallclock()); parcLogReporter_Release(&reporter); metisLogger_SetLogLevel(logger, MetisLoggerFacility_Processor, PARCLogLevel_Debug); MetisContentStoreConfig config = { .objectCapacity = capacity, }; MetisContentStoreInterface *store = metisLRUContentStore_Create(&config, logger); metisLogger_Release(&logger); return store; }