From: Pawel Wieczorek Date: Mon, 17 Nov 2014 13:07:20 +0000 (+0100) Subject: Move string consts to corresponding test commons X-Git-Tag: security-manager_5.5_testing~180 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d58c08be9d5381008f3f531f00ab4fb7f865f5c1;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git Move string consts to corresponding test commons New member has been added: * SERVICE (in CynaraTestConsts, for D-Bus) Change-Id: I6963cbbf9b57380447b764ae0f3b09ec2795ff9f --- diff --git a/tests/common/memory.h b/tests/common/memory.h index edd3dc97..22083cbc 100644 --- a/tests/common/memory.h +++ b/tests/common/memory.h @@ -3,6 +3,7 @@ #include #include +#include #define DEFINE_SMARTPTR(func, type, name) \ struct deleter_##func { \ @@ -22,6 +23,7 @@ void closePtr(int *fd); DEFINE_SMARTPTR(free, char, CStringPtr); DEFINE_SMARTPTR(closePtr, int, FdUniquePtr); DEFINE_SMARTPTR(smack_accesses_free, smack_accesses, SmackAccessesPtr); +DEFINE_SMARTPTR(closedir, DIR, DirPtr); // Custom typedefs diff --git a/tests/common/tests_common.h b/tests/common/tests_common.h index 34427daa..c03d37a0 100644 --- a/tests/common/tests_common.h +++ b/tests/common/tests_common.h @@ -38,6 +38,7 @@ const uid_t APP_UID = 5000; const gid_t APP_GID = 5000; const uid_t DB_ALARM_UID = 6001; const gid_t DB_ALARM_GID = 6001; +const std::string TMP_DIR("/tmp"); int smack_runtime_check(void); int smack_check(void); diff --git a/tests/cynara-tests/common/cynara_test_commons.cpp b/tests/cynara-tests/common/cynara_test_commons.cpp index 74c821e5..f500c262 100644 --- a/tests/cynara-tests/common/cynara_test_commons.cpp +++ b/tests/cynara-tests/common/cynara_test_commons.cpp @@ -22,6 +22,16 @@ #include +namespace CynaraTestConsts +{ + +const std::string DB_DIR(CYNARA_DB_DIR); +const std::string USER("cynara"); +const std::string LABEL("System"); +const std::string SERVICE("cynara.service"); + +} + void environmentWrap(const char *testName, const std::function &func) { CynaraTestEnv env(testName); diff --git a/tests/cynara-tests/common/cynara_test_commons.h b/tests/cynara-tests/common/cynara_test_commons.h index 2d971039..6622ffb6 100644 --- a/tests/cynara-tests/common/cynara_test_commons.h +++ b/tests/cynara-tests/common/cynara_test_commons.h @@ -25,6 +25,17 @@ #define CYNARA_TEST_COMMONS_H_ #include +#include + +namespace CynaraTestConsts +{ + +extern const std::string DB_DIR; +extern const std::string USER; +extern const std::string LABEL; +extern const std::string SERVICE; + +} void environmentWrap(const char *testName, const std::function &func); diff --git a/tests/cynara-tests/common/cynara_test_env.cpp b/tests/cynara-tests/common/cynara_test_env.cpp index ce606c88..2dc69c47 100644 --- a/tests/cynara-tests/common/cynara_test_env.cpp +++ b/tests/cynara-tests/common/cynara_test_env.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include @@ -34,13 +35,6 @@ namespace typedef CStringPtr PwBufPtr; -DEFINE_SMARTPTR(closedir, DIR, DirPtr); - -const std::string cynaraDbDir = CYNARA_DB_DIR; -const std::string tmpDir = "/tmp/"; -const std::string cynaraUser = "cynara"; -const std::string cynaraLabel = "System"; - int removeContents(const char *fpath, const struct stat * /*sb*/, int tflag, struct FTW * /*ftwbuf*/) { @@ -69,15 +63,15 @@ void copyFile(const std::string &src, const std::string &dst) PwBufPtr pwBufPtr(buf); struct passwd pwbuf, *pwbufp = nullptr; - int ret = TEMP_FAILURE_RETRY(getpwnam_r(cynaraUser.c_str(), + int ret = TEMP_FAILURE_RETRY(getpwnam_r(CynaraTestConsts::USER.c_str(), &pwbuf, buf, buflen, &pwbufp)); - RUNNER_ASSERT_ERRNO_MSG(ret == 0, "getpwnam_r failed on " << cynaraUser << " user"); - RUNNER_ASSERT_MSG(pwbufp, "User " << cynaraUser << " does not exist"); + RUNNER_ASSERT_ERRNO_MSG(ret == 0, "getpwnam_r failed on " << CynaraTestConsts::USER << " user"); + RUNNER_ASSERT_MSG(pwbufp, "User " << CynaraTestConsts::USER << " does not exist"); ret = fchown(outFd, pwbufp->pw_uid, pwbufp->pw_gid); RUNNER_ASSERT_ERRNO_MSG(ret != -1, "fchown failed"); - ret = smack_fsetlabel(outFd, cynaraLabel.c_str(), SMACK_LABEL_ACCESS); + ret = smack_fsetlabel(outFd, CynaraTestConsts::LABEL.c_str(), SMACK_LABEL_ACCESS); RUNNER_ASSERT_MSG(ret == 0, "Setting smack label failed"); struct stat statSrc; @@ -123,14 +117,14 @@ void removeDirIfExists(const std::string &dir) bool cynaraDbExists() { struct stat st; - int ret = stat(cynaraDbDir.c_str(), &st); + int ret = stat(CynaraTestConsts::DB_DIR.c_str(), &st); if (ret == -1 && errno == ENOENT) { return false; } else if (ret == -1) { - RUNNER_ASSERT_ERRNO_MSG(false, "Cannot stat " << cynaraDbDir + RUNNER_ASSERT_ERRNO_MSG(false, "Cannot stat " << CynaraTestConsts::DB_DIR << " not due to its nonexistence"); } - RUNNER_ASSERT_MSG(st.st_mode & S_IFDIR, cynaraDbDir << " is not a directory"); + RUNNER_ASSERT_MSG(st.st_mode & S_IFDIR, CynaraTestConsts::DB_DIR << " is not a directory"); return true; } @@ -139,7 +133,7 @@ bool cynaraDbExists() CynaraTestEnv::CynaraTestEnv(const char *dirName) : m_dbPresent(false) { - m_dir = tmpDir + dirName; + m_dir = TMP_DIR + "/" + dirName; } CynaraTestEnv::~CynaraTestEnv() @@ -151,7 +145,7 @@ void CynaraTestEnv::save() clear(m_dir); removeDirIfExists(m_dir); - DBusAccess dbusAccess("cynara.service"); + DBusAccess dbusAccess(CynaraTestConsts::SERVICE.c_str()); dbusAccess.maskService(); dbusAccess.stopService(); @@ -159,7 +153,7 @@ void CynaraTestEnv::save() if (m_dbPresent) { RUNNER_ASSERT_ERRNO_MSG(!mkdir(m_dir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO), "Unable to make " << m_dir << " test directory"); - copyDir(cynaraDbDir, m_dir); + copyDir(CynaraTestConsts::DB_DIR, m_dir); } dbusAccess.unmaskService(); @@ -168,15 +162,15 @@ void CynaraTestEnv::save() void CynaraTestEnv::restore() { - DBusAccess dbusAccess("cynara.service"); + DBusAccess dbusAccess(CynaraTestConsts::SERVICE.c_str()); dbusAccess.maskService(); dbusAccess.stopService(); - clear(cynaraDbDir); + clear(CynaraTestConsts::DB_DIR); if (m_dbPresent) - copyDir(m_dir, cynaraDbDir); + copyDir(m_dir, CynaraTestConsts::DB_DIR); else - removeDirIfExists(cynaraDbDir); + removeDirIfExists(CynaraTestConsts::DB_DIR); dbusAccess.unmaskService(); dbusAccess.startService();