Commit 9de7bdc8 authored by paarongiroux's avatar paarongiroux Committed by Stuart Sides
Browse files

Added FileList test (#3168)

* Added LineEqationTests.cpp

* Added FileListTests.cpp
Implemented an istream constructor in FileList.cpp to help with testing.

* added FileList tests. implemented istream constructor for FileList.cpp to help with testing.

* fixed whitespace issues in FileListTests.cpp

* Update FileListTests.cpp
parent 8f033e32
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -48,6 +48,15 @@ namespace Isis {
    read(listFile);
  }

  /**
   * Constructs a FileList from an istream.
   *
   * @param in the istream to read from
   */
  FileList::FileList(std::istream &in) {
    read(in);
  }


  /**
   * Opens and loads the list of files from a file.
+0 −10
Original line number Diff line number Diff line
Testing on unitTest.list:
/usgs/pkgs/isis3/isis/src/base/objs/FileList/FileList.cpp
/usgs/pkgs/isis3/isis/src/base/objs/FileList/FileList.h
unitTest.cpp
>This
^is
Makefile
FileList.h
Testing on nonexistant file:
Unable to open the file
+0 −24
Original line number Diff line number Diff line
#include "FileList.h"
#include "IException.h"
#include "Preference.h"
#include "FileName.h"

using namespace std;
using namespace Isis;

int main(void) {
  Isis::Preference::Preferences(true);
  cerr << "Testing on unitTest.list:" << endl;
  FileList fl2(FileName("unitTest.list"));
  fl2.write(cout);

  cerr << "Testing on nonexistant file:" << endl;
  try {
    FileList fl2(FileName("NoWayThisFileExists"));
  }
  catch(Isis::IException &e) {
//    e.print();
    cerr << "Unable to open the file" << endl;
  }
  return 0;
}
+0 −14
Original line number Diff line number Diff line
/usgs/pkgs/isis3/isis/src/base/objs/FileList/FileList.cpp
/usgs/pkgs/isis3/isis/src/base/objs/FileList/FileList.h
#Comment
unitTest.cpp
>This will not be comment ignored

^is a blank line, this line will not be ignored as a comment
  Makefile
  //Testing comment with prepended spaces

#Above and below are for testing multiple blank lines


FileList.h
+47 −0
Original line number Diff line number Diff line
#include <gtest/gtest.h>
#include <iostream>
#include "FileList.h"
#include "IException.h"

TEST(FileList, NonExistantFileConstructor)
{
  try
  {
    Isis::FileList fl1(Isis::FileName("FakeFile"));
  }
  catch(Isis::IException &e)
  {
    EXPECT_TRUE(e.toString().toLatin1().contains("Unable to open [FakeFile]."))
      << e.toString().toStdString();
  }
  catch(...)
  {
    FAIL() << "Expected an IException\"Unable to open [FakeFile].\"";
  }
}

TEST(FileList, FileNameConstructor)
{
  std::istringstream input(
  "/usgs/pkgs/isis3/isis/src/base/objs/FileList/FileList.cpp\n"
  "/usgs/pkgs/isis3/isis/src/base/objs/FileList/FileList.h\n"
  "#Comment\n"
  "unitTest.cpp\n"
  ">This will not be comment ignored\n"
  "\n"
  "^is a blank line, this line will not be ignored as a comment\n"
  "  Makefile\n"
  "  //Testing comment with prepended spaces\n"
  "\n"
  "#Above and below are for testing multiple blank lines\n"
  "\n"
  "\n"
  "FileList.h\n");
  std::ostringstream output;
  std::string expectedOutput = "/usgs/pkgs/isis3/isis/src/base/objs/FileList/FileList.cpp\n"
     "/usgs/pkgs/isis3/isis/src/base/objs/FileList/FileList.h\n"
     "unitTest.cpp\n>This\n^is\nMakefile\nFileList.h\n";
  Isis::FileList fl1(input);
  fl1.write(output);
  EXPECT_STREQ(expectedOutput.c_str(), output.str().c_str());
}