]> git.saurik.com Git - apt.git/blob - test/libapt/globalerror_test.cc
Merge branch 'debian/sid' of git://git.debian.org/git/apt/apt into debian/sid
[apt.git] / test / libapt / globalerror_test.cc
1 #include <apt-pkg/error.h>
2
3 #include "assert.h"
4 #include <string>
5 #include <errno.h>
6 #include <string.h>
7
8 int main(int argc,char *argv[])
9 {
10 std::string const textOfErrnoZero(strerror(0));
11
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);
18 equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
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);
25 equals(text, "Something horrible happend 2 times");
26 equals(_error->empty(GlobalError::DEBUG), true);
27 equals(_error->PendingError(), false);
28 equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
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);
36 equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
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);
52 equals(text, "Something horrible happend 2 times");
53 equals(_error->PendingError(), false);
54 equals(_error->empty(), true);
55
56 equals(_error->Notice("%s Notice", "A"), false);
57 equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false);
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);
73 equals(text, "Something horrible happend 2 times");
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
80 errno = 0;
81 equals(_error->Errno("errno", "%s horrible %s %d times", "Something", "happend", 2), false);
82 equals(_error->empty(), false);
83 equals(_error->PendingError(), true);
84 equals(_error->PopMessage(text), true);
85 equals(_error->PendingError(), false);
86 equals(text, std::string("Something horrible happend 2 times - errno (0: ").append(textOfErrnoZero).append(")"));
87 equals(_error->empty(), true);
88
89 std::string longText;
90 for (size_t i = 0; i < 500; ++i)
91 longText.append("a");
92 equals(_error->Error("%s horrible %s %d times", longText.c_str(), "happend", 2), false);
93 equals(_error->PopMessage(text), true);
94 equals(text, std::string(longText).append(" horrible happend 2 times"));
95
96 equals(_error->Errno("errno", "%s horrible %s %d times", longText.c_str(), "happend", 2), false);
97 equals(_error->PopMessage(text), true);
98 equals(text, std::string(longText).append(" horrible happend 2 times - errno (0: ").append(textOfErrnoZero).append(")"));
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");
107 equals(_error->Warning("%s", longText.c_str()), false);
108 equals(_error->PopMessage(text), false);
109 equals(text, longText);
110
111 return 0;
112 }