DCM API tests refactoring 57/180957/2
authorDariusz Michaluk <d.michaluk@samsung.com>
Wed, 13 Jun 2018 13:13:00 +0000 (15:13 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Wed, 13 Jun 2018 13:38:08 +0000 (15:38 +0200)
Rename dcm_hw_api_test to dcm_api_test.
Remove RSA tests (not supported by device).
Fix warnings.

Change-Id: Id0143b229c3c371aadb7a30eef8d3bc209fdc430

packaging/device-certificate-manager.spec
tests/CMakeLists.txt
tests/api_test.cpp [moved from tests/hw_api_test.cpp with 82% similarity]
tests/example_capi.c

index 279445a..01e5559 100644 (file)
@@ -120,5 +120,5 @@ fi
 %license LICENSE
 %{_bindir}/dcm_example_client
 %{_bindir}/dcm_example_capi
-%{_bindir}/dcm_hw_api_test
+%{_bindir}/dcm_api_test
 %{_bindir}/dcm_test_cert_rewriter
index a4fa1d6..022e861 100644 (file)
@@ -45,12 +45,12 @@ IF(Boost_UNIT_TEST_FRAMEWORK_FOUND)
                        ${MBEDCRYPTO_LIB}
                        ${MBEDX509_LIB})
 
-       add_executable(dcm_hw_api_test hw_api_test.cpp)
-       target_link_libraries(dcm_hw_api_test
+       add_executable(dcm_api_test api_test.cpp)
+       target_link_libraries(dcm_api_test
                        device-certificate-manager
                        ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES})
 
-       install(TARGETS dcm_test_cert_rewriter dcm_hw_api_test
+       install(TARGETS dcm_test_cert_rewriter dcm_api_test
                RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 ELSE()
        message(STATUS "Boost::test library not found. Disabling unit test build")
similarity index 82%
rename from tests/hw_api_test.cpp
rename to tests/api_test.cpp
index 2be7bd4..3b7a552 100644 (file)
@@ -92,22 +92,6 @@ BOOST_AUTO_TEST_CASE(test03_dcm_get_key_bit_length)
     ret = dcm_get_key_bit_length(NULL, &key_len);
     BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_INVALID_PARAMETER);
 
-    ret = dcm_create_key_context("a", "b", "RSA", &ctx);
-    BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_NONE);
-    BOOST_CHECK(ctx);
-
-    ret = dcm_get_key_bit_length(ctx, NULL);
-    BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_INVALID_PARAMETER);
-
-    ret = dcm_get_key_bit_length(ctx, &key_len);
-    BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_NONE);
-    BOOST_REQUIRE(key_len > 0);
-
-    ret = dcm_free_key_context(ctx);
-    BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_NONE);
-
-    ctx = NULL;
-    key_len = 0;
     ret = dcm_create_key_context("a", "b", "ECDSA", &ctx);
     BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_NONE);
     BOOST_CHECK(ctx);
@@ -129,23 +113,6 @@ BOOST_AUTO_TEST_CASE(test04_dcm_get_key_type)
     ret = dcm_get_key_type(NULL, &key_type);
     BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_INVALID_PARAMETER);
 
-    ret = dcm_create_key_context("a", "b", "RSA", &ctx);
-    BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_NONE);
-    BOOST_CHECK(ctx);
-
-    ret = dcm_get_key_type(ctx, NULL);
-    BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_INVALID_PARAMETER);
-
-    ret = dcm_get_key_type(ctx, &key_type);
-    BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_NONE);
-    BOOST_CHECK(key_type);
-    BOOST_CHECK(strcmp(key_type, "RSA") == 0);
-
-    ret = dcm_free_key_context(ctx);
-    BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_NONE);
-    free(key_type);
-
-    ctx = NULL;
     ret = dcm_create_key_context("a", "b", "ECDSA", &ctx);
     BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_NONE);
     BOOST_CHECK(ctx);
@@ -171,7 +138,7 @@ BOOST_AUTO_TEST_CASE(test05_dcm_create_signature)
     ret = dcm_create_signature(NULL, DCM_DIGEST_SHA256, data, sizeof(data), &signature, &signature_len);
     BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_INVALID_PARAMETER);
 
-    ret = dcm_create_key_context("a", "b", "RSA", &ctx);
+    ret = dcm_create_key_context("a", "b", "ECDSA", &ctx);
     BOOST_REQUIRE_EQUAL(ret, DCM_ERROR_NONE);
     BOOST_CHECK(ctx);
 
index 10a1317..a38aa97 100644 (file)
@@ -31,7 +31,7 @@ int main(int argc, char ** argv)
                printf("Can't get cert chain\n");
                goto exit;
        }
-       printf("Cert is %d bytes\n", cert_chain_len);
+       printf("Cert is %ld bytes\n", cert_chain_len);
        printf("Received cert %s\n", cert_chain);
 
        result = dcm_get_key_bit_length(key_ctx, &key_len);
@@ -39,7 +39,7 @@ int main(int argc, char ** argv)
                printf("Can't get key length\n");
                goto exit;
        }
-       printf("Private key is %d bits\n", key_len);
+       printf("Private key is %ld bits\n", key_len);
        printf("Private key is %s\n", key_type);
 
        result = dcm_create_signature(key_ctx, DCM_DIGEST_SHA256, "12345678901234567890123456789012", 32, &signature, &signature_len);