Adjust cynara wrapper to framework
[platform/core/test/security-tests.git] / src / cynara-tests / common / cynara_test_env.cpp
1 /*
2  * Copyright (c) 2014-2015 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 #include <cynara_test_commons.h>
18 #include <cynara_test_cynara_mask.h>
19 #include <cynara_test_file_operations.h>
20 #include <tests_common.h>
21
22 #include <cynara_test_env.h>
23
24 using namespace FileOperations;
25
26 CynaraTestEnv::CynaraTestEnv()
27     : m_dbPresent(false)
28 {
29 }
30
31 CynaraTestEnv::~CynaraTestEnv()
32 {
33 }
34
35 void CynaraTestEnv::init(const std::string &testName)
36 {
37     m_saveDir = TMP_DIR + "/" + testName;
38     m_dbSaveDir = m_saveDir + "/db";
39     m_pluginsSaveDir = m_saveDir + "/plugins";
40     m_defaultDir = "/etc/security-tests/db_patterns/default";
41
42     CynaraMask mask;
43
44     removeDirFiles(m_dbSaveDir);
45     removeDirIfExists(m_dbSaveDir);
46     removeDirFiles(m_pluginsSaveDir);
47     removeDirIfExists(m_pluginsSaveDir);
48     removeDirIfExists(m_saveDir);
49
50     makeDir(m_saveDir);
51     m_dbPresent = dirExists(CynaraTestConsts::DB_DIR);
52     if (m_dbPresent) {
53         makeDir(m_dbSaveDir);
54         copyCynaraFiles(CynaraTestConsts::DB_DIR, m_dbSaveDir);
55     }
56     makeDir(m_pluginsSaveDir);
57     copyCynaraFiles(CynaraTestConsts::SERVICE_PLUGINS_DIR, m_pluginsSaveDir);
58     unmaskedLoadDefaultDatabase();
59 }
60
61 void CynaraTestEnv::finish()
62 {
63     CynaraMask mask;
64
65     removeDirFiles(CynaraTestConsts::DB_DIR);
66     if (m_dbPresent)
67         copyCynaraFiles(m_dbSaveDir, CynaraTestConsts::DB_DIR);
68     else
69         removeDirIfExists(CynaraTestConsts::DB_DIR);
70
71     removeDirFiles(CynaraTestConsts::SERVICE_PLUGINS_DIR);
72     copyCynaraFiles(m_pluginsSaveDir, CynaraTestConsts::SERVICE_PLUGINS_DIR);
73
74     removeDirFiles(m_dbSaveDir);
75     removeDirIfExists(m_dbSaveDir);
76     removeDirFiles(m_pluginsSaveDir);
77     removeDirIfExists(m_pluginsSaveDir);
78     removeDirIfExists(m_saveDir);
79 }
80
81 void CynaraTestEnv::unmaskedLoadDefaultDatabase()
82 {
83     if (m_dbPresent) {
84         removeDirFiles(CynaraTestConsts::DB_DIR);
85         copyCynaraFiles(m_defaultDir, CynaraTestConsts::DB_DIR);
86     }
87 }
88
89 void CynaraTestEnv::loadDefaultDatabase()
90 {
91     CynaraMask mask;
92     unmaskedLoadDefaultDatabase();
93 }