I've two files that I need to compare. I would use something like this
BOOST_REQUIRE_EQUAL(filename1, filename2);
Step 1: Open both the file with pointer at the starting. Step 2: Fetch data from file as characters one by one. Step 3: Compare the characters. If the characters are different then return the line and position of the error character.
Boost unit testing framework (Boost. Test) is a part of the Boost library. It is a fully-functional and scalable framework, with wide range of assertion macros, XML output, and other features. Boost. Test itself lacks mocking functionality, but it can be combined with stand-alone mocking frameworks such as gmock.
You can use BOOST_CHECK_EQUAL_COLLECTIONS to compare file contents.
Code sample:
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <fstream>
#include <iterator>
BOOST_AUTO_TEST_CASE( test )
{
std::ifstream ifs1("data1.txt");
std::ifstream ifs2("data2.txt");
std::istream_iterator<char> b1(ifs1), e1;
std::istream_iterator<char> b2(ifs2), e2;
BOOST_CHECK_EQUAL_COLLECTIONS(b1, e1, b2, e2);
}
Files? Read both and compare contents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With