From: Harlan Stenn Date: Sat, 20 Jun 2015 02:39:45 +0000 (+0000) Subject: Unity cleanup of sntp/tests/ X-Git-Tag: NTP_4_3_43~2^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dae494a81419d007d85770334b247e073233ee66;p=thirdparty%2Fntp.git Unity cleanup of sntp/tests/ bk: 5584d271x8MafHRsseZsylcgzih46A --- diff --git a/sntp/tests/Makefile.am b/sntp/tests/Makefile.am index 32b6ff210..591fd101e 100644 --- a/sntp/tests/Makefile.am +++ b/sntp/tests/Makefile.am @@ -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 index cd1756d7e..000000000 --- a/sntp/tests/c_fileHandlingTest.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef FILE_HANDLING_TEST_H -#define FILE_HANDLING_TEST_H - -#include "stdlib.h" -#include "c_sntptest.h" - -#include -#include - - -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 index bb31f068e..000000000 --- a/sntp/tests/c_sntptest.h +++ /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 diff --git a/sntp/tests/crypto.cpp b/sntp/tests/crypto.cpp index a6f89f5aa..d9278127a 100644 --- a/sntp/tests/crypto.cpp +++ b/sntp/tests/crypto.cpp @@ -1,4 +1,4 @@ -#include "sntptest.h" +#include "g_sntptest.h" extern "C" { #include "crypto.h" diff --git a/sntp/tests/fileHandlingTest.h b/sntp/tests/fileHandlingTest.h index 502a248b9..0821c2e5d 100644 --- a/sntp/tests/fileHandlingTest.h +++ b/sntp/tests/fileHandlingTest.h @@ -1,64 +1,108 @@ #ifndef FILE_HANDLING_TEST_H #define FILE_HANDLING_TEST_H +#include "stdlib.h" #include "sntptest.h" -#include -#include +#include +#include -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 index 000000000..7c8a78a14 --- /dev/null +++ b/sntp/tests/g_fileHandlingTest.h @@ -0,0 +1,64 @@ +#ifndef FILE_HANDLING_TEST_H +#define FILE_HANDLING_TEST_H + +#include "g_sntptest.h" + +#include +#include + +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 diff --git a/sntp/tests/g_keyFile.cpp b/sntp/tests/g_keyFile.cpp index 3efbe8f8d..e144ba073 100644 --- a/sntp/tests/g_keyFile.cpp +++ b/sntp/tests/g_keyFile.cpp @@ -1,4 +1,4 @@ -#include "fileHandlingTest.h" +#include "g_fileHandlingTest.h" extern "C" { #include "crypto.h" diff --git a/sntp/tests/g_kodDatabase.cpp b/sntp/tests/g_kodDatabase.cpp index 515f4337a..bdac9eb7e 100644 --- a/sntp/tests/g_kodDatabase.cpp +++ b/sntp/tests/g_kodDatabase.cpp @@ -1,4 +1,4 @@ -#include "sntptest.h" +#include "g_sntptest.h" extern "C" { #include "kod_management.h" diff --git a/sntp/tests/g_kodFile.cpp b/sntp/tests/g_kodFile.cpp index e1775f637..767c69583 100644 --- a/sntp/tests/g_kodFile.cpp +++ b/sntp/tests/g_kodFile.cpp @@ -1,4 +1,4 @@ -#include "fileHandlingTest.h" +#include "g_fileHandlingTest.h" extern "C" { #include "kod_management.h" diff --git a/sntp/tests/g_networking.cpp b/sntp/tests/g_networking.cpp index 1d6ad6c44..d75f4a5cc 100644 --- a/sntp/tests/g_networking.cpp +++ b/sntp/tests/g_networking.cpp @@ -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 index 000000000..d5add9cbf --- /dev/null +++ b/sntp/tests/g_sntptest.h @@ -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 diff --git a/sntp/tests/keyFile.c b/sntp/tests/keyFile.c index b8fba41fe..3769947c5 100644 --- a/sntp/tests/keyFile.c +++ b/sntp/tests/keyFile.c @@ -1,5 +1,5 @@ #include "config.h" -#include "c_fileHandlingTest.h" +#include "fileHandlingTest.h" #include "ntp_stdlib.h" #include "ntp_types.h" diff --git a/sntp/tests/kodDatabase.c b/sntp/tests/kodDatabase.c index 25e7b12d8..a6b86d06b 100644 --- a/sntp/tests/kodDatabase.c +++ b/sntp/tests/kodDatabase.c @@ -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" diff --git a/sntp/tests/kodFile.c b/sntp/tests/kodFile.c index 9bc616b61..7daec2126 100644 --- a/sntp/tests/kodFile.c +++ b/sntp/tests/kodFile.c @@ -3,7 +3,7 @@ #include "ntp_stdlib.h" // For estrdup() -#include "c_fileHandlingTest.h" +#include "fileHandlingTest.h" #include "kod_management.h" diff --git a/sntp/tests/nameresolution.cpp b/sntp/tests/nameresolution.cpp index d7d6193bf..9b48189c8 100644 --- a/sntp/tests/nameresolution.cpp +++ b/sntp/tests/nameresolution.cpp @@ -1,4 +1,4 @@ -#include "sntptest.h" +#include "g_sntptest.h" extern "C" { #include "networking.h" diff --git a/sntp/tests/networking.c b/sntp/tests/networking.c index b2b5a1307..e2e371239 100644 --- a/sntp/tests/networking.c +++ b/sntp/tests/networking.c @@ -1,6 +1,6 @@ #include "config.h" -#include "c_sntptest.h" +#include "sntptest.h" #include "networking.h" diff --git a/sntp/tests/packetHandling.cpp b/sntp/tests/packetHandling.cpp index ef17489bd..bd5b14e0d 100644 --- a/sntp/tests/packetHandling.cpp +++ b/sntp/tests/packetHandling.cpp @@ -1,4 +1,4 @@ -#include "sntptest.h" +#include "g_sntptest.h" extern "C" { #include "kod_management.h" diff --git a/sntp/tests/packetProcessing.cpp b/sntp/tests/packetProcessing.cpp index 322b8938e..85659a43d 100644 --- a/sntp/tests/packetProcessing.cpp +++ b/sntp/tests/packetProcessing.cpp @@ -1,4 +1,4 @@ -#include "sntptest.h" +#include "g_sntptest.h" extern "C" { #include "networking.h" diff --git a/sntp/tests/run-keyFile.c b/sntp/tests/run-keyFile.c index 43b7f9466..0a6380d33 100644 --- a/sntp/tests/run-keyFile.c +++ b/sntp/tests/run-keyFile.c @@ -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); diff --git a/sntp/tests/sntptest.h b/sntp/tests/sntptest.h index d5add9cbf..bb31f068e 100644 --- a/sntp/tests/sntptest.h +++ b/sntp/tests/sntptest.h @@ -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 diff --git a/sntp/tests/utilities.cpp b/sntp/tests/utilities.cpp index 4c8c30535..2f02cf58d 100644 --- a/sntp/tests/utilities.cpp +++ b/sntp/tests/utilities.cpp @@ -1,5 +1,5 @@ -#include "sntptest.h" -#include "fileHandlingTest.h" +#include "g_sntptest.h" +#include "g_fileHandlingTest.h" extern "C" { #include "main.h"