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

Go to the SVN repository for this file.

1 #ifndef OBJMGR__TEST__UNIT_TEST_UTIL__HPP
2 #define OBJMGR__TEST__UNIT_TEST_UTIL__HPP
3 
4 /* $Id: unit_test_util.hpp 85937 2019-03-25 15:01:03Z bollin $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Colleen Bollin
30  *
31  * File Description:
32  * functions for creating Bioseqs, Bioseq-sets, and other objects for
33  * for testing purposes
34  * .......
35  *
36  */
37 #include <corelib/ncbistd.hpp>
38 #include <corelib/ncbifile.hpp>
39 #include <serial/serial.hpp>
40 #include <serial/objistr.hpp>
41 #include <serial/objostr.hpp>
42 #include <corelib/ncbidiag.hpp>
43 #include <serial/objectinfo.hpp>
44 #include <serial/serialbase.hpp>
45 #include <objmgr/scope.hpp>
52 #include <objects/seq/MolInfo.hpp>
59 #include <objects/pub/Pub.hpp>
61 #include <objects/seq/Seq_data.hpp>
62 #include <objects/seq/Pubdesc.hpp>
64 #include <objects/seq/Seq_ext.hpp>
70 
71 
72 #include <map>
73 
74 
77 
78 BEGIN_SCOPE(unit_test_util)
79 
80 // for controlling access to data loaders
82 {
83 public:
85  {
88  }
90  {
92  }
93 
94 private:
96 };
97 
98 
99 // Dbxrefs, for sources and features
100 NCBI_UNIT_TEST_UTIL_EXPORT void SetDbxref (objects::CBioSource& src, string db, objects::CObject_id::TId id);
101 NCBI_UNIT_TEST_UTIL_EXPORT void SetDbxref (objects::CBioSource& src, string db, string id);
102 NCBI_UNIT_TEST_UTIL_EXPORT void SetDbxref (CRef<objects::CSeq_entry> entry, string db, objects::CObject_id::TId id);
104 NCBI_UNIT_TEST_UTIL_EXPORT void SetDbxref (CRef<objects::CSeq_feat> feat, string db, objects::CObject_id::TId id);
106 
107 NCBI_UNIT_TEST_UTIL_EXPORT void RemoveDbxref (objects::CBioSource& src, string db, objects::CObject_id::TId id);
108 NCBI_UNIT_TEST_UTIL_EXPORT void RemoveDbxref (CRef<objects::CSeq_entry> entry, string db, objects::CObject_id::TId id);
109 NCBI_UNIT_TEST_UTIL_EXPORT void RemoveDbxref (CRef<objects::CSeq_feat> feat, string db, objects::CObject_id::TId id);
110 
111 // BioSource
112 NCBI_UNIT_TEST_UTIL_EXPORT void SetSubSource (objects::CBioSource& src, objects::CSubSource::TSubtype subtype, string val);
113 NCBI_UNIT_TEST_UTIL_EXPORT void SetSubSource (CRef<objects::CSeq_entry> entry, objects::CSubSource::TSubtype subtype, string val);
114 
115 // MolInfo
116 NCBI_UNIT_TEST_UTIL_EXPORT void SetCompleteness(CRef<objects::CSeq_entry> entry, objects::CMolInfo::TCompleteness completeness);
117 
118 
119 NCBI_UNIT_TEST_UTIL_EXPORT void SetTaxon (objects::CBioSource& src, size_t taxon);
134 NCBI_UNIT_TEST_UTIL_EXPORT void SetOrigin (CRef<objects::CSeq_entry> entry, objects::CBioSource::TOrigin origin);
135 NCBI_UNIT_TEST_UTIL_EXPORT void SetGcode (CRef<objects::CSeq_entry> entry, objects::COrgName::TGcode gcode);
136 NCBI_UNIT_TEST_UTIL_EXPORT void SetMGcode (CRef<objects::CSeq_entry> entry, objects::COrgName::TGcode mgcode);
137 NCBI_UNIT_TEST_UTIL_EXPORT void SetPGcode (CRef<objects::CSeq_entry> entry, objects::COrgName::TGcode pgcode);
141 NCBI_UNIT_TEST_UTIL_EXPORT void SetGenome (CRef<objects::CSeq_entry> entry, objects::CBioSource::TGenome genome);
142 NCBI_UNIT_TEST_UTIL_EXPORT void SetChromosome (objects::CBioSource& src, string chromosome) ;
144 NCBI_UNIT_TEST_UTIL_EXPORT void SetTransgenic (objects::CBioSource& src, bool do_set) ;
146 NCBI_UNIT_TEST_UTIL_EXPORT void SetOrgMod (objects::CBioSource& src, objects::COrgMod::TSubtype subtype, string val);
147 NCBI_UNIT_TEST_UTIL_EXPORT void SetOrgMod (CRef<objects::CSeq_entry> entry, objects::COrgMod::TSubtype subtype, string val);
154 NCBI_UNIT_TEST_UTIL_EXPORT void MakeSeqLong(objects::CBioseq& seq);
155 NCBI_UNIT_TEST_UTIL_EXPORT void SetBiomol (CRef<objects::CSeq_entry> entry, objects::CMolInfo::TBiomol biomol);
156 NCBI_UNIT_TEST_UTIL_EXPORT void SetTech (CRef<objects::CSeq_entry> entry, objects::CMolInfo::TTech tech);
158 NCBI_UNIT_TEST_UTIL_EXPORT CRef<objects::CSeq_feat> MakeCDSForGoodNucProtSet (const string& nuc_id, const string& prot_id);
166 NCBI_UNIT_TEST_UTIL_EXPORT void SetProteinPartial(CRef<objects::CSeq_entry> pentry, bool partial5, bool partial3);
185 NCBI_UNIT_TEST_UTIL_EXPORT void RevComp (objects::CBioseq& bioseq);
186 NCBI_UNIT_TEST_UTIL_EXPORT void RevComp (objects::CSeq_loc& loc, size_t len);
195 NCBI_UNIT_TEST_UTIL_EXPORT void ReverseAlignmentStrand(objects::CDense_seg& denseg, size_t pos, size_t seq_len);
197 NCBI_UNIT_TEST_UTIL_EXPORT void RemoveDescriptorType (CRef<objects::CSeq_entry> entry, objects::CSeqdesc::E_Choice desc_choice);
202 NCBI_UNIT_TEST_UTIL_EXPORT void SetSpliceForMixLoc (objects::CBioseq& seq);
205 
206 
207 // Adding Features
212 
213 // Building known good Seq-entries
219 
221 {
222 public:
223  virtual ~ITestRunner(void) { }
224 
226 
227  /// This function is called for each test.
228  /// For example, let's say we have test_cases/foo/bar/baz/
229  /// with BasicTest.input.asn and BasicTest.expected_output.asn
230  /// (and files for other tests, which we'll ignore), then
231  /// this would have a mapping from "input.asn" to the file test_cases/foo/bar/baz/BasicTest.input.asn
232  /// and "expected_output.asn" to the file test_cases/foo/bar/baz/BasicTest.expected_output.asn
233  virtual void RunTest(const string & sTestNAme,
234  const TMapSuffixToFile & mapSuffixToFile ) = 0;
235 
236  /// This is called when an error occurs, and if ITestRunner is using boost
237  /// it should indicate that using, for example, BOOST_ERROR.
238  virtual void OnError(const string & sErrorText) = 0;
239 };
240 
241 /// Flags that control TraverseAndRunTestCases, if needed.
243  /// Overrides default behavior (which is to disregard files whose prefix is "README")
245 };
247 
248 /// This is for running data-driven test cases below the given top-level
249 /// test directory. In a given directory,
250 /// each file is checked for its prefix and suffix, where the prefix is
251 /// the part before the first '.' and the suffix is the part after.
252 /// (e.g. "foo.input.asn" has prefix "foo" and suffix "input.asn").
253 /// Files with the same prefix are assumed to belong to the same test.
254 ///
255 /// There can be more than one test case in a test-case descendent dir and
256 /// test-cases is even permitted to have zero subdirectories and have all
257 /// the files be at the top level (though this could get messy if you
258 /// have many test cases)
259 ///
260 /// Any errors are handled through ITestRunner::OnError except for a NULL
261 /// ITestRunner which, by necessity, is handled by throwing an exception.
262 ///
263 /// @param pTestRunner
264 /// This class's "RunTest" func is called for each test.
265 /// @param dirWithTestCases
266 /// This is the directory holding the test cases. Sub-directories of
267 /// this are also checked for test-cases, although hidden subdirectories
268 /// and files (that is, those starting with a period, such as ".svn")
269 /// are skipped.
270 /// @param setOfRequiredSuffixes
271 /// Each test must have exactly one file with the given suffix. If any
272 /// test is missing any required suffix, this function will halt before
273 /// running any tests. At least one required suffix must be specified.
274 /// @param setOfOptionalSuffixes
275 /// These are the suffixes permitted but not required for each test.
276 /// @param setOfIgnoredSuffixes
277 /// This is the set of suffixes that are just ignored and not passed
278 /// to the pTestRunner. If a file is found whose suffix is not
279 /// in one of the "setOf[FOO]Suffixes" parameters, then an error
280 /// will occur, except that files with prefix "README" are also ignored.
281 /// @param fFlags
282 /// This controls the behavior of the function (usually not needed).
284  ITestRunner *pTestRunner,
285  CDir dirWithTestCases,
286  const set<string> & setOfRequiredSuffixes,
287  const set<string> & setOfOptionalSuffixes = set<string>(),
288  const set<string> & setOfIgnoredSuffixes = set<string>(),
289  TTraverseAndRunTestCasesFlags fFlags = 0 );
290 
291 END_SCOPE(unit_test_util)
294 
295 #endif /* OBJMGR__TEST__UNIT_TEST_UTIL__HPP */
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CDir –.
Definition: ncbifile.hpp:1695
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:366
CDataLoader * m_Loader
map< string, CFile > TMapSuffixToFile
virtual void RunTest(const string &sTestNAme, const TMapSuffixToFile &mapSuffixToFile)=0
This function is called for each test.
virtual void OnError(const string &sErrorText)=0
This is called when an error occurs, and if ITestRunner is using boost it should indicate that using,...
virtual ~ITestRunner(void)
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
TLoader * GetLoader(void) const
Get pointer to the loader.
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
bool RevokeDataLoader(CDataLoader &loader)
Revoke previously registered data loader.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_UNIT_TEST_UTIL_EXPORT
Definition: ncbi_export.h:961
int len
const struct ncbi::grid::netcache::search::fields::KEY key
Defines NCBI C++ diagnostic APIs, classes, and macros.
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
static const GLdouble origin[]
static const char * suffix[]
Definition: pcregrep.c:408
void SetSynthetic_construct(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_entry > BuildGenProdSetNucProtSet(CRef< objects::CSeq_id > nuc_id, CRef< objects::CSeq_id > prot_id)
CRef< objects::CPub > BuildGoodCitGenPub(CRef< objects::CAuthor > author, int serial_number)
void ReverseAlignmentStrand(objects::CDense_seg &denseg, size_t pos, size_t seq_len)
CRef< objects::CSeq_feat > MakeGeneForFeature(CRef< objects::CSeq_feat > feat)
CRef< objects::CSeq_feat > MakeMiscFeature(CRef< objects::CSeq_id > id, size_t right_end=10, size_t left_end=0)
CRef< objects::CAuthor > BuildGoodAuthor()
void SetDrosophila_melanogaster(CRef< objects::CSeq_entry > entry)
void SetTaxon(objects::CBioSource &src, size_t taxon)
void SetSubSource(objects::CBioSource &src, objects::CSubSource::TSubtype subtype, string val)
CRef< objects::CSeq_annot > BuildGoodGraphAnnot(string id)
void SetChromosome(objects::CBioSource &src, string chromosome)
void SetTech(CRef< objects::CSeq_entry > entry, objects::CMolInfo::TTech tech)
CRef< objects::CSeq_entry > BuildGoodEcoSetWithAlign(size_t front_insert=5)
void ChangeNucId(CRef< objects::CSeq_entry > np_set, CRef< objects::CSeq_id > id)
CRef< objects::CSeq_feat > AddProtFeat(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_id > BuildRefSeqId(void)
CRef< objects::CPub > BuildGoodArticlePub()
CRef< objects::CSeq_feat > AddGoodImpFeat(CRef< objects::CSeq_entry > entry, string key)
void SetFocus(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_entry > GetNucProtSetFromGenProdSet(CRef< objects::CSeq_entry > entry)
void SetGenome(CRef< objects::CSeq_entry > entry, objects::CBioSource::TGenome genome)
void AddToDeltaSeq(CRef< objects::CSeq_entry > entry, string seq)
void SetDiv(CRef< objects::CSeq_entry > entry, string div)
void ChangeProtId(CRef< objects::CSeq_entry > np_set, CRef< objects::CSeq_id > id)
CRef< objects::CSeq_entry > MakeProteinForGoodNucProtSet(string id)
void ChangeProductId(CRef< objects::CSeq_annot > annot, CRef< objects::CSeq_id > id)
CRef< objects::CSeq_feat > GetCDSFromGoodNucProtSet(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_align > BuildGoodAlign()
void SetSebaea_microphylla(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeqdesc > BuildGoodPubSeqdesc()
CRef< objects::CPub > BuildGoodCitSubPub()
CRef< CSeq_feat > BuildGoodFeat()
CRef< objects::CSeq_entry > BuildGoodProtSeq(void)
void ResetOrgname(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_feat > GetCDSFromGenProdSet(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_annot > AddFeat(CRef< objects::CSeq_feat > feat, CRef< objects::CSeq_entry > entry)
void SetTaxname(CRef< objects::CSeq_entry > entry, string taxname)
CRef< objects::CSeq_feat > GetmRNAFromGenProdSet(CRef< objects::CSeq_entry > entry)
ETraverseAndRunTestCasesFlags
Flags that control TraverseAndRunTestCases, if needed.
@ fTraverseAndRunTestCasesFlags_DoNOTIgnoreREADMEFiles
Overrides default behavior (which is to disregard files whose prefix is "README")
void RetranslateCdsForNucProtSet(CRef< objects::CSeq_entry > entry, objects::CScope &scope)
void ChangeNucProtSetProteinId(CRef< objects::CSeq_entry > entry, CRef< objects::CSeq_id > id)
void TraverseAndRunTestCases(ITestRunner *pTestRunner, CDir dirWithTestCases, const set< string > &setOfRequiredSuffixes, const set< string > &setOfOptionalSuffixes=set< string >(), const set< string > &setOfIgnoredSuffixes=set< string >(), TTraverseAndRunTestCasesFlags fFlags=0)
This is for running data-driven test cases below the given top-level test directory.
void SetCompleteness(CRef< objects::CSeq_entry > entry, objects::CMolInfo::TCompleteness completeness)
CRef< objects::CSeq_entry > BuildSegSetPart(string id_str)
void SetNucProtSetPartials(CRef< objects::CSeq_entry > entry, bool partial5, bool partial3)
void SetOrigin(CRef< objects::CSeq_entry > entry, objects::CBioSource::TOrigin origin)
int TTraverseAndRunTestCasesFlags
CRef< objects::CSeq_entry > BuildGoodSeq(void)
CRef< objects::CSeq_feat > MakeIntronForMixLoc(CRef< objects::CSeq_id > id)
void SetSpliceForMixLoc(objects::CBioseq &seq)
CRef< objects::CSeq_feat > AddMiscFeature(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_entry > BuildGoodEcoSet()
void SetTransgenic(objects::CBioSource &src, bool do_set)
CRef< objects::CSeq_id > IdFromEntry(CRef< objects::CSeq_entry > entry)
void ChangeId(CRef< objects::CSeq_annot > annot, CRef< objects::CSeq_id > id)
void MakeNucProtSet3Partial(CRef< objects::CSeq_entry > entry)
void SetMGcode(CRef< objects::CSeq_entry > entry, objects::COrgName::TGcode mgcode)
CRef< objects::CSeq_feat > GetProtFeatFromGoodNucProtSet(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_entry > GetProteinSequenceFromGoodNucProtSet(CRef< objects::CSeq_entry > entry)
void SetPGcode(CRef< objects::CSeq_entry > entry, objects::COrgName::TGcode pgcode)
void RemoveDescriptorType(CRef< objects::CSeq_entry > entry, objects::CSeqdesc::E_Choice desc_choice)
void SetProteinPartial(CRef< objects::CSeq_entry > pentry, bool partial5, bool partial3)
void SetBiomol(CRef< objects::CSeq_entry > entry, objects::CMolInfo::TBiomol biomol)
CRef< objects::CSeq_entry > BuildGoodNucProtSet(void)
CRef< objects::CSeq_feat > MakemRNAForCDS(CRef< objects::CSeq_feat > feat)
CRef< objects::CSeq_entry > BuildGoodSegSet(void)
void SetOrgMod(objects::CBioSource &src, objects::COrgMod::TSubtype subtype, string val)
CRef< objects::CSeq_entry > GetNucleotideSequenceFromGoodNucProtSet(CRef< objects::CSeq_entry > entry)
void ClearFocus(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_loc > MakeMixLoc(CRef< objects::CSeq_id > id)
void SetNucProtSetProductName(CRef< objects::CSeq_entry > entry, string new_name)
void AddGoodPub(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_feat > MakeCDSForGoodNucProtSet(const string &nuc_id, const string &prot_id)
void AddGoodSource(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_feat > BuildtRNA(CRef< objects::CSeq_id > id)
void SetCommon(CRef< objects::CSeq_entry > entry, string common)
void RevComp(objects::CBioseq &bioseq)
void SetGcode(CRef< objects::CSeq_entry > entry, objects::COrgName::TGcode gcode)
CRef< objects::CSeq_feat > BuildGoodtRNA(CRef< objects::CSeq_id > id)
void ChangeNucProtSetNucId(CRef< objects::CSeq_entry > entry, CRef< objects::CSeq_id > id)
void AdjustProtFeatForNucProtSet(CRef< objects::CSeq_entry > entry)
void RemoveDeltaSeqGaps(CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_entry > BuildGoodDeltaSeq(void)
CRef< objects::CSeq_feat > AddGoodSourceFeature(CRef< objects::CSeq_entry > entry)
void AddFeatAnnotToSeqEntry(CRef< objects::CSeq_annot > annot, CRef< objects::CSeq_entry > entry)
CRef< objects::CSeq_entry > GetGenomicFromGenProdSet(CRef< objects::CSeq_entry > entry)
void SetDbxref(objects::CBioSource &src, string db, objects::CObject_id::TId id)
void MakeSeqLong(objects::CBioseq &seq)
CRef< objects::CSeq_entry > BuildGoodGenProdSet()
void SetLineage(CRef< objects::CSeq_entry > entry, string lineage)
void RemoveDbxref(objects::CBioSource &src, string db, objects::CObject_id::TId id)
Modified on Sun May 19 04:43:16 2024 by modify_doxy.py rev. 669887