aboutsummaryrefslogtreecommitdiff
path: root/sntp/tests/fileHandlingTest.h
diff options
context:
space:
mode:
Diffstat (limited to 'sntp/tests/fileHandlingTest.h')
-rw-r--r--sntp/tests/fileHandlingTest.h124
1 files changed, 80 insertions, 44 deletions
diff --git a/sntp/tests/fileHandlingTest.h b/sntp/tests/fileHandlingTest.h
index 502a248b9bd0..38c3fa6391c4 100644
--- a/sntp/tests/fileHandlingTest.h
+++ b/sntp/tests/fileHandlingTest.h
@@ -1,64 +1,100 @@
#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);
+
+ printf("builddir is <.>\n");
+ printf("abs_srcdir is </deacon/backroom/snaps/ntp-stable/sntp/tests>\n");
+ strcpy(path,"/deacon/backroom/snaps/ntp-stable/sntp/tests/data/");
- return length;
- }
+ //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);
- 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++;
+ 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