Beispiel #1
0
LONGBOW_TEST_CASE(Global, athenaFIB_RemoveLink)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    athenaFIB_AddRoute(data->testFIB, data->testName1, data->testVector1);
    athenaFIB_AddRoute(data->testFIB, data->testName2, data->testVector2);

    PARCBitVector *result = athenaFIB_Lookup(data->testFIB, data->testName1, NULL);
    assertTrue(parcBitVector_Equals(result, data->testVector1), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);
    result = athenaFIB_Lookup(data->testFIB, data->testName2, NULL);
    assertTrue(parcBitVector_Equals(result, data->testVector2), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);

    athenaFIB_RemoveLink(data->testFIB, data->testVector1);
    result = athenaFIB_Lookup(data->testFIB, data->testName1, NULL);
    assertNull(result, "Expecting a NULL result from Lookup after Delete Route");
    result = athenaFIB_Lookup(data->testFIB, data->testName2, NULL);
    assertTrue(parcBitVector_Equals(result, data->testVector2), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);

    athenaFIB_AddRoute(data->testFIB, data->testName1, data->testVector12);

    athenaFIB_RemoveLink(data->testFIB, data->testVector2);
    result = athenaFIB_Lookup(data->testFIB, data->testName2, NULL);
    assertNull(result, "Expecting a NULL result from Lookup after Delete Route");
    result = athenaFIB_Lookup(data->testFIB, data->testName1, NULL);
    assertTrue(parcBitVector_Equals(result, data->testVector1), "Expected lookup to equal test vector");
    parcBitVector_Release(&result);
}
Beispiel #2
0
void testParseJSON()
{
	JSONAtom *atom;
	JSONObject *object;
	JSONArray *array, *innerArray;

	TRY("{\n\t\"testInt\": 0,\n\t\"testArray\": [\n\t\tnull,\n\t\ttrue,\n\t\tfalse\n\t]\n}",
		assertNotNull(atom);
		object = atom->asObject();
		assertIntEqual(object->size(), 2);
		assertTrue(object->exists("testInt"));
		assertIntEqual((*object)["testInt"].asInt(), 0);
		assertTrue(object->exists("testArray"));
		array = (*object)["testArray"].asArray();
		assertIntEqual(array->size(), 3);
		assertNotNull((*array)[0]);
		assertNotNull((*array)[1]);
		assertNotNull((*array)[2]);
		assertNull((*array)[0].asNull());
		assertTrue((*array)[1].asBool());
		assertFalse((*array)[2].asBool())
	);

	TRY("[\n\t0,\n\t\[\n\t\tnull,\n\t\ttrue,\n\t\tfalse\n\t]\n]",
		assertNotNull(atom);
		array = atom->asArray();
		assertIntEqual(array->size(), 2);
		assertNotNull((*array)[0]);
		assertIntEqual((*array)[0].asInt(), 0);
		assertNotNull((*array)[1]);
		innerArray = (*array)[1].asArray();
		assertIntEqual(innerArray->size(), 3);
		assertNotNull((*innerArray)[0]);
		assertNotNull((*innerArray)[1]);
		assertNotNull((*innerArray)[2]);
		assertNull((*innerArray)[0].asNull());
		assertTrue((*innerArray)[1].asBool());
		assertFalse((*innerArray)[2].asBool())
	);

	TRY("[\n\t0,\n\t1\n]",
		assertNotNull(atom);
		array = atom->asArray();
		assertIntEqual(array->size(), 2);
		assertIntEqual((*array)[0].asInt(), 0);
		assertIntEqual((*array)[1].asInt(), 1)
	);

	TRY_SHOULD_FAIL("true");
	TRY_SHOULD_FAIL("false");
	TRY_SHOULD_FAIL("null");
	TRY_SHOULD_FAIL("invalid");
	TRY_SHOULD_FAIL("0");
	TRY_SHOULD_FAIL("\"true\"");
}
static char *convertDivisions_ShouldReturnAListOfLeagueDivisions_GivenALeagueFileDataAndLeagueId()
{
     org_data_s org_data = { 0 };

     org_data.league_data  = buildFileLeagName();
     org_data.parks_data   = buildFileParks();
     org_data.players_data = buildFilePlayers();
     org_data.records      = buildRecords( org_data.league_data, 1, sp_Regular );

     fileleagname_s    *league_data      = org_data.league_data;
     league_division_s *league_divisions = convertDivisions( &org_data, 1, 0 );

     assertNotNull( league_divisions );

     assertNotNull(                                   league_divisions[0].division              );
     assertEqualsInt( 1,                              league_divisions[0].league_id             );
     assertEqualsInt( 1,                              league_divisions[0].division_id           );
     assertEqualsInt( 1,                              league_divisions[0].division->division_id );
     assertEqualsStr( league_data->divisions[0].name, league_divisions[0].division->name        );

     assertNotNull(                                   league_divisions[1].division              );
     assertEqualsInt( 1,                              league_divisions[1].league_id             );
     assertEqualsInt( 2,                              league_divisions[1].division_id           );
     assertEqualsInt( 2,                              league_divisions[1].division->division_id );
     assertEqualsStr( league_data->divisions[1].name, league_divisions[1].division->name        );

     assertNull( league_divisions[2].division );

     free_league_divisions( league_divisions );

     league_divisions = convertDivisions( &org_data, 2, 1 );

     assertNotNull( league_divisions );

     assertNotNull(                                   league_divisions[0].division              );
     assertEqualsInt( 2,                              league_divisions[0].league_id             );
     assertEqualsInt( 3,                              league_divisions[0].division_id           );
     assertEqualsInt( 3,                              league_divisions[0].division->division_id );
     assertEqualsStr( league_data->divisions[2].name, league_divisions[0].division->name        );

     assertNotNull(                                   league_divisions[1].division              );
     assertEqualsInt( 2,                              league_divisions[1].league_id             );
     assertEqualsInt( 4,                              league_divisions[1].division_id           );
     assertEqualsInt( 4,                              league_divisions[1].division->division_id );
     assertEqualsStr( league_data->divisions[3].name, league_divisions[1].division->name        );

     assertNull( league_divisions[2].division );

     free_league_divisions( league_divisions );

     return NULL;
}
LONGBOW_TEST_CASE(Global, ccnxInterest_Release)
{
    CCNxName *name = ccnxName_CreateFromURI("lci:/name");
    CCNxInterest *interest = ccnxInterest_CreateSimple(name);

    CCNxInterest *reference = ccnxInterest_Acquire(interest);

    ccnxName_Release(&name);
    ccnxInterest_Release(&interest);
    ccnxInterest_Release(&reference);

    assertNull(interest, "Expected ccnxInterest_Release to null the pointer.");
    assertNull(reference, "Expected ccnxInterest_Release to null the pointer.");
}
Beispiel #5
0
/**
 * Put is protected by the writer mutex.  This means that the tail mutex could
 * actually increase while this is happening. That's ok.  Increasing the tail
 * just means there is _more_ room in the ring.  We only modify writer_head.
 */
