Ejemplo n.º 1
0
LONGBOW_TEST_CASE(Global, PARCList_Equals_Empty)
{
    PARCArrayList *a = parcArrayList_Create(parcArrayList_StdlibFreeFunction);
    PARCArrayList *b = parcArrayList_Create(parcArrayList_StdlibFreeFunction);
    assertTrue(parcArrayList_Equals(a, b), "Equal values were expected to be equal");

    parcArrayList_Destroy(&a);
    parcArrayList_Destroy(&b);
}
Ejemplo n.º 2
0
LONGBOW_TEST_CASE(Global, PARC_TreeRedBlack_Values)
{
    PARCTreeRedBlack *tree1;
    PARCArrayList *list;

    tree1 = parcTreeRedBlack_Create(pointerComp, NULL, NULL, NULL, NULL, NULL);
    list = parcArrayList_Create(NULL);

    // Insert in tree out of order
    for (long i = 10; i < 20; i++) {
        // Add some elements to the tree
        parcTreeRedBlack_Insert(tree1, (void *) i, (void *) (i << 8));
    }
    for (long i = 1; i < 10; i++) {
        // Add some elements to the tree
        parcTreeRedBlack_Insert(tree1, (void *) i, (void *) (i << 8));
    }

    // Insert in list in order
    for (long i = 1; i < 20; i++) {
        // Add some elements to the tree
        parcArrayList_Add(list, (void *) (i << 8));
    }

    PARCArrayList *values = parcTreeRedBlack_Values(tree1);

    assertTrue(parcArrayList_Equals(list, values), "Key list doesnt' match");

    parcArrayList_Destroy(&values);
    parcArrayList_Destroy(&list);
    parcTreeRedBlack_Destroy(&tree1);
}
Ejemplo n.º 3
0
LONGBOW_TEST_CASE(Global, PARCList_Equals_Same)
{
    PARCArrayList *a = parcArrayList_Create(parcArrayList_StdlibFreeFunction);
    assertTrue(parcArrayList_Equals(a, a), "Expected the same array list to be equal to itself.");

    parcArrayList_Destroy(&a);
}
Ejemplo n.º 4
0
LONGBOW_TEST_CASE(Global, parcList_Release)
{
    PARCList *list = parcList(parcArrayList_Create(parcArrayList_StdlibFreeFunction), PARCArrayListAsPARCList);

    parcList_Release(&list);
    assertNull(list, "Expected null.");
}
Ejemplo n.º 5
0
AthenaTransportLinkAdapter *
athenaTransportLinkAdapter_Create(void (*removeLinkCallback)(void *removeLinkContext, PARCBitVector *parcBitVector), AthenaTransportLinkAdapter_RemoveLinkCallbackContext removeLinkContext)
{
    AthenaTransportLinkAdapter *athenaTransportLinkAdapter = parcMemory_AllocateAndClear(sizeof(AthenaTransportLinkAdapter));
    assertNotNull(athenaTransportLinkAdapter, "parcMemory_AllocateAndClear failed to create a new AthenaTransportLinkAdapter");
    athenaTransportLinkAdapter->moduleList = parcArrayList_Create((void (*)(void **))athenaTransportLinkModule_Destroy);
    athenaTransportLinkAdapter->instanceList = parcArrayList_Create(NULL);
    athenaTransportLinkAdapter->listenerList = parcArrayList_Create(NULL);
    athenaTransportLinkAdapter->nextLinkToRead = 0;
    athenaTransportLinkAdapter->pollfdListSize = 0;
    athenaTransportLinkAdapter->removeLink = removeLinkCallback;
    athenaTransportLinkAdapter->removeLinkContext = removeLinkContext;
    athenaTransportLinkAdapter->log = _parc_logger_create();

    return athenaTransportLinkAdapter;
}
Ejemplo n.º 6
0
LONGBOW_TEST_CASE(Global, PARCList_InsertAtIndex_Last)
{
    PARCArrayList *array = parcArrayList_Create(NULL);

    parcArrayList_Add(array, (void *) 1);
    parcArrayList_Add(array, (void *) 2);
    size_t actual = parcArrayList_Size(array);

    assertTrue(2 == actual, "Expected=%d, actual=%zu", 2, actual);

    parcArrayList_InsertAtIndex(array, 2, (void *) 3);

    actual = parcArrayList_Size(array);
    assertTrue(3 == actual, "Expected=%d, actual=%zu", 3, actual);

    void *element0 = parcArrayList_Get(array, 0);
    assertTrue(element0 == (void *) 1, "Element 1 moved?");

    void *element1 = parcArrayList_Get(array, 1);
    assertTrue(element1 == (void *) 2, "Element 1 moved?");

    void *element2 = parcArrayList_Get(array, 2);
    assertTrue(element2 == (void *) 3, "Element 1 moved?");

    parcArrayList_Destroy(&array);
}
Ejemplo n.º 7
0
int
main(int argc, char *argv[])
{
    char *programName = "parc_publickey";
    if (argc < 2) {
        printUsage(programName);
        exit(1);
    }

    PARCArrayList *args = parcArrayList_Create(NULL);
    parcArrayList_AddAll(args, (void **) argv, argc);

    parcSecurity_Init();

    char *arg = parcArrayList_Get(args, 1);
    if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
        printUsage(programName);
        return 0;
    } else if (strcmp(arg, "-c") == 0 || strcmp(arg, "--create") == 0) {
        parcPublicKey_Create(args);
    } else if (strcmp(arg, "-v") == 0 || strcmp(arg, "--validate") == 0) {
        parcPublicKey_Validate(args);
    } else {
        printUsage(programName);
        exit(1);
    }

    parcSecurity_Fini();
    return 0;
}
Ejemplo n.º 8
0
CPIInterfaceSet *
cpiInterfaceSet_Create(void)
{
    CPIInterfaceSet *set = parcMemory_AllocateAndClear(sizeof(CPIInterfaceSet));
    assertNotNull(set, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(CPIInterfaceSet));
    set->listOfInterfaces = parcArrayList_Create(_destroyInterface);
    return set;
}
Ejemplo n.º 9
0
LONGBOW_TEST_CASE(Global, PARCList_New)
{
    PARCArrayList *array = parcArrayList_Create(parcArrayList_StdlibFreeFunction);
    size_t size = parcArrayList_Size(array);
    assertTrue(0 == size, "Expected %d actual=%zd", 0, size);

    parcArrayList_Destroy(&array);
}
Ejemplo n.º 10
0
CPIConnectionList *
cpiConnectionList_Create()
{
    CPIConnectionList *list = parcMemory_AllocateAndClear(sizeof(CPIConnectionList));
    assertNotNull(list, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(CPIConnectionList));
    list->listOfConnections = parcArrayList_Create(_cpiConnectionList_ArrayDestroyer);
    return list;
}
Ejemplo n.º 11
0
LONGBOW_TEST_CASE(Global, PARCList_Length)
{
    PARCArrayList *array = parcArrayList_Create(NULL);
    parcArrayList_Add(array, 0);

    size_t size = parcArrayList_Size(array);
    assertTrue(1 == size, "Expected %d actual=%zd", 1, size);
    parcArrayList_Destroy(&array);
}
Ejemplo n.º 12
0
MetisListenerSet *
metisListenerSet_Create()
{
    MetisListenerSet *set = parcMemory_AllocateAndClear(sizeof(MetisListenerSet));
    assertNotNull(set, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(MetisListenerSet));
    set->listOfListeners = parcArrayList_Create(metisListenerSet_DestroyListenerOps);

    return set;
}
Ejemplo n.º 13
0
LONGBOW_TEST_CASE(Global, PARCList_Add)
{
    PARCList *list = parcList(parcArrayList_Create(parcArrayList_StdlibFreeFunction), PARCArrayListAsPARCList);

    parcList_Add(list, 0);
    size_t actual = parcList_Size(list);
    assertTrue(1 == actual, "Expected=%d, actual=%zu", 1, actual);

    parcList_Release(&list);
}
Ejemplo n.º 14
0
LONGBOW_TEST_CASE(Global, PARCList_IsEmpty)
{
    PARCArrayList *array = parcArrayList_Create(NULL);
    assertTrue(parcArrayList_IsEmpty(array), "Expected a new array to be empty.");

    parcArrayList_Add(array, 0);
    assertFalse(parcArrayList_IsEmpty(array), "Expected an array with more than zero elements to be empty.");

    parcArrayList_Destroy(&array);
}
Ejemplo n.º 15
0
MetisCommandLineInterface *
metisCommandLineInterface_Create(MetisForwarder *metis, uint16_t port)
{
    MetisCommandLineInterface *cli = parcMemory_AllocateAndClear(sizeof(MetisCommandLineInterface));
    assertNotNull(cli, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(MetisCommandLineInterface));
    cli->port = port;
    cli->listener = NULL;
    cli->metis = metis;
    cli->openSessions = parcArrayList_Create(_session_VoidDestroyer);

    return cli;
}
Ejemplo n.º 16
0
LONGBOW_TEST_CASE(Global, PARCList_InsertAtIndex_Empty)
{
    PARCArrayList *array = parcArrayList_Create(NULL);

    parcArrayList_InsertAtIndex(array, 0, (void *) 3);

    size_t actual = parcArrayList_Size(array);

    assertTrue(1 == actual, "Expected=%d, actual=%zu", 1, actual);

    parcArrayList_Destroy(&array);
}
Ejemplo n.º 17
0
LONGBOW_TEST_CASE(Global, PARCList_Get)
{
    PARCArrayList *array = parcArrayList_Create(parcArrayList_StdlibFreeFunction);

    char *expected = strdup("Hello World");
    parcArrayList_Add(array, expected);

    char *actual = parcArrayList_Get(array, 0);

    assertTrue(expected == actual, "Expected=%p, actual=%p", (void *) expected, (void *) actual);

    parcArrayList_Destroy(&array);
}
Ejemplo n.º 18
0
LONGBOW_TEST_CASE(Global, PARCList_RemoveAndDestroy_AtIndex_Last)
{
    char a[] = "apple";
    char b[] = "bananna";
    char c[] = "cherry";

    PARCArrayList *array = parcArrayList_Create(NULL);
    parcArrayList_Add(array, a);
    parcArrayList_Add(array, b);
    parcArrayList_Add(array, c);

    PARCArrayList *expected = parcArrayList_Create(NULL);
    parcArrayList_Add(expected, a);
    parcArrayList_Add(expected, b);

    parcArrayList_RemoveAndDestroyAtIndex(array, 2);

    assertTrue(parcArrayList_Equals(expected, array), "Expected ");

    parcArrayList_Destroy(&expected);
    parcArrayList_Destroy(&array);
}
Ejemplo n.º 19
0
/**
 * Parse a string in to a PARCList with one word per element
 *
 * The string passed will be modified by inserting NULLs after each token.
 *
 * @param [in] str A c-string (will be modified)
 *
 * @retval non-null A PARCList where each item is a single word
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
static PARCList *
_parseArgs(char *str)
{
    PARCList *list = parcList(parcArrayList_Create(NULL), PARCArrayListAsPARCList);

    const char delimiters[] = " \t";

    char *token;
    while ((token = strsep(&str, delimiters)) != NULL) {
        parcList_Add(list, token);
    }

    return list;
}
Ejemplo n.º 20
0
LONGBOW_TEST_CASE(Global, PARCList_Remove_AtIndex)
{
    char a[] = "apple";
    char b[] = "bananna";
    char c[] = "cherry";

    PARCArrayList *array = parcArrayList_Create(NULL);
    parcArrayList_Add(array, a);
    parcArrayList_Add(array, b);
    parcArrayList_Add(array, c);

    PARCArrayList *expected = parcArrayList_Create(NULL);
    parcArrayList_Add(expected, a);
    parcArrayList_Add(expected, c);

    void *removedElement = parcArrayList_RemoveAtIndex(array, 1);

    assertTrue(removedElement == b, "Expected ");
    assertTrue(parcArrayList_Equals(expected, array), "Expected ");

    parcArrayList_Destroy(&expected);
    parcArrayList_Destroy(&array);
}
Ejemplo n.º 21
0
LONGBOW_TEST_CASE(Global, PARCList_Copy)
{
    char *a = strdup("apple");
    char *b = strdup("bananna");
    char *c = strdup("cherry");

    PARCList *list = parcList(parcArrayList_Create(parcArrayList_StdlibFreeFunction), PARCArrayListAsPARCList);

    parcList_Add(list, a);
    parcList_Add(list, b);
    parcList_Add(list, c);

    parcList_Release(&list);
}
Ejemplo n.º 22
0
LONGBOW_TEST_CASE(Local, _metisControlAddConnection_EtherExecute)
{
    const char *argv[] = { "add", "connection", "ether", "conn3", "e8-06-88-cd-28-de", "em3" };
    PARCList *args = parcList(parcArrayList_Create(NULL), PARCArrayListAsPARCList);
    parcList_AddAll(args, 6, (void **) &argv[0]);


    TestData *data = longBowTestCase_GetClipBoardData(testCase);
    MetisCommandOps *ops = _metisControlAddConnection_EtherCreate(data->state);
    MetisCommandReturn result = ops->execute(data->state->parser, ops, args);
    metisCommandOps_Destroy(&ops);
    parcList_Release(&args);
    assertTrue(result == MetisCommandReturn_Success, "Valid command line should succeed");
}
Ejemplo n.º 23
0
LONGBOW_TEST_CASE(Local, _metisControlAddConnection_UdpExecute)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

    const char *argv[] = { "add", "connection", "tcp", "conn3", "1.2.3.4", "123" };
    PARCList *args = parcList(parcArrayList_Create(NULL), PARCArrayListAsPARCList);
    parcList_AddAll(args, 6, (void **) &argv[0]);

    MetisCommandOps *ops = _metisControlAddConnection_UdpCreate(data->state);
    MetisCommandReturn result = ops->execute(data->state->parser, ops, args);

    metisCommandOps_Destroy(&ops);
    parcList_Release(&args);

    assertTrue(result == MetisCommandReturn_Success, "Unimplemented execute should have failed");
}
//
// This function must be named "athenaTransportLinkModule" <module name> "_Init" so that
// athenaTransportLinkAdapter can locate it to invoke initialization when it's loaded.  It's
// named uniquely (as opposed to _init()) so that it can also be statically linked into Athena.
//
PARCArrayList *
athenaTransportLinkModuleTEMPLATE_Init()
{
    // Template module for establishing point to point tunnel connections.
    AthenaTransportLinkModule *athenaTransportLinkModule;
    PARCArrayList *moduleInstanceList = parcArrayList_Create(NULL);
    assertNotNull(moduleInstanceList, "parcArrayList_Create failed to create module list");

    athenaTransportLinkModule = athenaTransportLinkModule_Create("TEMPLATE",
                                                                 _TemplateOpen,
                                                                 _TemplatePoll);
    assertNotNull(athenaTransportLinkModule, "parcMemory_AllocateAndClear failed allocate Template athenaTransportLinkModule");
    bool result = parcArrayList_Add(moduleInstanceList, athenaTransportLinkModule);
    assertTrue(result == true, "parcArrayList_Add failed");

    return moduleInstanceList;
}
Ejemplo n.º 25
0
PARCArrayList *
athenaTransportLinkModuleUDP_Init()
{
    // Module for providing UDP tunnel connections.
    AthenaTransportLinkModule *athenaTransportLinkModule;
    PARCArrayList *moduleList = parcArrayList_Create(NULL);
    assertNotNull(moduleList, "parcArrayList_Create failed to create module list");

    athenaTransportLinkModule = athenaTransportLinkModule_Create("UDP",
                                                                 _UDPOpen,
                                                                 _UDPPoll);
    assertNotNull(athenaTransportLinkModule, "parcMemory_AllocateAndClear failed allocate UDP athenaTransportLinkModule");
    bool result = parcArrayList_Add(moduleList, athenaTransportLinkModule);
    assertTrue(result == true, "parcArrayList_Add failed");

    return moduleList;
}
PARCArrayList *
athenaTransportLinkModuleETH_Init()
{
    // Module for providing Ethernet links.
    AthenaTransportLinkModule *athenaTransportLinkModule;
    PARCArrayList *moduleList = parcArrayList_Create(NULL);
    assertNotNull(moduleList, "parcArrayList_Create failed to create module list");

    athenaTransportLinkModule = athenaTransportLinkModule_Create("ETH",
                                                                 _ETHOpen,
                                                                 _ETHPoll);
    assertNotNull(athenaTransportLinkModule, "parcMemory_AllocateAndClear failed allocate ETH athenaTransportLinkModule");
    bool result = parcArrayList_Add(moduleList, athenaTransportLinkModule);
    assertTrue(result == true, "parcArrayList_Add failed");

    return moduleList;
}
Ejemplo n.º 27
0
static MetisCommandReturn
testAddRoute(const LongBowTestCase *testCase, int argc, const char *prefix, const char *nexthop, const char *cost)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);
    metisControlState_SetDebug(data->state, true);

    const char *argv[] = { "add", "route", nexthop, prefix, cost };
    PARCList *args = parcList(parcArrayList_Create(NULL), PARCArrayListAsPARCList);
    parcList_AddAll(args, argc, (void **) &argv[0]);

    MetisCommandOps *ops = metisControlAddRoute_Create(data->state);

    MetisCommandReturn result = ops->execute(data->state->parser, ops, args);
    metisCommandOps_Destroy(&ops);
    parcList_Release(&args);
    return result;
}
Ejemplo n.º 28
0
LONGBOW_TEST_CASE(Global, PARCList_AddAll)
{
    PARCList *list = parcList(parcArrayList_Create(parcArrayList_StdlibFreeFunction), PARCArrayListAsPARCList);

    void *elements[] = {
        strdup("a"),
        strdup("b"),
        strdup("c"),
    };

    parcList_AddAll(list, 3, elements);
    size_t actual = parcList_Size(list);

    assertTrue(3 == actual, "Expected=%d, actual=%zu", 3, actual);

    parcList_Release(&list);
}
Ejemplo n.º 29
0
PARCURIPath *
parcURIPath_Copy(const PARCURIPath *path)
{
    assertNotNull(path, "Parameter must be a non-null PARC_URIPath pointer.");

    PARCURIPath *result = parcURIPath_Create();
    result->segments = parcArrayList_Create((void (*)(void **))parcURISegment_Release);

    size_t nSegments = parcURIPath_Count(path);

    for (size_t i = 0; i < nSegments; i++) {
        PARCURISegment *segment = parcURIPath_Get(path, i);
        PARCURISegment *segmentCopy = parcURISegment_Clone(segment);
        parcURIPath_Append(result, segmentCopy);
    }

    return result;
}
Ejemplo n.º 30
0
static MetisCommandReturn
testListConnections(const LongBowTestCase *testCase, int argc)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);
    metisControlState_SetDebug(data->state, true);
    data->customWriteReadReply = &customWriteReadResponse;

    const char *argv[] = { "list", "interfaces" };
    PARCList *args = parcList(parcArrayList_Create(NULL), PARCArrayListAsPARCList);
    parcList_AddAll(args, argc, (void **) &argv[0]);

    MetisCommandOps *ops = metisControlListConnections_Create(data->state);

    MetisCommandReturn result = ops->execute(data->state->parser, ops, args);
    metisCommandOps_Destroy(&ops);
    parcList_Release(&args);
    return result;
}