From: Tomasz Swierczek Date: Mon, 29 Mar 2021 09:09:01 +0000 (+0200) Subject: Add API tests for new DCM EXT API X-Git-Tag: submit/tizen/20210419.104558^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F03%2F256103%2F9;p=platform%2Fcore%2Fsecurity%2Fdevice-certificate-manager.git Add API tests for new DCM EXT API Change-Id: If68e66bd129cc0d567979243c743a5fbab640a21 --- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fac6b20..bb459c9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved +# Copyright (c) 2020 - 2021 Samsung Electronics Co., Ltd All Rights Reserved # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -64,6 +64,7 @@ ADD_EXECUTABLE(${TARGET_TESTS} colour_log_formatter.cpp ../src/dcm-client/dcm_client.cpp ../src/dcm-client/device_certificate_manager.cpp + ../src/dcm-client/device_certificate_manager_ext.cpp ../src/shared/log.cpp ../src/shared/protobuf_asio.cpp ${PROTO_SRCS} diff --git a/tests/api_test.cpp b/tests/api_test.cpp index 65aa90c..eb1aa73 100644 --- a/tests/api_test.cpp +++ b/tests/api_test.cpp @@ -23,6 +23,7 @@ #include #include "device_certificate_manager.h" +#include "device_certificate_manager_ext.h" #include "test_macros.h" BOOST_AUTO_TEST_SUITE(API_TEST) @@ -186,4 +187,34 @@ POSITIVE_TEST_CASE(test05_dcm_create_signature) free(signature); } +NEGATIVE_TEST_CASE(test06_dcm_ext_api_invalid_params_on_client_side) +{ + int ret = dcm_ext_call_api(NULL, NULL, 0, NULL, NULL); + BOOST_REQUIRE_EQUAL(ret, DCM_EXT_ERROR_INVALID_PARAMETER); +} + +NEGATIVE_TEST_CASE(test07_dcm_ext_api_invalid_method_name) +{ + int ret = dcm_ext_call_api("method-not-existing", NULL, 0, NULL, NULL); + BOOST_REQUIRE_EQUAL(ret, DCM_EXT_ERROR_INVALID_PARAMETER); +} + +NEGATIVE_TEST_CASE(test08_dcm_ext_api_no_privilege) +{ + int ret = dcm_ext_call_api("method-with-a-privilege-not-granted", NULL, 0, NULL, NULL); + BOOST_REQUIRE_EQUAL(ret, DCM_EXT_ERROR_PERMISSION_DENIED); +} + +POSITIVE_TEST_CASE(test09_dcm_ext_api_normal_call) +{ + size_t out_size; + char* output = NULL; + int input = 5; + int ret = dcm_ext_call_api("square-int-method", (char*)&input, sizeof(input), &output , &out_size); + BOOST_REQUIRE_EQUAL(ret, DCM_EXT_ERROR_NONE); + BOOST_REQUIRE_EQUAL(out_size, sizeof(int)); + BOOST_REQUIRE_EQUAL((int)(*output), 25); + free(output); +} + BOOST_AUTO_TEST_SUITE_END()