Skip to content

Commit 1265722

Browse files
committed
Updates
1 parent 553d363 commit 1265722

2 files changed

Lines changed: 79 additions & 60 deletions

File tree

file/config_file.c

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,63 +1143,3 @@ bool config_file_exists(const char *path)
11431143
config_file_free(config);
11441144
return true;
11451145
}
1146-
1147-
#if 0
1148-
static void test_config_file_parse_contains(
1149-
const char * cfgtext,
1150-
const char *key, const char *val)
1151-
{
1152-
config_file_t *cfg = config_file_new_from_string(cfgtext, NULL);
1153-
char *out = NULL;
1154-
bool ok = false;
1155-
1156-
if (!cfg)
1157-
abort();
1158-
1159-
ok = config_get_string(cfg, key, &out);
1160-
if (ok != (bool)val)
1161-
abort();
1162-
if (!val)
1163-
return;
1164-
1165-
if (!out)
1166-
out = strdup("");
1167-
if (strcmp(out, val) != 0)
1168-
abort();
1169-
free(out);
1170-
}
1171-
1172-
static void test_config_file(void)
1173-
{
1174-
test_config_file_parse_contains("foo = \"bar\"\n", "foo", "bar");
1175-
test_config_file_parse_contains("foo = \"bar\"", "foo", "bar");
1176-
test_config_file_parse_contains("foo = \"bar\"\r\n", "foo", "bar");
1177-
test_config_file_parse_contains("foo = \"bar\"", "foo", "bar");
1178-
1179-
#if 0
1180-
/* turns out it treats empty as nonexistent -
1181-
* should probably be fixed */
1182-
test_config_file_parse_contains("foo = \"\"\n", "foo", "");
1183-
test_config_file_parse_contains("foo = \"\"", "foo", "");
1184-
test_config_file_parse_contains("foo = \"\"\r\n", "foo", "");
1185-
test_config_file_parse_contains("foo = \"\"", "foo", "");
1186-
#endif
1187-
1188-
test_config_file_parse_contains("foo = \"\"\n", "bar", NULL);
1189-
test_config_file_parse_contains("foo = \"\"", "bar", NULL);
1190-
test_config_file_parse_contains("foo = \"\"\r\n", "bar", NULL);
1191-
test_config_file_parse_contains("foo = \"\"", "bar", NULL);
1192-
}
1193-
1194-
/* compile with:
1195-
gcc config_file.c -g -I ../include/ \
1196-
../streams/file_stream.c ../vfs/vfs_implementation.c ../lists/string_list.c \
1197-
../compat/compat_strl.c file_path.c ../compat/compat_strcasestr.c \
1198-
&& ./a.out
1199-
*/
1200-
1201-
int main(void)
1202-
{
1203-
test_config_file();
1204-
}
1205-
#endif
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Copyright (C) 2010-2020 The RetroArch team
2+
*
3+
* ---------------------------------------------------------------------------------------
4+
* The following license statement only applies to this file (config_file_test.c).
5+
* ---------------------------------------------------------------------------------------
6+
*
7+
* Permission is hereby granted, free of charge,
8+
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
9+
* to deal in the Software without restriction, including without limitation the rights to
10+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11+
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
23+
#include <stdlib.h>
24+
#include <string.h>
25+
#include <stdio.h>
26+
#include <ctype.h>
27+
#include <errno.h>
28+
29+
#include <file/config_file.h>
30+
31+
static void test_config_file_parse_contains(
32+
const char * cfgtext,
33+
const char *key, const char *val)
34+
{
35+
config_file_t *cfg = config_file_new_from_string(cfgtext, NULL);
36+
char *out = NULL;
37+
bool ok = false;
38+
39+
if (!cfg)
40+
abort();
41+
42+
ok = config_get_string(cfg, key, &out);
43+
if (ok != (bool)val)
44+
abort();
45+
if (!val)
46+
return;
47+
48+
if (!out)
49+
out = strdup("");
50+
if (strcmp(out, val) != 0)
51+
{
52+
printf("[FAILED] Key [%s] Doesn't contain val [%s]\n", key, val);
53+
abort();
54+
}
55+
printf("[SUCCESS] Key [%s] contains val [%s]\n", key, val);
56+
free(out);
57+
}
58+
59+
int main(void)
60+
{
61+
test_config_file_parse_contains("foo = \"bar\"\n", "foo", "bar");
62+
test_config_file_parse_contains("foo = \"bar\"", "foo", "bar");
63+
test_config_file_parse_contains("foo = \"bar\"\r\n", "foo", "bar");
64+
test_config_file_parse_contains("foo = \"bar\"", "foo", "bar");
65+
66+
#if 0
67+
/* turns out it treats empty as nonexistent -
68+
* should probably be fixed */
69+
test_config_file_parse_contains("foo = \"\"\n", "foo", "");
70+
test_config_file_parse_contains("foo = \"\"", "foo", "");
71+
test_config_file_parse_contains("foo = \"\"\r\n", "foo", "");
72+
test_config_file_parse_contains("foo = \"\"", "foo", "");
73+
#endif
74+
75+
test_config_file_parse_contains("foo = \"\"\n", "bar", NULL);
76+
test_config_file_parse_contains("foo = \"\"", "bar", NULL);
77+
test_config_file_parse_contains("foo = \"\"\r\n", "bar", NULL);
78+
test_config_file_parse_contains("foo = \"\"", "bar", NULL);
79+
}

0 commit comments

Comments
 (0)