bool
parcRingBuffer1x1_Put(PARCRingBuffer1x1 *ring, void *data)
{
    // Our speculative operation
    // The consumer modifies reader_tail, so make sure that's an atomic read.
    // only the prodcuer modifies writer_head, so there's only us

    uint32_t writer_head = ring->writer_head;
    uint32_t reader_tail = ATOMIC_FETCH(&ring->reader_tail);

    uint32_t writer_next = (writer_head + 1) & ring->ring_mask;

    // ring is full
    if (writer_next == reader_tail) {
        return false;
    }

    assertNull(ring->buffer[writer_head], "Ring index %u is not null!", writer_head);
    ring->buffer[writer_head] = data;

    // we're using this just for atomic write to the integer
    ATOMIC_SET(&ring->writer_head, writer_head, writer_next);

    return true;
}
LONGBOW_TEST_CASE(Global, PARC_TreeRedBlack_Remove_NonExistent)
{
    PARCTreeRedBlack *tree1;
    PARCTreeRedBlack *tree2;

    tree1 = parcTreeRedBlack_Create(pointerComp, NULL, NULL, NULL, NULL, NULL);
    tree2 = parcTreeRedBlack_Create(pointerComp, NULL, NULL, NULL, NULL, NULL);

    for (long i = 30; i < 40; i++) {
        // Add some elements to the tree
        parcTreeRedBlack_Insert(tree1, (void *) i, (void *) (i << 8));
        parcTreeRedBlack_Insert(tree2, (void *) i, (void *) (i << 8));
    }
    for (long i = 2; i < 10; i++) {
        // Add some elements to the tree
        parcTreeRedBlack_Insert(tree1, (void *) i, (void *) (i << 8));
        parcTreeRedBlack_Insert(tree2, (void *) i, (void *) (i << 8));
    }
    for (long i = 20; i < 30; i++) {
        // Add some elements to the tree
        parcTreeRedBlack_Insert(tree1, (void *) i, (void *) (i << 8));
        parcTreeRedBlack_Insert(tree2, (void *) i, (void *) (i << 8));
    }

    void *element = parcTreeRedBlack_Remove(tree1, (void *) 100);

    assertNull(element, "Return value must be NULL on non existing element");
    assertTrue(parcTreeRedBlack_Equals(tree1, tree2), "Trees dont match after remove");

    parcTreeRedBlack_Destroy(&tree1);
    parcTreeRedBlack_Destroy(&tree2);
}
Beispiel #7
0
void test_inserting_and_finding()
{
	struct avl_tree_node* root;
	int* value;

	root = avl_tree_create();
	root = avl_tree_insert(root, "esa", 3);
	root = avl_tree_insert(root, "vesa", 4);
	root = avl_tree_insert(root, "vvv", 5);
	root = avl_tree_insert(root, "aaa", 7);

	value = avl_tree_find(root, "vesa");
	assertIntEquals(4, *value);

	value = avl_tree_find(root, "esa");
	assertIntEquals(3, *value);

	value = avl_tree_find(root, "vvv");
	assertIntEquals(5, *value);

	value = avl_tree_find(root, "aaa");
	assertIntEquals(7, *value);

	value = avl_tree_find(root, "bbb");
	assertNull(value);

	avl_tree_destroy(root);
}
static char *batter_stats_t_delete__ShouldDeleteMatchingRecord_GivenThePlayerIdSeasonAndPhase()
{
     batter_stats_s expected = { 0 };

     expected.player_id      = 123;
     expected.season         = 7;
     expected.season_phase   = sp_Playoff;
     expected.games          = 134;
     expected.at_bats        = 543;
     expected.runs           = 101;
     expected.hits           = 220;
     expected.doubles        = 35;
     expected.triples        = 16;
     expected.home_runs      = 56;
     expected.runs_batted_in = 115;
     expected.walks          = 62;
     expected.strike_outs    = 131;
     expected.steals         = 45;
     expected.errors         = 5;

     insert_a_batter_stats( &expected );

     assertEquals( SQLITE_OK, batter_stats_t_delete( db, &expected ) );

     assertNull( get_a_batter_stats( expected.player_id ) );

     sqlite3_exec( db, "delete from batter_stats_t", NULL, NULL, NULL );

     return NULL;
}
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);
}
Beispiel #10
0
LONGBOW_TEST_CASE(Global, parcBufferComposer_Allocate_SizeMax)
{
    size_t size = SIZE_MAX;
    PARCBufferComposer *composer = parcBufferComposer_Allocate(size);

    assertNull(composer, "PARCBufferComposer instance should be NULL.");
}
Beispiel #11
0
void
metisConfiguration_StartCLI(MetisConfiguration *config, uint16_t port)
{
    assertNull(config->cli, "You cannot start more than one CLI");
    config->cli = metisCommandLineInterface_Create(config->metis, port);
    metisCommandLineInterface_Start(config->cli);
}
Beispiel #12
0
/**
 * @function parcFile_Delete
 * @abstract Deletes the file or directory
 * @discussion
 *
 * @param <#param1#>
 * @return true if everything deleted, false otherwise
 */
