示例#1
0
void
testValidationSetV1_KeyId_KeyLocator_KeyId_Key(TestData *data,
                                               bool (*set)(CCNxTlvDictionary *message, const PARCBuffer *keyid,
                                                           const CCNxKeyLocator *keyLocator),
                                               bool (*test)(const CCNxTlvDictionary *message))
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/parc/validation/test");
    CCNxTlvDictionary *packetV1 = ccnxContentObject_CreateWithImplAndPayload(&CCNxContentObjectFacadeV1_Implementation,
                                                                             name,
                                                                             CCNxPayloadType_DATA,
                                                                             NULL);
    bool success = set(packetV1, data->keyid, data->locatorByKey);
    assertTrue(success, "Failed to set on V1");

    bool testResult = test(packetV1);
    assertTrue(testResult, "Test function failed on V1 packet");

    PARCBuffer *testKeyId = ccnxValidationFacadeV1_GetKeyId(packetV1);
    assertTrue(parcBuffer_Equals(testKeyId, data->keyid), "keyid not equal");

    PARCBuffer *testKey = ccnxValidationFacadeV1_GetPublicKey(packetV1);
    assertTrue(parcBuffer_Equals(testKey, data->key), "keys not equal");

    ccnxName_Release(&name);
    ccnxTlvDictionary_Release(&packetV1);
}
LONGBOW_TEST_CASE(Global, cpiAddress_CreateFromLink)
{
    uint8_t mac[] = { 0x01, 0x02, 0x03, 0x04, 0xFF, 0x8F };
    PARCBuffer *macbuffer = parcBuffer_Flip(parcBuffer_CreateFromArray(mac, sizeof(mac)));

    CPIAddress *address = cpiAddress_CreateFromLink(mac, sizeof(mac));

    // Do not release test, it is the same reference as address->blob
    PARCBuffer *test = cpiAddress_GetLinkAddress(address);
    assertNotNull(test, "Got null link address buffer");
    assertTrue(parcBuffer_Equals(test, address->blob), "Returned buffer from cpiAddress_GetLinkAddress not equal to address");

    assertTrue(cpiAddress_GetType(address) == cpiAddressType_LINK,
               "Got wrong address type, expected %d, got %d", cpiAddressType_LINK, cpiAddress_GetType(address));

    PARCJSON *json = cpiAddress_ToJson(address);
    CPIAddress *fromjson = cpiAddress_CreateFromJson(json);

    assertTrue(cpiAddress_GetType(address) == cpiAddress_GetType(fromjson),
               "fromjson type does not equal known");
    assertTrue(parcBuffer_Equals(address->blob, fromjson->blob),
               "fromjson blob does not equal known address");
    assertTrue(cpiAddress_Equals(address, fromjson),
               "cpiAddress_Equals broken for LINK type");

    CPIAddress *copy = cpiAddress_Copy(address);
    assertTrue(cpiAddress_Equals(copy, address),
               "Copy and address not equal for LINK");

    parcJSON_Release(&json);
    cpiAddress_Destroy(&address);
    cpiAddress_Destroy(&copy);
    cpiAddress_Destroy(&fromjson);
    parcBuffer_Release(&macbuffer);
}
LONGBOW_TEST_CASE(Global, ccnxTlvCodecName_Encode)
{
    uint8_t truthBytes[] = { 0x10, 0x20, 0x00, 0x0E, 0x00, CCNxNameLabelType_NAME, 0x00, 0x0A, 'b', 'r', 'a', 'n', 'd', 'y', 'w', 'i', 'n', 'e' };
    PARCBuffer *truth = parcBuffer_Wrap(truthBytes, sizeof(truthBytes), 0, sizeof(truthBytes));

    CCNxCodecTlvEncoder *encoder = ccnxCodecTlvEncoder_Create();
    ccnxCodecTlvEncoder_Initialize(encoder);

    PARCBuffer *buffer = parcBuffer_WrapCString("brandywine");
    CCNxNameSegment *segment = ccnxNameSegment_CreateTypeValue(CCNxNameLabelType_NAME, buffer);

    CCNxName *name = ccnxName_Append(ccnxName_Create(), segment);
    ccnxNameSegment_Release(&segment);
    parcBuffer_Release(&buffer);

    ccnxCodecSchemaV1NameCodec_Encode(encoder, 0x1020, name);

    ccnxCodecTlvEncoder_Finalize(encoder);
    PARCBuffer *test = ccnxCodecTlvEncoder_CreateBuffer(encoder);

    if (!parcBuffer_Equals(truth, test)) {
        printf("Buffers do not match\n");
        printf("Excpected:\n");
        parcBuffer_Display(truth, 3);
        printf("Got:\n");
        parcBuffer_Display(test, 3);
        assertTrue(parcBuffer_Equals(truth, test), "Buffers do not match");
    }

    ccnxName_Release(&name);
    parcBuffer_Release(&test);
    ccnxCodecTlvEncoder_Destroy(&encoder);
    parcBuffer_Release(&truth);
}
示例#4
0
LONGBOW_TEST_CASE(JSON, parcJSON_GetPairByIndex)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    PARCJSONPair *pair = parcJSON_GetPairByIndex(data->json, 0);
    PARCBuffer *name = parcJSONPair_GetName(pair);
    PARCBuffer *expectedName = parcBuffer_WrapCString("string");
    assertTrue(parcBuffer_Equals(expectedName, name),
               "Expected 'string', actual '%s'", (char *) parcBuffer_ToString(name));
    parcBuffer_Release(&expectedName);

    pair = parcJSON_GetPairByIndex(data->json, 1);
    name = parcJSONPair_GetName(pair);
    expectedName = parcBuffer_WrapCString("null");
    assertTrue(parcBuffer_Equals(expectedName, name),
               "Expected 'null', actual '%s'", (char *) parcBuffer_ToString(name));
    parcBuffer_Release(&expectedName);

    pair = parcJSON_GetPairByIndex(data->json, 2);
    name = parcJSONPair_GetName(pair);
    expectedName = parcBuffer_WrapCString("true");
    assertTrue(parcBuffer_Equals(expectedName, name),
               "Expected 'true', actual '%s'", (char *) parcBuffer_ToString(name));
    parcBuffer_Release(&expectedName);

    pair = parcJSON_GetPairByIndex(data->json, 3);
    name = parcJSONPair_GetName(pair);
    expectedName = parcBuffer_WrapCString("false");
    assertTrue(parcBuffer_Equals(expectedName, name),
               "Expected 'false', actual '%s'", (char *) parcBuffer_ToString(name));
    parcBuffer_Release(&expectedName);

    pair = parcJSON_GetPairByIndex(data->json, 4);
    name = parcJSONPair_GetName(pair);
    expectedName = parcBuffer_WrapCString("integer");
    assertTrue(parcBuffer_Equals(expectedName, name),
               "Expected 'integer', actual '%s'", (char *) parcBuffer_ToString(name));
    parcBuffer_Release(&expectedName);

    pair = parcJSON_GetPairByIndex(data->json, 5);
    name = parcJSONPair_GetName(pair);
    expectedName = parcBuffer_WrapCString("float");
    assertTrue(parcBuffer_Equals(expectedName, name),
               "Expected 'float', actual '%s'", (char *) parcBuffer_ToString(name));
    parcBuffer_Release(&expectedName);

    pair = parcJSON_GetPairByIndex(data->json, 6);
    name = parcJSONPair_GetName(pair);
    expectedName = parcBuffer_WrapCString("json");
    assertTrue(parcBuffer_Equals(expectedName, name),
               "Expected 'json', actual '%s'", (char *) parcBuffer_ToString(name));
    parcBuffer_Release(&expectedName);

    pair = parcJSON_GetPairByIndex(data->json, 7);
    name = parcJSONPair_GetName(pair);
    expectedName = parcBuffer_WrapCString("array");
    assertTrue(parcBuffer_Equals(expectedName, name),
               "Expected 'array', actual '%s'", (char *) parcBuffer_ToString(name));
    parcBuffer_Release(&expectedName);
}
示例#5
0
LONGBOW_TEST_CASE(Global, ccnxInterest_SetPayloadAndId)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/name");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);

    CCNxInterestInterface *impl = ccnxInterestInterface_GetInterface(interest);

    if (impl->getPayload) {
        assertNull(ccnxInterest_GetPayload(interest), "Expected a NULL payload");
    }

    if (impl->getPayload && impl->setPayload) {
        PARCBuffer *payload = parcBuffer_WrapCString("impls have pimples");

        ccnxInterest_SetPayloadAndId(interest, payload);

        PARCBuffer *payloadOut = ccnxInterest_GetPayload(interest);

        assertTrue(parcBuffer_Equals(payload, payloadOut), "Expected an equal buffer");

        CCNxName *nameAfterPayload = ccnxInterest_GetName(interest);
        CCNxNameSegment *segment = ccnxName_GetSegment(nameAfterPayload, ccnxName_GetSegmentCount(nameAfterPayload) - 1);

        assertTrue(ccnxNameSegment_GetType(segment) == CCNxNameLabelType_PAYLOADID, "Expected to find a payload ID appended to the name");

        parcBuffer_Release(&payload);
    }
    ccnxName_Release(&name);
    ccnxInterest_Release(&interest);
}
LONGBOW_TEST_CASE(Global, cpiAddress_CreateFromInet6)
{
    struct sockaddr_in6 addr_in6;
    memset(&addr_in6, 0, sizeof(struct sockaddr_in6));

    inet_pton(AF_INET6, "2001:720:1500:1::a100", &(addr_in6.sin6_addr));
    addr_in6.sin6_family = AF_INET6;
    addr_in6.sin6_port = 0x0A0B;
    addr_in6.sin6_flowinfo = 0x01020304;

    CPIAddress *address = cpiAddress_CreateFromInet6(&addr_in6);

    struct sockaddr_in6 addr_test;
    bool success = cpiAddress_GetInet6(address, &addr_test);
    assertTrue(success, "Got false converting back address");

    assertTrue(memcmp(&addr_in6, &addr_test, sizeof(struct sockaddr_in6)) == 0, "Got mismatch addressed");

    assertTrue(cpiAddress_GetType(address) == cpiAddressType_INET6,
               "Got wrong address type, expected %d, got %d", cpiAddressType_INET6, cpiAddress_GetType(address));

    PARCJSON *json = cpiAddress_ToJson(address);
    CPIAddress *fromjson = cpiAddress_CreateFromJson(json);

    assertTrue(parcBuffer_Equals(address->blob, fromjson->blob), "fromjson blob does not equal known address");
    assertTrue(cpiAddress_Equals(address, fromjson), "cpiAddress_Equals broken for INET6 type");

    CPIAddress *copy = cpiAddress_Copy(address);
    assertTrue(cpiAddress_Equals(copy, address), "Copy and address not equal for INET6");

    parcJSON_Release(&json);
    cpiAddress_Destroy(&address);
    cpiAddress_Destroy(&copy);
    cpiAddress_Destroy(&fromjson);
}
示例#7
0
LONGBOW_TEST_CASE(Global, parcCryptoHash_GetDigest)
{
    int fd_buffer = open("test_digest_bytes_128.bin", O_RDONLY);
    int fd_truth = open("test_digest_bytes_128.sha256", O_RDONLY);
    assertFalse(fd_buffer < 0, "Could not open %s: %s", "test_digest_bytes_128.bin", strerror(errno));
    assertFalse(fd_truth < 0, "Could not open %s: %s", "test_digest_bytes_128.sha256", strerror(errno));

    uint8_t scratch[bufferLength];
    ssize_t read_length = read(fd_truth, scratch, bufferLength);

    PARCCryptoHash *hashTruth = parcCryptoHash_CreateFromArray(PARC_HASH_SHA256, scratch, read_length);

    read_length = read(fd_buffer, scratch, bufferLength);

    PARCCryptoHasher *hasher = parcCryptoHasher_Create(PARC_HASH_SHA256);
    parcCryptoHasher_Init(hasher);
    parcCryptoHasher_UpdateBytes(hasher, scratch, read_length);

    PARCCryptoHash *hashTest = parcCryptoHasher_Finalize(hasher);

    assertTrue(parcBuffer_Equals(parcCryptoHash_GetDigest(hashTruth), parcCryptoHash_GetDigest(hashTest)), "Expected to be true");

    parcCryptoHasher_Release(&hasher);
    parcCryptoHash_Release(&hashTruth);
    parcCryptoHash_Release(&hashTest);

    close(fd_buffer);
    close(fd_truth);
}
示例#8
0
void
testValidationSetV1_KeyId_KeyLocator_KeyId_KeyName(TestData *data,
                                                   bool (*set)(CCNxTlvDictionary *message, const PARCBuffer *keyid,
                                                               const CCNxKeyLocator *keyLocator),
                                                   bool (*test)(const CCNxTlvDictionary *message))
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/parc/validation/test");
    CCNxTlvDictionary *packetV1 = ccnxContentObject_CreateWithImplAndPayload(&CCNxContentObjectFacadeV1_Implementation,
                                                                             name,
                                                                             CCNxPayloadType_DATA,
                                                                             NULL);
    bool success = set(packetV1, data->keyid, data->locatorByName);
    assertTrue(success, "Failed to set on V1");

    bool testResult = test(packetV1);
    assertTrue(testResult, "Test function failed on V1 packet");

    PARCBuffer *testKeyId = ccnxValidationFacadeV1_GetKeyId(packetV1);
    assertTrue(parcBuffer_Equals(testKeyId, data->keyid), "keyid not equal");

    // XXX: TODO: GetKeyName() returns a Link, so it should be GetLink().
    //            It also creates a new object (the CCNxLink), so... needs thinking about.
    //            See BugzId: 3322

    CCNxLink *testLink = ccnxValidationFacadeV1_GetKeyName(packetV1);
    assertTrue(ccnxName_Equals(ccnxLink_GetName(testLink), data->keyname), "Keynames not equal");
    ccnxLink_Release(&testLink);

    ccnxName_Release(&name);
    ccnxTlvDictionary_Release(&packetV1);
}
示例#9
0
bool
parcJSONValue_Equals(const PARCJSONValue *objA, const PARCJSONValue *objB)
{
    bool result = false;

    if (objA == NULL || objB == NULL) {
        result = (objA == objB);
    } else {
        if (objA->type == objB->type) {
            switch (objA->type) {
                case PARCJSONValueType_Boolean:
                    result = objA->value.boolean == objB->value.boolean;
                    break;
                case PARCJSONValueType_String:
                    result = parcBuffer_Equals(objA->value.string, objB->value.string);
                    break;
                case PARCJSONValueType_Number:
                    result = _equalsNumber(objA, objB);
                    break;
                case PARCJSONValueType_Array:
                    result = parcJSONArray_Equals(objA->value.array, objB->value.array);
                    break;
                case PARCJSONValueType_JSON:
                    result = parcJSON_Equals(objA->value.object, objB->value.object);
                    break;
                case PARCJSONValueType_Null:
                    result = true;
                    break;
            }
        }
    }

    return result;
}
示例#10
0
LONGBOW_TEST_CASE(Specialization, parcSortedList_GetLast)
{
    PARCSortedList *instance = parcSortedList_Create();
    PARCBuffer *element1 = parcBuffer_WrapCString("1");
    PARCBuffer *element2 = parcBuffer_WrapCString("2");
    PARCBuffer *element3 = parcBuffer_WrapCString("3");
    PARCBuffer *element4 = parcBuffer_WrapCString("4");
    PARCBuffer *element7 = parcBuffer_WrapCString("7");
    PARCBuffer *element6 = parcBuffer_WrapCString("6");
    PARCBuffer *element5 = parcBuffer_WrapCString("5");
    PARCBuffer *element8 = parcBuffer_WrapCString("8");
   
    parcSortedList_Add(instance, element1);
    parcSortedList_Add(instance, element2);
    parcSortedList_Add(instance, element3);
   
    PARCBuffer *actual = (PARCBuffer *) parcSortedList_GetLast(instance);
    assertTrue(parcBuffer_Equals(element3, actual), "Got the wrong value at index 1");
   
    parcBuffer_Release(&element1);
    parcBuffer_Release(&element2);
    parcBuffer_Release(&element3);
    parcBuffer_Release(&element4);
    parcBuffer_Release(&element5);
    parcBuffer_Release(&element6);
    parcBuffer_Release(&element7);
    parcBuffer_Release(&element8);
    parcSortedList_Release(&instance);
}
示例#11
0
LONGBOW_TEST_CASE(Global, ccnxInterest_SetGetPayload)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/name");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    CCNxName *origNameCopy = ccnxName_Copy(name);

    CCNxInterestInterface *impl = ccnxInterestInterface_GetInterface(interest);

    if (impl->getPayload) {
        assertNull(ccnxInterest_GetPayload(interest), "Expected a NULL payload");
    }

    if (impl->getPayload && impl->setPayload) {
        PARCBuffer *payload = parcBuffer_WrapCString("impls have pimples");
        ccnxInterest_SetPayload(interest, payload);

        PARCBuffer *payloadOut = ccnxInterest_GetPayload(interest);

        assertTrue(parcBuffer_Equals(payload, payloadOut), "Expected an equal buffer");

        CCNxName *nameAfterPayload = ccnxInterest_GetName(interest);
        assertTrue(ccnxName_Equals(nameAfterPayload, origNameCopy), "Expected an unmodified name");

        parcBuffer_Release(&payload);
    }
    ccnxName_Release(&name);
    ccnxName_Release(&origNameCopy);
    ccnxInterest_Release(&interest);
}
bool
ccnxManifestHashGroup_Equals(const CCNxManifestHashGroup *objectA, const CCNxManifestHashGroup *objectB)
{
    if (objectA == objectB) {
        return true;
    }
    if (objectA == NULL || objectB == NULL) {
        return false;
    }

    if (objectA->dataSize == objectB->dataSize) {
        if (objectA->entrySize == objectB->entrySize) {
            if (objectA->blockSize == objectB->blockSize) {
                if (objectA->treeHeight == objectB->treeHeight) {
                    if (ccnxName_Equals(objectA->locator, objectB->locator)) {
                        if (parcBuffer_Equals(objectA->overallDataDigest, objectB->overallDataDigest)) {
                            if (parcLinkedList_Size(objectA->pointers) == parcLinkedList_Size(objectB->pointers)) {
                                for (size_t i = 0; i < parcLinkedList_Size(objectA->pointers); i++) {
                                    CCNxManifestHashGroupPointer *ptrA = parcLinkedList_GetAtIndex(objectA->pointers, i);
                                    CCNxManifestHashGroupPointer *ptrB = parcLinkedList_GetAtIndex(objectB->pointers, i);
                                    if (!_CCNxManifestHashGroupPointer_Equals(ptrA, ptrB)) {
                                        return false;
                                    }
                                }
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }

    return false;
}
示例#13
0
LONGBOW_TEST_CASE(JSON, parcJSON_AddValue)
{
    PARCJSON *json = parcJSON_Create();

    char *expectedName = "value";

    PARCJSONValue *value = parcJSONValue_CreateFromCString("Some Pig");

    parcJSON_AddValue(json, expectedName, value);

    const PARCJSONPair *pair = parcJSON_GetPairByName(json, expectedName);

    PARCBuffer *actualName = parcJSONPair_GetName(pair);
    PARCJSONValue *actualValue = parcJSONPair_GetValue(pair);
    assertTrue(strcmp(expectedName, parcBuffer_Overlay(actualName, 0)) == 0,
               "Expected name %s, actual %s", expectedName, (char *) parcBuffer_ToString(actualName));
    assertTrue(parcJSONValue_IsString(actualValue), "Expect value to be type PARCJSONArray");
    assertTrue(parcBuffer_Equals(parcJSONValue_GetString(actualValue), parcJSONValue_GetString(value)),
               "Expected %s actual %s",
               parcJSONValue_ToString(value),
               parcJSONValue_ToString(actualValue));

    parcJSONValue_Release(&value);

    parcJSON_Release(&json);
}
LONGBOW_TEST_CASE(Global, ccnxContentObject_GetKeyId)
{
    CCNxName *name = ccnxName_CreateFromCString("lci:/hello/dolly");
    PARCBuffer *payload = parcBuffer_WrapCString("hello");

    CCNxContentObject *contentObject = ccnxContentObject_CreateWithDataPayload(name, payload);

    assertNull(ccnxContentObject_GetKeyId(contentObject), "Expect NULL for KeyId here");

    PARCBuffer *testKeyId = parcBuffer_WrapCString("keyhash");
    PARCBuffer *sigbits = parcBuffer_WrapCString("siggybits");
    PARCSignature *signature = parcSignature_Create(PARCSigningAlgorithm_RSA, PARC_HASH_SHA256, parcBuffer_Flip(sigbits));

    ccnxContentObject_SetSignature(contentObject, testKeyId, signature, NULL);

    PARCBuffer *keyId = ccnxContentObject_GetKeyId(contentObject);

    assertTrue(parcBuffer_Equals(keyId, testKeyId), "Expect key ids to match");

    parcBuffer_Release(&payload);
    parcBuffer_Release(&sigbits);
    parcBuffer_Release(&keyId);
    parcSignature_Release(&signature);
    ccnxName_Release(&name);
    ccnxContentObject_Release(&contentObject);
}
LONGBOW_TEST_CASE(Global, cpiAddress_CreateFromInterface)
{
    uint32_t ifidx = 0x01020304;
    uint32_t test;

    CPIAddress *address = cpiAddress_CreateFromInterface(ifidx);

    bool success = cpiAddress_GetInterfaceIndex(address, &test);
    assertTrue(success, "Got false converting back address");

    assertTrue(ifidx == test, "Got mismatch addressed");

    assertTrue(cpiAddress_GetType(address) == cpiAddressType_IFACE,
               "Got wrong address type, expected %d, got %d", cpiAddressType_IFACE, cpiAddress_GetType(address));

    PARCJSON *json = cpiAddress_ToJson(address);
    CPIAddress *fromjson = cpiAddress_CreateFromJson(json);

    assertTrue(parcBuffer_Equals(address->blob, fromjson->blob), "fromjson blob does not equal known address");
    assertTrue(cpiAddress_Equals(address, fromjson), "cpiAddress_Equals broken for IFACE type");

    CPIAddress *copy = cpiAddress_Copy(address);
    assertTrue(cpiAddress_Equals(copy, address), "Copy and address not equal for IFACE");

    parcJSON_Release(&json);
    cpiAddress_Destroy(&address);
    cpiAddress_Destroy(&copy);
    cpiAddress_Destroy(&fromjson);
}
LONGBOW_TEST_CASE(Global, cpiAddress_CreateFromUnix)
{
    struct sockaddr_un addr_un;
    struct sockaddr_un addr_test;
    memset(&addr_un, 0, sizeof(struct sockaddr_un));
    char path[] = "/Hello/Cruel/World";
    strcpy(addr_un.sun_path, path);
    addr_un.sun_family = AF_UNIX;

    CPIAddress *address = cpiAddress_CreateFromUnix(&addr_un);

    bool success = cpiAddress_GetUnix(address, &addr_test);
    assertTrue(success, "Got false converting back address");

    assertTrue(memcmp(&addr_un, &addr_test, sizeof(struct sockaddr_un)) == 0, "Got mismatch addressed");

    assertTrue(cpiAddress_GetType(address) == cpiAddressType_UNIX,
               "Got wrong address type, expected %d, got %d", cpiAddressType_UNIX, cpiAddress_GetType(address));

    PARCJSON *json = cpiAddress_ToJson(address);
    CPIAddress *fromjson = cpiAddress_CreateFromJson(json);

    assertTrue(parcBuffer_Equals(address->blob, fromjson->blob), "fromjson blob does not equal known address");
    assertTrue(cpiAddress_Equals(address, fromjson), "cpiAddress_Equals broken for UNIX type");

    CPIAddress *copy = cpiAddress_Copy(address);
    assertTrue(cpiAddress_Equals(copy, address), "Copy and address not equal for UNIX");

    parcJSON_Release(&json);
    cpiAddress_Destroy(&address);
    cpiAddress_Destroy(&copy);
    cpiAddress_Destroy(&fromjson);
}
示例#17
0
bool
parcURISegment_Equals(const PARCURISegment *segmentA, const PARCURISegment *segmentB)
{
    if (segmentA == segmentB) {
        return true;
    }
    if (segmentA == NULL || segmentB == NULL) {
        return false;
    }
    return parcBuffer_Equals(segmentA->buffer, segmentB->buffer);
}
示例#18
0
LONGBOW_TEST_CASE(Global, parcSignature_GetSignature)
{
    PARCBuffer *expected = parcBuffer_Allocate(strlen("Hello"));
    parcBuffer_PutArray(expected, strlen("Hello"), (uint8_t *) "Hello");
    PARCSignature *signature = parcSignature_Create(PARCSigningAlgorithm_DSA, PARC_HASH_SHA256, expected);

    PARCBuffer *actual = parcSignature_GetSignature(signature);

    assertTrue(parcBuffer_Equals(expected, actual), "Expected the original signature bits to be equal to the actual bits");
    parcSignature_Release(&signature);
    parcBuffer_Release(&expected);
}
示例#19
0
LONGBOW_TEST_CASE(Specialization, parcSortedList_RemoveLast_SingleElement)
{
    PARCBuffer *object1 = parcBuffer_WrapCString("1");
   
    PARCSortedList *deque = parcSortedList_Create();
    parcSortedList_Add(deque, object1);
   
    PARCBuffer *peek = parcSortedList_RemoveLast(deque);
    assertTrue(parcBuffer_Equals(object1, peek),
               "Objects out of order.");
   
    parcBuffer_Release(&object1);
    parcSortedList_Release(&deque);
}
bool
ccnxSimpleFileTransferChunkList_Equals(const CCNxSimpleFileTransferChunkList *a,
                                       const CCNxSimpleFileTransferChunkList *b)
{
    bool result = false;
    if (a == b) {
        result = true;
    } else {
        result = (a != NULL && b != NULL
                  && a->chunkSize == b->chunkSize
                  && a->numChunks == b->numChunks
                  && parcBuffer_Equals(a->fileName, b->fileName));
    }

    return result;
}
static bool
_CCNxManifestHashGroupPointer_Equals(const CCNxManifestHashGroupPointer *objectA, const CCNxManifestHashGroupPointer *objectB)
{
    if (objectA == objectB) {
        return true;
    }
    if (objectA == NULL || objectB == NULL) {
        return false;
    }
    if (objectA->pointerType == objectB->pointerType) {
        if (parcBuffer_Equals(objectA->digest, objectB->digest)) {
            return true;
        }
    }
    return false;
}
示例#22
0
LONGBOW_TEST_CASE(Global, parcNetwork_LinkAddress_Parse_dots)
{
    char *expected = "link://0123.4567.89ab";
    PARCBuffer *address = parcNetwork_ParseLinkAddress(expected);

    PARCBuffer *e = parcBuffer_Wrap((uint8_t []) { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }, 6, 0, 6);

    parcBuffer_SetPosition(address, 0);
    parcBuffer_SetPosition(e, 0);
    parcBuffer_SetLimit(address, 6);
    parcBuffer_SetLimit(e, 6);

    assertTrue(parcBuffer_Equals(address, e),
               "Expected result failed.");

    parcBuffer_Release(&e);
    parcBuffer_Release(&address);
}
示例#23
0
bool
ccnxNameSegment_Equals(const CCNxNameSegment *segmentA, const CCNxNameSegment *segmentB)
{
    bool result = false;

    if (segmentA == segmentB) {
        result = true;
    } else if (segmentA == NULL || segmentB == NULL) {
        result = false;
    } else {
        if (ccnxNameLabel_Equals(segmentA->label, segmentB->label)) {
            if (parcBuffer_Equals(ccnxNameSegment_GetValue(segmentA), ccnxNameSegment_GetValue(segmentB))) {
                result = true;
            }
        }
    }

    return result;
}
示例#24
0
LONGBOW_TEST_CASE(Global, ccnxInterest_SetPayloadWithId)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/name");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    CCNxName *origNameCopy = ccnxName_Copy(name);

    CCNxInterestInterface *impl = ccnxInterestInterface_GetInterface(interest);

    if (impl->getPayload) {
        assertNull(ccnxInterest_GetPayload(interest), "Expected a NULL payload");
    }

    if (impl->getPayload && impl->setPayload) {
        PARCBuffer *payload = parcBuffer_WrapCString("impls have pimples");
        PARCBuffer *payloadIdBuffer = parcBuffer_WrapCString("payload Id buffer");

        CCNxInterestPayloadId *payloadId = ccnxInterestPayloadId_Create(payloadIdBuffer,
                                                                        CCNxInterestPayloadId_TypeCode_App + 2);

        ccnxInterest_SetPayloadWithId(interest, payload, payloadId);

        PARCBuffer *payloadOut = ccnxInterest_GetPayload(interest);

        assertTrue(parcBuffer_Equals(payload, payloadOut), "Expected an equal buffer");

        CCNxName *nameAfterPayload = ccnxInterest_GetName(interest);
        CCNxNameSegment *segment = ccnxName_GetSegment(nameAfterPayload, ccnxName_GetSegmentCount(nameAfterPayload) - 1);

        assertTrue(ccnxNameSegment_GetType(segment) == CCNxNameLabelType_PAYLOADID, "Expected to find a payload ID appended to the name");

        CCNxInterestPayloadId *outId = ccnxInterestPayloadId_CreateFromSegmentInName(nameAfterPayload);
        assertTrue(ccnxInterestPayloadId_Equals(outId, payloadId), "expected to see the same payload Id after setting the payload");

        ccnxInterestPayloadId_Release(&payloadId);
        ccnxInterestPayloadId_Release(&outId);

        parcBuffer_Release(&payload);
        parcBuffer_Release(&payloadIdBuffer);
    }
    ccnxName_Release(&name);
    ccnxName_Release(&origNameCopy);
    ccnxInterest_Release(&interest);
}
示例#25
0
LONGBOW_TEST_CASE(JSON, parcJSON_GetPairByName)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    int expected = 31415;
    const PARCJSONPair *pair = parcJSON_GetPairByName(data->json, "integer");

    PARCBuffer *name = parcJSONPair_GetName(pair);
    PARCJSONValue *value = parcJSONPair_GetValue(pair);

    int64_t actual = parcJSONValue_GetInteger(value);

    PARCBuffer *expectedName = parcBuffer_WrapCString("integer");

    assertTrue(parcBuffer_Equals(expectedName, name),
               "Expected 'integer', actual '%s'", (char *) parcBuffer_ToString(name));

    assertTrue(expected == actual, "Expected %d, actual %" PRIi64 "", expected, actual);

    parcBuffer_Release(&expectedName);
}
LONGBOW_TEST_CASE(Global, cpiAddress_CreateFromInet)
{
    struct sockaddr_in addr_in;
    struct sockaddr_in addr_test;
    memset(&addr_in, 0, sizeof(struct sockaddr_in));

    addr_in.sin_addr.s_addr = 0x01020304;
    addr_in.sin_family = AF_INET;
    addr_in.sin_port = 0x0A0B;

    CPIAddress *address = cpiAddress_CreateFromInet(&addr_in);

    bool success = cpiAddress_GetInet(address, &addr_test);
    assertTrue(success, "Got false converting back address");

    assertTrue(memcmp(&addr_in, &addr_test, sizeof(struct sockaddr_in)) == 0, "Got mismatch addressed");

    assertTrue(cpiAddress_GetType(address) == cpiAddressType_INET,
               "Got wrong address type, expected %d, got %d", cpiAddressType_INET, cpiAddress_GetType(address));

    PARCJSON *json = cpiAddress_ToJson(address);
    CPIAddress *fromjson = cpiAddress_CreateFromJson(json);

    assertTrue(cpiAddress_GetType(address) == cpiAddress_GetType(fromjson), "fromjson type does not equal known");
    assertTrue(parcBuffer_Equals(address->blob, fromjson->blob), "fromjson blob does not equal known address");
    assertTrue(cpiAddress_Equals(address, fromjson), "cpiAddress_Equals broken for INET type");

    // This test does too much.  Case 1032
    CPIAddress *copy = cpiAddress_Copy(address);
    assertTrue(cpiAddress_Equals(copy, address), "Copy and address not equal for INET");

    cpiAddress_Destroy(&copy);
    cpiAddress_Destroy(&fromjson);

    parcJSON_Release(&json);

    cpiAddress_Destroy(&address);
    return;
}
LONGBOW_TEST_CASE(Global, ccnxCodecSchemaV1ManifestDecoder_DecodeHashGroup)
{
    uint8_t rawManifest[40] = { 0x00, 0x07, 0x00, 0x24,
                                0x00, 0x02, 0x00, 0x20,
                                0x46, 0x46, 0x46, 0x46,
                                0x46, 0x46, 0x46, 0x46,
                                0x46, 0x46, 0x46, 0x46,
                                0x46, 0x46, 0x46, 0x46,
                                0x46, 0x46, 0x46, 0x46,
                                0x46, 0x46, 0x46, 0x46,
                                0x46, 0x46, 0x46, 0x46,
                                0x46, 0x46, 0x46, 0x46 };
    PARCBuffer *wireFormat = parcBuffer_Flip(parcBuffer_CreateFromArray(rawManifest, 40));

    CCNxCodecTlvDecoder *decoder = ccnxCodecTlvDecoder_Create(wireFormat);
    CCNxTlvDictionary *dict = ccnxCodecSchemaV1TlvDictionary_CreateManifest();

    ccnxCodecTlvDecoder_GetType(decoder); // swallow type
    uint16_t length = ccnxCodecTlvDecoder_GetLength(decoder);

    CCNxManifestHashGroup *group = ccnxManifestHashGroup_Create();
    bool result = _decodeHashGroup(decoder, dict, group, length);
    assertTrue(result, "Expected hash group to be decoded correctly.");

    PARCBuffer *expectedPointer = parcBuffer_AllocateCString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
    CCNxManifestHashGroupPointer *pointer = ccnxManifestHashGroup_GetPointerAtIndex(group, 0);
    const PARCBuffer *actualPointer = ccnxManifestHashGroupPointer_GetDigest(pointer);
    assertTrue(parcBuffer_Equals(expectedPointer, actualPointer), "Expected decoded pointer to equal %s, got %s", parcBuffer_ToHexString(expectedPointer), parcBuffer_ToHexString(actualPointer));

    parcBuffer_Release(&expectedPointer);

    ccnxManifestHashGroup_Release(&group);
    ccnxManifest_Release(&dict);
    ccnxCodecTlvDecoder_Destroy(&decoder);
    parcBuffer_Release(&wireFormat);
}
LONGBOW_TEST_CASE(Global, ccnxCodecSchemaV1ManifestDecoder_DecodeHashGroupMetadata)
{
    // Re-build the expected metadata from the manifest
    CCNxName *groupLocator = ccnxName_CreateFromCString("ccnx:/locator");
    PARCBuffer *digest = parcBuffer_Allocate(16);
    for (size_t i = 0; i < parcBuffer_Limit(digest); i++) {
        parcBuffer_PutUint8(digest, 0);
    }
    parcBuffer_Flip(digest);
    size_t entrySize = 1;
    size_t dataSize = 2;
    size_t blockSize = 3;
    size_t treeHeight = 4;

    // Compute the expected size of this metadata group.
    size_t metadataSize = 4 * (4 + 8) + 4 + parcBuffer_Limit(digest) + 4 + strlen("ccnx:/locator");

    // See test_ccnxCodecSchemaV1_ManifestEncoder.c for the packet construction details.
    uint8_t rawMetadata[89] = { 0x00, CCNxCodecSchemaV1Types_CCNxManifestHashGroup_Metadata,
                                0x00, metadataSize,
                                0x00, CCNxCodecSchemaV1Types_CCNxManifestHashGroupMetadata_Locator,
                                0x00, strlen("ccnx:/locator"),
                                'c',  'c',
                                'n',  'x',
                                ':',  '/',
                                'l',  'o',
                                'c',  'a',
                                't',  'o',
                                'r',
                                0x00, CCNxCodecSchemaV1Types_CCNxManifestHashGroupMetadata_DataSize,
                                0x00, 0x08,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, dataSize,
                                0x00, CCNxCodecSchemaV1Types_CCNxManifestHashGroupMetadata_BlockSize,
                                0x00, 0x08,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, blockSize,
                                0x00, CCNxCodecSchemaV1Types_CCNxManifestHashGroupMetadata_EntrySize,
                                0x00, 0x08,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, entrySize,
                                0x00, CCNxCodecSchemaV1Types_CCNxManifestHashGroupMetadata_TreeHeight,
                                0x00, 0x08,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, treeHeight,
                                0x00, CCNxCodecSchemaV1Types_CCNxManifestHashGroupMetadata_OverallDataSha256,
                                0x00, parcBuffer_Remaining(digest),
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, 0x00,
                                0x00, 0x00 };
    PARCBuffer *wireFormat = parcBuffer_Flip(parcBuffer_CreateFromArray(rawMetadata, sizeof(rawMetadata)));

    // Create the encoder and swallow the top level container
    CCNxCodecTlvDecoder *decoder = ccnxCodecTlvDecoder_Create(wireFormat);
    ccnxCodecTlvDecoder_GetType(decoder); // swallow type
    uint16_t length = ccnxCodecTlvDecoder_GetLength(decoder);

    // Decode the metadata
    CCNxManifestHashGroup *group = ccnxManifestHashGroup_Create();
    bool result = _decodeHashGroupMetadata(decoder, group, length);
    assertTrue(result, "Expected hash group metadata to be decoded correctly.");

    const CCNxName *actualLocator = ccnxManifestHashGroup_GetLocator(group);
    size_t actualEntrySize = ccnxManifestHashGroup_GetEntrySize(group);
    size_t actualDataSize = ccnxManifestHashGroup_GetDataSize(group);
    size_t actualBlockSize = ccnxManifestHashGroup_GetBlockSize(group);
    size_t actualTreeHeight = ccnxManifestHashGroup_GetTreeHeight(group);
    const PARCBuffer *actualDigest = ccnxManifestHashGroup_GetOverallDataDigest(group);

    assertTrue(ccnxName_Equals(groupLocator, actualLocator), "Expected decoded locator to equal %s, got %s", ccnxName_ToString(groupLocator), ccnxName_ToString(actualLocator));
    assertTrue(entrySize == actualEntrySize, "Expected %zu entry size, got %zu", entrySize, actualEntrySize);
    assertTrue(dataSize == actualDataSize, "Expected %zu data size, got %zu", dataSize, actualDataSize);
    assertTrue(blockSize == actualBlockSize, "Expected %zu block size, got %zu", blockSize, actualBlockSize);
    assertTrue(treeHeight == actualTreeHeight, "Expected %zu tree height, got %zu", treeHeight, actualTreeHeight);
    assertTrue(parcBuffer_Equals(digest, actualDigest), "Expected %s digest, got %s", parcBuffer_ToHexString(digest), parcBuffer_ToHexString(actualDigest));

    parcBuffer_Release(&digest);
    ccnxName_Release(&groupLocator);

    ccnxManifestHashGroup_Release(&group);
    ccnxCodecTlvDecoder_Destroy(&decoder);
    parcBuffer_Release(&wireFormat);
}