Remove PolicyBucket() constructor
[platform/core/security/cynara.git] / test / storage / inmemorystoragebackend / inmemeorystoragebackendfixture.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file        test/storage/inmemorystoragebackend/inmemeorystoragebackendfixture.h
18  * @author      Aleksander Zdyb <a.zdyb@samsung.com>
19  * @version     1.0
20  * @brief       Fixture for InMemeoryStorageBackend tests
21  */
22
23 #ifndef INMEMEORYSTORAGEBACKENDFIXTURE_H_
24 #define INMEMEORYSTORAGEBACKENDFIXTURE_H_
25
26 #include <gmock/gmock.h>
27 #include <gtest/gtest.h>
28
29 #include <types/PolicyBucket.h>
30 #include <types/PolicyCollection.h>
31 #include <storage/Buckets.h>
32 #include <storage/InMemoryStorageBackend.h>
33
34 class InMemeoryStorageBackendFixture : public ::testing::Test {
35
36 protected:
37     Cynara::Buckets::mapped_type &
38     createBucket(const Cynara::PolicyBucketId &bucketId) {
39         auto bucket = Cynara::PolicyBucket(bucketId);
40         return m_buckets.insert({ bucketId, bucket }).first->second;
41     }
42
43     Cynara::Buckets::mapped_type &
44     createBucket(const Cynara::PolicyBucketId &bucketId, const Cynara::PolicyCollection &policies) {
45         auto bucket = Cynara::PolicyBucket(bucketId, policies);
46         return m_buckets.insert({ bucketId, bucket }).first->second;
47     }
48
49     void addToBucket(Cynara::PolicyBucketId bucketId, const Cynara::PolicyCollection &policies) {
50         // TODO: Consider altering PolicyMap directly
51         for (const auto &policy : policies) {
52             m_buckets.at(bucketId).insertPolicy(policy);
53         }
54     }
55
56     static void ASSERT_DB_VIRGIN(Cynara::Buckets &buckets)  {
57         using ::testing::IsEmpty;
58         ASSERT_EQ(1, buckets.size());
59         auto defaultBucketIter = buckets.find(Cynara::defaultPolicyBucketId);
60         ASSERT_NE(buckets.end(), defaultBucketIter);
61         auto &defaultBucket = defaultBucketIter->second;
62         ASSERT_THAT(defaultBucket, IsEmpty());
63         ASSERT_EQ(Cynara::PredefinedPolicyType::DENY, defaultBucket.defaultPolicy());
64     }
65
66     virtual ~InMemeoryStorageBackendFixture() {}
67
68     // TODO: consider defaulting accessor with ON_CALL
69     Cynara::Buckets m_buckets;
70 };
71
72
73 #endif /* INMEMEORYSTORAGEBACKENDFIXTURE_H_ */