Add xmlSaveFormatFile() check routine
[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 static int sstm_xmlSaveFormatFile_enable = true;
28
29 API void sstm_xmlParseFile_setup(bool enable)
30 {
31         sstm_xmlParseFile_enable = enable;
32 }
33
34 API void sstm_xmlSaveFormatFile_setup(bool enable)
35 {
36         sstm_xmlSaveFormatFile_enable = enable;
37 }
38
39 API xmlDocPtr xmlParseFile(const char *filename)
40 {
41         if (false == sstm_xmlParseFile_enable)
42                 return NULL;
43
44         xmlDocPtr (*org_fn)(const char *path);
45         if (0 == strcmp(filename, SETTING_FONT_CONF_FILE)) {
46                 INFO("try xmlParseFile(%s)", TEST_FONT_CONF_FILE);
47                 org_fn = dlsym(RTLD_NEXT, "xmlParseFile");
48                 return org_fn(TEST_FONT_CONF_FILE);
49         }
50
51         org_fn = dlsym(RTLD_NEXT, "xmlParseFile");
52         return org_fn(filename);
53 }
54
55 API int xmlSaveFormatFile(const char * filename,
56                                          xmlDocPtr cur,
57                                          int format)
58 {
59         if (false == sstm_xmlParseFile_enable)
60                 return -1;
61
62         int (*org_fn)(const char * filename,
63                                          xmlDocPtr cur,
64                                          int format);
65         if (0 == strcmp(filename, SETTING_FONT_CONF_FILE)) {
66                 return 20;
67         }
68         org_fn = dlsym(RTLD_NEXT, "xmlSaveFormatFile");
69         return org_fn(filename, cur, format);
70 }