]> git.donarmstrong.com Git - bamtools.git/blob - src/test/api/internal/index/BamIndexFactoryTest.h
Reorganized test suite source tree
[bamtools.git] / src / test / api / internal / index / BamIndexFactoryTest.h
1 #ifndef BAMINDEX_FACTORYTEST_H
2 #define BAMINDEX_FACTORYTEST_H
3
4 #include "api/BamIndex.h"
5 #include "api/internal/index/BamIndexFactory_p.h"
6 #include "api/internal/index/BamStandardIndex_p.h"
7 #include "api/internal/index/BamToolsIndex_p.h"
8
9 #include <gtest/gtest.h>
10 #include <iostream>
11 #include <string>
12
13 TEST(BamIndex_FactoryTest, CreateIndexFilename) {
14
15     const std::string bamFilename      = "dummy.bam";
16     const std::string baiIndexFilename = BamTools::Internal::BamIndexFactory::CreateIndexFilename(bamFilename, BamTools::BamIndex::STANDARD);
17     const std::string btiIndexFilename = BamTools::Internal::BamIndexFactory::CreateIndexFilename(bamFilename, BamTools::BamIndex::BAMTOOLS);
18
19     EXPECT_EQ("dummy.bam.bai", baiIndexFilename);
20     EXPECT_EQ("dummy.bam.bti", btiIndexFilename);
21 }
22
23 TEST(BamIndex_FactoryTest, FileExtension) {
24
25     const std::string bamFilename      = "dummy.bam";
26     const std::string baiIndexFilename = "dummy.bam.bai";
27     const std::string btiIndexFilename = "path/to/dummy.bam.bti";
28
29     const std::string bamExtension = BamTools::Internal::BamIndexFactory::FileExtension(bamFilename);
30     const std::string baiExtension = BamTools::Internal::BamIndexFactory::FileExtension(baiIndexFilename);
31     const std::string btiExtension = BamTools::Internal::BamIndexFactory::FileExtension(btiIndexFilename);
32
33     EXPECT_EQ(".bam", bamExtension);
34     EXPECT_EQ(".bai", baiExtension);
35     EXPECT_EQ(".bti", btiExtension);
36
37     // TODO: try some invalid values, just to make sure this is robust/safe enough
38 }
39
40 TEST(BamIndex_FactoryTest, CreateIndexFromFilename) {
41
42     const std::string baiIndexFilename = "../data/ex1.bam.bai";
43     const std::string btiIndexFilename = "../data/ex1.bam.bti";
44
45     BamTools::BamIndex* bai = BamTools::Internal::BamIndexFactory::CreateIndexFromFilename(baiIndexFilename, 0);
46     BamTools::BamIndex* bti = BamTools::Internal::BamIndexFactory::CreateIndexFromFilename(btiIndexFilename, 0);
47
48     ASSERT_TRUE(bai != NULL);
49     ASSERT_TRUE(bti != NULL);
50
51     EXPECT_EQ(BamTools::BamIndex::STANDARD, bai->Type());
52     EXPECT_EQ(BamTools::BamIndex::BAMTOOLS, bti->Type());
53
54     delete bai;
55     delete bti;
56
57     std::cerr << "TestMessage 4" << std::endl;
58 }
59
60 TEST(BamIndex_FactoryTest, CreateIndexOfType) {
61
62     BamTools::BamIndex* bai = BamTools::Internal::BamIndexFactory::CreateIndexOfType(BamTools::BamIndex::STANDARD, 0);
63     BamTools::BamIndex* bti = BamTools::Internal::BamIndexFactory::CreateIndexOfType(BamTools::BamIndex::BAMTOOLS, 0);
64
65     EXPECT_EQ(BamTools::BamIndex::STANDARD, bai->Type());
66     EXPECT_EQ(BamTools::BamIndex::BAMTOOLS, bti->Type());
67
68     delete bai;
69     delete bti;
70 }
71
72 TEST(BamIndex_FactoryTest, FindIndexFilename) {
73
74     // Both BAI & BTI are available
75     const std::string bamFilename = "../data/ex1.bam";
76     const std::string baiIndexFilename = BamTools::Internal::BamIndexFactory::FindIndexFilename(bamFilename, BamTools::BamIndex::STANDARD);
77     const std::string btiIndexFilename = BamTools::Internal::BamIndexFactory::FindIndexFilename(bamFilename, BamTools::BamIndex::BAMTOOLS);
78     EXPECT_EQ("../data/ex1.bam.bai", baiIndexFilename);
79     EXPECT_EQ("../data/ex1.bam.bti", btiIndexFilename);
80
81     // No BTI index available, both requests should fall back to BAI
82     const std::string bamFilename2 = "../data/BCM.ceph.chr20.bam";
83     const std::string baiIndexFilename2 = BamTools::Internal::BamIndexFactory::FindIndexFilename(bamFilename2, BamTools::BamIndex::STANDARD);
84     const std::string btiIndexFilename2 = BamTools::Internal::BamIndexFactory::FindIndexFilename(bamFilename2, BamTools::BamIndex::BAMTOOLS);
85     EXPECT_EQ("../data/BCM.ceph.chr20.bam.bai", baiIndexFilename2);
86     EXPECT_EQ("../data/BCM.ceph.chr20.bam.bai", btiIndexFilename2);
87 }
88
89 #endif // BAMINDEX_FACTORYTEST_H