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

« back to all changes in this revision

Viewing changes to source/TEST/SemanticValidator_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: Andreas Bertsch $
 
25
// $Authors: Marc Sturm, Andreas Bertsch $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#include <OpenMS/CONCEPT/ClassTest.h>
 
29
 
 
30
#include <OpenMS/FORMAT/VALIDATORS/SemanticValidator.h>
 
31
#include <OpenMS/DATASTRUCTURES/CVMappings.h>
 
32
#include <OpenMS/FORMAT/CVMappingFile.h>
 
33
#include <OpenMS/FORMAT/ControlledVocabulary.h>
 
34
#include <OpenMS/SYSTEM/File.h>
 
35
 
 
36
///////////////////////////
 
37
 
 
38
START_TEST(SemanticValidator, "$Id: SemanticValidator_test.C 8210 2011-03-28 13:19:52Z aiche $")
 
39
 
 
40
/////////////////////////////////////////////////////////////
 
41
/////////////////////////////////////////////////////////////
 
42
 
 
43
using namespace OpenMS;
 
44
using namespace OpenMS::Internal;
 
45
using namespace std;
 
46
 
 
47
CVMappings mapping;
 
48
CVMappingFile().load(OPENMS_GET_TEST_DATA_PATH("SemanticValidator_mapping.xml"),mapping);
 
49
 
 
50
ControlledVocabulary cv;
 
51
cv.loadFromOBO("PSI",OPENMS_GET_TEST_DATA_PATH("SemanticValidator_cv.obo"));
 
52
cv.loadFromOBO("PATO",File::find("/CV/quality.obo"));
 
53
cv.loadFromOBO("UO",File::find("/CV/unit.obo"));
 
54
cv.loadFromOBO("brenda",File::find("/CV/brenda.obo"));
 
55
cv.loadFromOBO("GO",File::find("/CV/goslim_goa.obo"));
 
56
 
 
57
SemanticValidator* ptr = 0;
 
58
SemanticValidator* nullPointer = 0;
 
59
START_SECTION((SemanticValidator(const CVMappings& mapping, const ControlledVocabulary& cv)))
 
60
        ptr = new SemanticValidator(mapping,cv);
 
61
        TEST_NOT_EQUAL(ptr, nullPointer)
 
62
END_SECTION
 
63
 
 
64
START_SECTION((virtual ~SemanticValidator()))
 
65
        delete ptr;
 
66
END_SECTION
 
67
 
 
68
START_SECTION((void setTag(const String& tag)))
 
69
        NOT_TESTABLE
 
70
END_SECTION
 
71
        
 
72
START_SECTION((void setAccessionAttribute(const String& accession)))
 
73
        NOT_TESTABLE
 
74
END_SECTION
 
75
        
 
76
START_SECTION((void setNameAttribute(const String& name)))
 
77
        NOT_TESTABLE
 
78
END_SECTION
 
79
        
 
80
START_SECTION((void setValueAttribute(const String& value)))
 
81
        NOT_TESTABLE
 
82
END_SECTION
 
83
 
 
84
START_SECTION((bool validate(const String &filename, StringList &errors, StringList &warnings)))
 
85
        StringList errors, warnings;
 
86
        
 
87
        //----------------------------------------------------------------------------------------
 
88
        //test exceptions
 
89
        SemanticValidator sv(mapping, cv);
 
90
        TEST_EXCEPTION(Exception::FileNotFound, sv.validate("/does/not/exist", errors, warnings));
 
91
 
 
92
        //----------------------------------------------------------------------------------------
 
93
        //test of valid file
 
94
        TEST_EQUAL(sv.validate(OPENMS_GET_TEST_DATA_PATH("SemanticValidator_valid.xml"), errors, warnings),true);
 
95
        TEST_EQUAL(errors.size(),0)
 
96
        TEST_EQUAL(warnings.size(),0)
 
97
 
 
98
        //----------------------------------------------------------------------------------------
 
99
        //test of corrupt file
 
100
        TEST_EQUAL(sv.validate(OPENMS_GET_TEST_DATA_PATH("SemanticValidator_corrupt.xml"), errors, warnings),false);
 
101
        TEST_EQUAL(errors.size(),5)
 
102
        TEST_STRING_EQUAL(errors[0],"Violated mapping rule 'R3' at element '/mzML/fileDescription/sourceFileList/sourceFile', 2 should be present, 1 found!")
 
103
        TEST_STRING_EQUAL(errors[1],"Name of CV term not correct: 'MS:1000554 - LCQ Deca2 - invalid repeat' should be 'LCQ Deca'")
 
104
        TEST_STRING_EQUAL(errors[2],"CV term used in invalid element: 'MS:1000030 - vendor' at element '/mzML/instrumentConfigurationList/instrumentConfiguration'")
 
105
        TEST_STRING_EQUAL(errors[3],"Violated mapping rule 'R6a' number of term repeats at element '/mzML/instrumentConfigurationList/instrumentConfiguration'")
 
106
        TEST_STRING_EQUAL(errors[4],"Violated mapping rule 'R17a' at element '/mzML/run/spectrumList/spectrum/spectrumDescription', 1 should be present, 0 found!")
 
107
        TEST_EQUAL(warnings.size(),4)
 
108
        TEST_STRING_EQUAL(warnings[0],"Unknown CV term: 'MS:1111569 - SHA-1' at element '/mzML/fileDescription/sourceFileList/sourceFile'")
 
109
        TEST_STRING_EQUAL(warnings[1],"Obsolete CV term: 'MS:1000030 - vendor' at element '/mzML/instrumentConfigurationList/instrumentConfiguration'")
 
110
        TEST_STRING_EQUAL(warnings[2],"No mapping rule found for element '/mzML/acquisitionSettingsList/acquisitionSettings/targetList/target'")
 
111
        TEST_STRING_EQUAL(warnings[3],"No mapping rule found for element '/mzML/acquisitionSettingsList/acquisitionSettings/targetList/target'")
 
112
 
 
113
END_SECTION
 
114
 
 
115
START_SECTION((void setCheckTermValueTypes(bool check)))
 
116
        SemanticValidator sv(mapping, cv);
 
117
        sv.setCheckTermValueTypes(true);
 
118
        NOT_TESTABLE
 
119
END_SECTION
 
120
 
 
121
START_SECTION((void setCheckUnits(bool check)))
 
122
        SemanticValidator sv(mapping, cv);
 
123
        sv.setCheckUnits(true);
 
124
        NOT_TESTABLE
 
125
END_SECTION
 
126
 
 
127
START_SECTION((void setUnitAccessionAttribute(const String &accession)))
 
128
        SemanticValidator sv(mapping, cv);
 
129
        sv.setUnitAccessionAttribute("unitAccession");
 
130
        NOT_TESTABLE
 
131
END_SECTION
 
132
 
 
133
START_SECTION((void setUnitNameAttribute(const String &name)))
 
134
        SemanticValidator sv(mapping, cv);
 
135
        sv.setUnitNameAttribute("unit");
 
136
        NOT_TESTABLE
 
137
END_SECTION
 
138
 
 
139
 
 
140
 
 
141
 
 
142
/////////////////////////////////////////////////////////////
 
143
/////////////////////////////////////////////////////////////
 
144
END_TEST