1 /*===========================================================================
2 *
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26
27 /**
28 * Unit tests for the Loader module
29 */
30 #include <ktst/unit_test.hpp>
31
32 #include <klib/printf.h>
33
34 #include <stdexcept>
35 #include <string>
36
37 extern "C" {
38 #include <klib/rc.h>
39 #include <align/bam.h>
40 }
41
42 using namespace std;
43
44 TEST_SUITE(IndexTestSuite);
45
46 class LoaderFixture
47 {
48 BAMFile const *bam;
49
BAM_FILE_NAME(void)50 static std::string BAM_FILE_NAME(void) {
51 return std::string("/panfs/pan1/sra-test/bam/VDB-3148.bam");
52 }
INDEX_FILE_NAME(void)53 static std::string INDEX_FILE_NAME(void) {
54 return BAM_FILE_NAME() + ".bai";
55 }
56 public:
LoaderFixture()57 LoaderFixture()
58 {
59 rc_t const rc = BAMFileMake(&bam, BAM_FILE_NAME().c_str());
60 if (rc != 0)
61 throw std::runtime_error("can't open " + BAM_FILE_NAME());
62 }
~LoaderFixture()63 ~LoaderFixture()
64 {
65 BAMFileRelease(bam);
66 }
testIndex(void) const67 void testIndex(void) const {
68 rc_t const expected_rc = SILENT_RC(rcAlign, rcIndex, rcReading, rcData, rcExcessive);
69 rc_t const rc = BAMFileOpenIndex(bam, INDEX_FILE_NAME().c_str());
70 if (rc == 0)
71 throw std::runtime_error("Index open was supposed to fail");
72 if (rc != expected_rc)
73 throw std::runtime_error("Index open did not fail with the expected result code; perhaps the test file is missing?");
74 }
75 };
76
FIXTURE_TEST_CASE(LoadIndex,LoaderFixture)77 FIXTURE_TEST_CASE ( LoadIndex, LoaderFixture )
78 {
79 testIndex();
80 }
81
82 //////////////////////////////////////////// Main
83 #include <kapp/args.h>
84 #include <klib/out.h>
85 #include <kfg/config.h>
86
87 extern "C"
88 {
89
KAppVersion(void)90 ver_t CC KAppVersion ( void )
91 {
92 return 0x1000000;
93 }
94
95 const char UsageDefaultName[] = "test-loader";
96
UsageSummary(const char * progname)97 rc_t CC UsageSummary (const char * progname)
98 {
99 return KOutMsg ( "Usage:\n" "\t%s [options]\n\n", progname );
100 }
101
Usage(const Args * args)102 rc_t CC Usage( const Args* args )
103 {
104 return 0;
105 }
106
KMain(int argc,char * argv[])107 rc_t CC KMain ( int argc, char *argv [] )
108 {
109 return IndexTestSuite(argc, argv);
110 }
111
112 }
113
114