bool
parcFile_Delete(const PARCFile *file)
{
    char *string = parcPathName_ToString(file->pathName);

    // only allow under tmp
    assertTrue(strncmp(string, "/tmp/", 5) == 0,
               "Path must begin with /tmp/: %s", string);
    // dont allow ".."
    assertNull(strstr(string, ".."), "Path cannot have .. in it: %s", string);

    bool result = false;
    if (parcFile_IsDirectory(file)) {
        // depth first, dont't follow symlinks, do not cross mount points.
        int flags = FTW_DEPTH | FTW_PHYS | FTW_MOUNT;

        // maximum 20 fds open at a time
        int maximumFileDescriptors = 20;

        int failure = nftw(string, _deleteNode, maximumFileDescriptors, flags);
        assertFalse(failure, "Error on recursive delete: (%d) %s", errno, strerror(errno));

        result = failure == false;
    } else {
        result = (unlink(string) == 0);
    }

    parcMemory_Deallocate((void **) &string);

    return result;
}
LONGBOW_TEST_CASE(Local, getMatch_Expired)
{
    AthenaLRUContentStore *impl = _createLRUContentStore();

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

    _AthenaLRUContentStoreEntry *entry = _athenaLRUContentStoreEntry_Create(contentObject);
    ccnxContentObject_Release(&contentObject);

    entry->expiryTime = 10000;
    entry->hasExpiryTime = true;

    bool status = _athenaLRUContentStore_PutLRUContentStoreEntry(impl, entry);

    assertTrue(status, "Expected to put content into the store");

    assertTrue(status, "Expected to put content into the store a second time");
    assertTrue(impl->numEntries == 1, "Expected 1 entry in the store");
    assertTrue(impl->stats.numAdds == 1, "Expected stats to show 1 adds");

    CCNxInterest *interest = ccnxInterest_CreateSimple(name);
    ccnxName_Release(&name);

    CCNxContentObject *match = _athenaLRUContentStore_GetMatch(impl, interest);
    assertNull(match, "Expected to NOT match an interest, due to expired content");

    assertTrue(impl->numEntries == 0, "Expected 0 entries in the store, after removing expired content");

    _athenaLRUContentStoreEntry_Release(&entry);
    ccnxInterest_Release(&interest);

    _athenaLRUContentStore_Release((AthenaContentStoreImplementation *) &impl);
}
Beispiel #14
0
LONGBOW_TEST_CASE(parc_JSONArray, parcJSONArray_CreateRelease)
{
    PARCJSONArray *expected = parcJSONArray_Create();
    parcJSONArray_AssertValid(expected);
    assertNotNull(expected, "Expected non-null return value from parcJSONArray_Create");

    PARCJSONArray *actual = parcJSONArray_Acquire(expected);
    parcJSONArray_AssertValid(actual);

    parcJSONArray_Release(&actual);
    assertNull(actual, "Expected null value set by parcJSONArray_Release");
    parcJSONArray_AssertValid(expected);

    parcJSONArray_Release(&expected);
    assertNull(expected, "Expected null value set by parcJSONArray_Release");
}
LONGBOW_TEST_CASE(Global, rtaComponent_PutMessage_ClosedConnection)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    rtaConnection_SetState(data->connection, CONN_CLOSED);

    // Create the TransportMessage to put on the queue
    TransportMessage *tm = trafficTools_CreateTransportMessageWithDictionaryControl(data->connection, CCNxTlvDictionary_SchemaVersion_V1);

    // Send it down from the API connector to the Testing Lower component
    PARCEventQueue *outputQueue = rtaComponent_GetOutputQueue(data->connection, API_CONNECTOR, RTA_DOWN);

    int success = rtaComponent_PutMessage(outputQueue, tm);
    assertFalse(success, "Error putting message on API Connector's down queue");

    // check that we got it
    PARCEventQueue *inputQueue = rtaComponent_GetOutputQueue(data->connection, TESTING_LOWER, RTA_UP);

    TransportMessage *test_tm = rtaComponent_GetMessage(inputQueue);
    assertNull(test_tm, "Should have returned NULL on a closed connection");

    // The transport message was destroyed by PutMessage because the connection
    // was closed.  Don't need to destroy the transport message.

    // set state back to OPEN so the connection is properly disposed of
    rtaConnection_SetState(data->connection, CONN_OPEN);
}
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);
}
Beispiel #17
0
static char *team_stats_t_delete__ShouldDeleteMatchingRecord_GivenTheTeamIdSeasonAndPhase()
{
     team_stats_s expected = { 0 };

     expected.team_id         = 123;
     expected.season          = 2;
     expected.season_phase    = sp_Regular;
     expected.wins            = 85;
     expected.losses          = 67;
     expected.home_wins       = 56;
     expected.home_losses     = 20;
     expected.road_wins       = 29;
     expected.road_losses     = 47;
     expected.division_wins   = 30;
     expected.division_losses = 26;
     expected.league_wins     = 52;
     expected.league_losses   = 36;
     expected.runs_scored     = 234;
     expected.runs_allowed    = 222;

     insert_a_team_stats( &expected );

     assertEquals( SQLITE_OK, team_stats_t_delete( db, &expected ) );

     assertNull( get_a_team_stats( expected.team_id ) );

     sqlite3_exec( db, "delete from team_stats_t", NULL, NULL, NULL );

     return NULL;
}
LONGBOW_TEST_CASE(Global, parc_EventScheduler_Create_Destroy)
{
    PARCEventScheduler *parcEventScheduler = parcEventScheduler_Create();
    assertNotNull(parcEventScheduler, "parcEventScheduler_Create returned a null reference");
    parcEventScheduler_Destroy(&parcEventScheduler);
    assertNull(parcEventScheduler, "parcEventScheduler_Destroy failed to null reference");
}
LONGBOW_TEST_CASE(Core, bitmap_Create)
{
    Bitmap *map = bitmap_Create(256);
    assertNotNull(map, "Expected a non-NULL bitmap to be created");
    bitmap_Destroy(&map);
    assertNull(map, "Expected a NULL bitmap after bitmap_Destroy");
}
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, 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);
}
Beispiel #22
0
LONGBOW_TEST_CASE(JSON, parcJSON_GetByPath_DeadEndPath)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    const PARCJSONValue *value = parcJSON_GetByPath(data->json, "/string/foo");
    assertNull(value, "Expected null value return from parcJSON_GetByPath");
}
Beispiel #23
0
LONGBOW_TEST_CASE(Global, parcList_Release)
{
    PARCList *list = parcList(parcArrayList_Create(parcArrayList_StdlibFreeFunction), PARCArrayListAsPARCList);

    parcList_Release(&list);
    assertNull(list, "Expected null.");
}
Beispiel #24
0
LONGBOW_TEST_CASE(JSON, parcJSON_GetByPath)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);
    PARCJSON *json = data->json;

    char *s = parcJSON_ToString(json);
    printf("%s\n", s);
    parcMemory_Deallocate((void **) &s);

    const PARCJSONValue *value = parcJSON_GetByPath(json, "/string");
    assertTrue(parcJSONValue_IsString(value), "Expected /string to be a string type.");
    value = parcJSON_GetByPath(json, "/null");
    assertTrue(parcJSONValue_IsNull(value), "Expected /null to be a null type.");
    value = parcJSON_GetByPath(json, "/true");
    assertTrue(parcJSONValue_IsBoolean(value), "Expected /true to be a boolean type.");
    value = parcJSON_GetByPath(json, "/integer");
    assertTrue(parcJSONValue_IsNumber(value), "Expected /integer to be a number type.");
    value = parcJSON_GetByPath(json, "/float");
    assertTrue(parcJSONValue_IsNumber(value), "Expected /float to be a number type.");
    value = parcJSON_GetByPath(json, "/array");
    assertTrue(parcJSONValue_IsArray(value), "Expected /array to be an array type.");
    value = parcJSON_GetByPath(json, "/nonexistent");
    assertNull(value, "Expected /nonexistent to be NULL");

    value = parcJSON_GetByPath(json, "/array/1");
    assertTrue(parcJSONValue_IsBoolean(value), "Expected /array/0 to be a boolean type.");

    value = parcJSON_GetByPath(json, "/array/5");
    assertTrue(parcJSONValue_IsArray(value), "Expected /array/5 to be an array type.");

    assertNotNull(value, "Expected non-null pair");
}
Beispiel #25
0
LONGBOW_TEST_CASE(JSON, parcJSON_GetByPath_BadArrayIndex)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    const PARCJSONValue *value = parcJSON_GetByPath(data->json, "/array/100");
    assertNull(value, "Expected null value return from parcJSON_GetByPath");
}
Beispiel #26
0
LONGBOW_TEST_CASE(JSON, parcJSON_CreateRelease)
{
    PARCJSON *json = parcJSON_Create();

    parcJSON_Release(&json);
    assertNull(json, "Expected the NULL pointer side-effect of Release.");
}
Beispiel #27
0
LONGBOW_TEST_CASE(parcURISegment, parcURISegment_Parse_WithInvalidPercentage)
{
    const char *pointer;
    PARCURISegment *segment = parcURISegment_Parse(URI_PATH_SEGMENT "%G", &pointer);

    assertNull(segment, "Parsed segment should be NULL since the last percent-encoded byte is invalid");
}
Beispiel #28
0
LONGBOW_TEST_CASE(Global, athena_ProcessControl_CPI_REGISTER_PREFIX)
{
    PARCURI *connectionURI;
    Athena *athena = athena_Create(100);

    CCNxName *name = ccnxName_CreateFromCString("ccnx:/foo/bar");
    CCNxControl *control = ccnxControl_CreateAddRouteToSelfRequest(name); // CPI_REGISTER_PREFIX
    CCNxMetaMessage *registerPrefixCommand = ccnxMetaMessage_CreateFromControl(control);
    ccnxControl_Release(&control);

    control = ccnxControl_CreateRemoveRouteToSelfRequest(name); // CPI_UNREGISTER_PREFIX
    CCNxMetaMessage *unregisterPrefixCommand = ccnxMetaMessage_CreateFromControl(control);
    ccnxControl_Release(&control);
    ccnxName_Release(&name);

    connectionURI = parcURI_Parse("tcp://localhost:50100/listener/name=TCPListener");
    const char *result = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI);
    assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno));
    parcURI_Release(&connectionURI);

    connectionURI = parcURI_Parse("tcp://localhost:50100/name=TCP_0");
    result = athenaTransportLinkAdapter_Open(athena->athenaTransportLinkAdapter, connectionURI);
    assertTrue(result != NULL, "athenaTransportLinkAdapter_Open failed (%s)", strerror(errno));
    parcURI_Release(&connectionURI);

    int linkId = athenaTransportLinkAdapter_LinkNameToId(athena->athenaTransportLinkAdapter, "TCP_0");
    PARCBitVector *ingressVector = parcBitVector_Create();
    parcBitVector_Set(ingressVector, linkId);

    // Call _Receive() once to prime the link. Messages are dropped until _Receive() is called once.
    PARCBitVector *linksRead = NULL;
    CCNxMetaMessage *msg = athenaTransportLinkAdapter_Receive(athena->athenaTransportLinkAdapter, &linksRead, -1);
    assertNull(msg, "Expected to NOT receive a message after the first call to _Receive()");

    CCNxMetaMessage *cpiMessages[2];
    cpiMessages[0] = registerPrefixCommand;    // CPI_REGISTER_PREFIX
    cpiMessages[1] = unregisterPrefixCommand;  // CPI_UNREGISTER_PREFIX

    for (int i = 0; i < 2; i++) {
        CCNxMetaMessage *cpiMessageToSend = cpiMessages[i];
        athena_ProcessMessage(athena, cpiMessageToSend, ingressVector);
        ccnxMetaMessage_Release(&cpiMessageToSend);

        CCNxMetaMessage *ack = athenaTransportLinkAdapter_Receive(athena->athenaTransportLinkAdapter, &linksRead, -1);
        assertNotNull(ack, "Expected a CPI_ACK message back");
        assertTrue(ccnxMetaMessage_IsControl(ack), "Expected a control message back");
        parcBitVector_Release(&linksRead);

        PARCJSON *json = ccnxControl_GetJson(ack);
        const PARCJSONValue *cpiAckResult = parcJSON_GetByPath(json, "CPI_ACK/REQUEST/RESULT");
        bool commandResult = parcJSONValue_GetBoolean(cpiAckResult);
        assertTrue(commandResult, "Expected the ACK to contain RESULT=true");

        ccnxMetaMessage_Release(&ack);
    }

    parcBitVector_Release(&ingressVector);
    athena_Release(&athena);
}
Beispiel #29
0
LONGBOW_TEST_CASE(Global, metisCommandParser_Create_Destroy)
{
    MetisCommandParser *parser = metisCommandParser_Create();
    assertNotNull(parser, "Got null parser from metisCommandParser_Create");
    metisCommandParser_Destroy(&parser);
    assertTrue(parcSafeMemory_ReportAllocation(STDOUT_FILENO) == 0, "Memory imbalance!");
    assertNull(parser, "metisCommandParser_Destroy did not null pointer");
}
Beispiel #30
0
LONGBOW_TEST_CASE(Global, athenaFIB_Create)
{
    AthenaFIB *fib = athenaFIB_Create();
    assertNotNull(fib, "Expected athenaFIB_Create to return a non-NULL value");

    athenaFIB_Release(&fib);
    assertNull(fib, "Expected athenaFIB_Release to NULL the pointer");
}