]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
ntp_util.c:
authorLokesh Walase <lokeshw24@ntp.org>
Mon, 3 Aug 2015 07:00:29 +0000 (12:30 +0530)
committerLokesh Walase <lokeshw24@ntp.org>
Mon, 3 Aug 2015 07:00:29 +0000 (12:30 +0530)
  new file

bk: 55bf118dX6Ds4PSSwqTyMO0dDLcDjw

tests/libntp/decodenetnum.c
tests/libntp/socktoa.c
tests/ntpd/Makefile.am
tests/ntpd/ntp_util.c [new file with mode: 0644]

index 77491b8b312f105a5b4849c83230fe37cc098d8d..39f0320bf9bc4909f314c0377f16d64b81e587b7 100644 (file)
@@ -6,8 +6,10 @@
 
 extern void test_IPv4AddressOnly(void);
 extern void test_IPv4AddressWithPort(void);
+#ifdef ISC_PLATFORM_HAVEIPV6
 extern void test_IPv6AddressOnly(void);
 extern void test_IPv6AddressWithPort(void);
+#endif /* ISC_PLATFORM_HAVEIPV6 */
 extern void test_IllegalAddress(void);
 extern void test_IllegalCharInPort(void);
 
@@ -40,6 +42,7 @@ test_IPv4AddressWithPort(void) {
        TEST_ASSERT_TRUE(IsEqual(expected, actual));
 }
 
