2 * Copyright (c) 2016 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-resource.cpp
18 * @author Kyungwook Tak (k.tak@samsung.com)
20 * @brief Test resoure name and paths
22 #include "test-resource.h"
26 #include <sys/types.h>
29 #include "test-common.h"
33 std::string s_testDirMedia;
34 std::string s_testDirApps;
36 std::string s_testFileMedia;
37 std::string s_testFileInDirMalwares;
39 std::string s_wgtAppRoot;
40 std::string s_wgtMalFile;
41 std::string s_tpkAppRoot;
42 std::string s_tpkMalFile;
43 std::string s_fakeAppRoot;
44 std::string s_fakeAppFile;
46 #ifdef PLATFORM_VERSION_3
47 std::string getUsername(void)
50 struct passwd *result = nullptr;
52 auto bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
53 bufsize = (bufsize == -1) ? 16384 : bufsize;
55 std::vector<char> buf(bufsize, 0);
57 ::getpwuid_r(::getuid(), &pwd, buf.data(), buf.size(), &result);
58 if (result == nullptr)
59 throw std::logic_error("Failed to getpwuid_r with errno: " + errno);
61 return std::string(pwd.pw_name);
65 } // namespace anonymous
67 const char *TEST_DIR_MEDIA(void)
69 if (s_testDirMedia.empty())
70 #ifdef PLATFORM_VERSION_3
71 s_testDirMedia = "/home/" + ::getUsername() + "/content";
73 s_testDirMedia = "/opt/usr/media";
76 return s_testDirMedia.c_str();
79 const char *TEST_DIR_APPS(void)
81 if (s_testDirApps.empty())
82 #ifdef PLATFORM_VERSION_3
83 s_testDirApps = "/home/" + ::getUsername() + "/apps_rw";
85 s_testDirApps = "/opt/usr/apps";
88 return s_testDirApps.c_str();
91 const char *TEST_FILE_MEDIA(void)
93 if (s_testFileMedia.empty())
94 s_testFileMedia = std::string(TEST_DIR_MEDIA()) + "/test_malware_file";
96 return s_testFileMedia.c_str();
99 const char *TEST_WGT_APP_ROOT(void)
101 if (s_wgtAppRoot.empty())
102 s_wgtAppRoot = std::string(TEST_DIR_APPS()) + "/" TEST_WGT_PKG_ID;
104 return s_wgtAppRoot.c_str();
107 const char *TEST_WGT_MAL_FILE(void)
109 if (s_wgtMalFile.empty())
110 s_wgtMalFile = std::string(TEST_WGT_APP_ROOT()) + "/res/wgt/data/eicar.txt";
112 return s_wgtMalFile.c_str();
115 const char *TEST_TPK_APP_ROOT(void)
117 if (s_tpkAppRoot.empty())
118 s_tpkAppRoot = std::string(TEST_DIR_APPS()) + "/" TEST_TPK_PKG_ID;
120 return s_tpkAppRoot.c_str();
123 const char *TEST_TPK_MAL_FILE(void)
125 if (s_tpkMalFile.empty())
126 s_tpkMalFile = std::string(TEST_TPK_APP_ROOT()) + "/shared/res/eicar.txt";
128 return s_tpkMalFile.c_str();
131 const char *TEST_FAKE_APP_ROOT(void)
133 if (s_fakeAppRoot.empty())
134 s_fakeAppRoot = std::string(TEST_DIR_APPS()) + "/fake_app";
136 return s_fakeAppRoot.c_str();
139 const char *TEST_FAKE_APP_FILE(void)
141 if (s_fakeAppFile.empty())
142 s_fakeAppFile = std::string(TEST_FAKE_APP_ROOT()) + "/malicious.txt";
144 return s_fakeAppFile.c_str();