xref: /freebsd/contrib/ntp/sntp/tests/fileHandlingTest.h.in (revision 2ccda62ff8e78c384d3c55b8acc1bcf399d26f2c)
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
11enum DirectoryType {
12	INPUT_DIR = 0,
13	OUTPUT_DIR = 1
14};
15
16const 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   <@builddir@>\n");
39	printf("abs_srcdir is <@abs_srcdir@>\n");
40	strcpy(path,"@abs_srcdir@/data/");
41
42	//strcpy(path,"");
43	strcat(path,filename);
44	printf("PATH IS : %s\n",path);
45	return path;
46}
47
48int 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
63bool 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
91void 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
101