Test outlet is now functional
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
NADAL Jean-Baptiste
2020-02-24 16:39:30 +01:00
parent e4de72a4f6
commit 8e7e94568f
14 changed files with 456 additions and 81 deletions

View File

@@ -1,16 +1,10 @@
#define k_device_list_empty "{\n\
\"capabilities\": [\n\
{\n\
\"name\": \"outlets\",\n\
\"speech_name\": \"lumière\"\n\
},\n\
{\n\
\"name\": \"shutters\",\n\
\"speech_name\": \"volet\"\n\
},\n\
{\n\
\"name\": \"sprinklers\",\n\
\"speech_name\": \"station\"\n\
}\n\
]\n\
}"
#define k_outlet_list_empty "[ ]"
#define k_create_outlet_1 "{\"name\":\"outlet_1\", \"sender\": 12797322, \"switch\": 4}"
#define k_create_outlet_2 "{\"name\":\"outlet_2\", \"sender\": 87654321, \"switch\": 2}"
#define k_update_outlet_2 "{\"name\":\"updated_name\", \"sender\": 12345678, \"switch\": 3, \"state\": true}"
#define k_outlet_list_one_elem "[ { \"id\": 1, \"name\": \"outlet_1\", \"state\": false, \"zone\": \"\", \"sender\": 12797322, \"switch\": 4 } ]"
#define k_outlet_list_two_elem "[ { \"id\": 1, \"name\": \"outlet_1\", \"state\": false, \"zone\": \"\", \"sender\": 12797322, \"switch\": 4 }, { \"id\": 2, \"name\": \"outlet_2\", \"state\": false, \"zone\": \"\", \"sender\": 87654321, \"switch\": 2 } ]"
#define k_outlet_list_elem_2 "{ \"id\": 2, \"name\": \"updated_name\", \"state\": true, \"zone\": \"\", \"sender\": 12345678, \"switch\": 3 }"

View File

@@ -114,10 +114,7 @@ void device_create_three_devices_remove_second(const char *capability, const ch
free(device_serialized);
// Remove ID 2.
root_node = json_object_new_object();
json_object_object_add(root_node, k_entry_id, json_object_new_int(2));
ret = devices_manager_delete(dm, capability, root_node);
json_object_put(root_node);
ret = devices_manager_delete(dm, capability, 2);
ASSERT_EQUAL_INT(ret, 0);
device_serialized = devices_manager_get(dm, capability);

View File

@@ -142,36 +142,41 @@ TEST("Domo - Test API /api/v1/outlets - correct access\t")
// Outlets
// Get All Devices. Should be empty.
ret = exec_request(kget_method, "http://localhost:" kserver_port "/api/v1/capabilities", 200, "", k_device_list_empty, false);
ret = exec_request(kget_method, "http://localhost:" kserver_port "/api/v1/outlets", 200, "", k_outlet_list_empty, false);
ASSERT_EQUAL_INT(ret, 0);
// Create An Outlet. Should be empty.
ret = exec_request(kpost_method, "http://localhost:" kserver_port "/api/v1/outlets", 204, k_create_outlet_1, "", false);
ASSERT_EQUAL_INT(ret, 0);
// Get All Devices. Should Contain One Device.
ret = exec_request(kget_method, "http://localhost:" kserver_port "/api/v1/outlets", 200, "", k_outlet_list_one_elem, false);
ASSERT_EQUAL_INT(ret, 0);
// Create A second Outlet. Should Contain two Device.
ret = exec_request(kpost_method, "http://localhost:" kserver_port "/api/v1/outlets", 204, k_create_outlet_2, "", false);
ASSERT_EQUAL_INT(ret, 0);
// Get All Devices. Should Contain two Devices.
ret = exec_request(kget_method, "http://localhost:" kserver_port "/api/v1/outlets", 200, "", k_outlet_list_two_elem, false);
ASSERT_EQUAL_INT(ret, 0);
// Update the second Outlet. Device should contain.
ret = exec_request(kput_method, "http://localhost:" kserver_port "/api/v1/outlets/2", 204, k_update_outlet_2, "", false);
ASSERT_EQUAL_INT(ret, 0);
// Get Device 2 only. Should Contain Device two updated.
ret = exec_request(kget_method, "http://localhost:" kserver_port "/api/v1/outlets/2", 200, "", k_outlet_list_elem_2, false);
ASSERT_EQUAL_INT(ret, 0);
// Delete Device 2.
ret = exec_request(kdelete_method, "http://localhost:" kserver_port "/api/v1/outlets/2", 204, "", "", false);
ASSERT_EQUAL_INT(ret, 0);
// Get All Devices. Should Contain One Device.
ret = exec_request(kget_method, "http://localhost:" kserver_port "/api/v1/outlets", 200, "", k_outlet_list_one_elem, false);
ASSERT_EQUAL_INT(ret, 0);
restd_server_free(rest_server);
devices_manager_free(dm);
}
#if 0
// Outlets
restd_server_register_hook_on_path(rest_server, EVHTTP_REQ_POST, "/api/v1/outlets", outlet_create_handler, dm);
restd_server_register_hook_on_path(rest_server, EVHTTP_REQ_GET, "/api/v1/outlets", outlet_list_handler, dm);
restd_server_register_hook_on_path(rest_server, EVHTTP_REQ_GET, "/api/v1/outlets/:id", outlet_get_handler, dm);
restd_server_register_hook_on_path(rest_server, EVHTTP_REQ_PUT, "/api/v1/outlets/:id", outlet_update_handler, dm);
restd_server_register_hook_on_path(rest_server, EVHTTP_REQ_DELETE, "/api/v1/outlets/:id", outlet_remove_handler, dm);
#endif

View File

@@ -116,11 +116,13 @@ TEST("devices_manager create and free\t")
}
#include "test_utils.c"
#if 1
#include "test_devices.c"
#include "test_sprinkler.c"
#include "test_shutter.c"
#include "test_outlet.c"
#include "test_rest.c"
#endif
#include "test_domo.c"
QUNIT_END();

View File

@@ -43,8 +43,6 @@
#define kapi_test_put_id2 "/api/v1/test_put/:year/todo"
#define kapi_test_put_id2_body "/api/v1/test_put/1977/todo"
#define kserver_port "7777"
/*--------------------------------------------------------------------------*/
int my_error_handler(restd_resp_t *response, int reason, void *arg)

View File

@@ -30,6 +30,8 @@
#define kput_method "PUT"
#define kdelete_method "DELETE"
#define kserver_port "7777"
/*--------------------------------------------------------------------------*/
int rows_eq(int *a, int *b)
@@ -239,7 +241,8 @@ int exec_request(const char *request, const char *path, int expected_code, const
if (resp_body == NULL)
{
res = 1;
if (expected_code != 204)
res = 1;
}
else
{