Skip to content

Commit

Permalink
Trivial tests for <stdlib.h> *abs and <inttypes.h> *div functions.
Browse files Browse the repository at this point in the history
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: android/ndk#502
Test: ran tests
Change-Id: If43089d16691d6a4dcf5d972450b14ed85bbca81
  • Loading branch information
enh-google committed Sep 7, 2017
1 parent 04503da commit e83266c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/inttypes_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,27 @@ 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);
}
20 changes: 20 additions & 0 deletions tests/stdlib_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,23 @@ 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));
}

TEST(stdlib, imaxabs) {
ASSERT_EQ(INTMAX_MAX, imaxabs(-INTMAX_MAX));
ASSERT_EQ(INTMAX_MAX, imaxabs(INTMAX_MAX));
}

0 comments on commit e83266c

Please sign in to comment.