From c7585e43b10ddea090ede352a151bcaf2db13ca8 Mon Sep 17 00:00:00 2001 From: Damir Tomic Date: Wed, 17 Jun 2015 07:45:38 +0200 Subject: [PATCH] ssl_init.c, run-test-ssl_init.c: new file Makefile.am: added ssl-init.c building g_ssl_init.cpp: Rename: tests/libntp/ssl_init.cpp -> tests/libntp/g_ssl_init.cpp bk: 55810982zonWS8bG1FDAMfPzsy033g --- tests/libntp/Makefile.am | 23 +++++++- tests/libntp/{ssl_init.cpp => g_ssl_init.cpp} | 0 tests/libntp/run-test-socktoa.c | 2 +- tests/libntp/run-test-ssl_init.c | 57 +++++++++++++++++++ tests/libntp/ssl_init.c | 53 +++++++++++++++++ 5 files changed, 132 insertions(+), 3 deletions(-) rename tests/libntp/{ssl_init.cpp => g_ssl_init.cpp} (100%) create mode 100644 tests/libntp/run-test-ssl_init.c create mode 100644 tests/libntp/ssl_init.c diff --git a/tests/libntp/Makefile.am b/tests/libntp/Makefile.am index 04830dd33..5542ed1f3 100644 --- a/tests/libntp/Makefile.am +++ b/tests/libntp/Makefile.am @@ -31,6 +31,7 @@ check_PROGRAMS = \ test-decodenetnum \ test-timevalops \ test-timespecops \ + test-ssl_init \ $(NULL) if GTEST_AVAILABLE @@ -98,10 +99,10 @@ tests_SOURCES = \ g_refnumtoa.cpp \ sfptostr.cpp \ socktoa.cpp \ - ssl_init.cpp \ + g_ssl_init.cpp \ g_statestr.cpp \ strtolfp.cpp \ - g_timespecops.cpp \ + g_timespecops.cpp \ timestructs.cpp \ g_timevalops.cpp \ tstotv.cpp \ @@ -347,6 +348,15 @@ test_timespecops_LDADD = \ $(top_builddir)/sntp/unity/libunity.a \ $(NULL) +test_ssl_init_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) + +test_ssl_init_LDADD = \ + $(LDADD) \ + $(top_builddir)/sntp/unity/libunity.a \ + $(NULL) + test_modetoa_SOURCES = \ modetoa.c \ @@ -477,6 +487,12 @@ test_timespecops_SOURCES = \ run-test-timespecops.c \ $(NULL) +test_ssl_init_SOURCES = \ + ssl_init.c \ + run-test-ssl_init.c \ + $(NULL) + + BUILT_SOURCES += \ $(srcdir)/run-test-a_md5encrypt.c \ $(srcdir)/run-test-atoint.c \ @@ -503,6 +519,7 @@ BUILT_SOURCES += \ $(srcdir)/run-test-calendar.c \ $(srcdir)/run-test-timevalops.c \ $(srcdir)/run-test-timespecops.c \ + $(srcdir)/run-test-ssl_init.c \ $(NULL) $(srcdir)/run-test-modetoa.c: $(srcdir)/modetoa.c $(std_unity_list) @@ -580,6 +597,8 @@ $(srcdir)/run-test-timevalops.c: $(srcdir)/timevalops.c $(std_unity_list) $(srcdir)/run-test-timespecops.c: $(srcdir)/timespecops.c $(std_unity_list) $(run_unity) timespecops.c run-test-timespecops.c +$(srcdir)/run-test-ssl_init.c: $(srcdir)/ssl_init.c $(std_unity_list) + $(run_unity) ssl_init.c run-test-ssl_init.c TESTS = diff --git a/tests/libntp/ssl_init.cpp b/tests/libntp/g_ssl_init.cpp similarity index 100% rename from tests/libntp/ssl_init.cpp rename to tests/libntp/g_ssl_init.cpp diff --git a/tests/libntp/run-test-socktoa.c b/tests/libntp/run-test-socktoa.c index 39f56e241..81e4717d0 100644 --- a/tests/libntp/run-test-socktoa.c +++ b/tests/libntp/run-test-socktoa.c @@ -55,7 +55,7 @@ int main(int argc, char *argv[]) RUN_TEST(test_ScopedIPv6AddressWithPort, 40); RUN_TEST(test_HashEqual, 65); RUN_TEST(test_HashNotEqual, 73); - RUN_TEST(test_IgnoreIPv6Fields, 84); + RUN_TEST(test_IgnoreIPv6Fields, 86); return (UnityEnd()); } diff --git a/tests/libntp/run-test-ssl_init.c b/tests/libntp/run-test-ssl_init.c new file mode 100644 index 000000000..c40287337 --- /dev/null +++ b/tests/libntp/run-test-ssl_init.c @@ -0,0 +1,57 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +//=======Test Runner Used To Run Each Test Below===== +#define RUN_TEST(TestFunc, TestLineNum) \ +{ \ + Unity.CurrentTestName = #TestFunc; \ + Unity.CurrentTestLineNumber = TestLineNum; \ + Unity.NumberOfTests++; \ + if (TEST_PROTECT()) \ + { \ + setUp(); \ + TestFunc(); \ + } \ + if (TEST_PROTECT() && !TEST_IS_IGNORED) \ + { \ + tearDown(); \ + } \ + UnityConcludeTest(); \ +} + +//=======Automagically Detected Files To Include===== +#include "unity.h" +#include +#include + +//=======External Functions This Runner Calls===== +extern void setUp(void); +extern void tearDown(void); +extern void test_MD5KeyTypeWithoutDigestLength(); +extern void test_MD5KeyTypeWithDigestLength(); +extern void test_SHA1KeyTypeWithDigestLength(); +extern void test_MD5KeyName(); + + +//=======Test Reset Option===== +void resetTest() +{ + tearDown(); + setUp(); +} + +char *progname; + + +//=======MAIN===== +int main(int argc, char *argv[]) +{ + progname = argv[0]; + Unity.TestFile = "ssl_init.c"; + UnityBegin("ssl_init.c"); + RUN_TEST(test_MD5KeyTypeWithoutDigestLength, 18); + RUN_TEST(test_MD5KeyTypeWithDigestLength, 22); + RUN_TEST(test_SHA1KeyTypeWithDigestLength, 31); + RUN_TEST(test_MD5KeyName, 45); + + return (UnityEnd()); +} diff --git a/tests/libntp/ssl_init.c b/tests/libntp/ssl_init.c new file mode 100644 index 000000000..93b7afd6a --- /dev/null +++ b/tests/libntp/ssl_init.c @@ -0,0 +1,53 @@ +#include "config.h" + +#ifdef OPENSSL +# include "openssl/err.h" +# include "openssl/rand.h" +# include "openssl/evp.h" +#endif +#include "ntp.h" + +#include "unity.h" + + +static const size_t TEST_MD5_DIGEST_LENGTH = 16; +static const size_t TEST_SHA1_DIGEST_LENGTH = 20; + + +// keytype_from_text() +void test_MD5KeyTypeWithoutDigestLength() { + TEST_ASSERT_EQUAL(KEY_TYPE_MD5, keytype_from_text("MD5", NULL)); +} + +void test_MD5KeyTypeWithDigestLength() { + size_t digestLength; + size_t expected = TEST_MD5_DIGEST_LENGTH; + + TEST_ASSERT_EQUAL(KEY_TYPE_MD5, keytype_from_text("MD5", &digestLength)); + TEST_ASSERT_EQUAL(expected, digestLength); +} + + +void test_SHA1KeyTypeWithDigestLength() { +#ifdef OPENSSL + size_t digestLength; + size_t expected = TEST_SHA1_DIGEST_LENGTH; + + TEST_ASSERT_EQUAL(NID_sha, keytype_from_text("SHA", &digestLength)); + TEST_ASSERT_EQUAL(expected, digestLength); + /* OPENSSL */ +#else TEST_IGNORE_MESSAGE("Skipping because OPENSSL isn't defined"); +#endif +} + + +// keytype_name() +void test_MD5KeyName() { + TEST_ASSERT_EQUAL_STRING("MD5", keytype_name(KEY_TYPE_MD5)); +} + +#ifdef OPENSSL +TEvoid test_SHA1KeyName() { + TEST_ASSERT_EQUAL_STRING("SHA", keytype_name(NID_sha)); +} +#endif /* OPENSSL */ -- 2.47.3