globalerror_test.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <apt-pkg/error.h>
  2. #include "assert.h"
  3. #include <string>
  4. #include <errno.h>
  5. int main(int argc,char *argv[])
  6. {
  7. equals(_error->empty(), true);
  8. equals(_error->PendingError(), false);
  9. equals(_error->Notice("%s Notice", "A"), false);
  10. equals(_error->empty(), true);
  11. equals(_error->empty(GlobalError::DEBUG), false);
  12. equals(_error->PendingError(), false);
  13. equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
  14. equals(_error->PendingError(), true);
  15. std::string text;
  16. equals(_error->PopMessage(text), false);
  17. equals(_error->PendingError(), true);
  18. equals(text, "A Notice");
  19. equals(_error->PopMessage(text), true);
  20. equals(text, "Something horrible happend 2 times");
  21. equals(_error->empty(GlobalError::DEBUG), true);
  22. equals(_error->PendingError(), false);
  23. equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
  24. equals(_error->PendingError(), true);
  25. equals(_error->empty(GlobalError::FATAL), false);
  26. _error->Discard();
  27. equals(_error->empty(), true);
  28. equals(_error->PendingError(), false);
  29. equals(_error->Notice("%s Notice", "A"), false);
  30. equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
  31. equals(_error->PendingError(), true);
  32. equals(_error->empty(GlobalError::NOTICE), false);
  33. _error->PushToStack();
  34. equals(_error->empty(GlobalError::NOTICE), true);
  35. equals(_error->PendingError(), false);
  36. equals(_error->Warning("%s Warning", "A"), false);
  37. equals(_error->empty(GlobalError::ERROR), true);
  38. equals(_error->PendingError(), false);
  39. _error->RevertToStack();
  40. equals(_error->empty(GlobalError::ERROR), false);
  41. equals(_error->PendingError(), true);
  42. equals(_error->PopMessage(text), false);
  43. equals(_error->PendingError(), true);
  44. equals(text, "A Notice");
  45. equals(_error->PopMessage(text), true);
  46. equals(text, "Something horrible happend 2 times");
  47. equals(_error->PendingError(), false);
  48. equals(_error->empty(), true);
  49. equals(_error->Notice("%s Notice", "A"), false);
  50. equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
  51. equals(_error->PendingError(), true);
  52. equals(_error->empty(GlobalError::NOTICE), false);
  53. _error->PushToStack();
  54. equals(_error->empty(GlobalError::NOTICE), true);
  55. equals(_error->PendingError(), false);
  56. equals(_error->Warning("%s Warning", "A"), false);
  57. equals(_error->empty(GlobalError::ERROR), true);
  58. equals(_error->PendingError(), false);
  59. _error->MergeWithStack();
  60. equals(_error->empty(GlobalError::ERROR), false);
  61. equals(_error->PendingError(), true);
  62. equals(_error->PopMessage(text), false);
  63. equals(_error->PendingError(), true);
  64. equals(text, "A Notice");
  65. equals(_error->PopMessage(text), true);
  66. equals(text, "Something horrible happend 2 times");
  67. equals(_error->PendingError(), false);
  68. equals(_error->empty(), false);
  69. equals(_error->PopMessage(text), false);
  70. equals(text, "A Warning");
  71. equals(_error->empty(), true);
  72. errno = 0;
  73. equals(_error->Errno("errno", "%s horrible %s %d times", "Something", "happend", 2), false);
  74. equals(_error->empty(), false);
  75. equals(_error->PendingError(), true);
  76. equals(_error->PopMessage(text), true);
  77. equals(_error->PendingError(), false);
  78. equals(text, "Something horrible happend 2 times - errno (0: Success)");
  79. equals(_error->empty(), true);
  80. std::string longText;
  81. for (size_t i = 0; i < 500; ++i)
  82. longText.append("a");
  83. equals(_error->Error("%s horrible %s %d times", longText.c_str(), "happend", 2), false);
  84. equals(_error->PopMessage(text), true);
  85. equals(text, std::string(longText).append(" horrible happend 2 times"));
  86. equals(_error->Errno("errno", "%s horrible %s %d times", longText.c_str(), "happend", 2), false);
  87. equals(_error->PopMessage(text), true);
  88. equals(text, std::string(longText).append(" horrible happend 2 times - errno (0: Success)"));
  89. equals(_error->Warning("Репозиторий не обновлён и будут %d %s", 4, "test"), false);
  90. equals(_error->PopMessage(text), false);
  91. equals(text, "Репозиторий не обновлён и будут 4 test");
  92. longText.clear();
  93. for (size_t i = 0; i < 50; ++i)
  94. longText.append("РезийбёбAZ");
  95. equals(_error->Warning("%s", longText.c_str()), false);
  96. equals(_error->PopMessage(text), false);
  97. equals(text, longText);
  98. return 0;
  99. }