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