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