1
0
mirror of https://github.com/deadw00d/AROS.git synced 2025-10-26 21:18:42 +00:00

Migrate sscanf tests to cunit. Add test for different sizes of "%u"

This commit is contained in:
deadwood
2022-05-13 07:26:49 +02:00
parent 7fddc07d7c
commit 5f5ee98da6
3 changed files with 149 additions and 0 deletions

View File

@ -0,0 +1,147 @@
/*
Copyright <20> 2022, The AROS Development Team. All rights reserved.
$Id$
*/
#include <stdlib.h>
#include <CUnit/CUnitCI.h>
CU_SUITE_SETUP()
{
return CUE_SUCCESS;
}
CU_SUITE_TEARDOWN()
{
return CUE_SUCCESS;
}
CU_TEST_SETUP()
{
}
CU_TEST_TEARDOWN()
{
}
#define TESTSTRING1 "1.3 1 string"
#define TESTSTRING2 "NO_NUMBERS_TEXT"
#define TESTSTRING3 "FSOMETHING"
#define TESTSTRING4 "0xAF" /* Hex integer */
#define TESTSTRING5 "xAF" /* "Hex integer" without 0 */
#define TESTSTRING6 "AF" /* "Hex integer" without 0x */
static void test_integer()
{
int i, cnt;
i = 123456;
cnt = sscanf(TESTSTRING2, "%i", &i);
CU_ASSERT_EQUAL(0, cnt);
CU_ASSERT_EQUAL(123456, i);
i = 123456;
cnt = sscanf(TESTSTRING3, "%i", &i);
CU_ASSERT_EQUAL(0, cnt);
CU_ASSERT_EQUAL(123456, i);
i = 123456;
cnt = sscanf(TESTSTRING4, "%i", &i);
CU_ASSERT_EQUAL(1, cnt);
CU_ASSERT_EQUAL(0xaf, i);
i = 123456;
cnt = sscanf(TESTSTRING5, "%i", &i);
CU_ASSERT_EQUAL(0, cnt);
CU_ASSERT_EQUAL(123456, i);
i = 123456;
cnt = sscanf(TESTSTRING6, "%i", &i);
CU_ASSERT_EQUAL(0, cnt);
CU_ASSERT_EQUAL(123456, i);
}
static void test_multi()
{
char s[10];
int i, cnt;
float f;
cnt = sscanf(TESTSTRING1, "%f %d %s", &f, &i, s);
CU_ASSERT_EQUAL(3, cnt);
CU_ASSERT_DOUBLE_EQUAL(1.3f, f, 0.01f);
CU_ASSERT_EQUAL(1, i)
CU_ASSERT_STRING_EQUAL("string", s);
}
static void test_float()
{
int cnt;
float f;
cnt = sscanf("0.1", "%f", &f);
CU_ASSERT_EQUAL(1, cnt);
CU_ASSERT_DOUBLE_EQUAL(0.1f, f, 0.01f);
cnt = sscanf(".1", "%f", &f);
CU_ASSERT_EQUAL(1, cnt);
CU_ASSERT_DOUBLE_EQUAL(0.1f, f, 0.01f);
cnt = sscanf("1", "%f", &f);
CU_ASSERT_EQUAL(1, cnt);
CU_ASSERT_DOUBLE_EQUAL(1.0f, f, 0.01f);
cnt = sscanf("-.1", "%f", &f);
CU_ASSERT_EQUAL(1, cnt);
CU_ASSERT_DOUBLE_EQUAL(-0.1f, f, 0.01f);
cnt = sscanf("x", "%f", &f);
CU_ASSERT_EQUAL(0, cnt);
}
static void test_unsigned()
{
unsigned char hh;
unsigned short h;
unsigned long l;
unsigned long long ll;
unsigned int u;
int cnt;
cnt = sscanf("10", "%hhu", &hh);
CU_ASSERT_EQUAL(1, cnt);
CU_ASSERT_EQUAL(10, hh);
cnt = sscanf("1010", "%hu", &h);
CU_ASSERT_EQUAL(1, cnt);
CU_ASSERT_EQUAL(1010, h);
#if (__WORDSIZE == 64)
cnt = sscanf("100000000010", "%lu", &l);
CU_ASSERT_EQUAL(1, cnt);
CU_ASSERT_EQUAL(100000000010, l);
#else
cnt = sscanf("10000010", "%lu", &l);
CU_ASSERT_EQUAL(1, cnt);
CU_ASSERT_EQUAL(10000010, l);
#endif
cnt = sscanf("100000000010", "%llu", &ll);
CU_ASSERT_EQUAL(1, cnt);
CU_ASSERT_EQUAL(100000000010, ll);
cnt = sscanf("10000010", "%u", &u);
CU_ASSERT_EQUAL(1, cnt);
CU_ASSERT_EQUAL(10000010, u);
}
int main(int argc, char** argv)
{
CU_CI_DEFINE_SUITE("sscanf_Suite", __cu_suite_setup, __cu_suite_teardown, __cu_test_setup, __cu_test_teardown);
CUNIT_CI_TEST(test_integer);
CUNIT_CI_TEST(test_multi);
CUNIT_CI_TEST(test_float);
CUNIT_CI_TEST(test_unsigned);
return CU_CI_RUN_SUITES();
}

View File

@ -41,6 +41,7 @@ STDCPRINTTESTFILES := \
CUNITSTDCTESTFILES := \
cunit-crt-types \
cunit-crt-fileseek \
cunit-crt-sscanf \
cunit-crt-sxprintf
#MM- test-crt : test-crt-stdc test-crt-stdc-$(AROS_TARGET_CPU)

View File

@ -37,6 +37,7 @@ If NOT WARN
; Perform basic C library unit tests...
Execute S/Test cunit/crt/stdc/math/cunit-crt-math
Execute S/Test cunit/crt/stdc/cunit-crt-fileseek
Execute S/Test cunit/crt/stdc/cunit-crt-sscanf
Execute S/Test cunit/crt/stdc/cunit-crt-sxprintf
Execute S/Test cunit/crt/posix/cunit-crt-fread
Copy SYS:Development/Debug/Tests/crt/posix/execl2_slave SYS: