]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/sntp/tests/fileHandlingTest.c
Upgrade NTP to 4.2.8p4.
[FreeBSD/releng/10.2.git] / contrib / ntp / sntp / tests / fileHandlingTest.c
1
2 #include "config.h"
3 #include "stdlib.h"
4 #include "sntptest.h"
5
6 #include "fileHandlingTest.h" //required because of the h.in thingy
7
8 #include <string.h>
9 #include <unistd.h>
10
11 /*
12 enum DirectoryType {
13         INPUT_DIR = 0,
14         OUTPUT_DIR = 1
15 };
16 */
17 //extern const char srcdir[];
18
19 const char *
20 CreatePath(const char* filename, enum DirectoryType argument) {
21         const char srcdir[] = SRCDIR_DEF;//"@abs_srcdir@/data/";
22         char * path = emalloc (sizeof (char) * (strlen(srcdir) + 256));
23
24         //char cwd[1024];
25
26         strcpy(path, srcdir);
27         strcat(path, filename);
28
29         return path;
30 }
31
32
33 int
34 GetFileSize(FILE *file) {
35         fseek(file, 0L, SEEK_END);
36         int length = ftell(file);
37         fseek(file, 0L, SEEK_SET);
38
39         return length;
40 }
41
42
43 bool
44 CompareFileContent(FILE* expected, FILE* actual) {
45         int currentLine = 1;
46
47         char actualLine[1024];
48         char expectedLine[1024];
49         size_t lenAct = sizeof actualLine;
50         size_t lenExp = sizeof expectedLine;
51         
52         while (  ( (fgets(actualLine, lenAct, actual)) != NULL)
53               && ( (fgets(expectedLine, lenExp, expected)) != NULL )
54               ) {
55
56         
57                 if( strcmp(actualLine,expectedLine) !=0 ){
58                         printf("Comparision failed on line %d",currentLine);
59                         return FALSE;
60                 }
61
62                 currentLine++;
63         }
64
65         return TRUE;
66 }
67
68
69 void
70 ClearFile(const char * filename) {
71         if (!truncate(filename, 0))
72                 exit(1);
73 }
74