/*! * test_outlet.c * * Copyright (c) 2015-2020, NADAL Jean-Baptiste. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * * @Author: NADAL Jean-Baptiste * @Date: 08/01/2020 * */ // This is an independent project of an individual developer. Dear PVS-Studio, please check it. // PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com #define kOutletTestNameTrue "{ \"id\": 1, \"name\": \"test_name\", \"state\": true, \"zone\": \"\", \"sender\": 0, \"switch\": 0 }" #define kOutletTestNameFalse "{ \"id\": 1, \"name\": \"test_name\", \"state\": false, \"zone\": \"\", \"sender\": 0, \"switch\": 0 }" #define kOutletTestNameFullFalse "{ \"id\": 1, \"name\": \"test_name\", \"speech_name\": \"speech_name\", \"state\": false, \"zone\": \"zone\", \"sender\": 123456, \"switch\": 77 }" #define kOutletTestNameFull "[ { \"id\": 1, \"name\": \"test1\", \"state\": false, \"zone\": \"\", \"sender\": 0, \"switch\": 0 }, { \"id\": 2, \"name\": \"test2\", \"state\": false, \"zone\": \"\", \"sender\": 0, \"switch\": 0 }, { \"id\": 3, \"name\": \"test3\", \"state\": false, \"zone\": \"\", \"sender\": 0, \"switch\": 0 } ]" #define kOutletTestRemoved "[ { \"id\": 1, \"name\": \"test1\", \"state\": false, \"zone\": \"\", \"sender\": 0, \"switch\": 0 }, { \"id\": 3, \"name\": \"test3\", \"state\": false, \"zone\": \"\", \"sender\": 0, \"switch\": 0 } ]" /*--------------------------------------------------------------------------*/ TEST("Outlet - create set_state free\t") { device_create_set_state_free(kOutletEntry, kOutletTestNameTrue, kOutletTestNameFalse); } /*--------------------------------------------------------------------------*/ TEST("Outlet - create 3 device remove 2\t") { device_create_three_devices_remove_second(kOutletEntry, kOutletTestNameFull, kOutletTestRemoved); } /*--------------------------------------------------------------------------*/ TEST("Outlet - create - Error case\t") { device_create_error_case(kOutletEntry); } /*--------------------------------------------------------------------------*/ TEST("Outlet - get_by_id - Error case\t") { device_get_by_id_error_case(kOutletEntry); } /*--------------------------------------------------------------------------*/ TEST("Outlet - update - Error case\t") { device_get_by_id_error_case(kOutletEntry); } /*--------------------------------------------------------------------------*/ TEST("Outlet - update - Error case\t") { device_get_by_id_error_case(kOutletEntry); } /*--------------------------------------------------------------------------*/ TEST("Outlet - create - with all field\t") { struct json_object *root_node; devices_manager_t *dm; int ret; char *device_serialized; dm = devices_manager_new(); ASSERT_NOT_NULL(dm); // Create a New Entry. root_node = json_object_new_object(); json_object_object_add(root_node, k_entry_name, json_object_new_string("test_name")); json_object_object_add(root_node, k_entry_speech_name, json_object_new_string("speech_name")); json_object_object_add(root_node, k_entry_zone, json_object_new_string("zone")); json_object_object_add(root_node, k_entry_sender, json_object_new_int(123456)); json_object_object_add(root_node, k_entry_switch, json_object_new_int(77)); ret = devices_manager_create(dm, kOutletEntry, root_node); ASSERT_EQUAL_INT(ret, 0); // Check Objets. device_serialized = devices_manager_get_by_id(dm, kOutletEntry, 1); // printf ("device: %s\n", device_serialized); ASSERT_EQUAL_STR(device_serialized, kOutletTestNameFullFalse); free(device_serialized); json_object_put(root_node); // Free the Object. devices_manager_free(dm); }