aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/utils.h')
-rw-r--r--tests/utils.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/utils.h b/tests/utils.h
index 57226efc..39e15ce9 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -9,7 +9,9 @@
#include <sys/fcntl.h>
#endif
#include <stdio.h>
+#include <string.h>
#include <string>
+#include <fstream>
using namespace std;
@@ -45,6 +47,35 @@ inline void deleteFile(const string &filename)
remove(filename.c_str());
}
+inline bool fileEqual(const string &filename1, const string &filename2)
+{
+ char buf1[BUFSIZ];
+ char buf2[BUFSIZ];
+
+ ifstream stream1(filename1.c_str(), ios_base::in | ios_base::binary);
+ ifstream stream2(filename2.c_str(), ios_base::in | ios_base::binary);
+
+ if(!stream1 && !stream2) return true;
+ if(!stream1 || !stream2) return false;
+
+ for(;;)
+ {
+ stream1.read(buf1, BUFSIZ);
+ stream2.read(buf2, BUFSIZ);
+
+ streamsize n1 = stream1.gcount();
+ streamsize n2 = stream2.gcount();
+
+ if(n1 != n2) return false;
+
+ if(n1 == 0) break;
+
+ if(memcmp(buf1, buf2, n1) != 0) return false;
+ }
+
+ return stream1.good() == stream2.good();
+}
+
class ScopedFileCopy
{
public: