]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Unity cleanup of sntp/tests/
authorHarlan Stenn <stenn@ntp.org>
Sat, 20 Jun 2015 02:39:45 +0000 (02:39 +0000)
committerHarlan Stenn <stenn@ntp.org>
Sat, 20 Jun 2015 02:39:45 +0000 (02:39 +0000)
bk: 5584d271x8MafHRsseZsylcgzih46A

21 files changed:
sntp/tests/Makefile.am
sntp/tests/c_fileHandlingTest.h [deleted file]
sntp/tests/c_sntptest.h [deleted file]
sntp/tests/crypto.cpp
sntp/tests/fileHandlingTest.h
sntp/tests/g_fileHandlingTest.h [new file with mode: 0644]
sntp/tests/g_keyFile.cpp
sntp/tests/g_kodDatabase.cpp
sntp/tests/g_kodFile.cpp
sntp/tests/g_networking.cpp
sntp/tests/g_sntptest.h [new file with mode: 0644]
sntp/tests/keyFile.c
sntp/tests/kodDatabase.c
sntp/tests/kodFile.c
sntp/tests/nameresolution.cpp
sntp/tests/networking.c
sntp/tests/packetHandling.cpp
sntp/tests/packetProcessing.cpp
sntp/tests/run-keyFile.c
sntp/tests/sntptest.h
sntp/tests/utilities.cpp

index 32b6ff210a656ea137b2df3aca89d3251bb08690..591fd101e80d11e382b6fd7152023a9aac2a8deb 100644 (file)
@@ -44,10 +44,10 @@ tests_SOURCES =                     \
        $(NULL)
 
 noinst_HEADERS =               \
-       sntptest.h              \
-       c_sntptest.h            \
        fileHandlingTest.h      \
-       c_fileHandlingTest.h    \
+       sntptest.h              \
+       g_fileHandlingTest.h    \
+       g_sntptest.h            \
        $(NULL)
 
 dist_check_SCRIPTS =   tests-runner
@@ -114,6 +114,7 @@ BUILT_SOURCES +=                    \
        $(srcdir)/run-networking.c      \
        $(NULL)
 
+
 test_keyFile_CFLAGS =                  \
        -I$(top_srcdir)/unity           \
        $(NULL)
