commandlineasstring_test.cc 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <config.h>
  2. #include <apt-pkg/cmndline.h>
  3. #include <apt-pkg/configuration.h>
  4. #include <string>
  5. #include "assert.h"
  6. class CLT: public CommandLine {
  7. public:
  8. std::string static AsString(const char * const * const argv,
  9. unsigned int const argc) {
  10. std::string const static conf = "Commandline::AsString";
  11. _config->Clear(conf);
  12. SaveInConfig(argc, argv);
  13. return _config->Find(conf);
  14. }
  15. };
  16. #define CMD(y,z) equals(CLT::AsString(argv, y), z);
  17. int main() {
  18. {
  19. const char* const argv[] = {"apt-get", "install", "-sf"};
  20. CMD(3, "apt-get install -sf");
  21. }
  22. {
  23. const char* const argv[] = {"apt-cache", "-s", "apt", "-so", "Debug::test=Test"};
  24. CMD(5, "apt-cache -s apt -so Debug::test=Test");
  25. }
  26. {
  27. const char* const argv[] = {"apt-cache", "-s", "apt", "-so", "Debug::test=Das ist ein Test"};
  28. CMD(5, "apt-cache -s apt -so Debug::test=\"Das ist ein Test\"");
  29. }
  30. {
  31. const char* const argv[] = {"apt-cache", "-s", "apt", "--hallo", "test=1.0"};
  32. CMD(5, "apt-cache -s apt --hallo test=1.0");
  33. }
  34. }