Parsing nonkeyed options to a test

When you write tests that explicitly use nonkeyed options, you must parse the arguments with the TTextArgumentDictionary::NthValue member function.

Specify the arguments after the -o option as in this command line:

    RunTest -t TSampleObjectKeylessTest SampleObjectTestLib -o roz jim
This is the Setup function that parses the command line:

    1  void TSampleObjectKeylessTest::Setup() 
    2  {
    3      TTextArgumentDictionary args(*this);
    4  
    5      args.RemoveOnLookup(true);
    6  
    7          fTextOption = args.NthValue(1);// First nonkeyed argument, required.
    8      if (fTextOption == NIL) {
    9          OutputTextStream() << "No options specified. Must provide a value.\n";
    10          SetSuccess(false);
    11      }
    12  
    13          fSecondTextOption = args.NthValue(2); // Second nonkeyed argument, not required
    14      if (fSecondTextOption == NIL) {
    15      fSecondTextOption =  new (TAllocationHeap(this)) TStandardText ("BLANK");
    16          OutputTextStream() << "No options specified. Using default value: " << fSecondTextOption << " .\n";
    17      }
Line number 7 assigns the value of the first argument to the appropriate variable. In this example, the argument is required and the test fails if the argument is missing.

Line number 13 assigns the value of the second argument to the appropriate variable. In this example, if the argument is not provided, the function assigns the variable a default value.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker