eb74c986ab52b83b91dd92175a841ddfcd7eca81
[platform/core/api/system-settings.git] / tests / mocks / xml.c
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #define _GNU_SOURCE
17 #include <stdio.h>
18 #include <string.h>
19 #include <dlfcn.h>
20 #include <libxml/tree.h>
21 #include "sst.h"
22 #include "sstt_mock.h"
23
24 #define TEST_FONT_CONF_FILE "./tests/res/99-tizen.conf"
25
26 static bool sstm_xmlParseFile_enable = true;
27
28 API void sstm_xmlParseFile_setup(bool enable)
29 {
30         sstm_xmlParseFile_enable = enable;
31 }
32
33 API xmlDocPtr xmlParseFile(const char *filename)
34 {
35         if (false == sstm_xmlParseFile_enable)
36                 return NULL;
37
38         xmlDocPtr (*org_fn)(const char *path);
39         if (0 == strcmp(filename, SETTING_FONT_CONF_FILE)) {
40                 INFO("try xmlParseFile(%s)", TEST_FONT_CONF_FILE);
41                 org_fn = dlsym(RTLD_NEXT, "xmlParseFile");
42                 return org_fn(TEST_FONT_CONF_FILE);
43         }
44
45         org_fn = dlsym(RTLD_NEXT, "xmlParseFile");
46         return org_fn(filename);
47 }