Move string consts to corresponding test commons 10/31110/3
authorPawel Wieczorek <p.wieczorek2@samsung.com>
Mon, 17 Nov 2014 13:07:20 +0000 (14:07 +0100)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Wed, 3 Dec 2014 15:05:26 +0000 (16:05 +0100)
New member has been added:
* SERVICE (in CynaraTestConsts, for D-Bus)

Change-Id: I6963cbbf9b57380447b764ae0f3b09ec2795ff9f

tests/common/memory.h
tests/common/tests_common.h
tests/cynara-tests/common/cynara_test_commons.cpp
tests/cynara-tests/common/cynara_test_commons.h
tests/cynara-tests/common/cynara_test_env.cpp

index edd3dc9..22083cb 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <memory>
 #include <sys/smack.h>
+#include <dirent.h>
 
 #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
 
index 34427da..c03d37a 100644 (file)
@@ -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);
index 74c821e..f500c26 100644 (file)
 
 #include <exception>
 
+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<void(void)> &func)
 {
     CynaraTestEnv env(testName);
index 2d97103..6622ffb 100644 (file)
 #define CYNARA_TEST_COMMONS_H_
 
 #include <functional>
+#include <string>
+
+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<void(void)> &func);
 
index ce606c8..2dc69c4 100644 (file)
@@ -14,6 +14,7 @@
  *    limitations under the License.
  */
 
+#include <cynara_test_commons.h>
 #include <cynara_test_env.h>
 #include <tests_common.h>
 #include <dbus_access.h>
@@ -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();