diff --git a/sntp/tests/c_fileHandlingTest.h b/sntp/tests/c_fileHandlingTest.h
deleted file mode 100644 (file)
index cd1756d..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#ifndef FILE_HANDLING_TEST_H
-#define FILE_HANDLING_TEST_H
-
-#include "stdlib.h"
-#include "c_sntptest.h"
-
-#include <string.h>
-#include <unistd.h>
-
-
-enum DirectoryType {
-       INPUT_DIR = 0,
-       OUTPUT_DIR = 1
-};
-
-const char * CreatePath(const char* filename, enum DirectoryType argument) {
-       
-        char * path = malloc (sizeof (char) * 256);
-
-       /*
-       if (m_params.size() >= argument + 1) {
-               path = m_params[argument];
-       }
-
-       if (path[path.size()-1] != DIR_SEP && !path.empty()) {
-               path.append(1, DIR_SEP);
-       }
-       */
-       //strcpy(path,filename);
-       //path.append(filename);
-
-       //return path;
-
-       char cwd[1024];
-       if (getcwd(cwd, sizeof(cwd)) != NULL)
-               printf("Current working dir: %s\n", cwd);
-       
-       if(strstr(cwd,"sub/") == NULL){
-               strcpy(path,"../../../sntp/tests/data/");
-       }
-       else
-       if(strstr(cwd,"_build") == NULL){ //if it's run as make distcheck, it's in a different directory!
-               strcpy(path,"../../../sntp/tests/data/");
-       }
-
-       else {
-               strcpy(path,"../../../../sntp/tests/data/");
-       }
-
-       //strcpy(path,"");
-       strcat(path,filename);
-       printf("PATH IS : %s\n",path);
-       return path;
-}
-
-int GetFileSize(FILE *file) {
-
-       fseek(file, 0L, SEEK_END);
-       int length = ftell(file);
-       fseek(file, 0L, SEEK_SET);
-       
-       //int initial = file.tellg();
-
-       //file.seekg(0, ios::end);
-       //int length = file.tellg();
-       //file.seekg(initial);
-
-       return length;
-}
-
-bool CompareFileContent(FILE* expected, FILE* actual) {
-       int currentLine = 1;
-
-       char * actualLine=NULL;
-       char * expectedLine = NULL;
-       size_t lenAct = 0;
-       size_t lenExp = 0;
-       ssize_t readAct,readExp;
-       
-       while (  ( (readAct = getline(&actualLine, &lenAct, actual)) != -1) && ( (readExp = getline(&expectedLine, &lenExp, expected)) != -1  )    ) {
-
-               //printf("%s",actualLine);
-               //printf("%s",expectedLine);
-       
-               if( strcmp(actualLine,expectedLine) !=0 ){
-                       printf("Comparision failed on line %d",currentLine);
-                       return FALSE;
-               }
-
-               //I removed this and modified the test kodFile.c, because there shouldn't be any ASSERTs in .h files!
-               //TEST_ASSERT_EQUAL_STRING(actualLine,expectedLine);//EXPECT_EQ(expectedLine, actualLine) << "Comparision failed on line " << currentLine;
-               currentLine++;
-       }
-
-       return TRUE;
-}
-
-void ClearFile(const char * filename) {
-       FILE * clear = fopen(filename, "w");//ios::trunc); //similar to truncate, I GUESS???!
-       
-       //I removed this because there shouldn't be any ASSERTs in .h files!
-       //TEST_ASSERT_TRUE(clear != NULL);
-       fclose(clear);
-}
-
-
-#endif // FILE_HANDLING_TEST_H
diff --git a/sntp/tests/c_sntptest.h b/sntp/tests/c_sntptest.h
deleted file mode 100644 (file)
index bb31f06..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#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 a6f89f5aa84214c9accd676af9b7bc67e970dbb9..d9278127ad32e69855824e73bc8518c4178c0fd8 100644 (file)
@@ -1,4 +1,4 @@
-#include "sntptest.h"
+#include "g_sntptest.h"
 
 extern "C" {
 #include "crypto.h"
index 502a248b9bd084f502c6057905d0b0c1ca1a257a..0821c2e5d45d54fa61d56860c119d8fb82a6f510 100644 (file)
 #ifndef FILE_HANDLING_TEST_H
 #define FILE_HANDLING_TEST_H
 
+#include "stdlib.h"
 #include "sntptest.h"
 
-#include <fstream>
-#include <string>
+#include <string.h>
+#include <unistd.h>
 
-using std::ifstream;
-using std::string;
-using std::ios;
 
-class fileHandlingTest : public sntptest {
-protected:
-       enum DirectoryType {
-               INPUT_DIR = 0,
-               OUTPUT_DIR = 1
-       };
-
-       std::string CreatePath(const char* filename, DirectoryType argument) {
-               std::string path;
+enum DirectoryType {
+       INPUT_DIR = 0,
+       OUTPUT_DIR = 1
+};
 
-               if (m_params.size() >= argument + 1) {
-                       path = m_params[argument];
-               }
+const char * CreatePath(const char* filename, enum DirectoryType argument) {
+       
+        char * path = malloc (sizeof (char) * 256);
 
-               if (path[path.size()-1] != DIR_SEP && !path.empty()) {
-                       path.append(1, DIR_SEP);
-               }
-               path.append(filename);
+       /*
+       if (m_params.size() >= argument + 1) {
+               path = m_params[argument];
+       }
 
-               return path;
+       if (path[path.size()-1] != DIR_SEP && !path.empty()) {
+               path.append(1, DIR_SEP);
        }
+       */
+       //strcpy(path,filename);
+       //path.append(filename);
 
-       int GetFileSize(ifstream& file) {
-               int initial = file.tellg();
+       //return path;
 
-               file.seekg(0, ios::end);
-               int length = file.tellg();
-               file.seekg(initial);
+       char cwd[1024];
+       if (getcwd(cwd, sizeof(cwd)) != NULL)
+               printf("Current working dir: %s\n", cwd);
+       
+       if(strstr(cwd,"sub/") == NULL){
+               strcpy(path,"../../../sntp/tests/data/");
+       }
+       else
+       if(strstr(cwd,"_build") == NULL){ //if it's run as make distcheck, it's in a different directory!
+               strcpy(path,"../../../sntp/tests/data/");
+       }
 
-               return length;
+       else {
+               strcpy(path,"../../../../sntp/tests/data/");
        }
 
-       void CompareFileContent(ifstream& expected, ifstream& actual) {
-               int currentLine = 1;
-               while (actual.good() && expected.good()) {
-                       string actualLine, expectedLine;
-                       getline(actual, actualLine);
-                       getline(expected, expectedLine);
-                       
-                       EXPECT_EQ(expectedLine, actualLine) << "Comparision failed on line " << currentLine;
-                       currentLine++;
+       //strcpy(path,"");
+       strcat(path,filename);
+       printf("PATH IS : %s\n",path);
+       return path;
+}
+
+int GetFileSize(FILE *file) {
+
+       fseek(file, 0L, SEEK_END);
+       int length = ftell(file);
+       fseek(file, 0L, SEEK_SET);
+       
+       //int initial = file.tellg();
+
+       //file.seekg(0, ios::end);
+       //int length = file.tellg();
+       //file.seekg(initial);
+
+       return length;
+}
+
+bool CompareFileContent(FILE* expected, FILE* actual) {
+       int currentLine = 1;
+
+       char actualLine[1024];
+       char expectedLine[1024];
+       size_t lenAct = sizeof actualLine;
+       size_t lenExp = sizeof expectedLine;
+       
+       while (  ( (fgets(actualLine, lenAct, actual)) != NULL)
+             && ( (fgets(expectedLine, lenExp, expected)) != NULL )
+             ) {
+
+               //printf("%s",actualLine);
+               //printf("%s",expectedLine);
+       
+               if( strcmp(actualLine,expectedLine) !=0 ){
+                       printf("Comparision failed on line %d",currentLine);
+                       return FALSE;
                }
-       }
 
-       void ClearFile(const std::string& filename) {
-               std::ofstream clear(filename.c_str(), ios::trunc);
-               ASSERT_TRUE(clear.good());
-               clear.close();
+               //I removed this and modified the test kodFile.c, because there shouldn't be any ASSERTs in .h files!
+               //TEST_ASSERT_EQUAL_STRING(actualLine,expectedLine);//EXPECT_EQ(expectedLine, actualLine) << "Comparision failed on line " << currentLine;
+               currentLine++;
        }
-};
+
+       return TRUE;
+}
+
+void ClearFile(const char * filename) {
+       FILE * clear = fopen(filename, "w");//ios::trunc); //similar to truncate, I GUESS???!
+       
+       //I removed this because there shouldn't be any ASSERTs in .h files!
+       //TEST_ASSERT_TRUE(clear != NULL);
+       fclose(clear);
+}
+
 
 #endif // FILE_HANDLING_TEST_H
diff --git a/sntp/tests/g_fileHandlingTest.h b/sntp/tests/g_fileHandlingTest.h
new file mode 100644 (file)
index 0000000..7c8a78a
--- /dev/null
@@ -0,0 +1,64 @@
+#ifndef FILE_HANDLING_TEST_H
+#define FILE_HANDLING_TEST_H
+
+#include "g_sntptest.h"
+
+#include <fstream>
+#include <string>
+
+using std::ifstream;
+using std::string;
+using std::ios;
+
+class fileHandlingTest : public sntptest {
+protected:
+       enum DirectoryType {
+               INPUT_DIR = 0,
+               OUTPUT_DIR = 1
+       };
+
+       std::string CreatePath(const char* filename, DirectoryType argument) {
+               std::string path;
+
+               if (m_params.size() >= argument + 1) {
+                       path = m_params[argument];
+               }
+
+               if (path[path.size()-1] != DIR_SEP && !path.empty()) {
+                       path.append(1, DIR_SEP);
+               }
+               path.append(filename);
+
+               return path;
+       }
+
+       int GetFileSize(ifstream& file) {
+               int initial = file.tellg();
+
+               file.seekg(0, ios::end);
+               int length = file.tellg();
+               file.seekg(initial);
+
+               return length;
+       }
+
+       void CompareFileContent(ifstream& expected, ifstream& actual) {
+               int currentLine = 1;
+               while (actual.good() && expected.good()) {
+                       string actualLine, expectedLine;
+                       getline(actual, actualLine);
+                       getline(expected, expectedLine);
+                       
+                       EXPECT_EQ(expectedLine, actualLine) << "Comparision failed on line " << currentLine;
+                       currentLine++;
+               }
+       }
+
+       void ClearFile(const std::string& filename) {
+               std::ofstream clear(filename.c_str(), ios::trunc);
+               ASSERT_TRUE(clear.good());
+               clear.close();
+       }
+};
+
+#endif // FILE_HANDLING_TEST_H
index 3efbe8f8d8f68600e23369a191a955b3da3d7dfe..e144ba0735e088d8cfc8bc298dea0b915ccca806 100644 (file)
@@ -1,4 +1,4 @@
-#include "fileHandlingTest.h"
+#include "g_fileHandlingTest.h"
 
 extern "C" {
 #include "crypto.h"
index 515f4337a3e4a2cee99da6b8353d5a5507800d0c..bdac9eb7e0c6775db8fe2eab748567001817455b 100644 (file)
@@ -1,4 +1,4 @@
-#include "sntptest.h"
+#include "g_sntptest.h"
 
 extern "C" {
 #include "kod_management.h"
index e1775f6374fa6c6c50d5b355fb90ec3ac215d64e..767c6958334783c6d807dc1b28118e169f499664 100644 (file)
@@ -1,4 +1,4 @@
-#include "fileHandlingTest.h"
+#include "g_fileHandlingTest.h"
 
 extern "C" {
 #include "kod_management.h"
index 1d6ad6c44065bafb3eb4f23cb0792fb654a36455..d75f4a5cc6800fe9c5f8499fc94de5ba735ff27f 100644 (file)
@@ -1,4 +1,4 @@
-#include "sntptest.h"
+#include "g_sntptest.h"
 
 extern "C" {
 #include "networking.h"
diff --git a/sntp/tests/g_sntptest.h b/sntp/tests/g_sntptest.h
new file mode 100644 (file)
index 0000000..d5add9c
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef SNTPTEST_H
+#define SNTPTEST_H
+
+#include "tests_main.h"
+
+extern "C" {
+#include "ntp_stdlib.h"
+#include "sntp-opts.h"
+};
+
+class sntptest : public ntptest {
+protected:
+       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 b8fba41fed4f4ce4326467df0a91d0fd474e59e3..3769947c500890a0c491a1e8e3dea69386a47e44 100644 (file)
@@ -1,5 +1,5 @@
 #include "config.h"
-#include "c_fileHandlingTest.h"
+#include "fileHandlingTest.h"
 
 #include "ntp_stdlib.h"
 #include "ntp_types.h"
index 25e7b12d8bfe46bcdfa6fde7fdf60af70b3e19fb..a6b86d06bf00c1c33ef2541d205acf0903be7370 100644 (file)
@@ -1,7 +1,7 @@
 #include "config.h"
 
 #include "ntp_types.h"
-#include "c_sntptest.h"
+#include "sntptest.h"
 #include "ntp_stdlib.h"
 #include "sntp-opts.h"
 
index 9bc616b610926f666d44fe22f266e46aead1abf4..7daec212692e2915f8e92abe0f063c11b58a9ec0 100644 (file)
@@ -3,7 +3,7 @@
 #include "ntp_stdlib.h" // For estrdup()
 
 
-#include "c_fileHandlingTest.h"
+#include "fileHandlingTest.h"
 
 #include "kod_management.h"
 
index d7d6193bfcb8fb226b66c12b895daca76553698f..9b48189c8fc8226cce53dfb6c628074519a06842 100644 (file)
@@ -1,4 +1,4 @@
-#include "sntptest.h"
+#include "g_sntptest.h"
 
 extern "C" {
 #include "networking.h"
index b2b5a13070afed1f087c5e80be0fae503d27fc0d..e2e37123952e78d135ded3f15ebcb261d2936237 100644 (file)
@@ -1,6 +1,6 @@
 #include "config.h"
 
-#include "c_sntptest.h"
+#include "sntptest.h"
 
 #include "networking.h"
 
index ef17489bd6b90ab2964d33e26be3301959294219..bd5b14e0d70c5333ed430d7cc9ed308d946ea592 100644 (file)
@@ -1,4 +1,4 @@
-#include "sntptest.h"
+#include "g_sntptest.h"
 
 extern "C" {
 #include "kod_management.h"
index 322b8938ecc2f54410e545029cd7d912b55ad5f2..85659a43dda5a8c33adf9aa8136c94835aac6dfe 100644 (file)
@@ -1,4 +1,4 @@
-#include "sntptest.h"
+#include "g_sntptest.h"
 
 extern "C" {
 #include "networking.h"
index 43b7f9466c7eb557b96e5c1c2e4de030a5a831c8..0a6380d33b35f684f05af9096f7f6b7285698856 100644 (file)
@@ -47,7 +47,6 @@ char *progname;
 int main(int argc, char *argv[])
 {
   progname = argv[0];
-  //printf("NUM: %d , %s\n",argc,argv[0]);
   Unity.TestFile = "keyFile.c";
   UnityBegin("keyFile.c");
   RUN_TEST(test_ReadEmptyKeyFile, 53);
index d5add9cbf465e6623d84352fb57e4e5d52621c1c..bb31f068e0bd4bac4bb13f77c3f4049e26275375 100644 (file)
@@ -1,35 +1,32 @@
 #ifndef SNTPTEST_H
 #define SNTPTEST_H
 
-#include "tests_main.h"
+//#include "tests_main.h"
 
-extern "C" {
 #include "ntp_stdlib.h"
 #include "sntp-opts.h"
-};
-
-class sntptest : public ntptest {
-protected:
-       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);
-       }
-};
+
+
+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 4c8c305350649570627d011a0c00f26c500e26b6..2f02cf58df709bc6605ed820aa6014faea71e684 100644 (file)
@@ -1,5 +1,5 @@
-#include "sntptest.h"
-#include "fileHandlingTest.h"
+#include "g_sntptest.h"
+#include "g_fileHandlingTest.h"
 
 extern "C" {
 #include "main.h"