LUMIERA.clone/tests/library/test/test-option-test.cpp

100 lines
3.2 KiB
C++
Raw Permalink Normal View History

/*
TestOption(Test) - parsing of cmd line options for running Testcases
2010-12-17 23:28:49 +01:00
Copyright: clarify and simplify the file headers * Lumiera source code always was copyrighted by individual contributors * there is no entity "Lumiera.org" which holds any copyrights * Lumiera source code is provided under the GPL Version 2+ == Explanations == Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above. For this to become legally effective, the ''File COPYING in the root directory is sufficient.'' The licensing header in each file is not strictly necessary, yet considered good practice; attaching a licence notice increases the likeliness that this information is retained in case someone extracts individual code files. However, it is not by the presence of some text, that legally binding licensing terms become effective; rather the fact matters that a given piece of code was provably copyrighted and published under a license. Even reformatting the code, renaming some variables or deleting parts of the code will not alter this legal situation, but rather creates a derivative work, which is likewise covered by the GPL! The most relevant information in the file header is the notice regarding the time of the first individual copyright claim. By virtue of this initial copyright, the first author is entitled to choose the terms of licensing. All further modifications are permitted and covered by the License. The specific wording or format of the copyright header is not legally relevant, as long as the intention to publish under the GPL remains clear. The extended wording was based on a recommendation by the FSF. It can be shortened, because the full terms of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
Copyright (C)
2008, Hermann Vosseler <Ichthyostega@web.de>
2010-12-17 23:28:49 +01:00
Copyright: clarify and simplify the file headers * Lumiera source code always was copyrighted by individual contributors * there is no entity "Lumiera.org" which holds any copyrights * Lumiera source code is provided under the GPL Version 2+ == Explanations == Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above. For this to become legally effective, the ''File COPYING in the root directory is sufficient.'' The licensing header in each file is not strictly necessary, yet considered good practice; attaching a licence notice increases the likeliness that this information is retained in case someone extracts individual code files. However, it is not by the presence of some text, that legally binding licensing terms become effective; rather the fact matters that a given piece of code was provably copyrighted and published under a license. Even reformatting the code, renaming some variables or deleting parts of the code will not alter this legal situation, but rather creates a derivative work, which is likewise covered by the GPL! The most relevant information in the file header is the notice regarding the time of the first individual copyright claim. By virtue of this initial copyright, the first author is entitled to choose the terms of licensing. All further modifications are permitted and covered by the License. The specific wording or format of the copyright header is not legally relevant, as long as the intention to publish under the GPL remains clear. The extended wording was based on a recommendation by the FSF. It can be shortened, because the full terms of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
  **Lumiera** is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
  Free Software Foundation; either version 2 of the License, or (at your
  option) any later version. See the file COPYING for further details.
2010-12-17 23:28:49 +01:00
Copyright: clarify and simplify the file headers * Lumiera source code always was copyrighted by individual contributors * there is no entity "Lumiera.org" which holds any copyrights * Lumiera source code is provided under the GPL Version 2+ == Explanations == Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above. For this to become legally effective, the ''File COPYING in the root directory is sufficient.'' The licensing header in each file is not strictly necessary, yet considered good practice; attaching a licence notice increases the likeliness that this information is retained in case someone extracts individual code files. However, it is not by the presence of some text, that legally binding licensing terms become effective; rather the fact matters that a given piece of code was provably copyrighted and published under a license. Even reformatting the code, renaming some variables or deleting parts of the code will not alter this legal situation, but rather creates a derivative work, which is likewise covered by the GPL! The most relevant information in the file header is the notice regarding the time of the first individual copyright claim. By virtue of this initial copyright, the first author is entitled to choose the terms of licensing. All further modifications are permitted and covered by the License. The specific wording or format of the copyright header is not legally relevant, as long as the intention to publish under the GPL remains clear. The extended wording was based on a recommendation by the FSF. It can be shortened, because the full terms of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
* *****************************************************************/
/** @file test-option-test.cpp
** unit test \ref TestOption_test
*/
#include "lib/test/run.hpp"
#include "lib/test/test-helper.hpp"
#include "lib/test/testoption.hpp"
#include "lib/format-cout.hpp"
#include "lib/util.hpp"
#include <memory>
using std::make_unique;
using lib::Cmdline;
using util::isnil;
namespace test {
/************************************************************//**
* invokes the TestOption parser for various example commandlines
* @test for test::TestOption, parsing of commandline options
* @see test::Suite
* @see util::Cmdline
*/
class TestOption_test : public Test
{
2009-01-10 19:03:28 +01:00
void
run (Arg)
{
noOptions();
help();
groupID();
singleTest();
groupFilter1();
groupFilter2();
additionalCmd();
additionalCmd2();
verify_seed();
}
2009-01-10 19:03:28 +01:00
/** @test performs the actual test for the option parser test::TestOption */
auto
doIt (const string cmdline)
{
cout << "Testing invocation with cmdline: " << cmdline << "..." << endl;
Cmdline args(cmdline);
auto optparser = make_unique<TestOption>(args);
const string testID = optparser->getTestID();
cout << "--> Testgroup=" << optparser->getTestgroup() << endl;
cout << "--> Test-ID =" << (isnil(testID)? "--missing--" : testID ) << endl;
cout << "--> remaining=" << args << endl;
return optparser;
}
void noOptions() { doIt (""); }
void help() { doIt ("--help"); }
void groupID() { doIt ("--group TestGroupID"); }
void singleTest() { doIt (" SingleTestID"); }
void groupFilter1() { doIt (" SingleTestID --group TestGroupID"); }
void groupFilter2() { doIt (" --group TestGroupID SingleTestID "); }
void additionalCmd() { doIt (" --group TestGroupID SingleTestID spam eggs"); }
void additionalCmd2() { doIt ("\t\tSingleTestID spam --group TestGroupID \t --eggs"); }
void
verify_seed()
{
CHECK ( not doIt("ham --group spam")->optSeed());
CHECK (7 == * doIt("ham --seed 7 spam")->optSeed());
CHECK (0 == * doIt("ham --seed 0 spam")->optSeed());
VERIFY_FAIL("argument (\'spam\') for option \'--seed\' is invalid"
, doIt("ham --seed spam"));
// yet negative numbers are parsed and force-converted
CHECK (std::numeric_limits<uint64_t>::max()
== * doIt("--seed=-1")->optSeed());
}
};
2025-06-07 23:59:57 +02:00
LAUNCHER (TestOption_test, "function common");
} // namespace test