Commit 46834e63 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Calling statistics() or histogram() on unopened cube will throw descriptive error. Fixes #2085.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@5871 41f8697f-d340-4b68-9986-7bafba869bb8
parent 8f838b01
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1216,6 +1216,12 @@ namespace Isis {
   */
  Histogram *Cube::histogram(const int &band, const double &validMin,
                                const double &validMax, QString msg) {
    // Make sure cube is open
    if ( !isOpen() ) {
      QString msg = "Cannot create histogram object for an unopened cube";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    
    // Make sure band is valid
    if ((band < 0) || (band > bandCount())) {
      QString msg = "Invalid band in [CubeInfo::Histogram]";
@@ -1431,6 +1437,12 @@ namespace Isis {
   */
  Statistics *Cube::statistics(const int &band, const double &validMin,
                                     const double &validMax, QString msg) {
    // Make sure cube is open
    if ( !isOpen() ) {
      QString msg = "Cannot create statistics object for an unopened cube";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
    
    // Make sure band is valid
    if ((band < 0) || (band > bandCount())) {
      string msg = "Invalid band in [CubeInfo::Statistics]";
+2 −1
Original line number Diff line number Diff line
@@ -140,7 +140,8 @@ namespace Isis {
   *   @history 2012-11-06 Steven Lambright and Mathew Eis - Fixed (the lack of) deletion of
   *                           temporary files in the unit test. Fixes #1009.
   *   @history 2012-12-31 Steven Lambright - Removed 'get' prefix from accessors. Fixes #1356.
   *
   *   @history 2014-06-20 Ian Humphrey - Added checks to statistics() and histogram() to throw
   *                           an error if the cube is unopened. Fixes #2085.
   */
  class Cube {
    public:
+3 −0
Original line number Diff line number Diff line
@@ -102,6 +102,8 @@ Total Pixels: 60000
Null Pixels:    0

**PROGRAMMER ERROR** Invalid band in [CubeInfo::Histogram].
**PROGRAMMER ERROR** Cannot create histogram object for an unopened cube.

Testing statistics method, band 1 ... 
Gathering statistics
0% Processed10% Processed20% Processed30% Processed40% Processed50% Processed60% Processed70% Processed80% Processed90% Processed100% Processed
@@ -119,6 +121,7 @@ Total Pixels: 60000
Null Pixels:    0

**PROGRAMMER ERROR** Invalid band in [CubeInfo::Statistics].
**PROGRAMMER ERROR** Cannot create statistics object for an unopened cube.

Virtual band tests
Nbands = 2
+22 −0
Original line number Diff line number Diff line
@@ -207,6 +207,18 @@ int main(int argc, char *argv[]) {
      e.print();
    }
    
    // Check error for histogram object on a closed cube
    try {
      // out has already been closed
      out.histogram(0);
    }
    catch (IException &e)
    {
      e.print();
    }
    
    cerr << endl;
    
    // Test statistics object on a single band, 1 by default
    cerr << "Testing statistics method, band 1 ... " << endl;
    Statistics *bandOneStats = in.statistics();
@@ -237,6 +249,16 @@ int main(int argc, char *argv[]) {
      e.print();
    }
    
    // Check error for statistics object on a closed cube
    try {
      // out has already been closed
      out.statistics(0);
    }
    catch (IException &e)
    {
      e.print();
    }

    cerr << endl;

    cerr << "Virtual band tests" << endl;  // Virtual Band tests