joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Test.c Source File

Test.c

00001 /*
00002  * Copyright (c) 2015 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 /**
00017  * \file \test_libNsdl\Test.c
00018  *
00019  * \brief   Unit tests for libNsdl
00020  *          NOTE!! Needs libCoap.a from ../../nsdl-c/libCoap/x86_gcc
00021  *
00022  *  */
00023 
00024 #include "ns_types.h"
00025 
00026 #include "sn_nsdl.h"
00027 #include "sn_coap_header.h"
00028 #include "sn_coap_protocol.h"
00029 #include "sn_nsdl_lib.h"
00030 
00031 #include "unity.h"
00032 #include "string.h"
00033 #include "stdlib.h"
00034 
00035 /* non-test function declarations */
00036 void fill_with_random(uint8_t *ptr, uint16_t len);
00037 void *own_alloc(uint16_t size);
00038 void own_free(void *ptr);
00039 uint8_t nsdl_tx_dummy(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *);
00040 uint8_t nsdl_rx_dummy(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *);
00041 uint8_t dynamic_callback(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *address_ptr, sn_nsdl_capab_e protocol);
00042 static void init_temp_variables(void);
00043 
00044 static uint8_t res1_path[] = {"test/res1"};
00045 static uint8_t res1_content[] = {"res1 content"};
00046 
00047 static uint8_t res2_path[] = {"test/res2"};
00048 static uint8_t res2_content[] = {"res2 content"};
00049 
00050 static uint8_t res3_path[] = {"test/res3"};
00051 static uint8_t res3_content[] = {"res3 content"};
00052 
00053 static uint8_t res4_path[] = {"test/res4"};
00054 static uint8_t res4_content[] = {"res4 content"};
00055 
00056 static uint8_t res5_path[] = {"test/res5"};
00057 static uint8_t res5_content[] = {"res5 content"};
00058 
00059 static uint8_t res_negative_path[] = {"test/negative"};
00060 static uint8_t res_negative_content[] = {"negative_test content"};
00061 
00062 static uint8_t address[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
00063 
00064 /* Change byte 13 to differend resources */
00065 static uint8_t get_message[14] = {0x40, 0x01, 0x12, 0x34, 0xb4, 0x74, 0x65, 0x73, 0x74, 0x04, 0x72, 0x65, 0x73, 0x31};
00066 static uint8_t put_message[18] = {0x40, 0x03, 0x12, 0x34, 0xb4, 0x74, 0x65, 0x73, 0x74, 0x04, 0x72, 0x65, 0x73, 0x32, 0xff, 0x61, 0x62, 0x63};
00067 static uint8_t post_message[18] = {0x40, 0x02, 0x12, 0x34, 0xb4, 0x74, 0x65, 0x73, 0x74, 0x04, 0x72, 0x65, 0x73, 0x33, 0xff, 0x61, 0x62, 0x63};
00068 static uint8_t delete_message[14] = {0x40, 0x04, 0x12, 0x34, 0xb4, 0x74, 0x65, 0x73, 0x74, 0x04, 0x72, 0x65, 0x73, 0x34};
00069 
00070 static uint8_t message_payload[3] = {0x61, 0x62, 0x63};
00071 
00072 static uint8_t get_response[17] = {0x60, 0x45, 0x12, 0x34, 0xff, 0x72, 0x65, 0x73, 0x31, 0x20, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74};
00073 static uint8_t response_not_allowed[4] = {0x60, 0x85, 0x12, 0x34};
00074 static uint8_t response_changed[4] = {0x60, 0x44, 0x12, 0x34};
00075 static uint8_t response_created[4] = {0x60, 0x41, 0x12, 0x34};
00076 static uint8_t response_deleted[4] = {0x60, 0x42, 0x12, 0x34};
00077 
00078 #define NSP_PORT 5683
00079 
00080 #define NSP_REGISTRATION_MESSAGE_LEN 72
00081 static uint8_t registration_message[NSP_REGISTRATION_MESSAGE_LEN] = {
00082     0x40, 0x02, 0x01, 0x47, 0xb2, 0x72, 0x64, 0xff, 0x3c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x72,
00083     0x65, 0x73, 0x35, 0x3e, 0x2c, 0x3c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x72, 0x65, 0x73, 0x34,
00084     0x3e, 0x2c, 0x3c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x72, 0x65, 0x73, 0x33, 0x3e, 0x2c, 0x3c,
00085     0x2f, 0x74, 0x65, 0x73, 0x74, 0x2f, 0x72, 0x65, 0x73, 0x32, 0x3e, 0x2c, 0x3c, 0x2f, 0x74, 0x65,
00086     0x73, 0x74, 0x2f, 0x72, 0x65, 0x73, 0x31, 0x3e
00087 };
00088 
00089 static uint16_t message_temp_len = 0;
00090 static uint8_t *message_temp_ptr = 0;
00091 static sn_nsdl_addr_s *address_temp_ptr = 0;
00092 
00093 struct nsdl_s *handle;
00094 
00095 /* Unity test code starts */
00096 void setUp(void)
00097 {
00098     //This is run before EACH TEST
00099 
00100 }
00101 
00102 void tearDown(void)
00103 {
00104 
00105 }
00106 
00107 /**
00108  * \fn void test_libnsdl_init(void)
00109  *
00110  * \brief Tests sn_nsdl_init - function. Function must return failure (-1) if initialization fails.
00111  *
00112  *  Negative test cases:
00113  *  - Memory structure contains null pointer(s)
00114  *  - One of the parameter is null
00115  *
00116  */
00117 void test_libnsdl_init(void)
00118 {
00119     /* Memory struct contains null */
00120     handle = sn_nsdl_init(&nsdl_tx_dummy, &nsdl_rx_dummy, NULL, NULL);
00121     TEST_ASSERT_NULL(handle);
00122 
00123     handle = sn_nsdl_init(&nsdl_tx_dummy, &nsdl_rx_dummy, &own_alloc, NULL);
00124     TEST_ASSERT_NULL(handle);
00125 
00126     handle = sn_nsdl_init(&nsdl_tx_dummy, &nsdl_rx_dummy, NULL, &own_free);
00127     TEST_ASSERT_NULL(handle);
00128 
00129     /* One of parameters is null */
00130     handle = sn_nsdl_init(NULL, &nsdl_rx_dummy, &own_alloc, &own_free);
00131     TEST_ASSERT_NULL(handle);
00132 
00133     handle = sn_nsdl_init(&nsdl_tx_dummy, NULL, &own_alloc, &own_free);
00134     TEST_ASSERT_NULL(handle);
00135 
00136     /* OK case */
00137     handle = sn_nsdl_init(&nsdl_tx_dummy, &nsdl_rx_dummy, &own_alloc, &own_free);
00138     TEST_ASSERT_NOT_NULL(handle);
00139 }
00140 
00141 /**
00142  * \fn void test_libnsdl_create_resource(void)
00143  *
00144  * \brief Tests sn_nsdl_create_resource - function. Creates five resources.
00145  *
00146  *  STATIC RESOURCES:
00147  *  - Resource 1
00148  *      * Get allowed
00149  *  - Resource 2
00150  *      * Put allowed
00151  *  - Resource 3
00152  *      * Post allowed
00153  *  - Resource 4
00154  *      * Delete allowed
00155  *
00156  *  DYNAMIC RESOURCES:
00157  *  - Resource 5
00158  *      * All allowed
00159  *
00160  *  Negative test cases:
00161  *  - Resource already exists
00162  *  - Null pointer as a parameter
00163  *
00164  */
00165 void test_libnsdl_create_resource(void)
00166 {
00167     sn_nsdl_resource_info_s resource;
00168     sn_nsdl_resource_parameters_s resource_parameters;
00169     int8_t ret_val;
00170 
00171     memset(&resource, 0, sizeof(sn_nsdl_resource_info_s));
00172     memset(&resource_parameters, 0, sizeof(sn_nsdl_resource_parameters_s));
00173 
00174 
00175     /* Resource 1*/
00176     resource.access = SN_GRS_GET_ALLOWED;
00177     resource.mode = SN_GRS_STATIC;
00178     resource.path = res1_path;
00179     resource.pathlen = sizeof(res1_path) - 1;
00180     resource.resource = res1_content;
00181     resource.resourcelen = sizeof(res1_content) - 1;
00182     resource.resource_parameters_ptr = &resource_parameters;
00183 
00184     ret_val = sn_nsdl_create_resource(handle, &resource);
00185     TEST_ASSERT_EQUAL(0, ret_val);
00186 
00187 
00188     /* Resource 2 */
00189     resource.access = SN_GRS_PUT_ALLOWED;
00190     resource.path = res2_path;
00191     resource.pathlen = sizeof(res2_path) - 1;
00192     resource.resource = res2_content;
00193     resource.resourcelen = sizeof(res2_content) - 1;
00194 
00195     ret_val = sn_nsdl_create_resource(handle, &resource);
00196     TEST_ASSERT_EQUAL(0, ret_val);
00197 
00198 
00199     /* Resource 3 */
00200     resource.access = SN_GRS_POST_ALLOWED;
00201     resource.path = res3_path;
00202     resource.pathlen = sizeof(res3_path) - 1;
00203     resource.resource = res3_content;
00204     resource.resourcelen = sizeof(res3_content) - 1;
00205 
00206     ret_val = sn_nsdl_create_resource(handle, &resource);
00207     TEST_ASSERT_EQUAL(0, ret_val);
00208 
00209 
00210     /* Resource 4 */
00211     resource.access = SN_GRS_DELETE_ALLOWED;
00212     resource.path = res4_path;
00213     resource.pathlen = sizeof(res4_path) - 1;
00214     resource.resource = res4_content;
00215     resource.resourcelen = sizeof(res4_content) - 1;
00216 
00217     ret_val = sn_nsdl_create_resource(handle, &resource);
00218     TEST_ASSERT_EQUAL(0, ret_val);
00219 
00220 
00221     /* Resource 5 - Dynamic*/
00222     resource.mode = SN_GRS_DYNAMIC;
00223 
00224     resource.access = 0xFF;
00225     resource.path = res5_path;
00226     resource.pathlen = sizeof(res5_path) - 1;
00227     resource.resource = res5_content;
00228     resource.resourcelen = sizeof(res5_content) - 1;
00229     resource.sn_grs_dyn_res_callback = &dynamic_callback;
00230 
00231     ret_val = sn_nsdl_create_resource(handle, &resource);
00232     TEST_ASSERT_EQUAL(0, ret_val);
00233 
00234     /*** Negative test cases ***/
00235 
00236     /* Already exists */
00237     ret_val = sn_nsdl_create_resource(handle, &resource);
00238     TEST_ASSERT_EQUAL(-2, ret_val);
00239 
00240     /* Null pointer */
00241     ret_val = sn_nsdl_create_resource(handle, NULL);
00242     TEST_ASSERT_EQUAL(-1, ret_val);
00243 
00244     ret_val = sn_nsdl_create_resource(NULL, &resource);
00245     TEST_ASSERT_EQUAL(-1, ret_val);
00246 
00247     resource.path = NULL;
00248     resource.pathlen = sizeof(res_negative_path) - 1;
00249     resource.resource = res_negative_content;
00250     resource.resourcelen = sizeof(res_negative_content) - 1;
00251 
00252     ret_val = sn_nsdl_create_resource(handle, &resource);
00253     TEST_ASSERT_EQUAL(-3, ret_val);
00254 
00255     resource.path = res_negative_path;
00256     resource.pathlen = 0;
00257 
00258     ret_val = sn_nsdl_create_resource(handle, &resource);
00259     TEST_ASSERT_EQUAL(-3, ret_val);
00260 
00261 }
00262 
00263 /**
00264  * \fn test_libnsdl_list_resources(void)
00265  *
00266  * \brief Calls sn_nsdl_list_resource - function
00267  *  Function must return list of early created resources
00268  */
00269 
00270 void test_libnsdl_list_resources(void)
00271 {
00272     sn_grs_resource_list_s *resource_list_ptr;
00273 
00274     resource_list_ptr = sn_nsdl_list_resource(handle, 0, 0);
00275 
00276     TEST_ASSERT_EQUAL(5, resource_list_ptr->res_count);
00277 
00278     TEST_ASSERT_EQUAL_INT8_ARRAY(resource_list_ptr->res[4].path, res1_path, resource_list_ptr->res[4].pathlen);
00279     TEST_ASSERT_EQUAL_INT8_ARRAY(resource_list_ptr->res[3].path, res2_path, resource_list_ptr->res[3].pathlen);
00280     TEST_ASSERT_EQUAL_INT8_ARRAY(resource_list_ptr->res[2].path, res3_path, resource_list_ptr->res[2].pathlen);
00281     TEST_ASSERT_EQUAL_INT8_ARRAY(resource_list_ptr->res[1].path, res4_path, resource_list_ptr->res[1].pathlen);
00282     TEST_ASSERT_EQUAL_INT8_ARRAY(resource_list_ptr->res[0].path, res5_path, resource_list_ptr->res[0].pathlen);
00283 
00284 }
00285 
00286 /**
00287  * \fn test_libnsdl_get_resource(void)
00288  *
00289  * \brief Calls sn_nsdl_get_resource - function
00290  *  Function must return pointer to created resource
00291  *
00292  * Negative test cases:
00293  * - call function with null parameter
00294  *
00295  */
00296 
00297 void test_libnsdl_get_resource(void)
00298 {
00299     sn_nsdl_resource_info_s *res_ptr;
00300 
00301     /* With null pointer */
00302     res_ptr = sn_nsdl_get_resource(handle, 0, res1_path);
00303     TEST_ASSERT_NULL(res_ptr);
00304 
00305     res_ptr = sn_nsdl_get_resource(handle, sizeof(res1_path) - 1, NULL);
00306     TEST_ASSERT_NULL(res_ptr);
00307 
00308     res_ptr = sn_nsdl_get_resource(NULL, sizeof(res1_path) - 1, res1_path);
00309     TEST_ASSERT_NULL(res_ptr);
00310 
00311     /* Ok case, gets resource 1 and checks that path and content are ok */
00312     res_ptr = sn_nsdl_get_resource(handle, sizeof(res1_path) - 1, res1_path);
00313     TEST_ASSERT_NOT_NULL(res_ptr);
00314 
00315     TEST_ASSERT_EQUAL_INT8_ARRAY(res_ptr->path, res1_path, sizeof(res1_path) - 1);
00316     TEST_ASSERT_EQUAL_INT8_ARRAY(res_ptr->resource, res1_content, sizeof(res1_content) - 1);
00317 }
00318 
00319 /**
00320  * \fn test_libnsdl_set_nsp_address(void)
00321  *
00322  * \brief Sets NSP address to nsdl-library
00323  *
00324  *  Negative test cases:
00325  *  - call function with null parameter
00326  */
00327 void test_libnsdl_set_nsp_address(void)
00328 {
00329     int8_t ret_val = 0;
00330 
00331     /* with null pointer */
00332     ret_val = set_NSP_address(handle, NULL, NSP_PORT, SN_NSDL_ADDRESS_TYPE_IPV4);
00333     TEST_ASSERT_EQUAL(-1, ret_val);
00334 
00335     ret_val = set_NSP_address(NULL, address, NSP_PORT, SN_NSDL_ADDRESS_TYPE_IPV4);
00336     TEST_ASSERT_EQUAL(-1, ret_val);
00337 
00338     /* OK case */
00339     ret_val = set_NSP_address(handle, address, NSP_PORT, SN_NSDL_ADDRESS_TYPE_IPV4);
00340     TEST_ASSERT_EQUAL(0, ret_val);
00341 }
00342 
00343 /**
00344  * \fn test_libnsdl_register(void)
00345  *
00346  * \brief Calls sn_nsdl_get_resource - function
00347  *
00348  *  Negative test cases:
00349  *  - call function with null parameter
00350  *
00351  */
00352 
00353 void test_libnsdl_register(void)
00354 {
00355     int8_t ret_val = 0;
00356     sn_nsdl_ep_parameters_s endpoint_info;
00357 
00358     memset(&endpoint_info, 0, sizeof(sn_nsdl_ep_parameters_s));
00359 
00360     /* With null pointer */
00361     ret_val = sn_nsdl_register_endpoint(handle, NULL);
00362     TEST_ASSERT_EQUAL(0, ret_val);
00363 
00364     ret_val = sn_nsdl_register_endpoint(NULL, &endpoint_info);
00365     TEST_ASSERT_EQUAL(0, ret_val);
00366 
00367     /* OK case */
00368     ret_val = sn_nsdl_register_endpoint(handle, &endpoint_info);
00369     TEST_ASSERT_NOT_EQUAL(0, ret_val);
00370 
00371     /* Check address */
00372     TEST_ASSERT_EQUAL(NSP_PORT, address_temp_ptr->port);
00373     TEST_ASSERT_EQUAL_INT8_ARRAY(address, address_temp_ptr->addr_ptr, address_temp_ptr->addr_len);
00374 
00375     /* Check registration message !Note, message ID [bytes 2-3] is random in every message! */
00376     TEST_ASSERT_EQUAL(NSP_REGISTRATION_MESSAGE_LEN, message_temp_len);
00377     TEST_ASSERT_EQUAL_INT8_ARRAY(message_temp_ptr, registration_message, 2); //message header
00378     TEST_ASSERT_EQUAL_INT8_ARRAY(message_temp_ptr + 4, registration_message + 4, message_temp_len - 4); //Rest of the message
00379 
00380     init_temp_variables();
00381 }
00382 
00383 /**
00384  * \fn void test_libnsdl_get_requests_to_resources(void)
00385  *
00386  * \brief Process CoAP message "GET"
00387  *
00388  *  - GET to resource that is allowed
00389  *  - GET to resource that is not allowed
00390  *
00391  */
00392 
00393 void test_libnsdl_get_requests_to_resources(void)
00394 {
00395     sn_nsdl_addr_s address_struct;
00396     int8_t ret_val = 0;
00397 
00398     address_struct.addr_ptr = address;
00399     address_struct.addr_len = 16;
00400     address_struct.port = NSP_PORT;
00401 
00402     /* Get to resource that is allowed */
00403     ret_val = sn_nsdl_process_coap(handle, get_message, sizeof(get_message), &address_struct);
00404 
00405     TEST_ASSERT_EQUAL(0, ret_val);
00406     TEST_ASSERT_EQUAL(sizeof(get_response), message_temp_len);
00407     TEST_ASSERT_EQUAL_INT8_ARRAY(message_temp_ptr, get_response, message_temp_len);
00408 
00409     init_temp_variables();
00410 
00411     /* Get to resource that is not allowed */
00412     get_message[13] = 0x32;
00413     ret_val = sn_nsdl_process_coap(handle, get_message, sizeof(get_message), &address_struct);
00414     get_message[13] = 0x31;
00415 
00416     TEST_ASSERT_EQUAL(0, ret_val);
00417 
00418     TEST_ASSERT_EQUAL(sizeof(response_not_allowed), message_temp_len);
00419     TEST_ASSERT_EQUAL_INT8_ARRAY(message_temp_ptr, response_not_allowed, message_temp_len);
00420 
00421     init_temp_variables();
00422 }
00423 
00424 /**
00425  * \fn void test_libnsdl_put_requests_to_resources(void)
00426  *
00427  * \brief Process CoAP message "PUT"
00428  *
00429  *  - PUT to resource that is allowed
00430  *  - PUT to resource that is not allowed
00431  */
00432 void test_libnsdl_put_requests_to_resources(void)
00433 {
00434     sn_nsdl_addr_s address_struct;
00435     int8_t ret_val = 0;
00436     sn_nsdl_resource_info_s *res_ptr;
00437 
00438     address_struct.addr_ptr = address;
00439     address_struct.addr_len = 16;
00440     address_struct.port = NSP_PORT;
00441 
00442     /* Put to resource that is allowed */
00443     ret_val = sn_nsdl_process_coap(handle, put_message, sizeof(put_message), &address_struct);
00444 
00445     TEST_ASSERT_EQUAL(0, ret_val);
00446     TEST_ASSERT_EQUAL(sizeof(response_changed), message_temp_len);
00447     TEST_ASSERT_EQUAL_INT8_ARRAY(response_changed, message_temp_ptr, message_temp_len);
00448 
00449     //get resource and read res value
00450     res_ptr = sn_nsdl_get_resource(handle, sizeof(res2_path) - 1, res2_path);
00451     TEST_ASSERT_EQUAL_INT8_ARRAY(message_payload, res_ptr->resource, sizeof(message_payload));
00452 
00453     init_temp_variables();
00454 
00455     /* Put to resource that is not allowed */
00456     put_message[13] = 0x31;
00457     ret_val = sn_nsdl_process_coap(handle, put_message, sizeof(put_message), &address_struct);
00458     put_message[13] = 0x32;
00459 
00460     TEST_ASSERT_EQUAL(0, ret_val);
00461     TEST_ASSERT_EQUAL(sizeof(response_not_allowed), message_temp_len);
00462     TEST_ASSERT_EQUAL_INT8_ARRAY(response_not_allowed, message_temp_ptr, message_temp_len);
00463 
00464     init_temp_variables();
00465 }
00466 
00467 /**
00468  * \fn void test_libnsdl_post_requests_to_resources(void)
00469  *
00470  * \brief Process CoAP message "POST"
00471  *
00472  *  - POST to resource that is allowed
00473  *  - POST to resource that is not allowed
00474  *
00475  */
00476 void test_libnsdl_post_requests_to_resources(void)
00477 {
00478     sn_nsdl_addr_s address_struct;
00479     int8_t ret_val = 0;
00480     sn_nsdl_resource_info_s *res_ptr;
00481 
00482     address_struct.addr_ptr = address;
00483     address_struct.addr_len = 16;
00484     address_struct.port = NSP_PORT;
00485 
00486     /* Post to resource that is allowed */
00487     ret_val = sn_nsdl_process_coap(handle, post_message, sizeof(post_message), &address_struct);
00488 
00489     TEST_ASSERT_EQUAL(0, ret_val);
00490     TEST_ASSERT_EQUAL(sizeof(response_changed), message_temp_len);
00491     TEST_ASSERT_EQUAL_INT8_ARRAY(response_changed, message_temp_ptr, message_temp_len);
00492 
00493     //get resource and read res value
00494     res_ptr = sn_nsdl_get_resource(handle, sizeof(res3_path) - 1, res3_path);
00495     TEST_ASSERT_EQUAL_INT8_ARRAY(message_payload, res_ptr->resource, sizeof(message_payload));
00496 
00497     init_temp_variables();
00498 
00499     /* Post to resource that is not allowed */
00500     post_message[13] = 0x32;
00501     ret_val = sn_nsdl_process_coap(handle, post_message, sizeof(post_message), &address_struct);
00502     post_message[13] = 0x33;
00503 
00504     TEST_ASSERT_EQUAL(0, ret_val);
00505     TEST_ASSERT_EQUAL(sizeof(response_not_allowed), message_temp_len);
00506     TEST_ASSERT_EQUAL_INT8_ARRAY(response_not_allowed, message_temp_ptr, message_temp_len);
00507 
00508     init_temp_variables();
00509 }
00510 
00511 /**
00512  * \fn void test_libnsdl_delete_requests_to_resources(void)
00513  *
00514  * \brief Process CoAP message "DELETE"
00515  *
00516  *  - DELETE to resource that is allowed
00517  *  - DELETE to resource that is not allowed
00518  *
00519  */
00520 void test_libnsdl_delete_requests_to_resources(void)
00521 {
00522     sn_nsdl_addr_s address_struct;
00523     int8_t ret_val = 0;
00524     sn_nsdl_resource_info_s *res_ptr;
00525 
00526     address_struct.addr_ptr = address;
00527     address_struct.addr_len = 16;
00528     address_struct.port = NSP_PORT;
00529 
00530     /* Delete to resource that is not allowed */
00531     delete_message[13] = 0x33;
00532     ret_val = sn_nsdl_process_coap(handle, delete_message, sizeof(delete_message), &address_struct);
00533     delete_message[13] = 0x34;
00534 
00535     TEST_ASSERT_EQUAL(0, ret_val);
00536     TEST_ASSERT_EQUAL(sizeof(response_not_allowed), message_temp_len);
00537     TEST_ASSERT_EQUAL_INT8_ARRAY(response_not_allowed, message_temp_ptr, message_temp_len);
00538 
00539     init_temp_variables();
00540 }
00541 
00542 /**
00543  * \fn void test_libnsdl_update_resource_value(void)
00544  *
00545  * \brief Updates resource value from application
00546  *
00547  */
00548 void test_libnsdl_update_resource_value(void)
00549 {
00550     sn_nsdl_resource_info_s resource;
00551     sn_nsdl_resource_info_s *res_ptr;
00552     sn_nsdl_resource_parameters_s resource_parameters;
00553     int8_t ret_val;
00554 
00555     memset(&resource, 0, sizeof(sn_nsdl_resource_info_s));
00556     memset(&resource_parameters, 0, sizeof(sn_nsdl_resource_parameters_s));
00557 
00558     /* Resource 1*/
00559     resource.access = SN_GRS_GET_ALLOWED;
00560     resource.mode = SN_GRS_STATIC;
00561     resource.path = res1_path;
00562     resource.pathlen = sizeof(res1_path) - 1;
00563     resource.resource = message_payload;
00564     resource.resourcelen = sizeof(message_payload);
00565     resource.resource_parameters_ptr = &resource_parameters;
00566 
00567     ret_val = sn_nsdl_update_resource(handle, &resource);
00568 
00569     TEST_ASSERT_EQUAL(0, ret_val);
00570 
00571     //get resource and read res value
00572     res_ptr = sn_nsdl_get_resource(handle, sizeof(res1_path) - 1, res1_path);
00573     TEST_ASSERT_NOT_NULL(res_ptr);
00574     TEST_ASSERT_EQUAL_INT8_ARRAY(message_payload, res_ptr->resource, sizeof(message_payload));
00575 
00576 }
00577 
00578 /**
00579  * \fn void test_libnsdl_delete_resource(void)
00580  *
00581  * \brief Delete resource from application
00582  *
00583  */
00584 void test_libnsdl_delete_resource(void)
00585 {
00586     sn_nsdl_resource_info_s *res_ptr;
00587     int8_t ret_val;
00588 
00589     ret_val = sn_nsdl_delete_resource(handle, sizeof(res4_path) - 1, res4_path);
00590 
00591     TEST_ASSERT_EQUAL(0, ret_val);
00592 
00593     //get resource and read res value
00594     res_ptr = sn_nsdl_get_resource(handle, sizeof(res4_path) - 1, res4_path);
00595     TEST_ASSERT_NULL(res_ptr);
00596 }
00597 
00598 
00599 /*******************************/
00600 /***   non-test functions    ***/
00601 /*******************************/
00602 
00603 void fill_with_random(uint8_t *ptr, uint16_t len)
00604 {
00605     while (len--) {
00606         *(ptr + len) = 'a';
00607     }
00608 }
00609 
00610 void *own_alloc(uint16_t size)
00611 {
00612     return malloc(size);
00613 }
00614 
00615 void own_free(void *ptr)
00616 {
00617     free(ptr);
00618 }
00619 
00620 uint8_t nsdl_tx_dummy(struct nsdl_s *handle, sn_nsdl_capab_e protocol, uint8_t *data_ptr, uint16_t data_len, sn_nsdl_addr_s *address_ptr)
00621 {
00622     message_temp_ptr = malloc(data_len);
00623     memcpy(message_temp_ptr, data_ptr, data_len);
00624 
00625     message_temp_len = data_len;
00626 
00627     address_temp_ptr = malloc(sizeof(sn_nsdl_addr_s));
00628     memcpy(address_temp_ptr, address_ptr, sizeof(sn_nsdl_addr_s));
00629 
00630 #if 0
00631     uint8_t i;
00632     printf("\nlength = %d\n", data_len);
00633     for (i = 0; i < data_len; i++) {
00634         printf("0x");
00635         if (*(data_ptr + i) <= 0x0F) {
00636             printf("0");
00637         }
00638         printf("%x, ", *(data_ptr + i));
00639         if (!((i + 1) % 16)) {
00640             printf("\n");
00641         }
00642     }
00643     printf("\n");
00644 #endif
00645 }
00646 
00647 uint8_t nsdl_rx_dummy(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *address_ptr)
00648 {
00649 
00650 }
00651 
00652 uint8_t dynamic_callback(struct nsdl_s *handle, sn_coap_hdr_s *coap_header_ptr, sn_nsdl_addr_s *address_ptr, sn_nsdl_capab_e protocol)
00653 {
00654 
00655 }
00656 
00657 static void init_temp_variables(void)
00658 {
00659     if (message_temp_ptr) {
00660         free(message_temp_ptr);
00661         message_temp_ptr = 0;
00662     }
00663     if (address_temp_ptr) {
00664         free(address_temp_ptr);
00665         address_temp_ptr = 0;
00666     }
00667     message_temp_len = 0;
00668 }
00669 
00670 
00671 
00672 
00673 
00674 
00675 
00676