2 * Copyright (c) 2014 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 test/storage/inmemorystoragebackend/inmemeorystoragebackendfixture.h
18 * @author Aleksander Zdyb <a.zdyb@samsung.com>
20 * @brief Fixture for InMemeoryStorageBackend tests
23 #ifndef INMEMEORYSTORAGEBACKENDFIXTURE_H_
24 #define INMEMEORYSTORAGEBACKENDFIXTURE_H_
26 #include <gmock/gmock.h>
27 #include <gtest/gtest.h>
29 #include <types/PolicyBucket.h>
30 #include <types/PolicyCollection.h>
31 #include <storage/Buckets.h>
32 #include <storage/InMemoryStorageBackend.h>
34 class InMemeoryStorageBackendFixture : public ::testing::Test {
37 Cynara::Buckets::mapped_type &
38 createBucket(const Cynara::PolicyBucketId &bucketId) {
39 auto bucket = Cynara::PolicyBucket();
40 return m_buckets.insert({ bucketId, bucket }).first->second;
43 Cynara::Buckets::mapped_type &
44 createBucket(const Cynara::PolicyBucketId &bucketId, const Cynara::PolicyCollection &policies) {
45 auto bucket = Cynara::PolicyBucket(policies);
46 return m_buckets.insert({ bucketId, bucket }).first->second;
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[bucketId].insertPolicy(policy);
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());
66 virtual ~InMemeoryStorageBackendFixture() {}
68 // TODO: consider defaulting accessor with ON_CALL
69 Cynara::Buckets m_buckets;
73 #endif /* INMEMEORYSTORAGEBACKENDFIXTURE_H_ */