Changeset 3056


Ignore:
Timestamp:
Jun 24, 2013, 8:37:21 AM (9 years ago)
Author:
Peter
Message:

fixes #764: throw if region in BamReadIterator? is invalid

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r3024 r3056  
    1010  - ROC::area(void) is now declared const (ticket #754)
    1111  - tTest::score(void) is now declared const (ticket #755)
     12  - BamReadIterator(4) will now throw if region is invalid (ticket #764)
    1213
    1314  A complete list of closed tickets can be found here [[br]]
  • trunk/test/bam_region_iterator.cc

    r2943 r3056  
    11// $Id$
    22//
    3 // Copyright (C) 2012 Peter Johansson
     3// Copyright (C) 2012, 2013 Peter Johansson
    44//
    55// This program is free software; you can redistribute it and/or modify
     
    2929#include YAT_BAM_HEADER
    3030#endif
     31
     32#include <yat/utility/Exception.h>
    3133
    3234#include <algorithm>
     
    8890  suite.out() << count << std::endl;
    8991
    90   if (count==185)
    91     return;
     92  if (count!=185) {
     93    suite.err() << "count: " << count << "\nexpected: 185\n";
     94    suite.add(false);
     95  }
    9296
    93   suite.err() << "count: " << count << "\nexpected: 185\n";
    94   suite.add(false);
     97  // test negative coordinates trigger exception
     98  suite.out() << "test negative coordinates\n";
     99  try {
     100    BamReadIterator iter(bam_stream, 1, -2, -1);
     101    suite.add(false);
     102    suite.err() << "error: no exception thrown\n";
     103  }
     104  catch (utility::runtime_error& e) {
     105    suite.out() << "expected exception caught with what(): '" << e.what()
     106                << "'\n";
     107  }
     108
    95109#endif
    96110}
  • trunk/yat/omic/BamReadIterator.cc

    r3052 r3056  
    2929
    3030#include <cstddef>
     31#include <sstream>
    3132
    3233namespace theplu {
     
    112113  {
    113114    bam_iter_t it = bam_iter_query(bf.index(), tid, begin, end);
    114     assert(it);
     115    if (!it) {
     116      std::stringstream ss;
     117      ss << "BamReadIterator constructor: invalid region: ( tid=" << tid
     118         << ", begin=" << begin << ", end=" << end << ")";
     119      throw utility::runtime_error(ss.str());
     120    }
    115121    // iter_ takes ownership
    116122    iter_ = boost::shared_ptr<__bam_iter_t>(it, IndexDestroyer());
Note: See TracChangeset for help on using the changeset viewer.