Create a new class 'Options' whose constructor accepts command line arguments (int argc, char **argv).
This class should have no dependancies on existing RKB-B code.
The class should parse the parameters and store the results internally.
The class should provide 3 public methods (it can have as many private methods as are necessary):
bool isSet(std::string opt)
bool getOptionValues(std::string opt, std::vector<std::string> & values)
void getInvalidOptions(std::vector<std::string> & options)
isSet returns true if opt was specified on the command line.
getOptionValues populates the vector 'values' with the values of the cmd-line option. It returns false if the option is not set.
getInvalidOptions populates the vector 'options' with the values of cmd-line options that we don't support. The list of valid options can be found by downloading the latest version of RKH and looking in the 'rkhunter' script.
The 5 acceptable formats for options are shown below. Also shown are the tests that should be run and the expected results.
1. -x
* isSet("x") returns true
2. -xy
* isSet("x") returns true.
* isSet("y") returns true.
* isSet("xy") returns false
3. --word
* isSet("word") returns true.
* isSet("w") returns false.
* getOptionValues("word", values) returns true, values is an empty vector
4. --word value
* isSet("word") returns true.
* isSet("w") returns false.
* getOptionValues("word", values) returns true, values contains 1 entry
5. --word "value1 value2 ... valueN"
* isSet("word") returns true.
* isSet("w") returns false.
* getOptionValues("word", values) returns true, values contains N entries>
To test this class you create a new class called 'OptionsTest'
OptionsTest should have the 13 tests outlines above implemented as well as any other tests you think are relevant.
Missing:
# Your constructor doesn't actually do anything. It should split the argc variable up into the different options. So for example if someone types "rkhb -w --word value -z --test "v1 v2" on the command line the line should be parsed into the 4 different options. You should be able to use google to find techniques to do this.
# Create a OptionsTest.h and OptionsTest.cpp. Put the CppUnit code in here.
Bookmarks