From: Linux Karlsson Date: Thu, 17 Jun 2010 11:20:09 +0000 (+0200) Subject: Added tests for functions in ssl_init.c and uinttoa.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c3daf2461641283347a6516e5a3771e67bd2fdb;p=thirdparty%2Fntp.git Added tests for functions in ssl_init.c and uinttoa.c bk: 4c1a04e9t9h7HqwQthuX1YMOlQ7yGQ --- diff --git a/tests/libntp/Makefile.am b/tests/libntp/Makefile.am index 2902b2f99a..2113852b58 100644 --- a/tests/libntp/Makefile.am +++ b/tests/libntp/Makefile.am @@ -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 index 0000000000..8e8597acd5 --- /dev/null +++ b/tests/libntp/ssl_init.cpp @@ -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 index 0000000000..fac4480a70 --- /dev/null +++ b/tests/libntp/uinttoa.cpp @@ -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)); +}