From: Linux Karlsson Date: Tue, 8 Jun 2010 15:07:07 +0000 (+0200) Subject: Added tests for atoint and atolfp X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8d4e104e5c6deb2f1bd6dff48ff7006a2d8d821b;p=thirdparty%2Fntp.git Added tests for atoint and atolfp bk: 4c0e5c9bBUZKhJuL-3FLc5bi4M_mNw --- diff --git a/tests/libntp/Makefile.am b/tests/libntp/Makefile.am index d44d910ab3..0e062f0564 100644 --- a/tests/libntp/Makefile.am +++ b/tests/libntp/Makefile.am @@ -2,6 +2,8 @@ check_PROGRAMS = tests LDADD = @top_builddir@/libntp/libntp.a @LCRYPTO@ -lgtest_main -lpthread tests_SOURCES = libntptest.cpp \ a_md5encrypt.cpp \ + atoint.cpp \ + atolfp.cpp \ authkeys.cpp \ hextoint.cpp diff --git a/tests/libntp/atoint.cpp b/tests/libntp/atoint.cpp new file mode 100644 index 0000000000..fa2f11d3d0 --- /dev/null +++ b/tests/libntp/atoint.cpp @@ -0,0 +1,52 @@ +#include "libntptest.h" + +extern "C" { +#include "ntp_stdlib.h" +}; + +class atointTest : public libntptest { +}; + +TEST_F(atointTest, RegularPositive) { + const char *str = "17"; + long val; + + EXPECT_TRUE(atoint(str, &val)); + EXPECT_EQ(17, val); +} + +TEST_F(atointTest, RegularNegative) { + const char *str = "-20"; + long val; + + EXPECT_TRUE(atoint(str, &val)); + EXPECT_EQ(-20, val); +} + +TEST_F(atointTest, PositiveOverflowBoundary) { + const char *str = "2147483648"; + long val; + + EXPECT_FALSE(atoint(str, &val)); +} + +TEST_F(atointTest, NegativeOverflowBoundary) { + const char *str = "-2147483649"; + long val; + + EXPECT_FALSE(atoint(str, &val)); +} + +TEST_F(atointTest, PositiveOverflowBig) { + const char *str = "2300000000"; + long val; + + EXPECT_FALSE(atoint(str, &val)); +} + +TEST_F(atointTest, IllegalCharacter) { + const char *str = "4500l"; + long val; + + EXPECT_FALSE(atoint(str, &val)); +} diff --git a/tests/libntp/atolfp.cpp b/tests/libntp/atolfp.cpp new file mode 100644 index 0000000000..ddf361c5a0 --- /dev/null +++ b/tests/libntp/atolfp.cpp @@ -0,0 +1,14 @@ +#include "libntptest.h" + +extern "C" { +#include "ntp_fp.h" +#include "ntp_stdlib.h" +}; + +class atolfpTest : public libntptest { +}; + +TEST_F(atolfpTest, PositiveInteger) { + const char *str = "500"; + l_fp expected = {500,0}; +}