示例#1
0
LONGBOW_TEST_CASE(Global, ccnxInterest_SetContentObjectHashRestriction)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/name");
    PARCBuffer *coh = parcBuffer_Allocate(8);
    parcBuffer_PutUint64(coh, 77573L);

    CCNxInterest *interest = ccnxInterest_Create(name, CCNxInterestDefault_LifetimeMilliseconds, NULL, NULL);

    PARCBuffer *actual = ccnxInterest_GetContentObjectHashRestriction(interest);
    assertNull(actual, "Expected retrieved ContentObjectHash to be initially NULL");

    ccnxInterest_SetContentObjectHashRestriction(interest, coh);
    actual = ccnxInterest_GetContentObjectHashRestriction(interest);

    assertTrue(actual == coh, "Expected retrieved ContentObjectHash to be the same as assigned");

    // Re-setting is not yet supported. At the moment, you can only put the COHR once.
    // Now change it, and validate.
    //PARCBuffer *coh2 = parcBuffer_Allocate(8);
    //parcBuffer_PutUint64(coh2, 3262L);
    //ccnxInterest_SetContentObjectHashRestriction(interest, coh2);
    //actual = ccnxInterest_GetContentObjectHashRestriction(interest);
    //assertTrue(actual == coh2, "Expected retrieved ContentObjectHash to be the same as assigned");

    ccnxName_Release(&name);
    ccnxInterest_Release(&interest);
    parcBuffer_Release(&coh);
    //parcBuffer_Release(&coh2);
}
LONGBOW_TEST_CASE(Local, _athenaLRUContentStore_GetMatchByNameAndObjectHash)
{
    AthenaLRUContentStore *impl = _createLRUContentStore();

    PARCBuffer *payload = parcBuffer_Allocate(1200);

    CCNxName *name = ccnxName_CreateFromURI("lci:/boose/roo/pie");
    CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, NULL);

    parcBuffer_Release(&payload);
    _AthenaLRUContentStoreEntry *entry1 = _athenaLRUContentStoreEntry_Create(contentObject);

    entry1->hasKeyId = false;
    entry1->hasContentObjectHash = false;

    bool status = _athenaLRUContentStore_PutLRUContentStoreEntry(impl, entry1);
    assertTrue(status, "Expected to add the entry");

    // Now add another content object with the same name, but an object hash too.

    CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name, NULL);

    _AthenaLRUContentStoreEntry *entry2 = _athenaLRUContentStoreEntry_Create(contentObject2);

    entry2->contentObjectHash = parcBuffer_WrapCString("corned beef");
    entry2->hasContentObjectHash = true;

    status = _athenaLRUContentStore_PutLRUContentStoreEntry(impl, entry2);
    assertTrue(status, "Expected to add the entry");
    assertTrue(impl->numEntries == 2, "Expected 2 store items");

    // Now match on Name + ObjectHash.

    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    PARCBuffer *hashRestriction = parcBuffer_Copy(entry2->contentObjectHash);
    ccnxInterest_SetContentObjectHashRestriction(interest, hashRestriction);
    parcBuffer_Release(&hashRestriction);

    CCNxContentObject *match = _athenaLRUContentStore_GetMatch(impl, interest);
    assertNotNull(match, "Expected to match something");
    assertTrue(match == contentObject2, "Expected the content object with the keyId");

    _athenaLRUContentStoreEntry_Release(&entry1);
    _athenaLRUContentStoreEntry_Release(&entry2);
    ccnxContentObject_Release(&contentObject2);
    ccnxContentObject_Release(&contentObject);
    ccnxName_Release(&name);
    ccnxInterest_Release(&interest);

    _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl);
}