Files
Bjorn Andersson ed114a5e3d tests: Introduce test cases for contents XML handling
Introduce two initial set of test cases for the newly introduced
contents.xml handling.

One is used to validate the storage and flavor selector logic, and the
other more broadly the loading of contents.xml files.

Extract the common operation of creating a temporary directory to a new
file that is shared across tests.

Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
2026-05-14 16:39:30 -05:00

32 lines
667 B
C

// SPDX-License-Identifier: BSD-3-Clause
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "common.h"
int test_make_temp_dir(char *buf, size_t size, const char *prefix)
{
int ret;
#ifdef _WIN32
const char *tmp_base = getenv("TMPDIR");
if (!tmp_base || tmp_base[0] == '\0')
tmp_base = getenv("TEMP");
if (!tmp_base || tmp_base[0] == '\0')
tmp_base = getenv("TMP");
if (!tmp_base || tmp_base[0] == '\0')
tmp_base = ".";
ret = snprintf(buf, size, "%s/%s-XXXXXX", tmp_base, prefix);
#else
ret = snprintf(buf, size, "/tmp/%s-XXXXXX", prefix);
#endif
if (ret <= 0 || (size_t)ret >= size)
return -1;
return mkdtemp(buf) ? 0 : -1;
}