void setUp(void) { KINETIC_CONNECTION_INIT(&Connection); Connection.connected = false; // Ensure gets set appropriately by internal connect call HmacKey = ByteArray_CreateWithCString("some hmac key"); KINETIC_SESSION_INIT(&Session, "somehost.com", ClusterVersion, Identity, HmacKey); KineticConnection_NewConnection_ExpectAndReturn(&Session, DummyHandle); KineticConnection_FromHandle_ExpectAndReturn(DummyHandle, &Connection); KineticConnection_Connect_ExpectAndReturn(&Connection, KINETIC_STATUS_SUCCESS); KineticStatus status = KineticClient_Connect(&Session, &SessionHandle); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); TEST_ASSERT_EQUAL(DummyHandle, SessionHandle); }
static void ConnectSession(void) { KINETIC_CONNECTION_INIT(&Connection); Connection.connected = false; // Ensure gets set appropriately by internal connect call Connection.connectionID = 12374626536; // Fake connection ID to allow connection to complete for these tests HmacKey = ByteArray_CreateWithCString("some hmac key"); KINETIC_SESSION_INIT(&Session, "somehost.com", ClusterVersion, Identity, HmacKey); KineticConnection_NewConnection_ExpectAndReturn(&Session, DummyHandle); KineticConnection_FromHandle_ExpectAndReturn(DummyHandle, &Connection); KineticConnection_Connect_ExpectAndReturn(&Connection, KINETIC_STATUS_SUCCESS); // KineticConnection_ReceiveDeviceStatusMessage_ExpectAndReturn(&Connection, KINETIC_STATUS_SUCCESS); KineticStatus status = KineticClient_Connect(&Session, &SessionHandle); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); TEST_ASSERT_EQUAL(DummyHandle, SessionHandle); }
void test_KineticClient_Connect_should_return_KINETIC_STATUS_HOST_EMPTY_upon_NULL_host(void) { ByteArray key = ByteArray_CreateWithCString("some_key"); KineticSession config = { .host = "", .hmacKey = key, }; SessionHandle = 17; KineticStatus status = KineticClient_Connect(&config, &SessionHandle); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_HOST_EMPTY, status); TEST_ASSERT_EQUAL(KINETIC_HANDLE_INVALID, SessionHandle); } void test_KineticClient_Connect_should_return_KINETIC_STATUS_HMAC_EMPTY_upon_NULL_HMAC_key(void) { ByteArray key = {.len = 4, .data = NULL}; KineticSession config = { .host = "somehost.com", .hmacKey = key, }; SessionHandle = 17; KineticStatus status = KineticClient_Connect(&config, &SessionHandle); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_HMAC_EMPTY, status); TEST_ASSERT_EQUAL(KINETIC_HANDLE_INVALID, SessionHandle); } void test_KineticClient_Connect_should_return_false_upon_empty_HMAC_key(void) { uint8_t keyData[] = {0, 1, 2, 3}; ByteArray key = {.len = 0, .data = keyData}; KineticSession config = { .host = "somehost.com", .hmacKey = key, }; SessionHandle = 17; KineticStatus status = KineticClient_Connect(&config, &SessionHandle); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_HMAC_EMPTY, status); TEST_ASSERT_EQUAL(KINETIC_HANDLE_INVALID, SessionHandle); } void test_KineticClient_Connect_should_return_KINETIC_STATUS_SESSION_EMPTY_upon_NULL_handle(void) { KineticSession config = { .host = "somehost.com", .hmacKey = ByteArray_CreateWithCString("some_key"), }; SessionHandle = 17; KineticStatus status = KineticClient_Connect(&config, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SESSION_EMPTY, status); } void test_KineticClient_Connect_should_return_KINETIC_STATUS_SESSION_INVALID_if_connection_for_handle_is_NULL(void) { KineticSession config = { .host = "somehost.com", .hmacKey = ByteArray_CreateWithCString("some_key"), }; SessionHandle = 17; KineticConnection_NewConnection_ExpectAndReturn(&config, DummyHandle); KineticConnection_FromHandle_ExpectAndReturn(DummyHandle, NULL); KineticStatus status = KineticClient_Connect(&config, &SessionHandle); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_CONNECTION_ERROR, status); } void test_KineticClient_Connect_should_return_status_from_a_failed_connection(void) { KineticSession config = { .host = "somehost.com", .hmacKey = ByteArray_CreateWithCString("some_key"), }; SessionHandle = 17; KineticConnection_NewConnection_ExpectAndReturn(&config, DummyHandle); KineticConnection_FromHandle_ExpectAndReturn(DummyHandle, &Connection); KineticConnection_Connect_ExpectAndReturn(&Connection, KINETIC_STATUS_HMAC_EMPTY); KineticConnection_FreeConnection_Expect(&SessionHandle); KineticStatus status = KineticClient_Connect(&config, &SessionHandle); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_HMAC_EMPTY, status); TEST_ASSERT_EQUAL(KINETIC_HANDLE_INVALID, SessionHandle); } void test_KineticClient_Disconnect_should_return_KINETIC_STATUS_CONNECTION_ERROR_upon_failure_to_get_connection_from_handle(void) { SessionHandle = DummyHandle; KineticConnection_FromHandle_ExpectAndReturn(DummyHandle, NULL); KineticStatus status = KineticClient_Disconnect(&SessionHandle); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_CONNECTION_ERROR, status); } void test_KineticClient_Disconnect_should_disconnect_and_free_the_connection_associated_with_handle(void) { SessionHandle = DummyHandle; KineticConnection_FromHandle_ExpectAndReturn(DummyHandle, &Connection); KineticConnection_Disconnect_ExpectAndReturn(&Connection, KINETIC_STATUS_SUCCESS); KineticConnection_FreeConnection_Expect(&SessionHandle); KineticStatus status = KineticClient_Disconnect(&SessionHandle); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); TEST_ASSERT_EQUAL(KINETIC_HANDLE_INVALID, SessionHandle); } void test_KineticClient_Disconnect_should_return_status_from_KineticConnection_upon_faileure(void) { SessionHandle = DummyHandle; KineticConnection_FromHandle_ExpectAndReturn(DummyHandle, &Connection); KineticConnection_Disconnect_ExpectAndReturn(&Connection, KINETIC_STATUS_SESSION_INVALID); KineticConnection_FreeConnection_Expect(&SessionHandle); KineticStatus status = KineticClient_Disconnect(&SessionHandle); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SESSION_INVALID, status); TEST_ASSERT_EQUAL(KINETIC_HANDLE_INVALID, SessionHandle); }