#include #include #include #include #include "request.h" #include "xce/types.h" /* Tests for xce_hostctrl_req() validation paths. * We test only early-return paths (before xce_request() is called) * since a live endpoint is not available in unit tests. */ static void test_hostctrl_req_null_ep(void) { xce_hostctrl_t ctrl = { .action = HOST_OPEN, .hostname = "host1" }; int rc = xce_hostctrl_req(NULL, &ctrl); TEST_ASSERT_EQUAL_INT(-EINVAL, rc); } static void test_hostctrl_req_null_ctrl(void) { /* non-NULL dummy ep is enough; the NULL ctrl check fires first */ int rc = xce_hostctrl_req((endpoint_t*)0x1, NULL); TEST_ASSERT_EQUAL_INT(-EINVAL, rc); } static void test_hostctrl_req_null_hostname(void) { xce_hostctrl_t ctrl = { .action = HOST_OPEN, .hostname = NULL }; int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl); TEST_ASSERT_EQUAL_INT(-EINVAL, rc); } static void test_hostctrl_req_empty_hostname(void) { xce_hostctrl_t ctrl = { .action = HOST_OPEN, .hostname = "" }; int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl); TEST_ASSERT_EQUAL_INT(-EINVAL, rc); } static void test_hostctrl_req_noop(void) { xce_hostctrl_t ctrl = { .action = HOST_DO_NONE, .hostname = "host1" }; int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl); TEST_ASSERT_EQUAL_INT(0, rc); } static void test_hostctrl_req_reject_tag(void) { xce_hostctrl_t ctrl = { .action = HOST_TAG, .hostname = "host1" }; int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl); TEST_ASSERT_EQUAL_INT(-EINVAL, rc); } static void test_hostctrl_req_reject_untag(void) { xce_hostctrl_t ctrl = { .action = HOST_UNTAG, .hostname = "host1" }; int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl); TEST_ASSERT_EQUAL_INT(-EINVAL, rc); } static void test_hostctrl_req_reject_negative_action(void) { xce_hostctrl_t ctrl = { .action = -1, .hostname = "host1" }; int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl); TEST_ASSERT_EQUAL_INT(-EINVAL, rc); } void test_request(void) { printf("\n>> host control request validation tests\n\n"); RUN_TEST(test_hostctrl_req_null_ep); RUN_TEST(test_hostctrl_req_null_ctrl); RUN_TEST(test_hostctrl_req_null_hostname); RUN_TEST(test_hostctrl_req_empty_hostname); RUN_TEST(test_hostctrl_req_noop); RUN_TEST(test_hostctrl_req_reject_tag); RUN_TEST(test_hostctrl_req_reject_untag); RUN_TEST(test_hostctrl_req_reject_negative_action); }