NCBI C++ ToolKit
seqsrc_mock.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: seqsrc_mock.hpp 46644 2010-07-28 14:17:11Z camacho $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Christiam Camacho
27  *
28  */
29 
30 /** @file seqsrc_mock.hpp
31  * Mock object which implements the BlastSeqSrc interface for testing purposes
32  */
33 
34 #ifndef _SEQSRC_MOCK_HPP
35 #define _SEQSRC_MOCK_HPP
36 
38 #include <util/random_gen.hpp>
39 
41  eMBSS_AlwaysFail, ///< returns failure on all operations
42  eMBSS_RandomlyFail, ///< returns failure randomly on operations
43  eMBSS_Invalid ///< Sets a limit on the number of valid mock modes
44 };
45 
46 /// Mock BlastSeqSrc initialization function
49 
50 /// Abstract base class which defines a common interface for mock BlastSeqSrc
51 /// objects to implement
53 {
54  virtual ~IMockBlastSeqSrc() {}
55  virtual Int2 GetSequence(BlastSeqSrcGetSeqArg* seq_arg) = 0;
56  virtual Int4 GetSequenceLength(Int4 oid) = 0;
57  virtual void ReleaseSequence(BlastSeqSrcGetSeqArg* seq_arg) = 0;
58  virtual Int4 GetNumSeqs() = 0;
59  virtual Int4 GetMaxSeqLen() = 0;
60  virtual Int4 GetAvgSeqLen() = 0;
61  virtual Int8 GetTotLen() = 0;
62  virtual const char* GetSeqSrcName() = 0;
63  virtual Boolean GetIsProt() = 0;
65 };
66 
67 /// Mock BlastSeqSrc implementation which always fails
69 {
78  const char* GetSeqSrcName() { return NULL; }
79  Boolean GetIsProt() { return FALSE; }
81 };
82 
83 /// Mock BlastSeqSrc implementation which fails randomly.
84 /// Its allocation never fails, it is the interface it implements that fails
85 /// randomly.
86 /// Note that when the IteratorNext function returns a valid ordinal id
87 /// (kDefaultOid), GetSequence and GetSequenceLength should work with that
88 /// argument (assuming they don't fail randomly ;) ).
90 {
91 public:
94 
95  // Class constants
96  static const Int4 kDefaultInt4;
97  static const Int8 kDefaultInt8;
98  static const char* kDefaultString;
99  static const char* kNullString;
100  static const Int4 kDefaultOid;
101 
102  Int4 GetNumSeqs();
103  Int4 GetMaxSeqLen();
104  Int4 GetAvgSeqLen();
105  Int8 GetTotLen();
106  const char* GetSeqSrcName();
107  Boolean GetIsProt();
111  void ReleaseSequence(BlastSeqSrcGetSeqArg* seq_arg);
112 
113 private:
114 
115  /// Auxiliary function to randomly select a value among the two possible
116  /// options passed in as arguments
117  template <typename T>
118  T x_SelectRandomlyBetween(T success_value, T failure_value) {
119  if (m_RandGen->GetRand() % 2 == 0) {
120  return success_value;
121  } else {
122  return failure_value;
123  }
124  }
125 
126  /// Populate structure with some dummy data
128 
129  /// The random number generator
130  ncbi::CRandom* m_RandGen;
131  /// Determine whether this mock BlastSeqSrc contains protein or nucleotide
132  /// sequences
134 };
135 
136 #endif /* _SEQSRC_MOCK_HPP */
Declaration of ADT to retrieve sequences for the BLAST engine.
#define BLAST_SEQSRC_ERROR
Error while retrieving sequence.
Definition: blast_seqsrc.h:291
#define BLAST_SEQSRC_EOF
No more sequences available.
Definition: blast_seqsrc.h:292
Mock BlastSeqSrc implementation which fails randomly.
Definition: seqsrc_mock.hpp:90
Int4 GetSequenceLength(Int4 oid)
static const char * kDefaultString
Definition: seqsrc_mock.hpp:98
Boolean m_IsProtein
Determine whether this mock BlastSeqSrc contains protein or nucleotide sequences.
Int4 IteratorNext(BlastSeqSrcIterator *itr)
static const Int4 kDefaultOid
static const char * kNullString
Definition: seqsrc_mock.hpp:99
T x_SelectRandomlyBetween(T success_value, T failure_value)
Auxiliary function to randomly select a value among the two possible options passed in as arguments.
static const Int8 kDefaultInt8
Definition: seqsrc_mock.hpp:97
void x_PopulateBLAST_SequenceBlk(BlastSeqSrcGetSeqArg *seq_arg)
Populate structure with some dummy data.
void ReleaseSequence(BlastSeqSrcGetSeqArg *seq_arg)
Int2 GetSequence(BlastSeqSrcGetSeqArg *seq_arg)
ncbi::CRandom * m_RandGen
The random number generator.
static const Int4 kDefaultInt4
Definition: seqsrc_mock.hpp:96
#define T(s)
Definition: common.h:230
#define NULL
Definition: ncbistd.hpp:225
int16_t Int2
2-byte (16-bit) signed integer
Definition: ncbitype.h:100
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
mdb_mode_t mode
Definition: lmdb++.h:38
Uint1 Boolean
bool replacment for C
Definition: ncbi_std.h:94
#define FALSE
bool replacment for C indicating false.
Definition: ncbi_std.h:101
EMockBlastSeqSrcMode
Definition: seqsrc_mock.hpp:40
@ eMBSS_Invalid
Sets a limit on the number of valid mock modes.
Definition: seqsrc_mock.hpp:43
@ eMBSS_RandomlyFail
returns failure randomly on operations
Definition: seqsrc_mock.hpp:42
@ eMBSS_AlwaysFail
returns failure on all operations
Definition: seqsrc_mock.hpp:41
BlastSeqSrc * MockBlastSeqSrcInit(EMockBlastSeqSrcMode mode=eMBSS_AlwaysFail)
Mock BlastSeqSrc initialization function.
Structure used as the second argument to functions satisfying the GetSeqBlkFnPtr signature,...
Definition: blast_seqsrc.h:257
Complete type definition of Blast Sequence Source Iterator.
Complete type definition of Blast Sequence Source ADT.
Definition: blast_seqsrc.c:43
Mock BlastSeqSrc implementation which always fails.
Definition: seqsrc_mock.hpp:69
virtual ~CAlwaysFailMockBlastSeqSrc()
Definition: seqsrc_mock.hpp:70
Int2 GetSequence(BlastSeqSrcGetSeqArg *)
Definition: seqsrc_mock.hpp:71
const char * GetSeqSrcName()
Definition: seqsrc_mock.hpp:78
Int4 IteratorNext(BlastSeqSrcIterator *)
Definition: seqsrc_mock.hpp:80
void ReleaseSequence(BlastSeqSrcGetSeqArg *)
Definition: seqsrc_mock.hpp:73
Abstract base class which defines a common interface for mock BlastSeqSrc objects to implement.
Definition: seqsrc_mock.hpp:53
virtual Int4 GetNumSeqs()=0
virtual Int4 GetAvgSeqLen()=0
virtual Boolean GetIsProt()=0
virtual Int2 GetSequence(BlastSeqSrcGetSeqArg *seq_arg)=0
virtual const char * GetSeqSrcName()=0
virtual Int4 IteratorNext(BlastSeqSrcIterator *itr)=0
virtual void ReleaseSequence(BlastSeqSrcGetSeqArg *seq_arg)=0
virtual Int4 GetMaxSeqLen()=0
virtual ~IMockBlastSeqSrc()
Definition: seqsrc_mock.hpp:54
virtual Int4 GetSequenceLength(Int4 oid)=0
virtual Int8 GetTotLen()=0
Modified on Tue Apr 16 20:13:00 2024 by modify_doxy.py rev. 669887