2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file TestCases_CertificateDAO.cpp
18 * @author Slawomir Pajak (s.pajak@partner.samsung.com)
20 * @brief This file contains tests for certificate dao class.
23 #include <dpl/test/test_runner.h>
24 #include <wrt-commons/certificate-dao/certificate_dao.h>
26 RUNNER_TEST_GROUP_INIT(DAO)
28 using namespace CertificateDB;
32 class CertificateDAOWrapper {
34 static CertificateDAO* getCertificateDAO()
36 static CertificateDAOPtr certificateDAO(
37 new CertificateDB::CertificateDAO(DPL::FromASCIIString("testWidget123")));
38 return certificateDAO.get();
44 * Name: certificate_dao_save_remove_by_certdata
45 * Description: Tests saves certificateDao object, reads it, and removes it at the end
46 * using certificate data value.
47 * Expected: All operations should succeed.
49 RUNNER_TEST(certificate_dao_save_remove_by_certdata)
51 CertificateDAO* certificateDAO = CertificateDAOWrapper::getCertificateDAO();
53 CertificateDataList dataList = certificateDAO->getCertificateDataList();
54 RUNNER_ASSERT_MSG(dataList.empty(), "CertificateDataList should be empty");
56 CertificateData certData(DPL::FromASCIIString("sampleCetificate"));
57 certificateDAO->setCertificateData(certData, RESULT_ALLOW_ONCE);
59 dataList = certificateDAO->getCertificateDataList();
61 RUNNER_ASSERT_MSG(dataList.size() == 1, "CertificateDataList should not be empty");
62 RUNNER_ASSERT_MSG((*dataList.begin())->certificate == DPL::FromASCIIString("sampleCetificate"),
63 "Wrong element in table");
65 RUNNER_ASSERT_MSG(certificateDAO->getResult(**dataList.begin()) == RESULT_ALLOW_ONCE, "Wrong result");
67 certificateDAO->removeCertificateData(certData);
69 dataList = certificateDAO->getCertificateDataList();
70 RUNNER_ASSERT_MSG(dataList.empty(), "CertificateDataList should be empty");
75 * Name: certificate_dao_save_remove_by_result
76 * Description: Tests saves certificateDao object, reads it, and removes it at the end
78 * Expected: All operations should succeed.
80 RUNNER_TEST(certificate_dao_save_remove_by_result)
82 CertificateDAO* certificateDAO = CertificateDAOWrapper::getCertificateDAO();
84 CertificateDataList dataList = certificateDAO->getCertificateDataList();
85 RUNNER_ASSERT_MSG(dataList.empty(), "CertificateDataList should be empty");
87 CertificateData certData(DPL::FromASCIIString("sampleCetificate1"));
88 certificateDAO->setCertificateData(certData, RESULT_ALLOW_ALWAYS);
90 CertificateData certData2(DPL::FromASCIIString("sampleCetificate2"));
91 certificateDAO->setCertificateData(certData2, RESULT_ALLOW_ALWAYS);
93 dataList = certificateDAO->getCertificateDataList();
94 RUNNER_ASSERT_MSG(dataList.size() == 2, "CertificateDataList should not be empty");
96 certificateDAO->removeCertificateData(RESULT_ALLOW_ALWAYS);
97 dataList = certificateDAO->getCertificateDataList();
98 RUNNER_ASSERT_MSG(dataList.empty(), "CertificateDataList should be empty");
102 * Name: certificate_dao_update
103 * Description: Tests update of certificateDao object.
104 * Expected: All operations should succeed.
106 RUNNER_TEST(certificate_dao_update)
108 CertificateDAO* certificateDAO = CertificateDAOWrapper::getCertificateDAO();
110 CertificateDataList dataList = certificateDAO->getCertificateDataList();
111 RUNNER_ASSERT_MSG(dataList.empty(), "CertificateDataList should be empty");
113 CertificateData certData(DPL::FromASCIIString("sampleCetificate3"));
114 certificateDAO->setCertificateData(certData, RESULT_ALLOW_ONCE);
116 dataList = certificateDAO->getCertificateDataList();
117 RUNNER_ASSERT_MSG(dataList.size() == 1, "CertificateDataList should not be empty");
118 RUNNER_ASSERT_MSG((*dataList.begin())->certificate == DPL::FromASCIIString("sampleCetificate3"),
119 "Wrong element in table");
120 RUNNER_ASSERT_MSG(certificateDAO->getResult(**dataList.begin()) == RESULT_ALLOW_ONCE, "Wrong result");
122 certificateDAO->setCertificateData(certData, RESULT_DENY_ALWAYS);
123 dataList = certificateDAO->getCertificateDataList();
124 RUNNER_ASSERT_MSG(dataList.size() == 1, "CertificateDataList should not be empty");
125 RUNNER_ASSERT_MSG((*dataList.begin())->certificate == DPL::FromASCIIString("sampleCetificate3"),
126 "Wrong element in table");
127 RUNNER_ASSERT_MSG(certificateDAO->getResult(**dataList.begin()) == RESULT_DENY_ALWAYS, "Wrong result");
129 certificateDAO->removeCertificateData(certData);
130 dataList = certificateDAO->getCertificateDataList();
131 RUNNER_ASSERT_MSG(dataList.empty(), "CertificateDataList should be empty");
135 * Name: certificate_dao_equality_operator
136 * Description: Tests CertificateData equality operators.
137 * Expected: All operations should succeed.
139 RUNNER_TEST(certificate_dao_equality_operator)
141 CertificateData certData1(DPL::FromASCIIString("sampleCetificate1"));
142 CertificateData certData2(DPL::FromASCIIString("sampleCetificate1"));
143 CertificateData certData3(DPL::FromASCIIString("sampleCetificate2"));
145 RUNNER_ASSERT_MSG(certData1 == certData2, "Object should be equal");
146 RUNNER_ASSERT_MSG(certData1 != certData3, "Object should not be equal");
147 RUNNER_ASSERT_MSG(certData2 != certData3, "Object should not be equal");