The following example shows how to parse keyed arguments that allow you to use a keyword on the command line to qualify the option. This example uses an n
as the key for the value assigned to fIntegerOption, which is used in the Test member function. To pass a value of 255 to fIntegerOption, you use the following command line:
RunTest -t TSampleObjectLengthTest SampleObjectTestLib -o -n 255
SampleObjectTestLib
is the shared library containing the tests.
-o
tells RunTest to pass the rest of the options on the command line to the test class.
-n
is the key that tells the test class to assign the next value to fIntegerOption.
The following code interprets the command line:
Line number 10 assigns the value following the key to fIntegerOption.
The following code shows the Setup function for TSampleObjectLengthTest, which calls the ParseKeyedArgs member function to use the command-line argument that specifies the value passed to the TSampleObject instance.
Line number 6 defines // Copyright (C) 1995 Taligent, Inc. All rights reserved.
1 bool TSampleObjectLengthTest::ParseKeyedArgs(TTextArgumentDictionary& args)
2 {
3 bool result = true; // set to false if parsing fails
4 // fIntegerOption = 0;
5
6 static const TStandardText kMaxLengthKey("-n");
7 // *** ADD CONSTANTS FOR ANY OTHER KEYS.
8
9 try {
10 if (!args.NumberAt(kMaxLengthKey, fIntegerOption, 0, 100000)) {
11 result = false; // This argument is not optional.
12 }
13 } catch(const TTextArgumentDictionaryException& ) {
14 result = false; // Show help if value is out of range.
15 };
16
17 return result;
18 }
-n
as a key.
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
void TSampleObjectLengthTest::Setup()
{
// *** IN REPETITIVE TESTS, Setup(), Test() and Cleanup() get called
// repetitively.
bool result = true; // set to true if setup is successful, false otherwise
TTextArgumentDictionary args(*this);
args.RemoveOnLookup(true); // Optional -- removes arguments as
// they are read
if (result)
result = ParseKeyedArgs(args); // Parse keyed command-line arguments
if (!result) {
// Only set success if there is a failure in Setup. If nothing went wrong,
// do not change the success value.
SetSuccess(result);
ShowUsage();
}
}
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.