Skip to content

Commit d5c8f60

Browse files
InterLinked1Friendly Automation
authored and
Friendly Automation
committed
test_json: Remove duplicated static function.
Removes the function mkstemp_file and uses ast_file_mkftemp from file.h instead. ASTERISK-30295 #close Change-Id: I7412ec06f88c39ee353bcdb8c976c2fcac546609
1 parent 90784b8 commit d5c8f60

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

Diff for: tests/test_json.c

+4-24
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "asterisk/json.h"
4242
#include "asterisk/module.h"
4343
#include "asterisk/test.h"
44+
#include "asterisk/file.h"
4445

4546
#include <stdio.h>
4647
#include <unistd.h>
@@ -1269,27 +1270,6 @@ static int safe_fclose(FILE *f)
12691270
return 0;
12701271
}
12711272

1272-
static FILE *mkstemp_file(char *template, const char *mode)
1273-
{
1274-
int fd = mkstemp(template);
1275-
FILE *file;
1276-
1277-
if (fd < 0) {
1278-
ast_log(LOG_ERROR, "Failed to create temp file: %s\n",
1279-
strerror(errno));
1280-
return NULL;
1281-
}
1282-
1283-
file = fdopen(fd, mode);
1284-
if (!file) {
1285-
ast_log(LOG_ERROR, "Failed to create temp file: %s\n",
1286-
strerror(errno));
1287-
return NULL;
1288-
}
1289-
1290-
return file;
1291-
}
1292-
12931273
AST_TEST_DEFINE(json_test_dump_load_file)
12941274
{
12951275
RAII_VAR(struct ast_json *, uut, NULL, ast_json_unref);
@@ -1312,7 +1292,7 @@ AST_TEST_DEFINE(json_test_dump_load_file)
13121292

13131293
/* dump/load file */
13141294
expected = ast_json_pack("{ s: i }", "one", 1);
1315-
file = mkstemp_file(filename, "w");
1295+
file = ast_file_mkftemp(filename, 0644);
13161296
ast_test_validate(test, NULL != file);
13171297
uut_res = ast_json_dump_file(expected, file);
13181298
ast_test_validate(test, 0 == uut_res);
@@ -1347,7 +1327,7 @@ AST_TEST_DEFINE(json_test_dump_load_new_file)
13471327

13481328
/* dump/load filename */
13491329
expected = ast_json_pack("{ s: i }", "one", 1);
1350-
file = mkstemp_file(filename, "w");
1330+
file = ast_file_mkftemp(filename, 0644);
13511331
ast_test_validate(test, NULL != file);
13521332
uut_res = ast_json_dump_new_file(expected, filename);
13531333
ast_test_validate(test, 0 == uut_res);
@@ -1378,7 +1358,7 @@ AST_TEST_DEFINE(json_test_dump_load_null)
13781358
/* dump/load NULL tests */
13791359
uut = ast_json_load_string("{ \"one\": 1 }", NULL);
13801360
ast_test_validate(test, NULL != uut);
1381-
file = mkstemp_file(filename, "w");
1361+
file = ast_file_mkftemp(filename, 0644);
13821362
ast_test_validate(test, NULL != file);
13831363
ast_test_validate(test, NULL == ast_json_dump_string(NULL));
13841364
ast_test_validate(test, -1 == ast_json_dump_file(NULL, file));

0 commit comments

Comments
 (0)