2 * Copyright (c) 2020 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.
21 #include <sys/types.h>
23 #include "sstt_mock.h"
25 static bool sstm_access_enable = true;
26 static bool sstm_readlink_enable = true;
27 static bool sstm_opendir_enable = true;
28 static bool sstm_dlopen_enable = true;
30 API void sstm_access_setup(bool enable)
32 sstm_access_enable = enable;
35 API void sstm_readlink_setup(bool enable)
37 sstm_readlink_enable = enable;
40 API void sstm_opendir_setup(bool enable)
42 sstm_opendir_enable = enable;
45 API void sstm_dlopen_setup(bool enable)
47 sstm_dlopen_enable = enable;
50 API int access(const char *pathname, int mode)
52 if (false == sstm_access_enable)
55 if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/ringtone_sdk.mp3"))
57 if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/Over the horizon.mp3"))
59 if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/big_buck_bunny.mp3"))
61 if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/daliTestVideo.mp3"))
63 if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/sound_5.mp3"))
65 if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/tct-content-tizen-tests_video.mp3"))
67 if (0 == strcmp(pathname, "/opt/usr/data/settings/Alerts/General notification_sdk.wav"))
69 if (0 == strcmp(pathname, "/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3"))
71 if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/bg_test.png"))
73 if (0 == strcmp(pathname, SYS_SETTINGS_TEST_DIR"/bg_test.mp4"))
76 int (*org_fn)(const char *, int);
77 org_fn = dlsym(RTLD_NEXT, "access");
78 return org_fn(pathname, mode);
81 API ssize_t readlink(const char *restrict path, char *restrict buf, size_t len)
83 const char *local = "/usr/share/zoneinfo/Asia/Seoul";
85 if (false == sstm_readlink_enable)
88 if (0 == strcmp(path, "/opt/etc/localtime")) {
89 strncpy(buf, local, len);
90 return (sizeof(local) - 1);
93 ssize_t(*org_fn)(const char *restrict, char *restrict, size_t);
94 org_fn = dlsym(RTLD_NEXT, "readlink");
95 return org_fn(path, buf, len);
98 API DIR *opendir(const char *name)
100 DIR *(*org_fn)(const char *);
101 if (false == sstm_opendir_enable)
104 org_fn = dlsym(RTLD_NEXT, "opendir");
106 if (0 == strcmp(name, SST_RES_DIR"/Ringtones")) {
107 org_fn = dlsym(RTLD_NEXT, "opendir");
108 return org_fn("tests/res");
114 API void* dlopen(const char *filename, int flag)
116 if (false == sstm_dlopen_enable)
119 void *(*org_fn)(const char *filename, int flag);
120 org_fn = dlsym(RTLD_NEXT, "dlopen");
121 return org_fn(filename, flag);