Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'

This commit is contained in:
2024-01-17 17:02:59 +01:00
1244 changed files with 50102 additions and 28146 deletions

View File

@ -8,7 +8,7 @@
/* Test case functions */
/**
* \brief Call to SDL_strnlen
* Call to SDL_strnlen
*/
#undef SDL_strnlen
static int stdlib_strnlen(void *arg)
@ -36,7 +36,7 @@ static int stdlib_strnlen(void *arg)
}
/**
* \brief Call to SDL_strlcpy
* Call to SDL_strlcpy
*/
#undef SDL_strlcpy
static int stdlib_strlcpy(void *arg)
@ -60,6 +60,68 @@ static int stdlib_strlcpy(void *arg)
return TEST_COMPLETED;
}
/**
* Call to SDL_strstr
*/
static int stdlib_strstr(void *arg)
{
char *result;
const char *text = "abcdef";
const char *expected;
result = SDL_strstr(text, "");
expected = text;
SDLTest_AssertPass("Call to SDL_strstr(text, \"\")");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strstr(text, "abc");
expected = text;
SDLTest_AssertPass("Call to SDL_strstr(text, \"abc\")");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strstr(text, "bcd");
expected = text+1;
SDLTest_AssertPass("Call to SDL_strstr(text, \"bcd\")");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strstr(text, "xyz");
expected = NULL;
SDLTest_AssertPass("Call to SDL_strstr(text, \"xyz\")");
SDLTest_AssertCheck(result == expected, "Check result, expected: (null), got: %s", result);
result = SDL_strnstr(text, "", SDL_strlen(text));
expected = text;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"\", SDL_strlen(text))");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strnstr(text, "abc", SDL_strlen(text));
expected = text;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"abc\", SDL_strlen(text))");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strnstr(text, "bcd", SDL_strlen(text));
expected = text+1;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"bcd\", SDL_strlen(text))");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strnstr(text, "bcd", 3);
expected = NULL;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"bcd\", 3)");
SDLTest_AssertCheck(result == expected, "Check result, expected: (null), got: %s", result);
result = SDL_strnstr(text, "xyz", 3);
expected = NULL;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"xyz\", 3)");
SDLTest_AssertCheck(result == expected, "Check result, expected: (null), got: %s", result);
result = SDL_strnstr(text, "xyz", SDL_strlen(text)*100000);
expected = NULL;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"xyz\", SDL_strlen(text)*100000)");
SDLTest_AssertCheck(result == expected, "Check result, expected: (null), got: %s", result);
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
#pragma GCC diagnostic push
#ifdef HAVE_WFORMAT
@ -71,7 +133,7 @@ static int stdlib_strlcpy(void *arg)
#endif
/**
* \brief Call to SDL_snprintf
* Call to SDL_snprintf
*/
#undef SDL_snprintf
static int stdlib_snprintf(void *arg)
@ -258,11 +320,18 @@ static int stdlib_snprintf(void *arg)
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(expected), "Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
if (sizeof(void *) >= 8) {
result = SDL_snprintf(text, sizeof(text), "%p", (void *)0x1ba07bddf60L);
expected = "0x1ba07bddf60";
SDLTest_AssertPass("Call to SDL_snprintf(text, sizeof(text), \"%%p\", 0x1ba07bddf60)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(expected), "Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
}
return TEST_COMPLETED;
}
/**
* \brief Call to SDL_swprintf
* Call to SDL_swprintf
*/
#undef SDL_swprintf
static int stdlib_swprintf(void *arg)
@ -429,7 +498,7 @@ static int stdlib_swprintf(void *arg)
#endif
/**
* \brief Call to SDL_getenv and SDL_setenv
* Call to SDL_getenv and SDL_setenv
*/
static int stdlib_getsetenv(void *arg)
{
@ -453,10 +522,10 @@ static int stdlib_getsetenv(void *arg)
text = SDL_getenv(name);
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
if (text != NULL) {
if (text) {
SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, (int)SDL_strlen(text));
}
} while (text != NULL);
} while (text);
/* Create random values to set */
value1 = SDLTest_RandomAsciiStringOfSize(10);
@ -572,7 +641,7 @@ static int stdlib_getsetenv(void *arg)
#endif
/**
* \brief Call to SDL_sscanf
* Call to SDL_sscanf
*/
#undef SDL_sscanf
static int stdlib_sscanf(void *arg)
@ -585,7 +654,7 @@ static int stdlib_sscanf(void *arg)
long long_output, expected_long_output;
long long long_long_output, expected_long_long_output;
size_t size_output, expected_size_output;
char text[128];
char text[128], text2[128];
expected_output = output = 123;
expected_result = -1;
@ -649,6 +718,82 @@ static int stdlib_sscanf(void *arg)
SDLTest_AssertCheck(expected_size_output == size_output, "Check output, expected: %zu, got: %zu", expected_size_output, size_output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc def", "%s", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc def\", \"%%s\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc,def", "%s", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%s\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc,def") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc,def", "%[cba]", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[cba]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc,def", "%[a-z]", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[z-a]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc,def", "%[^,]", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[^,]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 0;
text[0] = '\0';
result = SDL_sscanf("abc,def", "%[A-Z]", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[A-Z]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "") == 0, "Check output, expected: \"\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 2;
text[0] = '\0';
text2[0] = '\0';
result = SDL_sscanf("abc,def", "%[abc],%[def]", text, text2);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[abc],%%[def]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(SDL_strcmp(text2, "def") == 0, "Check output, expected: \"def\", got: \"%s\"", text2);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 2;
text[0] = '\0';
text2[0] = '\0';
result = SDL_sscanf("abc,def", "%[abc]%*[,]%[def]", text, text2);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[abc]%%*[,]%%[def]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(SDL_strcmp(text2, "def") == 0, "Check output, expected: \"def\", got: \"%s\"", text2);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 2;
text[0] = '\0';
text2[0] = '\0';
result = SDL_sscanf("abc def", "%[abc] %[def]", text, text2);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc def\", \"%%[abc] %%[def]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(SDL_strcmp(text2, "def") == 0, "Check output, expected: \"def\", got: \"%s\"", text2);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc123XYZ", "%[a-zA-Z0-9]", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc123XYZ\", \"%%[a-zA-Z0-9]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc123XYZ") == 0, "Check output, expected: \"abc123XYZ\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
return TEST_COMPLETED;
}
@ -665,7 +810,7 @@ static int stdlib_sscanf(void *arg)
#endif
/**
* \brief Call to SDL_aligned_alloc
* Call to SDL_aligned_alloc
*/
static int stdlib_aligned_alloc(void *arg)
{
@ -854,22 +999,26 @@ static const SDLTest_TestCaseReference stdlibTest2 = {
};
static const SDLTest_TestCaseReference stdlibTest3 = {
stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED
stdlib_strstr, "stdlib_strstr", "Call to SDL_strstr", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest4 = {
stdlib_swprintf, "stdlib_swprintf", "Call to SDL_swprintf", TEST_ENABLED
stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest5 = {
stdlib_getsetenv, "stdlib_getsetenv", "Call to SDL_getenv and SDL_setenv", TEST_ENABLED
stdlib_swprintf, "stdlib_swprintf", "Call to SDL_swprintf", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest6 = {
stdlib_sscanf, "stdlib_sscanf", "Call to SDL_sscanf", TEST_ENABLED
stdlib_getsetenv, "stdlib_getsetenv", "Call to SDL_getenv and SDL_setenv", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest7 = {
stdlib_sscanf, "stdlib_sscanf", "Call to SDL_sscanf", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest8 = {
stdlib_aligned_alloc, "stdlib_aligned_alloc", "Call to SDL_aligned_alloc", TEST_ENABLED
};
@ -886,6 +1035,7 @@ static const SDLTest_TestCaseReference *stdlibTests[] = {
&stdlibTest5,
&stdlibTest6,
&stdlibTest7,
&stdlibTest8,
&stdlibTestOverflow,
NULL
};