1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
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.
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.
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
23
// --------------------------------------------------------------------------
24
// $Maintainer: Andreas Bertsch $
25
// $Authors: Marc Sturm, Andreas Bertsch $
26
// --------------------------------------------------------------------------
28
#include <OpenMS/CONCEPT/ClassTest.h>
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>
36
///////////////////////////
38
START_TEST(SemanticValidator, "$Id: SemanticValidator_test.C 8210 2011-03-28 13:19:52Z aiche $")
40
/////////////////////////////////////////////////////////////
41
/////////////////////////////////////////////////////////////
43
using namespace OpenMS;
44
using namespace OpenMS::Internal;
48
CVMappingFile().load(OPENMS_GET_TEST_DATA_PATH("SemanticValidator_mapping.xml"),mapping);
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"));
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)
64
START_SECTION((virtual ~SemanticValidator()))
68
START_SECTION((void setTag(const String& tag)))
72
START_SECTION((void setAccessionAttribute(const String& accession)))
76
START_SECTION((void setNameAttribute(const String& name)))
80
START_SECTION((void setValueAttribute(const String& value)))
84
START_SECTION((bool validate(const String &filename, StringList &errors, StringList &warnings)))
85
StringList errors, warnings;
87
//----------------------------------------------------------------------------------------
89
SemanticValidator sv(mapping, cv);
90
TEST_EXCEPTION(Exception::FileNotFound, sv.validate("/does/not/exist", errors, warnings));
92
//----------------------------------------------------------------------------------------
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)
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'")
115
START_SECTION((void setCheckTermValueTypes(bool check)))
116
SemanticValidator sv(mapping, cv);
117
sv.setCheckTermValueTypes(true);
121
START_SECTION((void setCheckUnits(bool check)))
122
SemanticValidator sv(mapping, cv);
123
sv.setCheckUnits(true);
127
START_SECTION((void setUnitAccessionAttribute(const String &accession)))
128
SemanticValidator sv(mapping, cv);
129
sv.setUnitAccessionAttribute("unitAccession");
133
START_SECTION((void setUnitNameAttribute(const String &name)))
134
SemanticValidator sv(mapping, cv);
135
sv.setUnitNameAttribute("unit");
142
/////////////////////////////////////////////////////////////
143
/////////////////////////////////////////////////////////////