]>
git.saurik.com Git - apt.git/blob - test/libapt/globalerror_test.cc
3 #include <apt-pkg/error.h>
10 #include <gtest/gtest.h>
12 TEST(GlobalErrorTest
,BasicDiscard
)
15 EXPECT_TRUE(e
.empty());
16 EXPECT_FALSE(e
.PendingError());
17 EXPECT_FALSE(e
.Notice("%s Notice", "A"));
18 EXPECT_TRUE(e
.empty());
19 EXPECT_FALSE(e
.empty(GlobalError::DEBUG
));
20 EXPECT_FALSE(e
.PendingError());
21 EXPECT_FALSE(e
.Error("%s horrible %s %d times", "Something", "happened", 2));
22 EXPECT_TRUE(e
.PendingError());
25 EXPECT_FALSE(e
.PopMessage(text
));
26 EXPECT_TRUE(e
.PendingError());
27 EXPECT_EQ("A Notice", text
);
28 EXPECT_TRUE(e
.PopMessage(text
));
29 EXPECT_EQ("Something horrible happened 2 times", text
);
30 EXPECT_TRUE(e
.empty(GlobalError::DEBUG
));
31 EXPECT_FALSE(e
.PendingError());
32 EXPECT_FALSE(e
.Error("%s horrible %s %d times", "Something", "happened", 2));
33 EXPECT_TRUE(e
.PendingError());
34 EXPECT_FALSE(e
.empty(GlobalError::FATAL
));
37 EXPECT_TRUE(e
.empty());
38 EXPECT_FALSE(e
.PendingError());
40 TEST(GlobalErrorTest
,StackPushing
)
43 EXPECT_FALSE(e
.Notice("%s Notice", "A"));
44 EXPECT_FALSE(e
.Error("%s horrible %s %d times", "Something", "happened", 2));
45 EXPECT_TRUE(e
.PendingError());
46 EXPECT_FALSE(e
.empty(GlobalError::NOTICE
));
48 EXPECT_TRUE(e
.empty(GlobalError::NOTICE
));
49 EXPECT_FALSE(e
.PendingError());
50 EXPECT_FALSE(e
.Warning("%s Warning", "A"));
51 EXPECT_TRUE(e
.empty(GlobalError::ERROR
));
52 EXPECT_FALSE(e
.PendingError());
54 EXPECT_FALSE(e
.empty(GlobalError::ERROR
));
55 EXPECT_TRUE(e
.PendingError());
58 EXPECT_FALSE(e
.PopMessage(text
));
59 EXPECT_TRUE(e
.PendingError());
60 EXPECT_EQ("A Notice", text
);
61 EXPECT_TRUE(e
.PopMessage(text
));
62 EXPECT_EQ("Something horrible happened 2 times", text
);
63 EXPECT_FALSE(e
.PendingError());
64 EXPECT_TRUE(e
.empty());
66 EXPECT_FALSE(e
.Notice("%s Notice", "A"));
67 EXPECT_FALSE(e
.Error("%s horrible %s %d times", "Something", "happened", 2));
68 EXPECT_TRUE(e
.PendingError());
69 EXPECT_FALSE(e
.empty(GlobalError::NOTICE
));
71 EXPECT_TRUE(e
.empty(GlobalError::NOTICE
));
72 EXPECT_FALSE(e
.PendingError());
73 EXPECT_FALSE(e
.Warning("%s Warning", "A"));
74 EXPECT_TRUE(e
.empty(GlobalError::ERROR
));
75 EXPECT_FALSE(e
.PendingError());
77 EXPECT_FALSE(e
.empty(GlobalError::ERROR
));
78 EXPECT_TRUE(e
.PendingError());
79 EXPECT_FALSE(e
.PopMessage(text
));
80 EXPECT_TRUE(e
.PendingError());
81 EXPECT_EQ("A Notice", text
);
82 EXPECT_TRUE(e
.PopMessage(text
));
83 EXPECT_EQ("Something horrible happened 2 times", text
);
84 EXPECT_FALSE(e
.PendingError());
85 EXPECT_FALSE(e
.empty());
86 EXPECT_FALSE(e
.PopMessage(text
));
87 EXPECT_EQ("A Warning", text
);
88 EXPECT_TRUE(e
.empty());
90 TEST(GlobalErrorTest
,Errno
)
93 std::string
const textOfErrnoZero(strerror(0));
95 EXPECT_FALSE(e
.Errno("errno", "%s horrible %s %d times", "Something", "happened", 2));
96 EXPECT_FALSE(e
.empty());
97 EXPECT_TRUE(e
.PendingError());
99 EXPECT_TRUE(e
.PopMessage(text
));
100 EXPECT_FALSE(e
.PendingError());
101 EXPECT_EQ(std::string("Something horrible happened 2 times - errno (0: ").append(textOfErrnoZero
).append(")"), text
);
102 EXPECT_TRUE(e
.empty());
104 TEST(GlobalErrorTest
,LongMessage
)
107 std::string
const textOfErrnoZero(strerror(0));
109 std::string text
, longText
;
110 for (size_t i
= 0; i
< 500; ++i
)
111 longText
.append("a");
112 EXPECT_FALSE(e
.Error("%s horrible %s %d times", longText
.c_str(), "happened", 2));
113 EXPECT_TRUE(e
.PopMessage(text
));
114 EXPECT_EQ(std::string(longText
).append(" horrible happened 2 times"), text
);
116 EXPECT_FALSE(e
.Errno("errno", "%s horrible %s %d times", longText
.c_str(), "happened", 2));
117 EXPECT_TRUE(e
.PopMessage(text
));
118 EXPECT_EQ(std::string(longText
).append(" horrible happened 2 times - errno (0: ").append(textOfErrnoZero
).append(")"), text
);
120 TEST(GlobalErrorTest
,UTF8Message
)
125 EXPECT_FALSE(e
.Warning("Репозиторий не обновлён и будут %d %s", 4, "test"));
126 EXPECT_FALSE(e
.PopMessage(text
));
127 EXPECT_EQ("Репозиторий не обновлён и будут 4 test", text
);
129 std::string longText
;
130 for (size_t i
= 0; i
< 50; ++i
)
131 longText
.append("РезийбёбAZ");
132 EXPECT_FALSE(e
.Warning("%s", longText
.c_str()));
133 EXPECT_FALSE(e
.PopMessage(text
));
134 EXPECT_EQ(longText
, text
);