]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
t-ntp_scanner.c:
authorDamir Tomic <viperus@ntp.org>
Thu, 20 Aug 2015 15:13:37 +0000 (17:13 +0200)
committerDamir Tomic <viperus@ntp.org>
Thu, 20 Aug 2015 15:13:37 +0000 (17:13 +0200)
  Rename: tests/ntpd/ntp_scanner.c -> tests/ntpd/t-ntp_scanner.c
  new static functions tested
run-t-ntp_scanner.c:
  Rename: tests/ntpd/run-ntp_scanner.c -> tests/ntpd/run-t-ntp_scanner.c
Makefile.am:
  updates required for include *.c to work
run-t-ntp_scanner.c:
  update

bk: 55d5eea1BJkoKTz-k8BQ9jdqvc65kw

tests/ntpd/Makefile.am
tests/ntpd/ntp_scanner.c [deleted file]
tests/ntpd/run-t-ntp_scanner.c [moved from tests/ntpd/run-ntp_scanner.c with 63% similarity]
tests/ntpd/t-ntp_scanner.c [new file with mode: 0644]

index 55bef305dbef49fd0acdc073327d8f6df383004d..a72533ed6180e7be56883d92642d612c6002b082 100644 (file)
@@ -162,17 +162,18 @@ test_ntp_scanner_CFLAGS =         \
 
 test_ntp_scanner_LDADD =               \
        $(unity_tests_LDADD)            \
-       $(top_builddir)/ntpd/ntp_scanner.o      \
+       $(top_builddir)/ntpd/ntp_config.o       \
+       $(top_builddir)/ntpd/ntp_parser.o       \       
        $(NULL)
 
 test_ntp_scanner_SOURCES =                     \
-       ntp_scanner.c                           \
-       run-ntp_scanner.c                       \
+       t-ntp_scanner.c                         \
+       run-t-ntp_scanner.c                     \
        $(srcdir)/../libntp/test-libntp.c       \
        $(NULL)
 
-$(srcdir)/run-ntp_scanner.c: $(srcdir)/ntp_scanner.c $(std_unity_list)
-       $(run_unity) ntp_scanner.c run-ntp_scanner.c
+$(srcdir)/run-t-ntp_scanner.c: $(srcdir)/t-ntp_scanner.c $(std_unity_list)
+       $(run_unity) t-ntp_scanner.c run-t-ntp_scanner.c
 
 
 TESTS =
diff --git a/tests/ntpd/ntp_scanner.c b/tests/ntpd/ntp_scanner.c
deleted file mode 100644 (file)
index 1bbe9fe..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "config.h"
-
-#include "unity.h"
-
-//#include <stdio.h>
-//#include <ctype.h>
-//#include <stdlib.h>
-//#include <errno.h>
-//#include <string.h>
-
-//#include "ntpd.h"
-//#include "ntp_config.h"
-//#include "ntpsim.h"
-#include "ntp_scanner.h"
-//#include "ntp_parser.h"
-
-
-/* ntp_keyword.h declares finite state machine and token text */
-//#include "ntp_keyword.h"
-
-void test_keywordIncorrectToken(void);
-void test_keywordServerToken(void);
-void test_DropUninitializedStack(void);
-void test_IncorrectlyInitializeLexStack(void);
-void test_InitializeLexStack(void);
-
-
-void test_keywordIncorrectToken(void){
-       char * temp = keyword(999);
-       //printf("%s\n",temp);
-       TEST_ASSERT_EQUAL_STRING("(keyword not found)",temp);
-}
-
-void test_keywordServerToken(void){
-       char * temp = keyword(401);
-       //printf("%s",temp); //143 or 401 ?
-       TEST_ASSERT_EQUAL_STRING("server",temp);
-}
-
-void test_DropUninitializedStack(void){
-       lex_drop_stack();
-}
-
-void test_IncorrectlyInitializeLexStack(void){
-
-       TEST_ASSERT_FALSE(lex_init_stack(NULL,NULL));
-       lex_drop_stack();
-}
-
-void test_InitializeLexStack(void){
-       
-       //Some sort of server is required for this to work.
-       sockaddr_u *    remote_addr;
-       char origin[128] ={ "" } ;
-       strcat(origin,"127.0.0.1");
-       //snprintf(origin, sizeof(origin), "remote config from %s", stoa(remote_addr));
-       TEST_ASSERT_TRUE(lex_init_stack(origin,NULL)); //path, mode -> NULL is ok!
-       lex_drop_stack();
-}
-
-void test_PopEmptyStack(void){
-       int temp = lex_pop_file();
-
-       TEST_ASSERT_FALSE(temp);
-}
similarity index 63%
rename from tests/ntpd/run-ntp_scanner.c
rename to tests/ntpd/run-t-ntp_scanner.c
index 7731e04feb0f7d701ab5331e6b1ac389b8c8e5d2..1d8d8d8698456031c1058381c0cc5ccecc743f49 100644 (file)
@@ -23,7 +23,6 @@
 #include <setjmp.h>
 #include <stdio.h>
 #include "config.h"
