]> git.saurik.com Git - apt.git/blame - test/libapt/globalerror_test.cc
Fix option name DPkg::Progress-Fancy in apt.8 manpage (LP: #1310506)
[apt.git] / test / libapt / globalerror_test.cc
CommitLineData
453b82a3
DK
1#include <config.h>
2
c4ba7c44
DK
3#include <apt-pkg/error.h>
4
453b82a3 5#include <stddef.h>
c4ba7c44 6#include <string>
38f29703 7#include <errno.h>
18aea9e6 8#include <string.h>
c4ba7c44 9
453b82a3
DK
10#include "assert.h"
11
65512241 12int main()
c4ba7c44 13{
18aea9e6
PT
14 std::string const textOfErrnoZero(strerror(0));
15
c4ba7c44
DK
16 equals(_error->empty(), true);
17 equals(_error->PendingError(), false);
18 equals(_error->Notice("%s Notice", "A"), false);
19 equals(_error->empty(), true);
20 equals(_error->empty(GlobalError::DEBUG), false);
21 equals(_error->PendingError(), false);
1e3f4083 22 equals(_error->Error("%s horrible %s %d times", "Something", "happened", 2), false);
c4ba7c44
DK
23 equals(_error->PendingError(), true);
24 std::string text;
25 equals(_error->PopMessage(text), false);
26 equals(_error->PendingError(), true);
27 equals(text, "A Notice");
28 equals(_error->PopMessage(text), true);
1e3f4083 29 equals(text, "Something horrible happened 2 times");
c4ba7c44
DK
30 equals(_error->empty(GlobalError::DEBUG), true);
31 equals(_error->PendingError(), false);
1e3f4083 32 equals(_error->Error("%s horrible %s %d times", "Something", "happened", 2), false);
c4ba7c44
DK
33 equals(_error->PendingError(), true);
34 equals(_error->empty(GlobalError::FATAL), false);
35 _error->Discard();
36
37 equals(_error->empty(), true);
38 equals(_error->PendingError(), false);
39 equals(_error->Notice("%s Notice", "A"), false);
1e3f4083 40 equals(_error->Error("%s horrible %s %d times", "Something", "happened", 2), false);
c4ba7c44
DK
41 equals(_error->PendingError(), true);
42 equals(_error->empty(GlobalError::NOTICE), false);
43 _error->PushToStack();
44 equals(_error->empty(GlobalError::NOTICE), true);
45 equals(_error->PendingError(), false);
46 equals(_error->Warning("%s Warning", "A"), false);
47 equals(_error->empty(GlobalError::ERROR), true);
48 equals(_error->PendingError(), false);
49 _error->RevertToStack();
50 equals(_error->empty(GlobalError::ERROR), false);
51 equals(_error->PendingError(), true);
52 equals(_error->PopMessage(text), false);
53 equals(_error->PendingError(), true);
54 equals(text, "A Notice");
55 equals(_error->PopMessage(text), true);
1e3f4083 56 equals(text, "Something horrible happened 2 times");
c4ba7c44
DK
57 equals(_error->PendingError(), false);
58 equals(_error->empty(), true);
59
60 equals(_error->Notice("%s Notice", "A"), false);
1e3f4083 61 equals(_error->Error("%s horrible %s %d times", "Something", "happened", 2), false);
c4ba7c44
DK
62 equals(_error->PendingError(), true);
63 equals(_error->empty(GlobalError::NOTICE), false);
64 _error->PushToStack();
65 equals(_error->empty(GlobalError::NOTICE), true);
66 equals(_error->PendingError(), false);
67 equals(_error->Warning("%s Warning", "A"), false);
68 equals(_error->empty(GlobalError::ERROR), true);
69 equals(_error->PendingError(), false);
70 _error->MergeWithStack();
71 equals(_error->empty(GlobalError::ERROR), false);
72 equals(_error->PendingError(), true);
73 equals(_error->PopMessage(text), false);
74 equals(_error->PendingError(), true);
75 equals(text, "A Notice");
76 equals(_error->PopMessage(text), true);
1e3f4083 77 equals(text, "Something horrible happened 2 times");
c4ba7c44
DK
78 equals(_error->PendingError(), false);
79 equals(_error->empty(), false);
80 equals(_error->PopMessage(text), false);
81 equals(text, "A Warning");
82 equals(_error->empty(), true);
83
38f29703 84 errno = 0;
1e3f4083 85 equals(_error->Errno("errno", "%s horrible %s %d times", "Something", "happened", 2), false);
38f29703
DK
86 equals(_error->empty(), false);
87 equals(_error->PendingError(), true);
88 equals(_error->PopMessage(text), true);
89 equals(_error->PendingError(), false);
1e3f4083 90 equals(text, std::string("Something horrible happened 2 times - errno (0: ").append(textOfErrnoZero).append(")"));
38f29703
DK
91 equals(_error->empty(), true);
92
93 std::string longText;
94 for (size_t i = 0; i < 500; ++i)
95 longText.append("a");
1e3f4083 96 equals(_error->Error("%s horrible %s %d times", longText.c_str(), "happened", 2), false);
38f29703 97 equals(_error->PopMessage(text), true);
1e3f4083 98 equals(text, std::string(longText).append(" horrible happened 2 times"));
38f29703 99
1e3f4083 100 equals(_error->Errno("errno", "%s horrible %s %d times", longText.c_str(), "happened", 2), false);
38f29703 101 equals(_error->PopMessage(text), true);
1e3f4083 102 equals(text, std::string(longText).append(" horrible happened 2 times - errno (0: ").append(textOfErrnoZero).append(")"));
38f29703
DK
103
104 equals(_error->Warning("Репозиторий не обновлён и будут %d %s", 4, "test"), false);
105 equals(_error->PopMessage(text), false);
106 equals(text, "Репозиторий не обновлён и будут 4 test");
107
108 longText.clear();
109 for (size_t i = 0; i < 50; ++i)
110 longText.append("РезийбёбAZ");
bf5438c1 111 equals(_error->Warning("%s", longText.c_str()), false);
38f29703
DK
112 equals(_error->PopMessage(text), false);
113 equals(text, longText);
114
c4ba7c44
DK
115 return 0;
116}