00001 // Torc - Copyright 2011 University of Southern California. All Rights Reserved. 00002 // $HeadURL: https://svn.east.isi.edu/torc/trunk/src/torc/common/TestHelpers.cpp $ 00003 // $Id: TestHelpers.cpp 386 2011-02-24 16:32:20Z nsteiner $ 00004 00005 // This program is free software: you can redistribute it and/or modify it under the terms of the 00006 // GNU General Public License as published by the Free Software Foundation, either version 3 of the 00007 // License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 00010 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 00011 // the GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License along with this program. If 00014 // not, see <http://www.gnu.org/licenses/>. 00015 00016 /// \file 00017 /// \brief Source for Boost.Test helper functions. 00018 00019 #include "torc/common/TestHelpers.hpp" 00020 #include <fstream> 00021 00022 namespace torc { 00023 namespace common { 00024 00025 bool readFileIntoString(const boost::filesystem::path& inPath, std::string& outString) { 00026 // open the file and point to the end of it 00027 std::ifstream input(inPath.string().c_str(), std::ios::in | std::ios::binary | std::ios::ate); 00028 if(input.is_open()) { 00029 // resize the string according to the file length 00030 std::ifstream::pos_type size = input.tellg(); 00031 outString.resize(size); 00032 // rewind to the beginning and read the entire file directly into the string 00033 input.seekg(0, std::ios::beg); 00034 input.read(const_cast<char*>(outString.data()), size); 00035 // close and return success 00036 input.close(); 00037 return true; 00038 } else { 00039 return false; 00040 } 00041 } 00042 00043 bool fileContentsAreEqual(const boost::filesystem::path& inA, const boost::filesystem::path& inB) { 00044 std::string a, b; 00045 if(!readFileIntoString(inA, a)) return false; 00046 if(!readFileIntoString(inB, b)) return false; 00047 return a == b; 00048 } 00049 00050 } // namespace common 00051 } // namespace torc