2 * Copyright (c) 2016-2017 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.
18 #include <sys/types.h>
20 #include <dpl/test/test_runner.h>
22 #include <temp_test_user.h>
23 #include <tzplatform.h>
25 namespace TzPlatformConfig {
27 DEFINE_SMARTPTR(tzplatform_context_destroy, tzplatform_context, TzPlatformContextPtr);
29 std::string getEnv(enum tzplatform_variable id)
31 auto env = tzplatform_getenv(id);
32 RUNNER_ASSERT_MSG(env != nullptr, "Tzplatform-config returned null for " << id);
36 uid_t getGlobalUserId(void)
38 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
41 uid_t getGlobalGroupId(void)
43 gid_t global_uid = getGlobalUserId();
45 passwd* pw = getpwuid(global_uid);
46 RUNNER_ASSERT_ERRNO_MSG(pw, "getpwuid() failed.");
50 const std::string appDirPath(const TemporaryTestUser &user, const std::string &appId,
51 const std::string &pkgId)
53 return appDirPath(user.getUid()) + pkgId + "/" + appId;
56 const std::string appDirPath(uid_t uid)
58 struct tzplatform_context *tzCtxPtr = nullptr;
60 RUNNER_ASSERT(0 == tzplatform_context_create(&tzCtxPtr));
61 TzPlatformContextPtr tzCtxPtrSmart(tzCtxPtr);
63 RUNNER_ASSERT_MSG(0 == tzplatform_context_set_user(tzCtxPtr, uid),
64 "Unable to set user with uid <" << uid << "> for tzplatform context");
66 const char *appDir = tzplatform_context_getenv(tzCtxPtr,
67 getGlobalUserId() == uid ? TZ_SYS_RW_APP : TZ_USER_APP);
68 RUNNER_ASSERT_MSG(nullptr != appDir,
69 "tzplatform_context_getenv failed"
70 << "for getting sys rw app of user with uid<" << uid << ">");
72 return std::string(appDir) + "/";
75 const std::string globalAppDir()
77 struct tzplatform_context *tzCtxPtr = nullptr;
79 RUNNER_ASSERT_MSG(0 == tzplatform_context_create(&tzCtxPtr), "Couldn't create tzplatform context");
80 TzPlatformContextPtr tzCtxPtrSmart(tzCtxPtr);
82 const char *appDir = tzplatform_context_getenv(tzCtxPtr, TZ_SYS_RW_APP);
83 RUNNER_ASSERT_MSG(nullptr != appDir,
84 "tzplatform_context_getenv failed for getting sys rw app");
88 const std::string extendedSdDir()
90 struct tzplatform_context *tzCtxPtr = nullptr;
92 RUNNER_ASSERT_MSG(0 == tzplatform_context_create(&tzCtxPtr), "Couldn't create tzplatform context");
93 TzPlatformContextPtr tzCtxPtrSmart(tzCtxPtr);
95 const char *appDir = tzplatform_context_getenv(tzCtxPtr, TZ_SYS_EXTENDEDSD_APP);
96 RUNNER_ASSERT_MSG(nullptr != appDir,
97 "tzplatform_context_getenv failed for getting sys extended sd");
101 const std::string extendedSdUserDir(uid_t uid)
103 struct tzplatform_context *tzCtxPtr = nullptr;
105 RUNNER_ASSERT_MSG(0 == tzplatform_context_create(&tzCtxPtr), "Couldn't create tzplatform context");
106 TzPlatformContextPtr tzCtxPtrSmart(tzCtxPtr);
108 RUNNER_ASSERT_MSG(0 == tzplatform_context_set_user(tzCtxPtr, uid),
109 "Unable to set user with uid <" << uid << "> for tzplatform context");
111 const char *appDir = tzplatform_context_getenv(tzCtxPtr, TZ_USER_EXTENDEDSD_APP);
112 RUNNER_ASSERT_MSG(nullptr != appDir,
113 "tzplatform_context_getenv failed for getting user extended sd");
117 const std::string getPath(enum tzplatform_variable id) {
118 struct tzplatform_context *tzCtxPtr = nullptr;
120 RUNNER_ASSERT_MSG(0 == tzplatform_context_create(&tzCtxPtr), "Couldn't create tzplatform context");
121 TzPlatformContextPtr tzCtxPtrSmart(tzCtxPtr);
123 const char *path = tzplatform_context_getenv(tzCtxPtr, id);
124 RUNNER_ASSERT_MSG(nullptr != path,
125 "tzplatform_context_getenv failed for getting " << static_cast<int>(id));