-#include "ntp_scanner.h"
 
 //=======External Functions This Runner Calls=====
 extern void setUp(void);
@@ -33,6 +32,12 @@ extern void test_keywordServerToken(void);
 extern void test_DropUninitializedStack(void);
 extern void test_IncorrectlyInitializeLexStack(void);
 extern void test_InitializeLexStack(void);
+extern void test_PopEmptyStack(void);
+extern void test_IsInteger(void);
+extern void test_IsUint(void);
+extern void test_IsDouble(void);
+extern void test_SpecialSymbols(void);
+extern void test_EOC(void);
 
 
 //=======Test Reset Option=====
@@ -50,12 +55,18 @@ char *progname;
 int main(int argc, char *argv[])
 {
   progname = argv[0];
-  UnityBegin("ntp_scanner.c");
-  RUN_TEST(test_keywordIncorrectToken, 20);
-  RUN_TEST(test_keywordServerToken, 21);
-  RUN_TEST(test_DropUninitializedStack, 22);
-  RUN_TEST(test_IncorrectlyInitializeLexStack, 23);
-  RUN_TEST(test_InitializeLexStack, 24);
+  UnityBegin("t-ntp_scanner.c");
+  RUN_TEST(test_keywordIncorrectToken, 21);
+  RUN_TEST(test_keywordServerToken, 22);
+  RUN_TEST(test_DropUninitializedStack, 23);
+  RUN_TEST(test_IncorrectlyInitializeLexStack, 24);
+  RUN_TEST(test_InitializeLexStack, 25);
+  RUN_TEST(test_PopEmptyStack, 61);
+  RUN_TEST(test_IsInteger, 69);
+  RUN_TEST(test_IsUint, 87);
+  RUN_TEST(test_IsDouble, 99);
+  RUN_TEST(test_SpecialSymbols, 111);
+  RUN_TEST(test_EOC, 120);
 
   return (UnityEnd());
 }
