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

Go to the SVN repository for this file.

1 /* $Id: seq_c_compat_unit_test.cpp 44949 2010-03-01 15:58: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: Aaron Ucko, NCBI
27  *
28  * File Description:
29  * Unit test to confirm C-Toolkit-compatible formatting and parsing of
30  * Seq-locs and the like.
31  *
32  * ===========================================================================
33  */
34 
35 #include <ncbi_pch.hpp>
36 
38 #include <serial/objectinfo.hpp>
39 #include <serial/objistrasn.hpp>
41 
42 #include <sequtil.h>
43 
44 #include <corelib/test_boost.hpp>
45 #include <boost/test/parameterized_test.hpp>
46 #include <common/test_assert.h> /* This header must go last */
47 
50 
51 #if defined(NCBI_COMPILER_MSVC) && defined(NCBI_DLL_BUILD)
53 {
55 }
56 
58 {
59 }
60 #else
61 static AsnTypePtr s_SeqIdATP;
62 
64 {
65  CONNECT_Init();
66  SeqLocAsnLoad();
67  s_SeqIdATP = AsnFind(const_cast<char*>("Seq-id")); // avoid warnings
68 }
69 
70 static const char* const kRepresentativeIDs[] = {
71  "local id 123",
72  "local str \"foo|\"\"bar\"\"\"",
73  "gibbsq 123",
74  "gibbmt 123",
75  "giim { id 123, db \"foo\", release \"bar\" }",
76  // NB: release and version not used together below due to a minor
77  // discrepancy whose resolution remains to be determined.
78  "genbank { name \"AMU12345\", accession \"U12345\", release \"foo\" }",
79  "embl { name \"MTBH37RV\", accession \"AL123456\", version 2 }",
80  "pir { name \"S16356\" }",
81  "swissprot { name \"RS22_SALTY\", accession \"Q7CQJ0\","
82  " release \"reviewed\" }",
83  "swissprot { name \"Q9ORT2_9HIV1\", accession \"Q90RT2\","
84  " release \"unreviewed\" }",
85  "swissprot { accession \"Q7CQJ0\", release \"reviewed\", version 1 }",
86  "patent { seqid 1, cit { country \"US\", id number \"RE33188\" } }",
87  "patent { seqid 7, cit { country \"EP\", id app-number \"0238993\" } }",
88  "other { accession \"NM_000170\", version 1 }",
89  "general { db \"EcoSeq\", tag str \"EcoAce\" }",
90  "general { db \"taxon\", tag id 9606 }",
91  "general { db \"dbSNP\", tag str \"rs31251_allelePos=201totallen=401"
92  "|taxid=9606|snpClass=1|alleles=?|mol=?|build=?\" }",
93  "gi 1234",
94  "ddbj { accession \"N00068\" }",
95  "prf { accession \"0806162C\" }",
96  "pdb { mol \"1GAV\" }",
97  "pdb { mol \"1GAV\", chain 0 }",
98  "pdb { mol \"1GAV\", chain 33 }", // !
99  "pdb { mol \"1GAV\", chain 88 }", // X
100  "pdb { mol \"1GAV\", chain 120 }", // x
101  "pdb { mol \"1GAV\", chain 124 }", // |
102  "tpg { accession \"BK003456\" }",
103  "tpe { accession \"BN000123\" }",
104  "tpd { accession \"FAA00017\" }",
105  "gpipe { accession \"GPC_123456789\", version 1 }",
106  "named-annot-track { accession \"AT_123456789\", version 1 }"
107 };
108 static const size_t kNumRepresentativeIDs
109 = sizeof(kRepresentativeIDs)/sizeof(*kRepresentativeIDs);
110 
112 {
113  static void Delete(SeqIdPtr sip) { SeqIdFree(sip); }
114 };
116 
118  eFastaShort = PRINTID_FASTA_SHORT,
119  eTextAccVer = PRINTID_TEXTID_ACC_VER,
120  eTextAccOnly = PRINTID_TEXTID_ACC_ONLY,
121  eReport = PRINTID_REPORT
122 };
123 
124 static string s_IdLabel(const TAutoSeqId& c_id, EIDLabelType type)
125 {
126  return string(SeqIdWholeLabel(c_id.get(), type));
127 }
128 
129 static string s_IdLabel(const CSeq_id& cxx_id, EIDLabelType type)
130 {
131  string label;
135 
136  switch (type) {
137  case eFastaShort: gl_type = CSeq_id::eFasta; break;
138  case eTextAccOnly: flags &= ~CSeq_id::fLabel_Version; break;
139  case eReport: flags &= ~CSeq_id::fLabel_GeneralDbIsContent; break;
140  default: break;
141  }
142  cxx_id.GetLabel(&label, gl_type, flags);
143  return label;
144 }
145 
146 static void s_TestIdFormatting(const char* s)
147 {
148  size_t len = strlen(s);
149  CObjectIStreamAsn ois(s, len);
150  CSeq_id cxx_id;
151  AsnIoMemPtr aimp = AsnIoMemOpen
152  (const_cast<char*>("r"),
153  reinterpret_cast<BytePtr>(const_cast<char*>(s)), len);
154  AsnIoPtr aip = AsnIoNew((ASNIO_IN | ASNIO_TEXT), NULL, aimp,
155  AsnIoMemRead, AsnIoMemWrite);
156  TAutoSeqId c_id;
157 
158  ois.Read(&cxx_id, CSeq_id::GetTypeInfo(), CObjectIStream::eNoFileHeader);
159  aip->read_id = TRUE;
160  c_id = SeqIdAsnRead(aip, s_SeqIdATP);
161 
162  BOOST_CHECK_EQUAL(s_IdLabel(c_id, eFastaShort),
163  s_IdLabel(cxx_id, eFastaShort));
164  BOOST_CHECK_EQUAL(s_IdLabel(c_id, eTextAccVer),
165  s_IdLabel(cxx_id, eTextAccVer));
166  BOOST_CHECK_EQUAL(s_IdLabel(c_id, eTextAccOnly),
167  s_IdLabel(cxx_id, eTextAccOnly));
168  BOOST_CHECK_EQUAL(s_IdLabel(c_id, eReport), s_IdLabel(cxx_id, eReport));
169 }
170 
171 BOOST_AUTO_PARAM_TEST_CASE(s_TestIdFormatting, kRepresentativeIDs + 0,
172  kRepresentativeIDs + kNumRepresentativeIDs);
173 #endif
CObjectIStreamAsn –.
Definition: objistrasn.hpp:53
ELabelType
return the label for a given string
Definition: Seq_id.hpp:445
static void Delete(SeqIdPtr sip)
BOOST_AUTO_PARAM_TEST_CASE(s_TestIdFormatting, kRepresentativeIDs+0, kRepresentativeIDs+kNumRepresentativeIDs)
void NcbiTestSetGlobalDisabled(void)
Disable execution of all tests in current configuration.
string
Definition: cgiapp.hpp:498
#define NULL
Definition: ncbistd.hpp:225
static int type
Definition: getdata.c:34
static int flags
Definition: mdb_load.c:31
void GetLabel(string *label, ELabelType type=eDefault, TLabelFlags flags=fLabel_Default) const
Definition: Seq_id.cpp:1469
int TLabelFlags
Definition: Seq_id.hpp:462
BOOST_AUTO_TEST_CASE(TestUsingArg)
static void s_TestIdFormatting(const char *s)
Definition: testodbc.c:30
Utility stuff for more convenient using of Boost.Test library.
Definition: type.c:8
static const size_t kNumRepresentativeIDs
static const char *const kRepresentativeIDs[]
void CONNECT_Init(const IRWRegistry *reg=0, CRWLock *lock=0, TConnectInitFlags flag=eConnectInit_OwnNothing, FSSLSetup ssl=0)
Init [X]CONNECT library with the specified "reg" and "lock" (ownerhsip for either or both can be deta...
USING_SCOPE(objects)
NCBITEST_AUTO_INIT()
static string s_IdLabel(const TAutoSeqId &c_id, EIDLabelType type)
AutoPtr –.
Definition: ncbimisc.hpp:384
int len
element_type * get(void) const
Get pointer.
Definition: ncbimisc.hpp:453
AutoPtr< SeqId, SSeqIdDeleter > TAutoSeqId
void Read(const CObjectInfo &object)
Read object of know type.
Definition: objistr.cpp:920
static AsnTypePtr s_SeqIdATP
Modified on Tue Sep 19 16:25:48 2017 by modify_doxy.py rev. 546573