#include "src/__support/macros/config.h"
#include "src/stdio/sprintf.h"
#include "src/__support/FPUtil/FPBits.h"
#include "test/UnitTest/RoundingModeUtils.h"
#include "test/UnitTest/Test.h"
#include <inttypes.h>
class LlvmLibcSPrintfTest : public LIBC_NAMESPACE::testing::Test { … };
ForceRoundingMode;
RoundingMode;
#define ASSERT_STREQ_LEN(actual_written, actual_str, expected_str) …
#define macro_test(FMT, X, expected) …
TEST(LlvmLibcSPrintfTest, Macros) { … }
TEST(LlvmLibcSPrintfTest, SimpleNoConv) { … }
TEST(LlvmLibcSPrintfTest, PercentConv) { … }
TEST(LlvmLibcSPrintfTest, CharConv) { … }
TEST(LlvmLibcSPrintfTest, StringConv) { … }
TEST(LlvmLibcSPrintfTest, IntConv) { … }
TEST(LlvmLibcSPrintfTest, HexConv) { … }
TEST(LlvmLibcSPrintfTest, BinConv) { … }
TEST(LlvmLibcSPrintfTest, PointerConv) { … }
TEST(LlvmLibcSPrintfTest, OctConv) { … }
#ifndef LIBC_COPT_PRINTF_DISABLE_FLOAT
TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) { … }
TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) { … }
TEST_F(LlvmLibcSPrintfTest, FloatDecimalLongDoubleConv) { … }
TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) { … }
TEST_F(LlvmLibcSPrintfTest, FloatExponentLongDoubleConv) { … }
TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) { … }
TEST_F(LlvmLibcSPrintfTest, FloatAutoLongDoubleConv) { … }
#endif
#if defined(LIBC_COMPILER_HAS_FIXED_POINT) && \
!defined(LIBC_COPT_PRINTF_DISABLE_FIXED_POINT)
TEST_F(LlvmLibcSPrintfTest, FixedConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%k", 0x0);
ASSERT_STREQ_LEN(written, buff, "0.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%k", 0x80000000);
ASSERT_STREQ_LEN(written, buff, "-0.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%r", 0xffff);
ASSERT_STREQ_LEN(written, buff, "-0.999969");
written = LIBC_NAMESPACE::sprintf(buff, "%R", 0xffff);
ASSERT_STREQ_LEN(written, buff, "0.999985");
written = LIBC_NAMESPACE::sprintf(buff, "%k", 0xffffffff);
ASSERT_STREQ_LEN(written, buff, "-65535.999969");
written =
LIBC_NAMESPACE::sprintf(buff, "%K", 0xffffffff);
ASSERT_STREQ_LEN(written, buff, "65535.999985");
written = LIBC_NAMESPACE::sprintf(buff, "%r", 0x7fff);
ASSERT_STREQ_LEN(written, buff, "0.999969");
written = LIBC_NAMESPACE::sprintf(buff, "%k", 0x7fffffff);
ASSERT_STREQ_LEN(written, buff, "65535.999969");
written = LIBC_NAMESPACE::sprintf(buff, "%hk", 0x0);
ASSERT_STREQ_LEN(written, buff, "0.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%hk", 0xffff);
ASSERT_STREQ_LEN(written, buff, "-255.992188");
written = LIBC_NAMESPACE::sprintf(buff, "%hr", 0x0);
ASSERT_STREQ_LEN(written, buff, "0.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%hr", 0xff);
ASSERT_STREQ_LEN(written, buff, "-0.992188");
written = LIBC_NAMESPACE::sprintf(buff, "%hK", 0x0);
ASSERT_STREQ_LEN(written, buff, "0.000000");
written =
LIBC_NAMESPACE::sprintf(buff, "%hK", 0xffff);
ASSERT_STREQ_LEN(written, buff, "255.996094");
written = LIBC_NAMESPACE::sprintf(buff, "%hR", 0x0);
ASSERT_STREQ_LEN(written, buff, "0.000000");
written =
LIBC_NAMESPACE::sprintf(buff, "%hR", 0xff);
ASSERT_STREQ_LEN(written, buff, "0.996094");
written = LIBC_NAMESPACE::sprintf(buff, "%lk", 0x0ll);
ASSERT_STREQ_LEN(written, buff, "0.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%lk",
0xffffffffffffffff);
ASSERT_STREQ_LEN(written, buff, "-4294967296.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%lr", 0x0);
ASSERT_STREQ_LEN(written, buff, "0.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%lr",
0xffffffff);
ASSERT_STREQ_LEN(written, buff, "-1.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%lK", 0x0ll);
ASSERT_STREQ_LEN(written, buff, "0.000000");
written =
LIBC_NAMESPACE::sprintf(buff, "%lK",
0xffffffffffffffff);
ASSERT_STREQ_LEN(written, buff, "4294967296.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%lR", 0x0);
ASSERT_STREQ_LEN(written, buff, "0.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%lR",
0xffffffff);
ASSERT_STREQ_LEN(written, buff, "1.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%10k", 0x0000a000);
ASSERT_STREQ_LEN(written, buff, " 1.250000");
written = LIBC_NAMESPACE::sprintf(buff, "%10k", 0x8000a000);
ASSERT_STREQ_LEN(written, buff, " -1.250000");
written = LIBC_NAMESPACE::sprintf(buff, "%8k", 0x0000a000);
ASSERT_STREQ_LEN(written, buff, "1.250000");
written = LIBC_NAMESPACE::sprintf(buff, "%9k", 0x8000a000);
ASSERT_STREQ_LEN(written, buff, "-1.250000");
written = LIBC_NAMESPACE::sprintf(buff, "%4k", 0x0000a000);
ASSERT_STREQ_LEN(written, buff, "1.250000");
written = LIBC_NAMESPACE::sprintf(buff, "%4k", 0x8000a000);
ASSERT_STREQ_LEN(written, buff, "-1.250000");
written =
LIBC_NAMESPACE::sprintf(buff, "%.16K", 0xFFFFFFFF);
ASSERT_STREQ_LEN(written, buff, "65535.9999847412109375");
written = LIBC_NAMESPACE::sprintf(
buff, "%.32lK", 0xFFFFFFFFFFFFFFFF);
ASSERT_STREQ_LEN(written, buff,
"4294967295.99999999976716935634613037109375");
written =
LIBC_NAMESPACE::sprintf(buff, "%.0K", 0xFFFFFFFF);
ASSERT_STREQ_LEN(written, buff, "65536");
written = LIBC_NAMESPACE::sprintf(buff, "%.0R", 0xFFFF);
ASSERT_STREQ_LEN(written, buff, "1");
written = LIBC_NAMESPACE::sprintf(buff, "%+k", 0x0000a000);
ASSERT_STREQ_LEN(written, buff, "+1.250000");
written = LIBC_NAMESPACE::sprintf(buff, "%+k", 0x8000a000);
ASSERT_STREQ_LEN(written, buff, "-1.250000");
written = LIBC_NAMESPACE::sprintf(buff, "% k", 0x0000a000);
ASSERT_STREQ_LEN(written, buff, " 1.250000");
written = LIBC_NAMESPACE::sprintf(buff, "% k", 0x8000a000);
ASSERT_STREQ_LEN(written, buff, "-1.250000");
written = LIBC_NAMESPACE::sprintf(buff, "%+K", 0x00014000);
ASSERT_STREQ_LEN(written, buff, "1.250000");
written = LIBC_NAMESPACE::sprintf(buff, "% K", 0x00014000);
ASSERT_STREQ_LEN(written, buff, "1.250000");
written = LIBC_NAMESPACE::sprintf(buff, "%-10k", 0x0000c000);
ASSERT_STREQ_LEN(written, buff, "1.500000 ");
written = LIBC_NAMESPACE::sprintf(buff, "%#.k", 0x00008000);
ASSERT_STREQ_LEN(written, buff, "1.");
written = LIBC_NAMESPACE::sprintf(buff, "%#.0k", 0x0000c000);
ASSERT_STREQ_LEN(written, buff, "2.");
written = LIBC_NAMESPACE::sprintf(buff, "%010k", 0x0000c000);
ASSERT_STREQ_LEN(written, buff, "001.500000");
written = LIBC_NAMESPACE::sprintf(buff, "%010k", 0x8000c000);
ASSERT_STREQ_LEN(written, buff, "-01.500000");
written = LIBC_NAMESPACE::sprintf(buff, "%+- #0k", 0);
ASSERT_STREQ_LEN(written, buff, "+0.000000");
written = LIBC_NAMESPACE::sprintf(buff, "%10.2k", 0x0004feb8);
ASSERT_STREQ_LEN(written, buff, " 9.99");
written = LIBC_NAMESPACE::sprintf(buff, "%5.1k", 0x0004feb8);
ASSERT_STREQ_LEN(written, buff, " 10.0");
written = LIBC_NAMESPACE::sprintf(buff, "%-10.2k", 0x0004feb8);
ASSERT_STREQ_LEN(written, buff, "9.99 ");
written = LIBC_NAMESPACE::sprintf(buff, "%-5.1k", 0x0004feb8);
ASSERT_STREQ_LEN(written, buff, "10.0 ");
written = LIBC_NAMESPACE::sprintf(buff, "%-5.1k", 0x00000001);
ASSERT_STREQ_LEN(written, buff, "0.0 ");
written = LIBC_NAMESPACE::sprintf(buff, "%30k", 0x7fffffff);
ASSERT_STREQ_LEN(written, buff, " 65535.999969");
written = LIBC_NAMESPACE::sprintf(buff, "%-30k", 0x7fffffff);
ASSERT_STREQ_LEN(written, buff, "65535.999969 ");
written = LIBC_NAMESPACE::sprintf(buff, "%20.2lK",
0x3b9ac9ffFD70A3D7);
ASSERT_STREQ_LEN(written, buff, " 999999999.99");
written = LIBC_NAMESPACE::sprintf(buff, "%20.1lK",
0x3b9ac9ffFD70A3D7);
ASSERT_STREQ_LEN(written, buff, " 1000000000.0");
written = LIBC_NAMESPACE::sprintf(buff, "%12.3R %-12.3k", 0x1999,
0x00800000);
ASSERT_STREQ_LEN(written, buff, " 0.100 256.000 ");
written =
LIBC_NAMESPACE::sprintf(buff, "%+-#12.3lk % 012.3k", 0x000000001013a92all,
0x02740000);
ASSERT_STREQ_LEN(written, buff, "+0.126 0001256.000");
}
#endif
#ifndef LIBC_COPT_PRINTF_DISABLE_WRITE_INT
TEST(LlvmLibcSPrintfTest, WriteIntConv) { … }
#endif
#ifndef LIBC_COPT_PRINTF_DISABLE_INDEX_MODE
TEST(LlvmLibcSPrintfTest, IndexModeParsing) { … }
#endif