CMake/Source/kwsys/testCommandLineArguments1.cxx

107 lines
3.1 KiB
C++
Raw Normal View History

/*============================================================================
KWSys - Kitware System Library
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "kwsysPrivate.h"
#include KWSYS_HEADER(CommandLineArguments.hxx)
#include KWSYS_HEADER(ios/iostream)
#include KWSYS_HEADER(stl/vector)
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
# include "CommandLineArguments.hxx.in"
# include "kwsys_ios_iostream.h.in"
#endif
#include <string.h> /* strcmp */
int testCommandLineArguments1(int argc, char* argv[])
{
kwsys::CommandLineArguments arg;
arg.Initialize(argc, argv);
int n = 0;
char* m = 0;
kwsys_stl::string p;
int res = 0;
typedef kwsys::CommandLineArguments argT;
arg.AddArgument("-n", argT::SPACE_ARGUMENT, &n, "Argument N");
arg.AddArgument("-m", argT::EQUAL_ARGUMENT, &m, "Argument M");
arg.AddBooleanArgument("-p", &p, "Argument P");
arg.StoreUnusedArguments(true);
if ( !arg.Parse() )
{
kwsys_ios::cerr << "Problem parsing arguments" << kwsys_ios::endl;
res = 1;
}
if ( n != 24 )
{
kwsys_ios::cout << "Problem setting N. Value of N: " << n << kwsys_ios::endl;
res = 1;
}
if ( !m || strcmp(m, "test value") != 0 )
{
kwsys_ios::cout << "Problem setting M. Value of M: " << m << kwsys_ios::endl;
res = 1;
}
if ( p != "1" )
{
KWSys 2014-05-07 (6074f33f) Extract upstream KWSys using the following shell commands. $ git archive --prefix=upstream-kwsys/ 6074f33f | tar x $ git shortlog --no-merges --abbrev=8 --format='%h %s' f3a36760..6074f33f Ben Boeckel (22): ef3bfa01 c_str: Don't use .c_str() when streaming strings 9c165368 Glob: Use string comparisons if you have them ready 53ba0bc6 containers: Use .empty() instead of .size() where possible 6cbb57ac strings: Use string methods instead of size calculations e53596b7 RegularExpression: Add string overloads aec9de6a CommandLineArguments: Push the string back, not its C string 1d531416 Glob: Accept a string in Glob::AddFile 81f5e0a8 Glob: Accept a string in Glob::AddExpression d40c2706 SystemTools: Remove redundant if guards c1296f4a SystemTools: Defer computing length until after a .empty() check 7ffb7106 SystemTools: Use the iterator constructor for strings 29e3b1d8 SystemTools: Use .rfind('/') rather than .find_last_of("/") 5eb3a65c SystemTools: Don't construct a string just for its length b07b5fc1 SystemTools: Take a string in GetShortPath 153f6df7 SystemTools: Use strings in ComparePath 2c2f6604 SystemTools: Accept strings in IsSubDirectory 84db9ee5 SystemTools: Take strings in AddTranslationPath 4b409aa4 SystemTools: Take strings in SplitPath d2dbff07 SystemTools: Take strings in CollapseFullPath e9204f8f SystemTools: Take strings in AddKeepPath 3254681a SystemTools: Reserve memory in JoinPath 6074f33f SystemTools: Use static strings in SystemToolsAppendComponents Change-Id: I53c7a1005206dba43ee785bf807c478bf146ca0e
2014-05-08 00:31:11 +04:00
kwsys_ios::cout << "Problem setting P. Value of P: " << p << kwsys_ios::endl;
res = 1;
}
kwsys_ios::cout << "Value of N: " << n << kwsys_ios::endl;
kwsys_ios::cout << "Value of M: " << m << kwsys_ios::endl;
KWSys 2014-05-07 (6074f33f) Extract upstream KWSys using the following shell commands. $ git archive --prefix=upstream-kwsys/ 6074f33f | tar x $ git shortlog --no-merges --abbrev=8 --format='%h %s' f3a36760..6074f33f Ben Boeckel (22): ef3bfa01 c_str: Don't use .c_str() when streaming strings 9c165368 Glob: Use string comparisons if you have them ready 53ba0bc6 containers: Use .empty() instead of .size() where possible 6cbb57ac strings: Use string methods instead of size calculations e53596b7 RegularExpression: Add string overloads aec9de6a CommandLineArguments: Push the string back, not its C string 1d531416 Glob: Accept a string in Glob::AddFile 81f5e0a8 Glob: Accept a string in Glob::AddExpression d40c2706 SystemTools: Remove redundant if guards c1296f4a SystemTools: Defer computing length until after a .empty() check 7ffb7106 SystemTools: Use the iterator constructor for strings 29e3b1d8 SystemTools: Use .rfind('/') rather than .find_last_of("/") 5eb3a65c SystemTools: Don't construct a string just for its length b07b5fc1 SystemTools: Take a string in GetShortPath 153f6df7 SystemTools: Use strings in ComparePath 2c2f6604 SystemTools: Accept strings in IsSubDirectory 84db9ee5 SystemTools: Take strings in AddTranslationPath 4b409aa4 SystemTools: Take strings in SplitPath d2dbff07 SystemTools: Take strings in CollapseFullPath e9204f8f SystemTools: Take strings in AddKeepPath 3254681a SystemTools: Reserve memory in JoinPath 6074f33f SystemTools: Use static strings in SystemToolsAppendComponents Change-Id: I53c7a1005206dba43ee785bf807c478bf146ca0e
2014-05-08 00:31:11 +04:00
kwsys_ios::cout << "Value of P: " << p << kwsys_ios::endl;
if ( m )
{
delete [] m;
}
char** newArgv = 0;
int newArgc = 0;
arg.GetUnusedArguments(&newArgc, &newArgv);
int cc;
const char* valid_unused_args[9] = {
0, "--ignored", "--second-ignored", "third-ignored",
"some", "junk", "at", "the", "end"
};
if ( newArgc != 9 )
{
kwsys_ios::cerr << "Bad number of unused arguments: " << newArgc << kwsys_ios::endl;
res = 1;
}
for ( cc = 0; cc < newArgc; ++ cc )
{
kwsys_ios::cout << "Unused argument[" << cc << "] = [" << newArgv[cc] << "]"
<< kwsys_ios::endl;
if ( cc >= 9 )
{
kwsys_ios::cerr << "Too many unused arguments: " << cc << kwsys_ios::endl;
res = 1;
}
else if ( valid_unused_args[cc] &&
strcmp(valid_unused_args[cc], newArgv[cc]) != 0 )
{
kwsys_ios::cerr << "Bad unused argument [" << cc << "] \""
<< newArgv[cc] << "\" should be: \"" << valid_unused_args[cc] << "\""
<< kwsys_ios::endl;
res = 1;
}
}
arg.DeleteRemainingArguments(newArgc, &newArgv);
return res;
}