Snoke
shared.h
Go to the documentation of this file.
1 
11 #ifndef SHARED_H
12 #define SHARED_H
13 
14 #include <gtest/gtest.h>
15 #include "Common/common.h"
16 
17 constexpr bool TRAVIS = 0;
18 
19 
25 int changeStream(FILE* file) {
26  int oldstdOut = dup(1);
27  close(1);
28  dup2(fileno(file), 1);
29 
30  return oldstdOut;
31 }
32 
38 void returnStream(FILE* file, int oldstdOut) {
39  fflush(stdout);
40  fclose(file);
41  dup2(oldstdOut, 1);
42 }
43 
50 bool executeTest(FILE* expectedData, FILE* outputData) {
51  if (expectedData == NULL) {
52  printf("Cannot open expected file \n");
53  return 0;
54  }
55  if (outputData == NULL) {
56  printf("Cannot open output file \n");
57  return 0;
58  }
59 
60  char expectedLine[MAXLINE];
61  char outputLine[MAXLINE];
62 
63  while ((fgets(expectedLine, MAXLINE, expectedData) != NULL) | (fgets(outputLine, MAXLINE, outputData) != NULL)) {
64  expectedLine[strlen(expectedLine) - 1] = '\0';
65  outputLine[strlen(outputLine) - 1] = '\0';
66  printf("Expected line: \"%s\", output line: \"%s\" \n", expectedLine, outputLine);
67  if (strcmp(expectedLine, outputLine) != 0) return false;
68  }
69 
70  return true;
71 }
72 
73 #endif // SHARED_H
bool executeTest(FILE *expectedData, FILE *outputData)
compare files of expected and actual output and decide if test passes
Definition: shared.h:50
const int MAXLINE
Definition: common.h:28
int changeStream(FILE *file)
redirects stdout to a file
Definition: shared.h:25
void returnStream(FILE *file, int oldstdOut)
returns stdout back
Definition: shared.h:38
constexpr bool TRAVIS
Definition: shared.h:17
shared functions prototypes, structures, main classes declarations