Add test case for get_certificate_status_from_store function in cert-server-logic.c 75/315775/8
authortranthanhtung2001 <tran.tung@samsung.com>
Wed, 7 Aug 2024 09:11:31 +0000 (16:11 +0700)
committertung tran <tran.tung@samsung.com>
Tue, 20 Aug 2024 09:56:32 +0000 (09:56 +0000)
Change-Id: I272a2b4f8e7045feb5cd166ec5c402f78c57d07f
Signed-off-by: tranthanhtung2001 <tran.tung@samsung.com>
unit-tests/test_cert_server_logic.cpp

index e669d19..ab6f2dc 100644 (file)
@@ -150,8 +150,61 @@ void setCertStatusToStore(CertStatus certStatus)
        }
 }
 
+void getCertStatusFromStore(int expectedResult, CertStatus expectedStatus, bool isInstallCert)
+{
+       int result;
+       for (auto storeType : storeTypeMap)
+       {
+               CertStatus status = DISABLED;
+               if (isInstallCert)
+                       installCertToStore(std::string(), std::string(), PemCertInfo::CertPEM.c_str(), PEM_CRT);
+
+               result = getCertificateStatusFromStore(storeType.second, gNamePrefix.c_str(), &status);
+
+               BOOST_CHECK_EQUAL(result, expectedResult);
+               BOOST_CHECK_EQUAL(status, expectedStatus);
+
+               if (isInstallCert)
+                       uninstallCertFromStore();
+       }
+}
+
 BOOST_AUTO_TEST_SUITE(CERT_SERVER_LOGIC_TEST)
 
+POSITIVE_TEST_CASE(T_get_certificate_status_from_store)
+{
+       int result = initialize_db();
+       BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+       getCertStatusFromStore(CERTSVC_SUCCESS, ENABLED, true);
+
+       deinitialize_db();
+}
+
+NEGATIVE_TEST_CASE(T_get_certificate_status_from_store_with_no_records)
+{
+       int result = initialize_db();
+       BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+       getCertStatusFromStore(CERTSVC_FAIL, DISABLED, false);
+
+       deinitialize_db();
+}
+
+NEGATIVE_TEST_CASE(T_get_certificate_status_from_store_with_gname_param_null_and_db_no_init)
+{
+       int result;
+       for (auto storeType : storeTypeMap)
+       {
+               result = getCertificateStatusFromStore(storeType.second, NULL, NULL);
+               BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
+
+               CertStatus status;
+               result = getCertificateStatusFromStore(storeType.second, gNamePrefix.c_str(), &status);
+               BOOST_CHECK_EQUAL(result, CERTSVC_FAIL);
+       }
+}
+
 POSITIVE_TEST_CASE(T_set_certificate_status_to_store)
 {
        int result = initialize_db();