commandlineasstring_test.cc 1003 B

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