Fix security_manager_02_app_install_uninstall_full test
[platform/core/test/security-tests.git] / tests / 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(const char *dirName)
27     : m_dbPresent(false)
28 {
29     m_saveDir = TMP_DIR + "/" + dirName;
30     m_dbSaveDir = m_saveDir + "/db";
31     m_pluginsSaveDir = m_saveDir + "/plugins";
32 }
33
34 CynaraTestEnv::~CynaraTestEnv()
35 {
36 }
37
38 void CynaraTestEnv::save()
39 {
40     CynaraMask mask;
41
42     removeDirFiles(m_dbSaveDir);
43     removeDirIfExists(m_dbSaveDir);
44     removeDirFiles(m_pluginsSaveDir);
45     removeDirIfExists(m_pluginsSaveDir);
46     removeDirIfExists(m_saveDir);
47
48     makeDir(m_saveDir);
49     m_dbPresent = dirExists(CynaraTestConsts::DB_DIR);
50     if (m_dbPresent) {
51         makeDir(m_dbSaveDir);
52         copyCynaraFiles(CynaraTestConsts::DB_DIR, m_dbSaveDir);
53     }
54     makeDir(m_pluginsSaveDir);
55     copyCynaraFiles(CynaraTestConsts::SERVICE_PLUGINS_DIR, m_pluginsSaveDir);
56 }
57
58 void CynaraTestEnv::restore()
59 {
60     CynaraMask mask;
61
62     removeDirFiles(CynaraTestConsts::DB_DIR);
63     if (m_dbPresent)
64         copyCynaraFiles(m_dbSaveDir, CynaraTestConsts::DB_DIR);
65     else
66         removeDirIfExists(CynaraTestConsts::DB_DIR);
67
68     removeDirFiles(CynaraTestConsts::SERVICE_PLUGINS_DIR);
69     copyCynaraFiles(m_pluginsSaveDir, CynaraTestConsts::SERVICE_PLUGINS_DIR);
70
71     removeDirFiles(m_dbSaveDir);
72     removeDirIfExists(m_dbSaveDir);
73     removeDirFiles(m_pluginsSaveDir);
74     removeDirIfExists(m_pluginsSaveDir);
75     removeDirIfExists(m_saveDir);
76 }