~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/TEST/Bzip2InputStream_test.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
9
//  This library is free software; you can redistribute it and/or
 
10
//  modify it under the terms of the GNU Lesser General Public
 
11
//  License as published by the Free Software Foundation; either
 
12
//  version 2.1 of the License, or (at your option) any later version.
 
13
//
 
14
//  This library is distributed in the hope that it will be useful,
 
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
//  Lesser General Public License for more details.
 
18
//
 
19
//  You should have received a copy of the GNU Lesser General Public
 
20
//  License along with this library; if not, write to the Free Software
 
21
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: David Wojnar$
 
25
// $Authors: David Wojnar $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#include <OpenMS/CONCEPT/ClassTest.h>
 
29
 
 
30
///////////////////////////
 
31
#include <OpenMS/FORMAT/Bzip2InputStream.h>
 
32
 
 
33
using namespace OpenMS;
 
34
 
 
35
 
 
36
///////////////////////////
 
37
 
 
38
START_TEST(Bzip2InputStream, "$Id: Bzip2InputStream_test.C 8226 2011-04-05 11:35:18Z aiche $")
 
39
 
 
40
Bzip2InputStream* ptr = 0;
 
41
Bzip2InputStream* nullPointer = 0;
 
42
START_SECTION(Bzip2InputStream(const   char* const     file_name))
 
43
        TEST_EXCEPTION(Exception::FileNotFound, Bzip2InputStream bzip2(OPENMS_GET_TEST_DATA_PATH("ThisFileDoesNotExist")))
 
44
        ptr = new Bzip2InputStream(OPENMS_GET_TEST_DATA_PATH("Bzip2IfStream_1.bz2"));
 
45
        TEST_NOT_EQUAL(ptr, nullPointer)
 
46
        TEST_EQUAL(ptr->getIsOpen(),true)
 
47
END_SECTION
 
48
 
 
49
START_SECTION((~Bzip2InputStream()))
 
50
        delete ptr;
 
51
END_SECTION
 
52
 
 
53
START_SECTION(Bzip2InputStream(const String& file_name))
 
54
        TEST_EXCEPTION(Exception::FileNotFound, Bzip2InputStream bzip2(OPENMS_GET_TEST_DATA_PATH("ThisFileDoesNotExist")))
 
55
        String filename = OPENMS_GET_TEST_DATA_PATH("Bzip2IfStream_1.bz2");
 
56
        ptr = new Bzip2InputStream(filename);
 
57
        TEST_NOT_EQUAL(ptr, nullPointer)
 
58
        TEST_EQUAL(ptr->getIsOpen(),true)
 
59
        delete ptr;
 
60
END_SECTION
 
61
 
 
62
START_SECTION(virtual XMLSize_t readBytes(XMLByte *const to_fill, const XMLSize_t max_to_read))
 
63
        
 
64
        Bzip2InputStream bzip(OPENMS_GET_TEST_DATA_PATH("Bzip2IfStream_1.bz2"));
 
65
        char buffer[31];
 
66
        buffer[30] = buffer[29] = '\0';
 
67
        XMLByte*  xml_buffer = reinterpret_cast<XMLByte* >(buffer);
 
68
                TEST_EQUAL(bzip.getIsOpen(),true)
 
69
        TEST_EQUAL(bzip.readBytes(xml_buffer,(XMLSize_t)10),10)
 
70
        TEST_EQUAL(bzip.readBytes(&xml_buffer[10],(XMLSize_t)10),10)
 
71
        TEST_EQUAL(bzip.readBytes(&xml_buffer[20],(XMLSize_t)9),9)
 
72
        TEST_EQUAL(String(buffer), String("Was decompression successful?"))
 
73
        TEST_EQUAL(bzip.getIsOpen(),true)
 
74
        TEST_EQUAL(bzip.readBytes(&xml_buffer[30],(XMLSize_t)10),1)
 
75
        TEST_EQUAL(bzip.getIsOpen(),false)
 
76
 
 
77
END_SECTION
 
78
 
 
79
START_SECTION(XMLFilePos curPos() const)
 
80
        Bzip2InputStream bzip(OPENMS_GET_TEST_DATA_PATH("Bzip2IfStream_1.bz2"));
 
81
  TEST_EQUAL(bzip.curPos(), 0)
 
82
        char buffer[31];
 
83
        buffer[30] = buffer[29] = '\0';
 
84
        XMLByte*  xml_buffer = reinterpret_cast<XMLByte* >(buffer);
 
85
        bzip.readBytes(xml_buffer,(XMLSize_t)10);
 
86
        TEST_EQUAL(bzip.curPos(),10)
 
87
        
 
88
END_SECTION
 
89
 
 
90
START_SECTION(bool getIsOpen() const)
 
91
        //test above
 
92
        NOT_TESTABLE
 
93
END_SECTION
 
94
 
 
95
START_SECTION(virtual const XMLCh* getContentType() const)
 
96
        Bzip2InputStream bzip2(OPENMS_GET_TEST_DATA_PATH("Bzip2IfStream_1.bz2"));
 
97
  XMLCh* xmlch_nullPointer = 0;
 
98
  TEST_EQUAL(bzip2.getContentType(),xmlch_nullPointer)
 
99
END_SECTION
 
100
 
 
101
/////////////////////////////////////////////////////////////
 
102
/////////////////////////////////////////////////////////////
 
103
END_TEST