Remove "secret" key for software backend
[platform/core/security/key-manager.git] / tests / DBFixture.h
1 /*
2  *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Kyungwook Tak <k.tak@samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  *
18  * @file        DBFixture.h
19  * @author      Maciej Karpiuk (m.karpiuk2@samsung.com)
20  * @version
21  * @brief
22  */
23 #pragma once
24
25 #include <test_common.h>
26 #include <ckm/ckm-type.h>
27 #include <protocols.h>
28 #include <chrono>
29
30 class DBFixture {
31 public:
32         DBFixture();
33         DBFixture(const char *db_fname);
34
35         constexpr static const char *m_default_name = "name";
36         constexpr static const char *m_default_owner = "owner";
37
38         // ::::::::::::::::::::::::: helper methods :::::::::::::::::::::::::
39         static void generate_name(unsigned int id, CKM::Name &output);
40         static void generate_owner(unsigned int id, CKM::ClientId &output);
41         static CKM::DB::Row create_default_row(CKM::DataType type =
42                         CKM::DataType::BINARY_DATA);
43         static CKM::DB::Row create_default_row(const CKM::Name &name,
44                                                                                    const CKM::ClientId &owner,
45                                                                                    CKM::DataType type = CKM::DataType::BINARY_DATA);
46         static void compare_row(const CKM::DB::Row &lhs, const CKM::DB::Row &rhs);
47
48         // ::::::::::::::::::::::::: time measurement :::::::::::::::::::::::::
49         void performance_start(const char *operation_name);
50         void performance_stop(long num_operations_performed);
51
52         // ::::::::::::::::::::::::: DB :::::::::::::::::::::::::
53         void generate_perf_DB(unsigned int num_name, unsigned int names_per_owner);
54         long add_full_access_rights(unsigned int num_name,
55                                                                 unsigned int num_names_per_owner);
56         void check_DB_integrity(const CKM::DB::Row &rowPattern);
57         void insert_row();
58         void insert_row(const CKM::Name &name, const CKM::ClientId &owner);
59         void delete_row(const CKM::Name &name, const CKM::ClientId &owner);
60         void add_permission(const CKM::Name &name, const CKM::ClientId &owner,
61                                                 const CKM::ClientId &accessor);
62         void read_row_expect_success(const CKM::Name &name,
63                                                                  const CKM::ClientId &owner);
64
65         CKM::DB::Crypto    m_db;
66
67 private:
68         void    init();
69         double  performance_get_time_elapsed_ms();
70
71         constexpr static const char *m_crypto_db_fname = "/tmp/testme.db";
72         std::string m_operation;
73         std::chrono::high_resolution_clock::time_point m_start_time, m_end_time;
74 };