1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
/*
* =====================================================================================
*
* Filename: FileUtils_gtest.cpp
*
* Description: Test alignment/utils/FileUtils.hpp
*
* Version: 1.0
* Created: 10/29/2012 05:20:43 PM
* Revision: 08/20/2014
* Compiler: gcc
*
* Author: Yuan Li (yli), yli@pacificbiosciences.com
* Company: Pacific Biosciences
*
* =====================================================================================
*/
#include "gtest/gtest.h"
#include "utils/FileUtils.hpp"
using namespace std;
string nonexistfile = "/nonexistingdir/nonexistingfile";
string readablefile = "/bin/ls";
string writeablefile = "/tmp/writabletmpfile";
string expected_errmsg = "^.+$";
TEST(FILEUTILS, CriticalOpenRead) {
ifstream ifs;
EXPECT_EXIT(CriticalOpenRead(nonexistfile, ifs, std::ios::in),
::testing::ExitedWithCode(1), expected_errmsg);
CriticalOpenRead(readablefile, ifs, std::ios::in);
}
TEST(FILEUTILS, OpenRead) {
ifstream ifs;
EXPECT_EQ( OpenRead(nonexistfile, ifs, std::ios::in), 0);
EXPECT_EQ( OpenRead(readablefile, ifs, std::ios::in), 1);
}
TEST(FILEUTILS, CriticalOpenWrite) {
ofstream ofs;
EXPECT_EXIT( CriticalOpenWrite(nonexistfile, ofs, std::ios::out),
::testing::ExitedWithCode(1), expected_errmsg);
CriticalOpenWrite(writeablefile, ofs, std::ios::out);
}
TEST(FILEUTILS, OpenWrite) {
ofstream ofs;
EXPECT_EQ(OpenWrite(nonexistfile, ofs, std::ios::out), 0);
EXPECT_EQ(OpenWrite(writeablefile, ofs, std::ios::out), 1);
}
|