NCBI C++ ToolKit
mockseqsrc1_unit_test.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: mockseqsrc1_unit_test.cpp 100942 2023-10-03 17:36:50Z ucko $
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 * File Description:
29 * Unit tests for mock implementation(s) of the BlastSeqSrc which fails always
30 *
31 * ===========================================================================
32 */
33 #include <ncbi_pch.hpp>
34 
35 #define BLAST_SECONDARY_SOURCE 1
36 
37 #include <corelib/test_boost.hpp>
39 #include "seqsrc_mock.hpp"
40 #include "test_objmgr.hpp"
41 
43 using namespace blast;
44 
45 /// Initializes m_SeqSrc with a BlastSeqSrc that always fails
48 
51  }
52 
54  m_SeqSrc = BlastSeqSrcFree(m_SeqSrc);
55  }
56 };
57 
58 BOOST_FIXTURE_TEST_SUITE(mockseqsrc1, FailingMockSeqSrcTestFixture)
59 
60 BOOST_AUTO_TEST_CASE(TestCreation) {
61  BOOST_REQUIRE(m_SeqSrc != NULL);
62 }
63 
64 BOOST_AUTO_TEST_CASE(TestNumberOfSeqs) {
65  int rv = BlastSeqSrcGetNumSeqs(m_SeqSrc);
66  BOOST_REQUIRE(rv == BLAST_SEQSRC_ERROR);
67 }
68 
69 BOOST_AUTO_TEST_CASE(TestMaxSeqLen) {
70  int rv = BlastSeqSrcGetMaxSeqLen(m_SeqSrc);
71  BOOST_REQUIRE(rv == BLAST_SEQSRC_ERROR);
72 }
73 
74 BOOST_AUTO_TEST_CASE(TestAvgSeqLen) {
75  int rv = BlastSeqSrcGetAvgSeqLen(m_SeqSrc);
76  BOOST_REQUIRE(rv == BLAST_SEQSRC_ERROR);
77 }
78 
79 BOOST_AUTO_TEST_CASE(TestTotLen) {
80  Int8 rv = BlastSeqSrcGetTotLen(m_SeqSrc);
81  BOOST_REQUIRE(rv == BLAST_SEQSRC_ERROR);
82 }
83 
84 BOOST_AUTO_TEST_CASE(TestGetName) {
85  const char* str = BlastSeqSrcGetName(m_SeqSrc);
86  BOOST_REQUIRE(str == NULL);
87 }
88 
89 BOOST_AUTO_TEST_CASE(TestIsProtein) {
90  Boolean rv = BlastSeqSrcGetIsProt(m_SeqSrc);
91  BOOST_REQUIRE(rv == FALSE);
92  // repeated calls to this function should return the same value
93  rv = BlastSeqSrcGetIsProt(m_SeqSrc);
94  BOOST_REQUIRE(rv == FALSE);
95 }
96 
97 BOOST_AUTO_TEST_CASE(TestGetSequence) {
99  int rv = BlastSeqSrcGetSequence(m_SeqSrc, empty);
100  BOOST_REQUIRE(rv == BLAST_SEQSRC_ERROR);
101 }
102 
103 BOOST_AUTO_TEST_CASE(TestGetSeqLen) {
104  void* dummy = (void*) &m_SeqSrc;
105  int rv = BlastSeqSrcGetSeqLen(m_SeqSrc, dummy);
106  BOOST_REQUIRE(rv == BLAST_SEQSRC_ERROR);
107 }
108 
109 BOOST_AUTO_TEST_CASE(TestGetInitError) {
110  const char* rv = BlastSeqSrcGetInitError(m_SeqSrc);
111  BOOST_REQUIRE(rv == NULL);
112 }
113 
114 /// This shouldn't really need to be here
115 BOOST_AUTO_TEST_CASE(TestIteratorCreation) {
117  BOOST_REQUIRE(itr != NULL);
118  itr = BlastSeqSrcIteratorFree(itr);
119  BOOST_REQUIRE(itr == NULL);
120 }
121 
122 BOOST_AUTO_TEST_CASE(TestIterationUseCase) {
124  BlastSeqSrcGetSeqArg seq_arg;
125 
126  memset((void*) &seq_arg, 0, sizeof(seq_arg));
127 
128  int i = 0;
129  while ( (seq_arg.oid = BlastSeqSrcIteratorNext(m_SeqSrc, itr)) !=
131  i++;
132  }
133  BOOST_REQUIRE(i == 0);
134 }
135 
136 BOOST_AUTO_TEST_CASE(TestCreationFailure)
137 {
139  BOOST_REQUIRE(seqsrc.Get() != NULL);
140  char* error_str = BlastSeqSrcGetInitError(seqsrc);
141  BOOST_REQUIRE(error_str != NULL);
142  sfree(error_str);
143 }
144 
Contains C++ wrapper classes to structures in algo/blast/core as well as some auxiliary functions to ...
#define sfree(x)
Safe free a pointer: belongs to a higher level header.
Definition: blast_def.h:112
#define BLAST_SEQSRC_ERROR
Error while retrieving sequence.
Definition: blast_seqsrc.h:291
Int4 BlastSeqSrcIteratorNext(const BlastSeqSrc *seq_src, BlastSeqSrcIterator *itr)
Increments the BlastSeqSrcIterator.
Definition: blast_seqsrc.c:425
BlastSeqSrcIterator * BlastSeqSrcIteratorFree(BlastSeqSrcIterator *itr)
Frees the BlastSeqSrcIterator structure.
Definition: blast_seqsrc.c:412
Int4 BlastSeqSrcGetSeqLen(const BlastSeqSrc *seq_src, void *oid)
Retrieve sequence length (number of residues/bases)
Definition: blast_seqsrc.c:281
Boolean BlastSeqSrcGetIsProt(const BlastSeqSrc *seq_src)
Find if the Blast Sequence Source contains protein or nucleotide sequences.
Definition: blast_seqsrc.c:243
BlastSeqSrcIterator * BlastSeqSrcIteratorNew(void)
Allocate and initialize an iterator over a BlastSeqSrc with a default chunk size for MT-safe iteratio...
Definition: blast_seqsrc.c:380
Int4 BlastSeqSrcGetAvgSeqLen(const BlastSeqSrc *seq_src)
Get the average length of all sequences in the sequence source.
Definition: blast_seqsrc.c:211
char * BlastSeqSrcGetInitError(const BlastSeqSrc *seq_src)
Function to retrieve NULL terminated string containing the description of an initialization error or ...
Definition: blast_seqsrc.c:159
Int4 BlastSeqSrcGetNumSeqs(const BlastSeqSrc *seq_src)
Get the number of sequences contained in the sequence source.
Definition: blast_seqsrc.c:177
Int8 BlastSeqSrcGetTotLen(const BlastSeqSrc *seq_src)
Get the total length of all sequences in the sequence source.
Definition: blast_seqsrc.c:219
BlastSeqSrc * BlastSeqSrcFree(BlastSeqSrc *seq_src)
Frees the BlastSeqSrc structure by invoking the destructor function set by the user-defined construct...
Definition: blast_seqsrc.c:112
Int4 BlastSeqSrcGetMaxSeqLen(const BlastSeqSrc *seq_src)
Get the length of the longest sequence in the sequence source.
Definition: blast_seqsrc.c:193
const char * BlastSeqSrcGetName(const BlastSeqSrc *seq_src)
Get the Blast Sequence source name (e.g.
Definition: blast_seqsrc.c:235
Int2 BlastSeqSrcGetSequence(const BlastSeqSrc *seq_src, BlastSeqSrcGetSeqArg *getseq_arg)
Retrieve an individual sequence.
Definition: blast_seqsrc.c:271
#define BLAST_SEQSRC_EOF
No more sequences available.
Definition: blast_seqsrc.h:292
BOOST_AUTO_TEST_SUITE_END() static int s_GetSegmentFlags(const CBioseq &bioseq)
unsigned dummy
Definition: block_cipher.h:0
Wrapper class for BlastSeqSrcIterator .
Definition: blast_aux.hpp:351
Wrapper class for BlastSeqSrc .
Definition: blast_aux.hpp:350
static const char * str(char *buf, int n)
Definition: stats.c:84
BlastSeqSrc * Get() const
Definition: blast_aux.hpp:350
#define NULL
Definition: ncbistd.hpp:225
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
int i
BOOST_AUTO_TEST_CASE(TestCreation)
constexpr bool empty(list< Ts... >) noexcept
Uint1 Boolean
bool replacment for C
Definition: ncbi_std.h:94
#define FALSE
bool replacment for C indicating false.
Definition: ncbi_std.h:101
BlastSeqSrc * MockBlastSeqSrcInit(EMockBlastSeqSrcMode mode)
Mock BlastSeqSrc initialization function.
Mock object which implements the BlastSeqSrc interface for testing purposes.
@ eMBSS_Invalid
Sets a limit on the number of valid mock modes.
Definition: seqsrc_mock.hpp:43
@ eMBSS_AlwaysFail
returns failure on all operations
Definition: seqsrc_mock.hpp:41
Structure used as the second argument to functions satisfying the GetSeqBlkFnPtr signature,...
Definition: blast_seqsrc.h:257
Int4 oid
Oid in BLAST database, index in an array of sequences, etc [in].
Definition: blast_seqsrc.h:259
Complete type definition of Blast Sequence Source Iterator.
Complete type definition of Blast Sequence Source ADT.
Definition: blast_seqsrc.c:43
Initializes m_SeqSrc with a BlastSeqSrc that always fails.
Utility stuff for more convenient using of Boost.Test library.
Modified on Wed Sep 04 15:03:53 2024 by modify_doxy.py rev. 669887