1 #ifndef BAMINDEX_FACTORYTEST_H
2 #define BAMINDEX_FACTORYTEST_H
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"
9 #include <gtest/gtest.h>
13 TEST(BamIndex_FactoryTest, CreateIndexFilename) {
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);
19 EXPECT_EQ("dummy.bam.bai", baiIndexFilename);
20 EXPECT_EQ("dummy.bam.bti", btiIndexFilename);
23 TEST(BamIndex_FactoryTest, FileExtension) {
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";
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);
33 EXPECT_EQ(".bam", bamExtension);
34 EXPECT_EQ(".bai", baiExtension);
35 EXPECT_EQ(".bti", btiExtension);
37 // TODO: try some invalid values, just to make sure this is robust/safe enough
40 TEST(BamIndex_FactoryTest, CreateIndexFromFilename) {
42 const std::string baiIndexFilename = "../data/ex1.bam.bai";
43 const std::string btiIndexFilename = "../data/ex1.bam.bti";
45 BamTools::BamIndex* bai = BamTools::Internal::BamIndexFactory::CreateIndexFromFilename(baiIndexFilename, 0);
46 BamTools::BamIndex* bti = BamTools::Internal::BamIndexFactory::CreateIndexFromFilename(btiIndexFilename, 0);
48 ASSERT_TRUE(bai != NULL);
49 ASSERT_TRUE(bti != NULL);
51 EXPECT_EQ(BamTools::BamIndex::STANDARD, bai->Type());
52 EXPECT_EQ(BamTools::BamIndex::BAMTOOLS, bti->Type());
57 std::cerr << "TestMessage 4" << std::endl;
60 TEST(BamIndex_FactoryTest, CreateIndexOfType) {
62 BamTools::BamIndex* bai = BamTools::Internal::BamIndexFactory::CreateIndexOfType(BamTools::BamIndex::STANDARD, 0);
63 BamTools::BamIndex* bti = BamTools::Internal::BamIndexFactory::CreateIndexOfType(BamTools::BamIndex::BAMTOOLS, 0);
65 EXPECT_EQ(BamTools::BamIndex::STANDARD, bai->Type());
66 EXPECT_EQ(BamTools::BamIndex::BAMTOOLS, bti->Type());
72 TEST(BamIndex_FactoryTest, FindIndexFilename) {
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);
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);
89 #endif // BAMINDEX_FACTORYTEST_H