Add test for shutter objects.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* test_sprinkler.c
|
||||
* test_devices.c
|
||||
*
|
||||
* Copyright (c) 2015-2020, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
@@ -26,17 +26,14 @@
|
||||
// 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 kDeviceTestNameFalse "{ \"id\": 1, \"name\": \"test_name\", \"state\": false }"
|
||||
#define kDeviceTestNameTrue "{ \"id\": 1, \"name\": \"test_name\", \"state\": true }"
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
void device_create_set_state_remove(const char *capability)
|
||||
void device_create_set_state_remove(const char *capability, const char *test_name_true, const char *test_name_false)
|
||||
{
|
||||
struct json_object *root_node;
|
||||
devices_manager_t *dm;
|
||||
int ret;
|
||||
char *sprinkler_serialized;
|
||||
char *device_serialized;
|
||||
dm = devices_manager_new();
|
||||
ASSERT_NOT_NULL(dm);
|
||||
|
||||
@@ -50,9 +47,9 @@ void device_create_set_state_remove(const char *capability)
|
||||
ASSERT_EQUAL_INT(ret, 0);
|
||||
|
||||
// Check Objets.
|
||||
sprinkler_serialized = devices_manager_get_by_id(dm, capability, 1);
|
||||
ASSERT_EQUAL_STR(sprinkler_serialized, kDeviceTestNameFalse);
|
||||
free(sprinkler_serialized);
|
||||
device_serialized = devices_manager_get_by_id(dm, capability, 1);
|
||||
ASSERT_EQUAL_STR(device_serialized, test_name_false);
|
||||
free(device_serialized);
|
||||
|
||||
// Change the State.
|
||||
root_node = json_object_new_object();
|
||||
@@ -65,9 +62,9 @@ void device_create_set_state_remove(const char *capability)
|
||||
json_object_put(root_node);
|
||||
|
||||
// Check Objets.
|
||||
sprinkler_serialized = devices_manager_get_by_id(dm, capability, 1);
|
||||
ASSERT_EQUAL_STR(sprinkler_serialized, kDeviceTestNameTrue);
|
||||
free(sprinkler_serialized);
|
||||
device_serialized = devices_manager_get_by_id(dm, capability, 1);
|
||||
ASSERT_EQUAL_STR(device_serialized, test_name_true);
|
||||
free(device_serialized);
|
||||
|
||||
// Free the Object.
|
||||
devices_manager_free(dm);
|
||||
@@ -115,7 +112,7 @@ void device_get_by_id_error_case(const char *capability)
|
||||
struct json_object *root_node;
|
||||
devices_manager_t *dm;
|
||||
int ret;
|
||||
char *sprinkler_serialized;
|
||||
char *device_serialized;
|
||||
dm = devices_manager_new();
|
||||
ASSERT_NOT_NULL(dm);
|
||||
|
||||
@@ -127,16 +124,16 @@ void device_get_by_id_error_case(const char *capability)
|
||||
ASSERT_EQUAL_INT(ret, 0);
|
||||
|
||||
// dm is NULL
|
||||
sprinkler_serialized = devices_manager_get_by_id(NULL, capability, 1);
|
||||
ASSERT_NULL(sprinkler_serialized);
|
||||
device_serialized = devices_manager_get_by_id(NULL, capability, 1);
|
||||
ASSERT_NULL(device_serialized);
|
||||
|
||||
// unknown capability
|
||||
sprinkler_serialized = devices_manager_get_by_id(dm, "", 1);
|
||||
ASSERT_NULL(sprinkler_serialized);
|
||||
device_serialized = devices_manager_get_by_id(dm, "", 1);
|
||||
ASSERT_NULL(device_serialized);
|
||||
|
||||
// unknown id
|
||||
sprinkler_serialized = devices_manager_get_by_id(dm, capability, 7);
|
||||
ASSERT_NULL(sprinkler_serialized);
|
||||
device_serialized = devices_manager_get_by_id(dm, capability, 7);
|
||||
ASSERT_NULL(device_serialized);
|
||||
|
||||
json_object_put(root_node);
|
||||
|
||||
|
||||
@@ -49,6 +49,8 @@ TEST("devices_manager create and free")
|
||||
|
||||
#include "test_devices.c"
|
||||
#include "test_sprinkler.c"
|
||||
#include "test_shutter.c"
|
||||
//#include "test_outlet.c"
|
||||
|
||||
#if 0
|
||||
devices_manager_t
|
||||
|
||||
55
src/tests/test_outlet.c
Normal file
55
src/tests/test_outlet.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/*!
|
||||
* 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
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("Outlet - create set_state remove.")
|
||||
{
|
||||
device_create_set_state_remove(kOutletEntry);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("Outlet - create - Error case")
|
||||
{
|
||||
device_create_error_case(kOutletEntry);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("Outlet - get_by_id - Error case")
|
||||
{
|
||||
device_get_by_id_error_case(kOutletEntry);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("Outlet - update - Error case")
|
||||
{
|
||||
device_get_by_id_error_case(kOutletEntry);
|
||||
}
|
||||
59
src/tests/test_shutter.c
Normal file
59
src/tests/test_shutter.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/*!
|
||||
* test_shutter.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 kShutterTestNameTrue "{ \"id\": 1, \"name\": \"test_name\", \"state\": true, \"zone\": \"\", \"sender\": 0, \"switch\": 0, \"speed_up\": 0, \"speed_down\": 0 }"
|
||||
#define kShutterTestNameFalse "{ \"id\": 1, \"name\": \"test_name\", \"state\": false, \"zone\": \"\", \"sender\": 0, \"switch\": 0, \"speed_up\": 0, \"speed_down\": 0 }"
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("Shutter - create set_state remove.")
|
||||
{
|
||||
device_create_set_state_remove(kShutterEntry, kShutterTestNameTrue, kShutterTestNameFalse);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("Shutter - create - Error case")
|
||||
{
|
||||
device_create_error_case(kShutterEntry);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("Shutter - get_by_id - Error case")
|
||||
{
|
||||
device_get_by_id_error_case(kShutterEntry);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("Shutter - update - Error case")
|
||||
{
|
||||
device_get_by_id_error_case(kShutterEntry);
|
||||
}
|
||||
@@ -19,37 +19,41 @@
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* @Author: NADAL Jean-Baptiste
|
||||
* @Date: 26/12/2019
|
||||
* @Date: 07/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 kSprinklerTestNameTrue "{ \"id\": 1, \"name\": \"test_name\", \"state\": true }"
|
||||
#define kSprinklerTestNameFalse "{ \"id\": 1, \"name\": \"test_name\", \"state\": false }"
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("sprinkler - create set_state remove.")
|
||||
TEST("Sprinkler - create set_state remove.")
|
||||
{
|
||||
device_create_set_state_remove(kSprinklerEntry);
|
||||
device_create_set_state_remove(kSprinklerEntry, kSprinklerTestNameTrue, kSprinklerTestNameFalse);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("sprinkler - create - Error case")
|
||||
TEST("Sprinkler - create - Error case")
|
||||
{
|
||||
device_create_error_case(kSprinklerEntry);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("sprinkler - get_by_id - Error case")
|
||||
TEST("Sprinkler - get_by_id - Error case")
|
||||
{
|
||||
device_get_by_id_error_case(kSprinklerEntry);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
TEST("sprinkler - update - Error case")
|
||||
TEST("Sprinkler - update - Error case")
|
||||
{
|
||||
device_get_by_id_error_case(kSprinklerEntry);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user