|
23 | 23 | #include "checkmemoryleak.h" |
24 | 24 | #include "testsuite.h" |
25 | 25 | #include "symboldatabase.h" |
| 26 | +#include "preprocessor.h" |
26 | 27 | #include <sstream> |
27 | 28 |
|
28 | 29 | extern std::ostringstream errout; |
@@ -6273,3 +6274,57 @@ class TestMemleakNoVar : public TestFixture { |
6273 | 6274 | } |
6274 | 6275 | }; |
6275 | 6276 | REGISTER_TEST(TestMemleakNoVar) |
| 6277 | + |
| 6278 | + |
| 6279 | + |
| 6280 | + |
| 6281 | + |
| 6282 | +class TestMemleakGLib : public TestFixture { |
| 6283 | +public: |
| 6284 | + TestMemleakGLib() : TestFixture("TestMemleakGLib") { |
| 6285 | + } |
| 6286 | + |
| 6287 | +private: |
| 6288 | + void check(const char code[]) { |
| 6289 | + // Clear the error buffer.. |
| 6290 | + errout.str(""); |
| 6291 | + |
| 6292 | + Settings settings; |
| 6293 | + LOAD_LIB("gtk.cfg"); |
| 6294 | + settings.library = _lib; |
| 6295 | + |
| 6296 | + // Preprocess... |
| 6297 | + Preprocessor preprocessor(&settings, this); |
| 6298 | + std::istringstream istrpreproc(code); |
| 6299 | + std::map<std::string, std::string> actual; |
| 6300 | + preprocessor.preprocess(istrpreproc, actual, "test.c"); |
| 6301 | + |
| 6302 | + // Tokenize.. |
| 6303 | + Tokenizer tokenizer(&settings, this); |
| 6304 | + std::istringstream istr(actual[""]); |
| 6305 | + tokenizer.tokenize(istr, "test.c"); |
| 6306 | + tokenizer.simplifyTokenList2(); |
| 6307 | + |
| 6308 | + // Check for memory leaks.. |
| 6309 | + CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this); |
| 6310 | + checkMemoryLeak.checkReallocUsage(); |
| 6311 | + checkMemoryLeak.check(); |
| 6312 | + } |
| 6313 | + |
| 6314 | + void run() { |
| 6315 | + TEST_CASE(glib1); |
| 6316 | + } |
| 6317 | + |
| 6318 | + void glib1() { |
| 6319 | + check("void f(gchar *_a, gchar *_b) {" |
| 6320 | + " g_return_if_fail(_a);" |
| 6321 | + " gchar *a = g_strdup(_a);" |
| 6322 | + " g_return_if_fail(_b);" |
| 6323 | + " gchar *b = g_strdup(_b);" |
| 6324 | + " g_free(a);" |
| 6325 | + " g_free(b);" |
| 6326 | + "}"); |
| 6327 | + ASSERT_EQUALS("[test.c:1]: (error) Memory leak: a\n", errout.str()); |
| 6328 | + } |
| 6329 | +}; |
| 6330 | +static TestMemleakGLib testMemleakGLib; |
0 commit comments