]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Added tests for functions in ssl_init.c and uinttoa.c
authorLinux Karlsson <karlsson@ntp.org>
Thu, 17 Jun 2010 11:20:09 +0000 (13:20 +0200)
committerLinux Karlsson <karlsson@ntp.org>
Thu, 17 Jun 2010 11:20:09 +0000 (13:20 +0200)
bk: 4c1a04e9t9h7HqwQthuX1YMOlQ7yGQ

tests/libntp/Makefile.am
tests/libntp/ssl_init.cpp [new file with mode: 0644]
tests/libntp/uinttoa.cpp [new file with mode: 0644]

index 2902b2f99a38563300503a73ab497fc7170090bb..2113852b58d5fcb52ca5fd71b89ad672df965f2b 100644 (file)
@@ -21,7 +21,9 @@ tests_SOURCES = ../main.cpp           \
                octtoint.cpp            \
                sfptostr.cpp            \
                socktoa.cpp             \
-               strtolfp.cpp
+               ssl_init.cpp            \
+               strtolfp.cpp            \
+               uinttoa.cpp
 
 INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/lib/isc/include \
        -I$(top_srcdir)/lib/isc/nothreads/include \
diff --git a/tests/libntp/ssl_init.cpp b/tests/libntp/ssl_init.cpp
new file mode 100644 (file)
index 0000000..8e8597a
--- /dev/null
@@ -0,0 +1,41 @@
+#include "libntptest.h"
+
+extern "C" {
+#include "ntp.h"
+};
+
+class ssl_initTest : public libntptest {
+protected:
+       static const size_t MD5_DIGEST_LENGTH = 16;
+       static const size_t SHA1_DIGEST_LENGTH = 20;
+};
+
+// keytype_from_text()
+TEST_F(ssl_initTest, MD5KeyTypeWithoutDigestLength) {
+       ASSERT_EQ(KEY_TYPE_MD5, keytype_from_text("MD5", NULL));
+}
+
+TEST_F(ssl_initTest, MD5KeyTypeWithDigestLength) {
+       size_t digestLength;
+       size_t expected = MD5_DIGEST_LENGTH;
+
+       EXPECT_EQ(KEY_TYPE_MD5, keytype_from_text("MD5", &digestLength));
+       EXPECT_EQ(expected, digestLength);
+}
+
+TEST_F(ssl_initTest, SHA1KeyTypeWithDigestLength) {
+       size_t digestLength;
+       size_t expected = SHA1_DIGEST_LENGTH;
+
+       EXPECT_EQ(NID_sha, keytype_from_text("SHA", &digestLength));
+       EXPECT_EQ(expected, digestLength);
+}
+
+// keytype_name()
+TEST_F(ssl_initTest, MD5KeyName) {
+       EXPECT_STREQ("MD5", keytype_name(KEY_TYPE_MD5));
+}
+
+TEST_F(ssl_initTest, SHA1KeyName) {
+       EXPECT_STREQ("SHA", keytype_name(NID_sha));
+}
diff --git a/tests/libntp/uinttoa.cpp b/tests/libntp/uinttoa.cpp
new file mode 100644 (file)
index 0000000..fac4480
--- /dev/null
@@ -0,0 +1,12 @@
+#include "libntptest.h"
+
+class uinttoaTest : public libntptest {
+};
+
+TEST_F(uinttoaTest, RegularNumber) {
+       EXPECT_STREQ("39", uinttoa(39UL));
+}
+
+TEST_F(uinttoaTest, BiggestULong) {
+       EXPECT_STREQ("4294967295", uinttoa(4294967295UL));
+}