From 00d8a8b77922da018d71984ff90fd8877eaafd09 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 7 Sep 2017 16:42:13 -0700 Subject: [PATCH] Trivial tests for / *abs and *div functions. Because I want something to copy & paste into the NDK support library test that's slightly better than taking the address of the function... Bug: https://github.com/android-ndk/ndk/issues/502 Test: ran tests Change-Id: If43089d16691d6a4dcf5d972450b14ed85bbca81 --- tests/inttypes_test.cpp | 29 +++++++++++++++++++++++++++++ tests/stdlib_test.cpp | 15 +++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/tests/inttypes_test.cpp b/tests/inttypes_test.cpp index 01d6b829e..da12ec4fd 100644 --- a/tests/inttypes_test.cpp +++ b/tests/inttypes_test.cpp @@ -156,3 +156,32 @@ TEST(inttypes, wcstoumax_EINVAL) { wcstoumax(L"123", NULL, 37); ASSERT_EQ(EINVAL, errno); } + +TEST(inttypes, div) { + div_t r = div(-5, 3); + ASSERT_EQ(-1, r.quot); + ASSERT_EQ(-2, r.rem); +} + +TEST(inttypes, ldiv) { + ldiv_t r = ldiv(-5, 3); + ASSERT_EQ(-1, r.quot); + ASSERT_EQ(-2, r.rem); +} + +TEST(inttypes, lldiv) { + lldiv_t r = lldiv(-5, 3); + ASSERT_EQ(-1, r.quot); + ASSERT_EQ(-2, r.rem); +} + +TEST(inttypes, imaxdiv) { + imaxdiv_t r = imaxdiv(-5, 3); + ASSERT_EQ(-1, r.quot); + ASSERT_EQ(-2, r.rem); +} + +TEST(inttypes, imaxabs) { + ASSERT_EQ(INTMAX_MAX, imaxabs(-INTMAX_MAX)); + ASSERT_EQ(INTMAX_MAX, imaxabs(INTMAX_MAX)); +} diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp index 7d2dc20ce..27495d88f 100644 --- a/tests/stdlib_test.cpp +++ b/tests/stdlib_test.cpp @@ -650,3 +650,18 @@ TEST(stdlib, strtoimax_smoke) { TEST(stdlib, strtoumax_smoke) { CheckStrToInt(strtoumax); } + +TEST(stdlib, abs) { + ASSERT_EQ(INT_MAX, abs(-INT_MAX)); + ASSERT_EQ(INT_MAX, abs(INT_MAX)); +} + +TEST(stdlib, labs) { + ASSERT_EQ(LONG_MAX, labs(-LONG_MAX)); + ASSERT_EQ(LONG_MAX, labs(LONG_MAX)); +} + +TEST(stdlib, llabs) { + ASSERT_EQ(LLONG_MAX, llabs(-LLONG_MAX)); + ASSERT_EQ(LLONG_MAX, llabs(LLONG_MAX)); +}