diff --git a/tests/ntpd/t-ntp_scanner.c b/tests/ntpd/t-ntp_scanner.c
new file mode 100644 (file)
index 0000000..9bc77c4
--- /dev/null
@@ -0,0 +1,136 @@
+#include "config.h"
+
+#include "unity.h"
+
+//#include <stdio.h>
+//#include <ctype.h>
+//#include <stdlib.h>
+//#include <errno.h>
+//#include <string.h>
+
+//#include "ntpd.h"
+//#include "ntp_config.h"
+//#include "ntpsim.h"
+//#include "ntp_scanner.h"
+//#include "ntp_parser.h"
+
+#include "ntp_scanner.c"
+/* ntp_keyword.h declares finite state machine and token text */
+//#include "ntp_keyword.h"
+
+void test_keywordIncorrectToken(void);
+void test_keywordServerToken(void);
+void test_DropUninitializedStack(void);
+void test_IncorrectlyInitializeLexStack(void);
+void test_InitializeLexStack(void);
+
+
+void test_keywordIncorrectToken(void){
+       char * temp = keyword(999);
+       //printf("%s\n",temp);
+       TEST_ASSERT_EQUAL_STRING("(keyword not found)",temp);
+}
+
+void test_keywordServerToken(void){
+       char * temp = keyword(401);
+       //printf("%s",temp); //143 or 401 ?
+       TEST_ASSERT_EQUAL_STRING("server",temp);
+}
+
+void test_DropUninitializedStack(void){
+       lex_drop_stack();
+}
+
+void test_IncorrectlyInitializeLexStack(void){
+
+       TEST_ASSERT_FALSE(lex_init_stack(NULL,NULL));
+       lex_drop_stack();
+}
+
+void test_InitializeLexStack(void){
+       
+       //Some sort of server is required for this to work.
+       sockaddr_u *    remote_addr;
+       char origin[128] ={ "" } ;
+       strcat(origin,"127.0.0.1");
+       //snprintf(origin, sizeof(origin), "remote config from %s", stoa(remote_addr));
+       TEST_ASSERT_TRUE(lex_init_stack(origin,NULL)); //path, mode -> NULL is ok!
+       lex_drop_stack();
+}
+
+void test_PopEmptyStack(void){
+       int temp = lex_pop_file();
+
+       TEST_ASSERT_FALSE(temp);
+}
+
+
+
+void test_IsInteger(void){ //boolean
+       int temp = is_integer("123");
+       TEST_ASSERT_TRUE(temp);
+       temp = is_integer("-999");
+       TEST_ASSERT_TRUE(temp);
+       temp = is_integer("0"); //what about -0?
+       TEST_ASSERT_TRUE(temp);
+       temp = is_integer("16.5");
+       TEST_ASSERT_FALSE(temp);
+       temp = is_integer("12ab");
+       TEST_ASSERT_FALSE(temp);
+       temp = is_integer("2147483647");
+       TEST_ASSERT_TRUE(temp);
+       temp = is_integer("2347483647"); //too big for signed int
+       TEST_ASSERT_FALSE(temp);
+
+}
+
+void test_IsUint(void){
+       int temp;
+       temp = is_u_int("-123");
+       TEST_ASSERT_FALSE(temp);
+       temp = is_u_int("0");
+       TEST_ASSERT_TRUE(temp); //-0 fails btw
+       temp = is_u_int("2347483647"); //fits into u_int
+       TEST_ASSERT_TRUE(temp);
+       temp = is_u_int("112347483647"); //too big even for uint
+       TEST_ASSERT_TRUE(temp);         
+}
+
+void test_IsDouble(void){
+       int temp;       
+       temp = is_double("0");
+       TEST_ASSERT_TRUE(temp);
+       temp = is_double("123");
+       TEST_ASSERT_TRUE(temp);
+       temp = is_double("123.45"); //DOESN'T WORK WITH 123,45, not sure if intented?
+       TEST_ASSERT_TRUE(temp);
+       temp = is_double("-123.45"); //DOESN'T WORK WITH 123,45, not sure if intented?
+       TEST_ASSERT_TRUE(temp);
+}
+
+void test_SpecialSymbols(void){
+       int temp ;
+       temp = is_special('a');
+       TEST_ASSERT_FALSE(temp);
+       temp = is_special('?');
+       TEST_ASSERT_FALSE(temp);
+
+}
+
+void test_EOC(void){
+       int temp;
+       if(old_config_style){
+               temp = is_EOC('\n');
+               TEST_ASSERT_TRUE(temp);
+       }
+       else {
+               temp = is_EOC(';');
+               TEST_ASSERT_TRUE(temp);
+       }
+       temp = is_EOC("A");
+       TEST_ASSERT_FALSE(temp);
+       temp = is_EOC('1');
+       TEST_ASSERT_FALSE(temp);
+
+}
+