]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Added tests for atoint and atolfp
authorLinux Karlsson <karlsson@ntp.org>
Tue, 8 Jun 2010 15:07:07 +0000 (17:07 +0200)
committerLinux Karlsson <karlsson@ntp.org>
Tue, 8 Jun 2010 15:07:07 +0000 (17:07 +0200)
bk: 4c0e5c9bBUZKhJuL-3FLc5bi4M_mNw

tests/libntp/Makefile.am
tests/libntp/atoint.cpp [new file with mode: 0644]
tests/libntp/atolfp.cpp [new file with mode: 0644]

index d44d910ab3d2976c29ffc65d1ed7c9ef731abce4..0e062f05640db933bd949dc2b52c4104a999e404 100644 (file)
@@ -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 (file)
index 0000000..fa2f11d
--- /dev/null
@@ -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 (file)
index 0000000..ddf361c
--- /dev/null
@@ -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};
+}