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"); }
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; }
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; }
/** * 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); }