LONGBOW_TEST_CASE(Local, _athenaLRUContentStore_GetMatchByNameAndKeyId)
{
    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 a KeyId too.

    CCNxContentObject *contentObject2 = ccnxContentObject_CreateWithDataPayload(name, NULL);

    _AthenaLRUContentStoreEntry *entry2 = _athenaLRUContentStoreEntry_Create(contentObject2);

    entry2->keyId = parcBuffer_WrapCString("key id buffer");
    entry2->hasKeyId = 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 + KeyIdRestriction.

    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    PARCBuffer *keyIdRestriction = parcBuffer_Copy(entry2->keyId);
    ccnxInterest_SetKeyIdRestriction(interest, keyIdRestriction);
    parcBuffer_Release(&keyIdRestriction);

    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);
}
예제 #2
0
LONGBOW_TEST_CASE(Global, ccnxInterest_SetKeyIdRestriction)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/name");
    PARCBuffer *key = parcBuffer_Allocate(8);
    parcBuffer_PutUint64(key, 1234L);

    CCNxInterest *interest = ccnxInterest_Create(name, 3000, NULL, NULL);
    ccnxInterest_SetKeyIdRestriction(interest, key);
    PARCBuffer *actual = ccnxInterest_GetKeyIdRestriction(interest);

    actual = ccnxInterest_GetKeyIdRestriction(interest);
    assertTrue(actual == key, "Expected retrieved key to be the same as assigned");

    ccnxName_Release(&name);
    ccnxInterest_Release(&interest);
    parcBuffer_Release(&key);
}