1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
|
// --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
//
// This software is released under a three-clause BSD license:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// --------------------------------------------------------------------------
// $Maintainer: Stephan Aiche $
// $Authors: Marc Sturm, Clemens Groepl, Stephan Aiche $
// --------------------------------------------------------------------------
#include <OpenMS/CONCEPT/ClassTest.h>
///////////////////////////
#include <OpenMS/FORMAT/TextFile.h>
#include <OpenMS/FORMAT/ParamXMLFile.h>
#include <OpenMS/APPLICATIONS/TOPPBase.h>
#include <OpenMS/KERNEL/FeatureMap.h>
#include <OpenMS/KERNEL/ConsensusMap.h>
///////////////////////////
using namespace OpenMS;
using namespace std;
//test class with optional parameters
class TOPPBaseTest
: public TOPPBase
{
public:
TOPPBaseTest()
: TOPPBase("TOPPBaseTest", "A test class", false)
{
main(0,0);
}
TOPPBaseTest(int argc ,const char** argv)
: TOPPBase("TOPPBaseTest", "A test class", false)
{
main(argc,argv);
}
virtual void registerOptionsAndFlags_()
{
registerStringOption_("stringoption","<string>","string default","string description",false);
registerIntOption_("intoption","<int>",4711,"int description",false);
registerDoubleOption_("doubleoption","<double>",0.4711,"double description",false);
registerIntList_("intlist","<intlist>",IntList::create("1,2,3,4"),"intlist description",false);
registerDoubleList_("doublelist","<doublelist>",DoubleList::create("0.4711,1.022,4.0"),"doubelist description",false);
registerStringList_("stringlist","<stringlist>",StringList::create("abc,def,ghi,jkl"),"stringlist description",false);
registerFlag_("flag","flag description");
//for testing write_ini parameter (and with it setDefaults)
registerStringList_("stringlist2","<stringlist>",StringList::create("hopla,dude"),"stringlist with restrictions",false);
vector<String> rest;
rest.push_back("hopla");
rest.push_back("dude");
setValidStrings_("stringlist2",rest);
registerIntList_("intlist2","<int>",IntList::create("3,4,5"),"intlist with restrictions",false);
setMinInt_("intlist2",2);
setMaxInt_("intlist2",6);
registerDoubleList_("doublelist2","<double>",DoubleList::create("1.2,2.33"),"doublelist with restrictions",false);
setMinFloat_("doublelist2",0.2);
setMaxFloat_("doublelist2",5.4);
}
String getStringOption(const String& name) const
{
return getStringOption_(name);
}
double getDoubleOption(const String& name) const
{
return getDoubleOption_(name);
}
Int getIntOption(const String& name) const
{
return getIntOption_(name);
}
StringList getStringList(const String& name) const
{
return getStringList_(name);
}
IntList getIntList(const String& name) const
{
return getIntList_(name);
}
DoubleList getDoubleList(const String& name) const
{
return getDoubleList_(name);
}
Param const& getParam() const
{
return getParam_();
}
bool getFlag(const String& name) const
{
return getFlag_(name);
}
virtual ExitCodes main_(int /*argc*/ , const char** /*argv*/)
{
return EXECUTION_OK;
}
String const& getIniLocation() const
{
return getIniLocation_();
}
void inputFileReadable(const String& filename, const String& param_name) const
{
inputFileReadable_(filename, param_name);
}
void outputFileWritable(const String& filename, const String& param_name) const
{
outputFileWritable_(filename, param_name);
}
void addDataProcessing(MSExperiment<>& map, DataProcessing::ProcessingAction action)
{
DataProcessing dp = getProcessingInfo_(action);
addDataProcessing_(map, dp);
//additionally test FeatureMap and ConsensusMap
FeatureMap<> f_map;
addDataProcessing_(f_map, dp);
ConsensusMap c_map;
addDataProcessing_(c_map, dp);
}
void parseRange(const String& text, double& low, double& high) const
{
parseRange_(text, low, high);
}
};
// Test class for no-optional parameters
class TOPPBaseTestNOP
: public TOPPBase
{
public:
TOPPBaseTestNOP()
: TOPPBase("TOPPBaseTestNOP", "A test class with non-optional parameters", false)
{
main(0,0);
}
TOPPBaseTestNOP(int argc , const char** argv)
: TOPPBase("TOPPBaseTestNOP", "A test class with non-optional parameters", false)
{
main(argc,argv);
}
virtual void registerOptionsAndFlags_()
{
registerStringOption_("stringoption","<string>","","string description");
registerIntOption_("intoption","<int>",0,"int description",false);
registerDoubleOption_("doubleoption","<double>", -1.0,"double description", false);
registerFlag_("flag","flag description");
registerStringList_("stringlist","<stringlist>",StringList::create(""),"stringlist description");
registerIntList_("intlist","<intlist>",IntList::create(""),"intlist description");
registerDoubleList_("doublelist","<doublelist>",DoubleList::create(""),"doubelist description");
}
String getStringOption(const String& name) const
{
return getStringOption_(name);
}
double getDoubleOption(const String& name) const
{
return getDoubleOption_(name);
}
Int getIntOption(const String& name) const
{
return getIntOption_(name);
}
StringList getStringList(const String& name) const
{
return getStringList_(name);
}
IntList getIntList(const String& name) const
{
return getIntList_(name);
}
DoubleList getDoubleList(const String& name) const
{
return getDoubleList_(name);
}
virtual ExitCodes main_(int /*argc*/ , const char** /*argv*/)
{
return EXECUTION_OK;
}
};
// Test class for parameters derived from a Param object
class TOPPBaseTestParam: public TOPPBase
{
public:
TOPPBaseTestParam(const Param& param):
TOPPBase("TOPPBaseTestParam", "A test class with parameters derived from Param", false), test_param_(param)
{
main(0, 0);
}
virtual void registerOptionsAndFlags_()
{
registerFullParam_(test_param_);
}
virtual ExitCodes main_(int /*argc*/ , const char** /*argv*/)
{
return EXECUTION_OK;
}
const Param& getParam() const
{
return getParam_();
}
private:
Param test_param_;
};
//test class with optional parameters
class TOPPBaseCmdParseTest
: public TOPPBase
{
public:
TOPPBaseCmdParseTest()
: TOPPBase("TOPPBaseCmdParseTest", "A test class to test parts of the cmd parser functionality", false)
{}
virtual void registerOptionsAndFlags_()
{
}
ExitCodes run(int argc , const char** argv)
{
return main(argc, argv);
}
virtual ExitCodes main_(int /*argc*/ , const char** /*argv*/)
{
return EXECUTION_OK;
}
};
//test class with optional parameters
class TOPPBaseCmdParseSubsectionsTest
: public TOPPBase
{
public:
TOPPBaseCmdParseSubsectionsTest()
: TOPPBase("TOPPBaseCmdParseSubsectionsTest", "A test class to test parts of the cmd parser functionality", false)
{}
void registerOptionsAndFlags_()
{
registerStringOption_("stringoption","<string>","","string description");
registerSubsection_("algorithm", "Algorithm parameters section");
registerSubsection_("other", "Other parameters section");
}
Param getSubsectionDefaults_(const String & section) const
{
Param p;
if (section == "algorithm")
{
p.setValue("param1", "param1_value", "param1_description");
p.setValue("param2", "param2_value", "param2_description");
}
else
{
p.setValue("param3", "param3_value", "param3_description");
p.setValue("param4", "param4_value", "param4_description");
}
return p;
}
ExitCodes run(int argc , const char** argv)
{
return main(argc, argv);
}
virtual ExitCodes main_(int /*argc*/ , const char** /*argv*/)
{
return EXECUTION_OK;
}
String getStringOption(String name)
{
return getStringOption_(name);
}
Param getParam()
{
return getParam_();
}
};
/////////////////////////////////////////////////////////////
START_TEST(TOPPBase, "$Id: TOPPBase_test.C 10915 2013-04-04 20:14:57Z aiche $");
/////////////////////////////////////////////////////////////
TOPPBaseTest* ptr = 0;
TOPPBaseTest* nullPointer = 0;
START_SECTION((TOPPBase(const String& name, const String& description, bool official = true, bool id_tag_support = false, bool require_args = true, const String& version = "")))
ptr = new TOPPBaseTest();
TEST_NOT_EQUAL(ptr, nullPointer)
END_SECTION
START_SECTION((virtual ~TOPPBase()))
delete ptr;
END_SECTION
START_SECTION((ExitCodes main(int argc, const char**argv)))
NOT_TESTABLE
// is tested implicitly in all tests
END_SECTION
//parts to build command lines
const char* a1 ="TOPPBaseTest";
const char* a3 ="-ini";
const char* a5 ="-instance";
const char* a6 ="6";
// needed to get the correct pathes
char* a7;
std::string temp_a7(OPENMS_GET_TEST_DATA_PATH("TOPPBase_toolcommon.ini"));
a7 = new char[temp_a7.size() + 1];
strcpy(a7, temp_a7.c_str());
//
char* a8;
std::string temp_a8(OPENMS_GET_TEST_DATA_PATH("TOPPBase_common.ini"));
a8 = new char[temp_a8.size() + 1];
strcpy(a8, temp_a8.c_str());
//
const char* a9 ="5";
const char* a10 ="-stringoption";
const char* a11 ="-flag";
const char* a12 ="commandline";
const char* a13 ="4.5";
const char* a14 ="-intoption";
const char* a15 ="-doubleoption";
const char* a16 ="4711";
const char* a17 ="-stringlist";
const char* a18 ="-intlist";
const char* a19 ="-doublelist";
const char* a20 ="0.411";
const char* a21 = "-write_ini";
START_SECTION(([EXTRA]String const& getIniLocation_() const))
//default
TOPPBaseTest tmp;
TEST_EQUAL(tmp.getIniLocation(),"TOPPBaseTest:1:")
//command line
const char* instance_cl[3] = {a1, a5, a9}; //command line: "TOPPBaseTest -instance 5"
TOPPBaseTest tmp2(3,instance_cl);
TEST_EQUAL(tmp2.getIniLocation(),"TOPPBaseTest:5:")
END_SECTION
START_SECTION(([EXTRA]String getStringOption_(const String& name) const))
//default
TOPPBaseTest tmp;
TEST_EQUAL(tmp.getStringOption("stringoption"),"string default");
//command line
const char* string_cl[3] = {a1, a10, a12}; //command line: "TOPPBaseTest -stringoption commandline"
TOPPBaseTest tmp2(3,string_cl);
TEST_EQUAL(tmp2.getStringOption("stringoption"),"commandline");
//command line (when there is a ini file value too)
const char* both_cl[5] = {a1, a10, a12, a3, a7}; //command line: "TOPPBaseTest -stringoption commandline -ini data/TOPPBase_toolcommon.ini"
TOPPBaseTest tmp3(5,both_cl);
TEST_EQUAL(tmp3.getStringOption("stringoption"),DataValue("commandline"));
//ini file: instance section
const char* common_cl[3] = {a1, a3, a7}; //command line: "TOPPBaseTest -ini data/TOPPBase_toolcommon.ini"
TOPPBaseTest tmp4(3,common_cl);
TEST_EQUAL(tmp4.getStringOption("stringoption"),DataValue("instance1"));
const char* common5_cl[5] = {a1, a3, a7, a5, a9}; //command line: "TOPPBaseTest -ini data/TOPPBase_toolcommon.ini -instance 5"
TOPPBaseTest tmp5(5,common5_cl);
TEST_EQUAL(tmp5.getStringOption("stringoption"),DataValue("instance5"));
//ini file: tool common section
const char* common6_cl[5] = {a1, a3, a7, a5, a6}; //command line: "TOPPBaseTest -ini data/TOPPBase_toolcommon.ini -instance 6"
TOPPBaseTest tmp6(5,common6_cl);
TEST_EQUAL(tmp6.getStringOption("stringoption"),DataValue("toolcommon"));
//ini file: common section
const char* common7_cl[5] = {a1, a3, a8, a5, a6}; //command line: "TOPPBaseTest -ini data/TOPPBase_common.ini -instance 6"
TOPPBaseTest tmp7(5,common7_cl);
TEST_EQUAL(tmp7.getStringOption("stringoption"),DataValue("common"));
TEST_EXCEPTION(Exception::WrongParameterType,tmp2.getStringOption("doubleoption"));
TEST_EXCEPTION(Exception::UnregisteredParameter,tmp2.getStringOption("imleeewenit"));
//missing required parameters
const char* string_cl2[2] = {a1, a11}; // TOPPBaseTest -flag
TOPPBaseTestNOP tmp8(2,string_cl2);
TEST_EXCEPTION(Exception::RequiredParameterNotGiven,tmp8.getStringOption("stringoption"));
//test option write_ini
String filename;
NEW_TMP_FILE(filename);
const char* f_name = filename.c_str();
const char* write_ini[3]={a1, a21, f_name};
TOPPBaseTest tmp9(3, write_ini);
Param p1, p2;
ParamXMLFile paramFile;
paramFile.load(filename, p1);
//remove id pool (the path is dependent on the installation path)
p1.remove("TOPPBaseTest:1:id_pool");
//every parameter except for help,ini.instance, write_ini and write_wsdl
//toolname : TOPPBaseTest
p2.setValue("TOPPBaseTest:version",VersionInfo::getVersion());
p2.setValue("TOPPBaseTest:1:stringoption","string default","string description");
p2.setValue("TOPPBaseTest:1:intoption",4711,"int description");
p2.setValue("TOPPBaseTest:1:doubleoption",0.4711,"double description");
p2.setValue("TOPPBaseTest:1:intlist",IntList::create("1,2,3,4"),"intlist description");
p2.setValue("TOPPBaseTest:1:doublelist",DoubleList::create("0.4711,1.022,4.0"),"doubelist description");
p2.setValue("TOPPBaseTest:1:stringlist",StringList::create("abc,def,ghi,jkl"),"stringlist description");
p2.setValue("TOPPBaseTest:1:flag","false","flag description");
p2.setValue("TOPPBaseTest:1:log","","Name of log file (created only when specified)");
p2.setValue("TOPPBaseTest:1:debug",0,"Sets the debug level");
p2.setValue("TOPPBaseTest:1:threads",1, "Sets the number of threads allowed to be used by the TOPP tool");
p2.setValue("TOPPBaseTest:1:no_progress","false","Disables progress logging to command line");
p2.setValue("TOPPBaseTest:1:test","false","Enables the test mode (needed for software testing only)");
//with restriction
p2.setValue("TOPPBaseTest:1:stringlist2",StringList::create("hopla,dude"),"stringlist with restrictions");
vector<String> rest;
rest.push_back("hopla");
rest.push_back("dude");
String stringlist2 = "TOPPBaseTest:1:stringlist2";
p2.setValidStrings(stringlist2,rest);
String intlist2 = "TOPPBaseTest:1:intlist2";
String doublelist2 = "TOPPBaseTest:1:doublelist2";
p2.setValue(intlist2,IntList::create("3,4,5"),"intlist with restriction");
p2.setMinInt(intlist2,2);
p2.setMaxInt(intlist2,6);
p2.setValue(doublelist2,DoubleList::create("1.2,2.33"),"doubelist with restrictions");
p2.setMinFloat(doublelist2,0.2);
p2.setMaxFloat(doublelist2,5.4);
TEST_EQUAL(p1,p2)
END_SECTION
START_SECTION(([EXTRA]String getIntOption_(const String& name) const))
//default
TOPPBaseTest tmp;
TEST_EQUAL(tmp.getIntOption("intoption"),4711);
//command line
const char* string_cl[3] = {a1, a14, a6}; //command line: "TOPPBaseTest -intoption 6"
TOPPBaseTest tmp2(3,string_cl);
TEST_EQUAL(tmp2.getIntOption("intoption"),6);
TEST_EXCEPTION(Exception::WrongParameterType,tmp2.getIntOption("doubleoption"));
TEST_EXCEPTION(Exception::UnregisteredParameter,tmp2.getIntOption("imleeewenit"));
//missing required parameters
//-> not testable, as ints cannot be made 'required' (no NAN supported)
END_SECTION
START_SECTION(([EXTRA]String getDoubleOption_(const String& name) const))
//default
TOPPBaseTest tmp;
TEST_REAL_SIMILAR(tmp.getDoubleOption("doubleoption"),0.4711);
//command line
const char* string_cl[3] = {a1, a15, a13}; //command line: "TOPPBaseTest -doubleoption 4.5"
TOPPBaseTest tmp2(3,string_cl);
TEST_REAL_SIMILAR(tmp2.getDoubleOption("doubleoption"),4.5);
TEST_EXCEPTION(Exception::WrongParameterType,tmp2.getDoubleOption("intoption"));
TEST_EXCEPTION(Exception::UnregisteredParameter,tmp2.getDoubleOption("imleeewenit"));
END_SECTION
START_SECTION(([EXTRA] String getIntList_(const String& name) const))
//default
TOPPBaseTest tmp;
TEST_EQUAL(tmp.getIntList("intlist"),IntList::create("1,2,3,4"))
//command line
const char* string_cl[5]={a1, a18, a6 ,a9 ,a16}; //commandline: "TOPPBaseTest -intlist 6 5 4711"
TOPPBaseTest tmp2(5, string_cl);
TEST_EQUAL(tmp2.getIntList("intlist"),IntList::create("6,5,4711"))
const char* string_cl1[3]={a1, a18, a6}; //commandline: "TOPPBaseTest -intlist 6"
TOPPBaseTest tmp3(3, string_cl1);
TEST_EQUAL(tmp3.getIntList("intlist"),IntList::create("6"))
TEST_EXCEPTION(Exception::WrongParameterType,tmp2.getIntList("intoption"));
TEST_EXCEPTION(Exception::UnregisteredParameter,tmp2.getIntList("imleeewenit"));
//missing required parameters
const char* string_cl2[2] = {a1, a11};
TOPPBaseTestNOP tmp4(2,string_cl2);
TEST_EXCEPTION(Exception::RequiredParameterNotGiven,tmp4.getIntList("intlist"));
END_SECTION
START_SECTION(([EXTRA] String getDoubleList_(const String& name) const))
//default
TOPPBaseTest tmp;
TEST_EQUAL(tmp.getDoubleList("doublelist"),DoubleList::create("0.4711,1.022,4.0"));
//command line
const char* string_cl[3]={a1, a19, a20}; //commandline:"TOPPBaseTest -doublelist 0.411"
TOPPBaseTest tmp2(3, string_cl);
TEST_EQUAL(tmp2.getDoubleList("doublelist"),DoubleList::create("0.411"));
const char* a21 = "4.0";
const char* string_cl2[5]={a1,a19,a20,a13,a21};//commandline :"TOPPBaseTest -doublelist 0.411 4.5 4.0
TOPPBaseTest tmp3(5,string_cl2);
TEST_EQUAL(tmp3.getDoubleList("doublelist"),DoubleList::create("0.411,4.5,4.0"));
const char* string_cl21[4]={a1,a19,a20,a13};//commandline :"TOPPBaseTest -doublelist 0.411 4.5
TOPPBaseTest tmp31(4,string_cl21);
TEST_EQUAL(tmp31.getDoubleList("doublelist"),DoubleList::create("0.411,4.5"));
TEST_EXCEPTION(Exception::WrongParameterType,tmp2.getDoubleList("intoption"));
TEST_EXCEPTION(Exception::UnregisteredParameter,tmp2.getDoubleList("imleeewenit"));
//missing required parameters
const char* string_cl3[2] = {a1, a11};
TOPPBaseTestNOP tmp4(2,string_cl3);
TEST_EXCEPTION(Exception::RequiredParameterNotGiven,tmp4.getDoubleList("doublelist"));
END_SECTION
START_SECTION(([EXTRA] String getStringList_(const String& name) const))
//default
TOPPBaseTest tmp;
TEST_EQUAL(tmp.getStringList("stringlist"),StringList::create("abc,def,ghi,jkl"));
//command line
const char* string_cl[3]={a1,a17,a12}; //commandline: "TOPPBaseTest -stringlist conmandline"
TOPPBaseTest tmp2(3, string_cl);
TEST_EQUAL(tmp2.getStringList("stringlist"),StringList::create("commandline"))
const char* string_cl2[5]={a1,a17,a12,a7, a8}; //commandline: "TOPPBaseTest -stringlist conmandline data/TOPPBase_toolcommon.ini data/TOPPBase_common.ini"
TOPPBaseTest tmp3(5, string_cl2);
StringList tmp_stringlist;
tmp_stringlist << "commandline";
tmp_stringlist << OPENMS_GET_TEST_DATA_PATH("TOPPBase_toolcommon.ini");
tmp_stringlist << OPENMS_GET_TEST_DATA_PATH("TOPPBase_common.ini");
TEST_EQUAL(tmp3.getStringList("stringlist"),tmp_stringlist);
TEST_EXCEPTION(Exception::WrongParameterType,tmp2.getStringList("intoption"));
TEST_EXCEPTION(Exception::UnregisteredParameter,tmp2.getStringList("imleeewenit"));
//missing required parameters
const char* string_cl3[2] = {a1, a11};
TOPPBaseTestNOP tmp4(2,string_cl3);
TEST_EXCEPTION(Exception::RequiredParameterNotGiven,tmp4.getStringList("stringlist"));
END_SECTION
START_SECTION(([EXTRA]bool getFlag_(const String& name) const))
//default
TOPPBaseTest tmp;
TEST_EQUAL(tmp.getFlag("flag"),false);
//command line
const char* flag_cl[2] = {a1, a11}; //command line: "TOPPBaseTest -flag"
TOPPBaseTest tmp2(2,flag_cl);
TEST_EQUAL(tmp2.getFlag("flag"),true);
TEST_EXCEPTION(Exception::WrongParameterType,tmp2.getFlag("doubleoption"));
TEST_EXCEPTION(Exception::UnregisteredParameter,tmp2.getFlag("imleeewenit"));
END_SECTION
START_SECTION(([EXTRA]void inputFileReadable_(const String& filename, const String& param_name) const))
TOPPBaseTest tmp;
TEST_EXCEPTION(Exception::FileNotFound,tmp.inputFileReadable("/this/file/does/not/exist.txt","someparam"));
TEST_EXCEPTION(Exception::FileEmpty,tmp.inputFileReadable(OPENMS_GET_TEST_DATA_PATH("TOPPBase_empty.txt"), "someparam"));
tmp.inputFileReadable(OPENMS_GET_TEST_DATA_PATH("TOPPBase_common.ini"),"ini");
END_SECTION
START_SECTION(([EXTRA]void outputFileWritable_(const String& filename, const String& param_name) const))
TEST_EXCEPTION(Exception::UnableToCreateFile,TOPPBaseTest().outputFileWritable("/this/file/cannot/be/written/does_not_exists.txt","someparam"));
String filename;
NEW_TMP_FILE(filename);
TOPPBaseTest().outputFileWritable(filename, "");
//Actually writing something to the file is not necessary, but on Mac all tmp files are called 'source_<line>.tmp'.
//So we have to make sure the file is empty. Otherwise the test might fail...
TextFile dummy;
dummy.resize(5);
dummy.store(filename);
END_SECTION
START_SECTION(([EXTRA]void parseRange_(const String& text, double& low, double& high) const))
TOPPBaseTest topp;
double a = -1.0;
double b = -1.0;
String s;
s = ":";
topp.parseRange(s,a,b);
TEST_REAL_SIMILAR(a,-1.0);
TEST_REAL_SIMILAR(b,-1.0);
s = "4.5:";
topp.parseRange(s,a,b);
TEST_REAL_SIMILAR(a,4.5);
TEST_REAL_SIMILAR(b,-1.0);
s = ":5.5";
topp.parseRange(s,a,b);
TEST_REAL_SIMILAR(a,4.5);
TEST_REAL_SIMILAR(b,5.5);
s = "6.5:7.5";
topp.parseRange(s,a,b);
TEST_REAL_SIMILAR(a,6.5);
TEST_REAL_SIMILAR(b,7.5);
END_SECTION
START_SECTION(([EXTRA]Param getParam_( const std::string& prefix ) const))
{
//ini file
const char* tmp_argv[] = {a1, a3, a7}; //command line: "TOPPBaseTest -ini data/TOPPBase_toolcommon.ini"
TOPPBaseTest tmp_topp(sizeof(tmp_argv)/sizeof(*tmp_argv),tmp_argv);
Param good_params = tmp_topp.getParam();
good_params.setValue( "TOPPBaseTest:stringoption", "toolcommon" );
good_params.setValue( "ini", OPENMS_GET_TEST_DATA_PATH("TOPPBase_toolcommon.ini") );
good_params.setValue( "stringoption", "instance1" );
TEST_EQUAL(tmp_topp.getParam(), good_params);
}
END_SECTION
START_SECTION(([EXTRA] data processing methods))
MSExperiment<> exp;
exp.resize(2);
TOPPBaseTest topp;
topp.addDataProcessing(exp, DataProcessing::ALIGNMENT);
for (Size i=0; i<exp.size(); ++i)
{
TEST_EQUAL(exp[i].getDataProcessing().size(),1)
TEST_EQUAL(exp[i].getDataProcessing()[0].getSoftware().getName(),"TOPPBaseTest")
TEST_NOT_EQUAL(exp[i].getDataProcessing()[0].getSoftware().getVersion(),"1.1")
TEST_EQUAL(exp[i].getDataProcessing()[0].getCompletionTime().isValid(),true)
TEST_EQUAL(exp[i].getDataProcessing()[0].getProcessingActions().size(),1)
TEST_EQUAL(*(exp[i].getDataProcessing()[0].getProcessingActions().begin()),DataProcessing::ALIGNMENT)
}
END_SECTION
START_SECTION(([EXTRA] const Param& getParam_()))
{
Param test_param;
test_param.setValue("param_int", 123, "param int description");
test_param.setValue("param_double", -4.56, "param double description");
test_param.setValue("param_string", "test", "param string description");
test_param.setValue("param_stringlist", StringList::create("this,is,a,test"), "param stringlist description");
test_param.setValue("param_intlist", IntList::create("7,-8,9"), "param intlist description");
test_param.setValue("param_doublelist", DoubleList::create("123,-4.56,0.789"), "param doublelist description");
test_param.setValue("param_flag", "true", "param flag description");
test_param.setValidStrings("param_flag", StringList::create("true,false"));
TOPPBaseTestParam temp(test_param);
Param result = temp.getParam(); // contains "test_param" + some default stuff
for (Param::ParamIterator it = test_param.begin(); it != test_param.end(); ++it)
{
TEST_EQUAL(*it == result.getEntry(it.getName()), true);
}
}
END_SECTION
START_SECTION((static void setMaxNumberOfThreads(int num_threads)))
{
// this is a helper function that is only working if openmp is active
// due to bugs in the different OpenMP implementations it is not realy
// testable
NOT_TESTABLE
}
END_SECTION
START_SECTION(([EXTRA] misc options on command line))
{
// misc text option
const char* string_cl[2] = {a1, a12}; //command line: "TOPPBaseTest commandline"
TOPPBaseCmdParseTest tmp1;
TOPPBase::ExitCodes ec1 = tmp1.run(2,string_cl);
TEST_EQUAL(ec1, TOPPBase::ILLEGAL_PARAMETERS)
// unknown option
TOPPBaseCmdParseTest tmp2;
const char* string_cl_2[3] = {a1, a10, a12}; //command line: "TOPPBaseTest -stringoption commandline"
TOPPBase::ExitCodes ec2 = tmp1.run(3,string_cl_2);
TEST_EQUAL(ec2, TOPPBase::ILLEGAL_PARAMETERS)
}
END_SECTION
const char* a22 = "-algorithm:param1";
const char* a23 = "-algorithm:param2";
const char* a24 = "-other:param3";
const char* a25 = "-other:param4";
const char* a26 = "val1";
const char* a27 = "val2";
const char* a28 = "val3";
const char* a29 = "val4";
std::string temp_a30(OPENMS_GET_TEST_DATA_PATH("TOPPBaseCmdParseSubsectionsTest.ini"));
const char* a30 = temp_a30.c_str();
START_SECTION(([EXTRA] test subsection parameters))
{
const char* string_cl_1[3] = {a1, a10, a12}; //command line: "TOPPBaseTest -stringoption commandline"
TOPPBaseCmdParseSubsectionsTest tmp1;
TOPPBase::ExitCodes ec1 = tmp1.run(3, string_cl_1);
TEST_EQUAL(ec1, TOPPBase::EXECUTION_OK)
TEST_EQUAL(tmp1.getStringOption("stringoption"), "commandline");
TEST_EQUAL(tmp1.getParam().getValue("algorithm:param1"), "param1_value");
TEST_EQUAL(tmp1.getParam().getValue("algorithm:param2"), "param2_value");
TEST_EQUAL(tmp1.getParam().getValue("other:param3"), "param3_value");
TEST_EQUAL(tmp1.getParam().getValue("other:param4"), "param4_value");
// overwrite from cmd
const char* string_cl_2[11] = {a1, a10, a12, a22, a26, a23, a27, a24, a28, a25, a29}; //command line: "TOPPBaseTest -algorithm:param1 val1 -algorithm:param2 val2 -algorithm:param3 val3 -algorithm:param4 val4 -stringoption commandline"
TOPPBaseCmdParseSubsectionsTest tmp2;
TOPPBase::ExitCodes ec2 = tmp2.run(11, string_cl_2);
TEST_EQUAL(ec2, TOPPBase::EXECUTION_OK)
TEST_EQUAL(tmp2.getStringOption("stringoption"), "commandline");
TEST_EQUAL(tmp2.getParam().getValue("algorithm:param1"), "val1");
TEST_EQUAL(tmp2.getParam().getValue("algorithm:param2"), "val2");
TEST_EQUAL(tmp2.getParam().getValue("other:param3"), "val3");
TEST_EQUAL(tmp2.getParam().getValue("other:param4"), "val4");
// overwrite ini values from cmd
const char* string_cl_3[9] = {a1, a3, a30, a22, a26, a25, a29, a10, a12 }; //command line: "TOPPBaseTest -ini TOPPBaseCmdParseSubsectionsTest.ini -algorithm:param1 val1 -algorithm:param4 val4"
TOPPBaseCmdParseSubsectionsTest tmp3;
TOPPBase::ExitCodes ec3 = tmp3.run(9, string_cl_3);
TEST_EQUAL(ec3, TOPPBase::EXECUTION_OK)
TEST_EQUAL(tmp3.getStringOption("stringoption"), "commandline");
TEST_EQUAL(tmp3.getParam().getValue("algorithm:param1"), "val1");
TEST_EQUAL(tmp3.getParam().getValue("algorithm:param2"), "param2_ini_value");
TEST_EQUAL(tmp3.getParam().getValue("other:param3"), "param3_ini_value");
TEST_EQUAL(tmp3.getParam().getValue("other:param4"), "val4");
}
END_SECTION
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
|