Exemple #1
0
LONGBOW_TEST_CASE(Global, parcList_Release)
{
    PARCList *list = parcList(parcArrayList_Create(parcArrayList_StdlibFreeFunction), PARCArrayListAsPARCList);

    parcList_Release(&list);
    assertNull(list, "Expected null.");
}
Exemple #2
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);
}
Exemple #3
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;
}
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");
}
Exemple #5
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);
}
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");
}
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;
}
Exemple #8
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);
}
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;
}
static MetisCommandReturn
testDebug(const LongBowTestCase *testCase, MetisCommandOps * (*create)(MetisControlState * state), int argc, bool initialDebugSetting, bool expectedDebugSetting)
{
    TestData *data = longBowTestCase_GetClipBoardData(testCase);

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

    metisControlState_SetDebug(data->state, initialDebugSetting);
    MetisCommandOps *ops = create(data->state);
    MetisCommandReturn result = ops->execute(data->state->parser, ops, args);
    if (result == MetisCommandReturn_Success) {
        assertTrue(data->state->debugFlag == expectedDebugSetting,
                   "Debug flag wrong, expected %d got %d",
                   expectedDebugSetting,
                   data->state->debugFlag);
    }

    metisCommandOps_Destroy(&ops);
    parcList_Release(&args);
    return result;
}
Exemple #11
0
/**
 * argc = the exact number of args, don't include the command name
 * example: argc = 2, argv = {"Hello", "World"}
 *
 * expectedResult true means the execute function is called
 */
static void
dispatchCommand(const char *command_string, int argc, char **argv, bool expectedResult)
{
    MetisCommandParser *parser = metisCommandParser_Create();

    bool execute_called = false;

    MetisCommandOps *ops = metisCommandOps_Create(&execute_called, command_string, NULL, test_execute, metisCommandOps_Destroy);

    PARCList *args = parcList(parcArrayList_Create(NULL), PARCArrayListAsPARCList);
    parcList_AddAll(args, argc, (void **) &argv[0]);

    execute_called = false;
    metisCommandParser_RegisterCommand(parser, ops);
    metisCommandParser_DispatchCommand(parser, args);
    if (expectedResult) {
        assertTrue(execute_called, "Did not call the execute function");
    } else {
        assertFalse(execute_called, "The execute function should not have been called but was");
    }

    metisCommandParser_Destroy(&parser);
    parcList_Release(&args);
}