]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/sntp/tests/fileHandlingTest.h
Fix a regression with SA-15:24 patch that prevented NIS from
[FreeBSD/releng/10.2.git] / contrib / ntp / sntp / tests / fileHandlingTest.h
1 #ifndef FILE_HANDLING_TEST_H
2 #define FILE_HANDLING_TEST_H
3
4 #include "stdlib.h"
5 #include "sntptest.h"
6
7 #include <string.h>
8 #include <unistd.h>
9
10
11 enum DirectoryType {
12         INPUT_DIR = 0,
13         OUTPUT_DIR = 1
14 };
15
16 const char * CreatePath(const char* filename, enum DirectoryType argument) {
17         
18          char * path = malloc (sizeof (char) * 256);
19
20         /*
21         if (m_params.size() >= argument + 1) {
22                 path = m_params[argument];
23         }
24
25         if (path[path.size()-1] != DIR_SEP && !path.empty()) {
26                 path.append(1, DIR_SEP);
27         }
28         */
29         //strcpy(path,filename);
30         //path.append(filename);
31
32         //return path;
33
34         char cwd[1024];
35         if (getcwd(cwd, sizeof(cwd)) != NULL)
36                 printf("Current working dir: %s\n", cwd);
37         
38         printf("builddir is   <.>\n");
39         printf("abs_srcdir is </deacon/backroom/snaps/ntp-stable/sntp/tests>\n");
40         strcpy(path,"/deacon/backroom/snaps/ntp-stable/sntp/tests/data/");
41
42         //strcpy(path,"");
43         strcat(path,filename);
44         printf("PATH IS : %s\n",path);
45         return path;
46 }
47
48 int GetFileSize(FILE *file) {
49
50         fseek(file, 0L, SEEK_END);
51         int length = ftell(file);
52         fseek(file, 0L, SEEK_SET);
53         
54         //int initial = file.tellg();
55
56         //file.seekg(0, ios::end);
57         //int length = file.tellg();
58         //file.seekg(initial);
59
60         return length;
61 }
62
63 bool CompareFileContent(FILE* expected, FILE* actual) {
64         int currentLine = 1;
65
66         char actualLine[1024];
67         char expectedLine[1024];
68         size_t lenAct = sizeof actualLine;
69         size_t lenExp = sizeof expectedLine;
70         
71         while (  ( (fgets(actualLine, lenAct, actual)) != NULL)
72               && ( (fgets(expectedLine, lenExp, expected)) != NULL )
73               ) {
74
75                 //printf("%s",actualLine);
76                 //printf("%s",expectedLine);
77         
78                 if( strcmp(actualLine,expectedLine) !=0 ){
79                         printf("Comparision failed on line %d",currentLine);
80                         return FALSE;
81                 }
82
83                 //I removed this and modified the test kodFile.c, because there shouldn't be any ASSERTs in .h files!
84                 //TEST_ASSERT_EQUAL_STRING(actualLine,expectedLine);//EXPECT_EQ(expectedLine, actualLine) << "Comparision failed on line " << currentLine;
85                 currentLine++;
86         }
87
88         return TRUE;
89 }
90
91 void ClearFile(const char * filename) {
92         FILE * clear = fopen(filename, "w");//ios::trunc); //similar to truncate, I GUESS???!
93         
94         //I removed this because there shouldn't be any ASSERTs in .h files!
95         //TEST_ASSERT_TRUE(clear != NULL);
96         fclose(clear);
97 }
98
99
100 #endif // FILE_HANDLING_TEST_H