summaryrefslogtreecommitdiff
path: root/tests/stdio_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-11-02 16:58:44 -0700
committerElliott Hughes <enh@google.com>2017-11-02 16:58:44 -0700
commit618303ca4ad2754071ba6955da690fec2b27a76d (patch)
tree97f8db830c0241850a8bdb3008127b9a92afecfc /tests/stdio_test.cpp
parent46621f43b083d9743545b31e97011a1c44e784b2 (diff)
More printf de-duplication.
Fix the 'j' (intmax_t/uintmax_t) length qualifier in the wide variant. (With new tests that fail without this fix.) Fix a typo in the wide support for intmax_t*, which isn't testable because %n is disabled on Android (and will be removed in a later cleanup pass). Also move the public vfprintf/vfwprint functions into stdio.cpp. Bug: http://b/67371539 Test: ran tests Change-Id: Ib003599b1e9cb789044a068940b59e447f2cb7cb
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r--tests/stdio_test.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index e07980e77..87a0eae26 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -621,6 +621,38 @@ TEST(STDIO_TEST, swprintf_C) { // Synonym for %lc.
EXPECT_EQ(std::wstring(L"<a>"), buf);
}
+TEST(STDIO_TEST, swprintf_jd_INTMAX_MAX) {
+ constexpr size_t nchars = 32;
+ wchar_t buf[nchars];
+
+ swprintf(buf, nchars, L"%jd", INTMAX_MAX);
+ EXPECT_EQ(std::wstring(L"9223372036854775807"), buf);
+}
+
+TEST(STDIO_TEST, swprintf_jd_INTMAX_MIN) {
+ constexpr size_t nchars = 32;
+ wchar_t buf[nchars];
+
+ swprintf(buf, nchars, L"%jd", INTMAX_MIN);
+ EXPECT_EQ(std::wstring(L"-9223372036854775808"), buf);
+}
+
+TEST(STDIO_TEST, swprintf_ju_UINTMAX_MAX) {
+ constexpr size_t nchars = 32;
+ wchar_t buf[nchars];
+
+ swprintf(buf, nchars, L"%ju", UINTMAX_MAX);
+ EXPECT_EQ(std::wstring(L"18446744073709551615"), buf);
+}
+
+TEST(STDIO_TEST, swprintf_1$ju_UINTMAX_MAX) {
+ constexpr size_t nchars = 32;
+ wchar_t buf[nchars];
+
+ swprintf(buf, nchars, L"%1$ju", UINTMAX_MAX);
+ EXPECT_EQ(std::wstring(L"18446744073709551615"), buf);
+}
+
TEST(STDIO_TEST, swprintf_ls) {
constexpr size_t nchars = 32;
wchar_t buf[nchars];
@@ -655,6 +687,30 @@ TEST(STDIO_TEST, snprintf_d_INT_MIN) {
EXPECT_STREQ("-2147483648", buf);
}
+TEST(STDIO_TEST, snprintf_jd_INTMAX_MAX) {
+ char buf[BUFSIZ];
+ snprintf(buf, sizeof(buf), "%jd", INTMAX_MAX);
+ EXPECT_STREQ("9223372036854775807", buf);
+}
+
+TEST(STDIO_TEST, snprintf_jd_INTMAX_MIN) {
+ char buf[BUFSIZ];
+ snprintf(buf, sizeof(buf), "%jd", INTMAX_MIN);
+ EXPECT_STREQ("-9223372036854775808", buf);
+}
+
+TEST(STDIO_TEST, snprintf_ju_UINTMAX_MAX) {
+ char buf[BUFSIZ];
+ snprintf(buf, sizeof(buf), "%ju", UINTMAX_MAX);
+ EXPECT_STREQ("18446744073709551615", buf);
+}
+
+TEST(STDIO_TEST, snprintf_1$ju_UINTMAX_MAX) {
+ char buf[BUFSIZ];
+ snprintf(buf, sizeof(buf), "%1$ju", UINTMAX_MAX);
+ EXPECT_STREQ("18446744073709551615", buf);
+}
+
TEST(STDIO_TEST, snprintf_ld_LONG_MAX) {
char buf[BUFSIZ];
snprintf(buf, sizeof(buf), "%ld", LONG_MAX);