END_TEST START_TEST(SecureChannel_cableunplugged) { UA_Client *client = UA_Client_new(); UA_ClientConfig_setDefault(UA_Client_getConfig(client)); UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); UA_Variant val; UA_Variant_init(&val); UA_NodeId nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_STATE); retval = UA_Client_readValueAttribute(client, nodeId, &val); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); UA_Variant_deleteMembers(&val); UA_Client_recv = client->connection.recv; client->connection.recv = UA_Client_recvTesting; /* Simulate network cable unplugged (no response from server) */ UA_Client_recvTesting_result = UA_STATUSCODE_GOODNONCRITICALTIMEOUT; UA_Variant_init(&val); retval = UA_Client_readValueAttribute(client, nodeId, &val); ck_assert_uint_eq(retval, UA_STATUSCODE_BADCONNECTIONCLOSED); ck_assert_msg(UA_Client_getState(client) == UA_CLIENTSTATE_DISCONNECTED); UA_Client_recvTesting_result = UA_STATUSCODE_GOOD; UA_Client_delete(client); }
static void onConnect (UA_Client *Client, void *connected, UA_UInt32 requestId, void *response) { if (UA_Client_getState (Client) == UA_CLIENTSTATE_SESSION) *(UA_Boolean *)connected = true; }