+#ifdef ISC_PLATFORM_HAVEIPV6
 void
 test_IPv6AddressOnly(void) {
        const struct in6_addr address = {
@@ -60,7 +63,9 @@ test_IPv6AddressOnly(void) {
        TEST_ASSERT_TRUE(decodenetnum(str, &actual));
        TEST_ASSERT_TRUE(IsEqual(expected, actual));
 }
+#endif /* ISC_PLATFORM_HAVEIPV6 */
 
+#ifdef ISC_PLATFORM_HAVEIPV6
 void
 test_IPv6AddressWithPort(void) {
        const struct in6_addr address = {
@@ -82,6 +87,7 @@ test_IPv6AddressWithPort(void) {
        TEST_ASSERT_TRUE(IsEqual(expected, actual));
 }
 
+#endif /* ISC_PLATFORM_HAVEIPV6 */
 void
 test_IllegalAddress(void) {
        const char *str = "192.0.2.270:2000";
index 9ce3a1e9946b732323e2ab53abb4e3075eb11e6b..6d65fea949db8ea0cc7f1443145cc57a4c9bf4f5 100644 (file)
@@ -6,12 +6,15 @@
 #include "unity.h"
 #include "sockaddrtest.h"
 
+
 void test_IPv4AddressWithPort(void);
+#ifdef ISC_PLATFORM_HAVEIPV6
 void test_IPv6AddressWithPort(void);
+void test_IgnoreIPv6Fields(void);
+#endif /* ISC_PLATFORM_HAVEIPV6 */
 void test_ScopedIPv6AddressWithPort(void);
 void test_HashEqual(void);
 void test_HashNotEqual(void);
-void test_IgnoreIPv6Fields(void);
 
 void 
 test_IPv4AddressWithPort(void) {
@@ -21,6 +24,7 @@ test_IPv4AddressWithPort(void) {
        TEST_ASSERT_EQUAL_STRING("192.0.2.10:123", sockporttoa(&input));
 }
 
+#ifdef ISC_PLATFORM_HAVEIPV6
 void 
 test_IPv6AddressWithPort(void) {
        const struct in6_addr address = {
@@ -44,6 +48,7 @@ test_IPv6AddressWithPort(void) {
        TEST_ASSERT_EQUAL_STRING(expected, socktoa(&input));
        TEST_ASSERT_EQUAL_STRING(expected_port, sockporttoa(&input));
 }
+#endif /* ISC_PLATFORM_HAVEIPV6 */
 
 void 
 test_ScopedIPv6AddressWithPort(void) {
@@ -93,6 +98,7 @@ test_HashNotEqual(void) {
        TEST_ASSERT_FALSE(sock_hash(&input1) == sock_hash(&input2)); 
 }
 
+#ifdef ISC_PLATFORM_HAVEIPV6
 void 
 test_IgnoreIPv6Fields(void) {
        const struct in6_addr address = {
@@ -116,3 +122,4 @@ test_IgnoreIPv6Fields(void) {
 
        TEST_ASSERT_EQUAL(sock_hash(&input1), sock_hash(&input2));
 }
+#endif /* ISC_PLATFORM_HAVEIPV6 */
index c9430efcd4bc96b908bc688fdcf4eeb2a0291926..c984f9a77298f6750d57082fc064cfb52ba5c095 100644 (file)
@@ -12,6 +12,7 @@ check_PROGRAMS =              \
        test-leapsec            \
        test-ntp_prio_q         \
        test-ntp_restrict       \
+       test-ntp_util       \
        test-rc_cmdlength       \
        test-ntp_scanner        \
        $(NULL)
@@ -59,6 +60,7 @@ tests_SOURCES = $(top_srcdir)/sntp/tests_main.cpp     \
                $(top_srcdir)/ntpd/ntp_leapsec.c        \
                $(top_srcdir)/ntpd/ntp_prio_q.c         \
                $(top_srcdir)/ntpd/ntp_restrict.c       \
+               $(top_srcdir)/ntpd/ntp_util.c   \
                $(top_srcdir)/ntpd/rc_cmdlength.c       \
                $(top_srcdir)/ntpd/ntp_signd.c  \
                g_leapsec.cpp   \
@@ -68,12 +70,14 @@ BUILT_SOURCES +=                    \
        $(srcdir)/run-leapsec.c         \
        $(srcdir)/run-ntp_prio_q.c      \
        $(srcdir)/run-ntp_restrict.c    \
+       $(srcdir)/run-ntp_util.c        \
        $(srcdir)/run-rc_cmdlength.c            \
        $(srcdir)/run-ntp_signd.c               \
        $(NULL)
 
 noinst_HEADERS =       g_ntpdtest.h            \
                        $(srcdir)/../libntp/test-libntp.h       \
+                       sockaddrtest.h  \
                        $(NULL)
 
 ###
@@ -135,6 +139,25 @@ $(srcdir)/run-ntp_restrict.c: $(srcdir)/ntp_restrict.c $(std_unity_list)
        $(run_unity) ntp_restrict.c run-ntp_restrict.c
 
 
+###
+test_ntp_util_CFLAGS =                 \
+       -I$(top_srcdir)/sntp/unity      \
+       $(NULL)
+
+test_ntp_util_LDADD =                  \
+       $(unity_tests_LDADD)            \
+       $(NULL)
+
+test_ntp_util_SOURCES =                        \
+       ntp_util.c                      \
+       run-ntp_util.c                  \
+       $(srcdir)/../libntp/test-libntp.c               \
+       $(NULL)
+
+$(srcdir)/run-ntp_util.c: $(srcdir)/ntp_util.c $(std_unity_list)
+       $(run_unity) ntp_util.c run-ntp_util.c
+
+
 ###
 test_rc_cmdlength_CFLAGS =                     \
        -I$(top_srcdir)/sntp/unity      \
diff --git a/tests/ntpd/ntp_util.c b/tests/ntpd/ntp_util.c
new file mode 100644 (file)
index 0000000..8b90a72
--- /dev/null
@@ -0,0 +1,74 @@
+#include "config.h"
+
+#include "ntp.h"
+#include "ntp_calendar.h"
+#include "ntp_stdlib.h"
+
+#include "unity.h"
+#include "test-libntp.h"
+
+#include <time.h>
+#include <string.h>
+
+void test_mprintf_clock_stats(void){
+       char *one = "this";
+       char *two = "is";
+       char *three = "becoming a string";
+
+       int ret_value1 = mprintf_clock_stats(NULL, "%s", one) ;
+       int ret_value2 = mprintf_clock_stats(NULL, "%s %s %s", one, two, three) ;
+
+       TEST_ASSERT_EQUAL( strlen(one),  ret_value1);
+       TEST_ASSERT_EQUAL(25, ret_value2);
+
+}
+
+
+void test_fstostr(void){
+       u_int32 ntp;
+       char *buf ;
+
+       ntp = 0;
+       buf = fstostr(ntp); 
+       TEST_ASSERT_EQUAL_STRING("203602070628", buf);
+       //The output format of function fstostr() is : YYYY-MM-DD-HH-MI 
+       //[ Year-Month-MonthDay-Hour-Minute ]
+
+       ntp += 60;  //Increment by 60 secs ie 1 minute
+       buf = fstostr(ntp); 
+       TEST_ASSERT_EQUAL_STRING("203602070629", buf);
+
+       ntp += 60;  //Increment by 60 secs ie 1 minute
+       buf = fstostr(ntp); 
+       TEST_ASSERT_EQUAL_STRING("203602070630", buf);
+
+       ntp += 3600;  //Increment by 3600 secs ie 1 hour 
+       buf = fstostr(ntp); 
+       TEST_ASSERT_EQUAL_STRING("203602070730", buf);
+
+       ntp += 3600;  //Increment by 3600 secs ie 1 hour 
+       buf = fstostr(ntp); 
+       TEST_ASSERT_EQUAL_STRING("203602070830", buf);
+
+       ntp += (24*60*60);  //Increment by 1 day 
+       buf = fstostr(ntp); 
+       TEST_ASSERT_EQUAL_STRING("203602080830", buf);
+
+       ntp += (24*60*60);  //Increment by 1 day
+       buf = fstostr(ntp); 
+       TEST_ASSERT_EQUAL_STRING("203602090830", buf);
+       
+       ntp += (10*24*60*60);  //Increment by 10 days
+       buf = fstostr(ntp); 
+       TEST_ASSERT_EQUAL_STRING("203602190830", buf);
+
+       ntp += (12*24*60*60);  //Increment by 12 days
+       buf = fstostr(ntp); 
+       TEST_ASSERT_EQUAL_STRING("203603020830", buf);
+
+       ntp += (31*24*60*60);  //Increment by 1 month
+       buf = fstostr(ntp); 
+       TEST_ASSERT_EQUAL_STRING("203604020830", buf);
+       
+}
+