]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
run-test-networking.c, c_sntptest.h:
authorDamir Tomic <viperus@ntp.org>
Wed, 17 Jun 2015 07:35:55 +0000 (09:35 +0200)
committerDamir Tomic <viperus@ntp.org>
Wed, 17 Jun 2015 07:35:55 +0000 (09:35 +0200)
  new file
networking.c:
  added c_sntptest.h include
Makefile.am:
  modified so Makefile.am runs unity tests and gtests

bk: 5581235bznlwxp9qgGjldrNeZYbRCQ

sntp/tests/Makefile.am
sntp/tests/c_sntptest.h [new file with mode: 0644]
sntp/tests/networking.c
sntp/tests/run-test-networking.c [new file with mode: 0644]

index 804acb19c0b1f8e65b665c5d4368e024094895ef..4b75e5f99b39aec340721004e94d378db1bae0c9 100644 (file)
@@ -2,17 +2,22 @@ NULL =
 BUILT_SOURCES =
 CLEANFILES =
 
-run_unity =    cd $(srcdir) && ruby /unity/auto/generate_test_runner.rb
+run_unity =    cd $(srcdir) && ruby ../../sntp/unity/auto/generate_test_runner.rb
 
 check_PROGRAMS =               \
        test-networking         \
        $(NULL)
 
-#maybe an issue where with if GTEST...
-if BUILD_SNTP
+if GTEST_AVAILABLE
 check_PROGRAMS += tests
+else
+EXTRA_PROGRAMS = tests
 endif
 
+#if BUILD_SNTP
+#check_PROGRAMS += tests
+#endif
+
 base_SOURCES =                         \
        $(srcdir)/../tests_main.cpp     \
        $(NULL)
@@ -31,6 +36,7 @@ tests_SOURCES =                       \
 
 noinst_HEADERS =               \
        sntptest.h              \
+       c_sntptest.h            \
        fileHandlingTest.h      \
        $(NULL)
 
@@ -93,16 +99,16 @@ AM_LDFLAGS = $(LDFLAGS_NTP)
 
 
 test_networking_CFLAGS =                       \
-       -I$(top_srcdir)/sntp/unity      \
+       -I$(top_srcdir)/unity                   \
        $(NULL)
 
 test_networking_LDADD =                                \
        $(LDADD)                                \
-       $(top_builddir)/sntp/unity/libunity.a   \
+       $(top_builddir)/unity/libunity.a        \
        $(NULL)
 
 BUILT_SOURCES +=                                       \
-       $(run_unity) networking.c run-test-networking.c \
+       $(srcdir)/networking.c run-test-networking.c    \
        $(NULL)
 
 test_networking_SOURCES =                      \
@@ -116,8 +122,11 @@ $(srcdir)/run-test-networking.c: $(srcdir)/networking.c $(std_unity_list)
 TESTS = 
 
 if !NTP_CROSSCOMPILE
-TESTS += tests-runner
+TESTS += $(check_PROGRAMS)
 endif
+#if !NTP_CROSSCOMPILE
+#TESTS += tests-runner
+#endif
 
 ## ensure ../libsntp.a is built
 
@@ -133,8 +142,8 @@ check-libsntp: ../libsntp.a
 ## check-libntp.mf - automake fragment
 ## slightly adapted for deeper directory
 
-BUILT_SOURCES  += check-libntp
-CLEANFILES     += check-libntp
+BUILT_SOURCES  += check-libntp check-libunity
+CLEANFILES     += check-libntp check-libunity
 
 check-libntp: ../../libntp/libntp.a
        @echo stamp > $@
@@ -142,5 +151,11 @@ check-libntp: ../../libntp/libntp.a
 ../../libntp/libntp.a:
        cd ../../libntp && $(MAKE) $(AM_MAKEFLAGS) libntp.a
 
+check-libunity: ../sntp/unity/libunity.a
+       @echo stamp > $@
+
+../sntp/unity/libunity.a:
+       cd ../unity && $(MAKE) $(AM_MAKEFLAGS) libunity.a
+
 include $(top_srcdir)/depsver.mf
 include $(top_srcdir)/includes.mf
diff --git a/sntp/tests/c_sntptest.h b/sntp/tests/c_sntptest.h
new file mode 100644 (file)
index 0000000..bb31f06
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef SNTPTEST_H
+#define SNTPTEST_H
+
+//#include "tests_main.h"
+
+#include "ntp_stdlib.h"
+#include "sntp-opts.h"
+
+
+sntptest() {
+       optionSaveState(&sntpOptions);
+}
+/*
+~sntptest() {
+       optionRestore(&sntpOptions);
+}
+*/
+void ActivateOption(const char* option, const char* argument) {
+       const int ARGV_SIZE = 4;
+
+       char* opts[ARGV_SIZE];
+       
+       opts[0] = estrdup("sntpopts");
+       opts[1] = estrdup(option);
+       opts[2] = estrdup(argument);
+       opts[3] = estrdup("127.0.0.1");
+
+       optionProcess(&sntpOptions, ARGV_SIZE, opts);
+}
+
+
+#endif // SNTPTEST_H
index 34df1c15c52af187f39f64b0154b84b96b6446bc..b2b5a13070afed1f087c5e80be0fae503d27fc0d 100644 (file)
@@ -1,4 +1,7 @@
-#include "sntptest.h"
+#include "config.h"
+
+#include "c_sntptest.h"
 
 #include "networking.h"
 
+#include "unity.h"
diff --git a/sntp/tests/run-test-networking.c b/sntp/tests/run-test-networking.c
new file mode 100644 (file)
index 0000000..d5e822c
--- /dev/null
@@ -0,0 +1,49 @@
+/* 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);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "networking.c";
+  UnityBegin("networking.c");
+
+  return (UnityEnd());
+}