#removed test-libntp
check_PROGRAMS = test-modetoa test-uglydate test-ymd2yd test-statestr test-numtoa test-numtohost \
-test-hextoint test-atoint test-atouint test-authkeys test-a_md5encrypt test-lfpfunc test-octtoint
+test-hextoint test-atoint test-atouint test-authkeys test-a_md5encrypt test-lfpfunc test-octtoint \
+test-hextolfp
if GTEST_AVAILABLE
check_PROGRAMS += tests
clocktime.cpp \
decodenetnum.cpp \
g_hextoint.cpp \
- hextolfp.cpp \
+ g_hextolfp.cpp \
humandate.cpp \
g_lfpfunc.cpp \
lfptostr.cpp \
$(unity_tests_LDADD)
$(NULL)
+test_hextolfp_CFLAGS = \
+ -I$(top_srcdir)/sntp/unity \
+ $(NULL)
+
+test_hextolfp_LDADD = \
+ $(unity_tests_LDADD)
+ $(NULL)
+
test_a_md5encrypt_CFLAGS = \
-I$(top_srcdir)/sntp/unity \
run-test-octtoint.c \
$(NULL)
+test_hextolfp_SOURCES = \
+ hextolfp.c \
+ run-test-hextolfp.c \
+ $(NULL)
+
test_a_md5encrypt_SOURCES = \
a_md5encrypt.c \
$(srcdir)/run-test-octtoint.c: $(srcdir)/octtoint.c $(std_unity_list)
$(run_unity) octtoint.c run-test-octtoint.c
+$(srcdir)/run-test-hextolfp.c: $(srcdir)/hextolfp.c $(std_unity_list)
+ $(run_unity) hextolfp.c run-test-hextolfp.c
+
$(srcdir)/run-test-a_md5encrypt.c: $(srcdir)/a_md5encrypt.c $(std_unity_list)
$(run_unity) a_md5encrypt.c run-test-a_md5encrypt.c
--- /dev/null
+#include "lfptest.h"
+
+class hextolfpTest : public lfptest {
+};
+
+TEST_F(hextolfpTest, PositiveInteger) {
+ const char *str = "00001000.00000000";
+ l_fp actual;
+
+ l_fp expected = {4096, 0}; // 16^3, no fraction part.
+
+ ASSERT_TRUE(hextolfp(str, &actual));
+ EXPECT_TRUE(IsEqual(expected, actual));
+}
+
+TEST_F(hextolfpTest, NegativeInteger) {
+ const char *str = "ffffffff.00000000"; // -1 decimal
+ l_fp actual;
+
+ l_fp expected = {-1, 0};
+
+ ASSERT_TRUE(hextolfp(str, &actual));
+ EXPECT_TRUE(IsEqual(expected, actual));
+}
+
+TEST_F(hextolfpTest, PositiveFraction) {
+ const char *str = "00002000.80000000"; // 8196.5 decimal
+ l_fp actual;
+
+ l_fp expected = {8192, HALF};
+
+ ASSERT_TRUE(hextolfp(str, &actual));
+ EXPECT_TRUE(IsEqual(expected, actual));
+}
+
+TEST_F(hextolfpTest, NegativeFraction) {
+ const char *str = "ffffffff.40000000"; // -1 + 0.25 decimal
+ l_fp actual;
+
+ l_fp expected = {-1, QUARTER}; //-1 + 0.25
+
+ ASSERT_TRUE(hextolfp(str, &actual));
+ EXPECT_TRUE(IsEqual(expected, actual));
+}
+
+TEST_F(hextolfpTest, IllegalNumberOfInteger) {
+ const char *str = "1000000.00000000"; // Missing one digit in integral part.
+ l_fp actual;
+
+ ASSERT_FALSE(hextolfp(str, &actual));
+}
+
+TEST_F(hextolfpTest, IllegalChar) {
+ const char *str = "10000000.0000h000"; // Illegal character h.
+ l_fp actual;
+
+ ASSERT_FALSE(hextolfp(str, &actual));
+}
--- /dev/null
+#include "testcalshims.h"
+#include "unity.h"
+#include "lfptest.h"
+
+
+void test_PositiveInteger(void) {
+ const char *str = "00001000.00000000";
+ l_fp actual;
+
+ l_fp expected = {4096, 0}; // 16^3, no fraction part.
+
+ TEST_ASSERT_TRUE(hextolfp(str, &actual));
+ TEST_ASSERT_TRUE(IsEqual(expected, actual));
+}
+
+/*
+TEST_F(hextolfpTest, NegativeInteger) {
+ const char *str = "ffffffff.00000000"; // -1 decimal
+ l_fp actual;
+
+ l_fp expected = {-1, 0};
+
+ ASSERT_TRUE(hextolfp(str, &actual));
+ EXPECT_TRUE(IsEqual(expected, actual));
+}
+
+TEST_F(hextolfpTest, PositiveFraction) {
+ const char *str = "00002000.80000000"; // 8196.5 decimal
+ l_fp actual;
+
+ l_fp expected = {8192, HALF};
+
+ ASSERT_TRUE(hextolfp(str, &actual));
+ EXPECT_TRUE(IsEqual(expected, actual));
+}
+
+TEST_F(hextolfpTest, NegativeFraction) {
+ const char *str = "ffffffff.40000000"; // -1 + 0.25 decimal
+ l_fp actual;
+
+ l_fp expected = {-1, QUARTER}; //-1 + 0.25
+
+ ASSERT_TRUE(hextolfp(str, &actual));
+ EXPECT_TRUE(IsEqual(expected, actual));
+}
+
+TEST_F(hextolfpTest, IllegalNumberOfInteger) {
+ const char *str = "1000000.00000000"; // Missing one digit in integral part.
+ l_fp actual;
+
+ ASSERT_FALSE(hextolfp(str, &actual));
+}
+
+TEST_F(hextolfpTest, IllegalChar) {
+ const char *str = "10000000.0000h000"; // Illegal character h.
+ l_fp actual;
+
+ ASSERT_FALSE(hextolfp(str, &actual));
+}
+
+*/
#ifndef NTP_TESTS_LFPTEST_H
#define NTP_TESTS_LFPTEST_H
+//#include "libntptest.h"
+//Including this gives some error during compilation.
+//Hence right now commenting it out, as it is not required currently.
+
+#include "ntp_fp.h"
+
+int IsEqual(const l_fp expected, const l_fp actual) {
+ if (L_ISEQU(&expected, &actual)) {
+ return 1==1;
+ } else {
+ return 1==2;
+ }
+
+}
+
+#endif
+
+
+/*
+#ifndef NTP_TESTS_LFPTEST_H
+#define NTP_TESTS_LFPTEST_H
+
#include "libntptest.h"
extern "C" {
static const int32 QUARTER_PROMILLE_APPRX = 1073742L;
};
-#endif /* NTP_TESTS_LFPTEST_H */
+#endif
+*/
+/* NTP_TESTS_LFPTEST_H */