TCLAP/examples/test28.cpp
Daniel Aarno 4970b7e793 Check for NULL constraint and raise exception if found.
User is not allowed to provide a NULL constraint to the various ARG
constructors. This patch makes sure the Constraint is not NULL before
dereferencing and raises a logic_error if it is NULL.

Also included the two new tests test88 and test89 in runtests script.
2015-05-11 22:47:42 +02:00

36 lines
976 B
C++

#include <iostream>
#include "tclap/CmdLine.h"
using namespace TCLAP;
using namespace std;
int main()
{
try {
CmdLine cmd("test constraint bug");
ValueArg<int> arg("i","int", "tests int arg", false, 4711, NULL, cmd);
cout << "Expected exception" << endl;
} catch(std::logic_error &e) { /* expected */ }
try {
CmdLine cmd("test constraint bug");
ValueArg<int> arg1("i","int", "tests int arg", false, 4711, NULL, NULL);
cout << "Expected exception" << endl;
} catch(std::logic_error &e) { /* expected */ }
try {
CmdLine cmd("test constraint bug");
MultiArg<int> arg1("i","int", "tests int arg", false, NULL, NULL);
cout << "Expected exception" << endl;
} catch(std::logic_error &e) { /* expected */ }
try {
CmdLine cmd("test constraint bug");
MultiArg<int> arg1("i","int", "tests int arg", false, NULL, cmd);
cout << "Expected exception" << endl;
} catch(std::logic_error &e) { /* expected */ }
cout << "Passed" << endl;
}