]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
ssl_init.c, run-test-ssl_init.c:
authorDamir Tomic <viperus@ntp.org>
Wed, 17 Jun 2015 05:45:38 +0000 (07:45 +0200)
committerDamir Tomic <viperus@ntp.org>
Wed, 17 Jun 2015 05:45:38 +0000 (07:45 +0200)
  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
tests/libntp/g_ssl_init.cpp [moved from tests/libntp/ssl_init.cpp with 100% similarity]
tests/libntp/run-test-socktoa.c
tests/libntp/run-test-ssl_init.c [new file with mode: 0644]
tests/libntp/ssl_init.c [new file with mode: 0644]

index 04830dd338a2208884e0d71d5ba0db1a1dad2f94..5542ed1f38e03a44bfb39544c538824ae2e0ac5a 100644 (file)
@@ -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 =
 
index 39f56e241c09c450b6301cba16c6fabb95c90f24..81e4717d0e8cc35391db22a2cd20efc43225bde2 100644 (file)
@@ -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 (file)
index 0000000..c402873
--- /dev/null
@@ -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 <setjmp.h>
+#include <stdio.h>
+
+//=======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 (file)
index 0000000..93b7afd
--- /dev/null
@@ -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 */