2 * Copyright (c) 2014-2015 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 #include <cynara_test_commons.h>
18 #include <cynara_test_cynara_mask.h>
19 #include <cynara_test_file_operations.h>
20 #include <tests_common.h>
22 #include <cynara_test_env.h>
24 using namespace FileOperations;
26 CynaraTestEnv::CynaraTestEnv()
31 CynaraTestEnv::~CynaraTestEnv()
35 void CynaraTestEnv::init(const std::string &testName)
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";
44 removeDirFiles(m_dbSaveDir);
45 removeDirIfExists(m_dbSaveDir);
46 removeDirFiles(m_pluginsSaveDir);
47 removeDirIfExists(m_pluginsSaveDir);
48 removeDirIfExists(m_saveDir);
51 m_dbPresent = dirExists(CynaraTestConsts::DB_DIR);
54 copyCynaraFiles(CynaraTestConsts::DB_DIR, m_dbSaveDir);
56 makeDir(m_pluginsSaveDir);
57 copyCynaraFiles(CynaraTestConsts::SERVICE_PLUGINS_DIR, m_pluginsSaveDir);
58 unmaskedLoadDefaultDatabase();
61 void CynaraTestEnv::finish()
65 removeDirFiles(CynaraTestConsts::DB_DIR);
67 copyCynaraFiles(m_dbSaveDir, CynaraTestConsts::DB_DIR);
69 removeDirIfExists(CynaraTestConsts::DB_DIR);
71 removeDirFiles(CynaraTestConsts::SERVICE_PLUGINS_DIR);
72 copyCynaraFiles(m_pluginsSaveDir, CynaraTestConsts::SERVICE_PLUGINS_DIR);
74 removeDirFiles(m_dbSaveDir);
75 removeDirIfExists(m_dbSaveDir);
76 removeDirFiles(m_pluginsSaveDir);
77 removeDirIfExists(m_pluginsSaveDir);
78 removeDirIfExists(m_saveDir);
81 void CynaraTestEnv::unmaskedLoadDefaultDatabase()
84 removeDirFiles(CynaraTestConsts::DB_DIR);
85 copyCynaraFiles(m_defaultDir, CynaraTestConsts::DB_DIR);
89 void CynaraTestEnv::loadDefaultDatabase()
92 unmaskedLoadDefaultDatabase();