From 57c5ca5b7fc3db3ab16d9a1cf2760d114e5685ca Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 17 Aug 2010 07:24:27 +0000 Subject: More tests --- client/test/.cvsignore | 1 + client/test/testlineedit.cc | 9 +++++++++ client/test/testmacrowindow.cc | 30 ++++++++++++++++++++++++++++++ client/test/testmultilist.cc | 35 +++++++++++++++++++++++++++++++++++ client/test/testresumewidget.cc | 17 +++++++++++++++++ client/test/testwindow.cc | 33 +++++++++++++++++++++++++++++++++ client/test/util.h | 13 +++++++++++++ 7 files changed, 138 insertions(+) create mode 100644 client/test/testmacrowindow.cc create mode 100644 client/test/testmultilist.cc create mode 100644 client/test/testresumewidget.cc create mode 100644 client/test/testwindow.cc (limited to 'client') diff --git a/client/test/.cvsignore b/client/test/.cvsignore index 868255a..dcb34bb 100644 --- a/client/test/.cvsignore +++ b/client/test/.cvsignore @@ -1 +1,2 @@ test*.log +test*.bin \ No newline at end of file diff --git a/client/test/testlineedit.cc b/client/test/testlineedit.cc index 0cf70fd..577e0da 100644 --- a/client/test/testlineedit.cc +++ b/client/test/testlineedit.cc @@ -10,6 +10,15 @@ class TestLineEdit: public QObject Q_OBJECT private slots: void creation() { TEST_CREATION(LineEdit); } + + void memleak() { + QDomDocument doc; doc.setContent(xml); + QDomElement e = doc.documentElement(); + MacroWindow *w = createMacroWindow(); + TEST_MEMLEAK(LineEdit le(e, w)); + delete w; + } + void disable() { TEST_DISABLE(LineEdit); } void value() { TEST_VALUE(LineEdit); } void edit() diff --git a/client/test/testmacrowindow.cc b/client/test/testmacrowindow.cc new file mode 100644 index 0000000..6c90445 --- /dev/null +++ b/client/test/testmacrowindow.cc @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +#include +#include "util.h" +#include "macrowindow.h" + +static QString xml = "\n" + "\n" + "\n" + ""; + +class TestMacroWindow: public QObject +{ +Q_OBJECT +private slots: + void memleak() { + /* + MacroWindow(NetCom &netcom, QDomNode &xml_doc, QString templ, + bool collapsed = true, bool compact = false); + */ + QDomDocument doc;// doc.setContent(xml); + NetCom netcom("nohost", 42); + + // MacroWindow w(netcom, doc, "test"); + + TEST_MEMLEAK(MacroWindow w(netcom, doc, "test")); + } +}; + +QTEST_MAIN(TestMacroWindow) +#include "testmacrowindow.moc" diff --git a/client/test/testmultilist.cc b/client/test/testmultilist.cc new file mode 100644 index 0000000..65c14d7 --- /dev/null +++ b/client/test/testmultilist.cc @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +#include +#include "util.h" +#include "widgets/multilist.h" +#include +#include + +static QString xml = + ""; +static QString xml2 = + "" + " " + ""; + +class TestMultiList: public QObject +{ +Q_OBJECT +private slots: + void memleak() { + QDomDocument doc; doc.setContent(xml2); + QDomElement e = doc.documentElement(); + MacroWindow *w = createMacroWindow(); + + // FIXME: this is used to make sure all resources (icons and pixmaps) + // are loaded. + MultiList ml(e, w); + + TEST_MEMLEAK(MultiList ml(e, w)); + + delete w; + } +}; + +QTEST_MAIN(TestMultiList) +#include "testmultilist.moc" diff --git a/client/test/testresumewidget.cc b/client/test/testresumewidget.cc new file mode 100644 index 0000000..299d597 --- /dev/null +++ b/client/test/testresumewidget.cc @@ -0,0 +1,17 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +#include +#include "util.h" +#include "resumewidget.h" + +class TestResumeWidget: public QObject +{ +Q_OBJECT +private slots: + void memleak() { + + TEST_MEMLEAK(ResumeWidget r(false)); + } +}; + +QTEST_MAIN(TestResumeWidget) +#include "testresumewidget.moc" diff --git a/client/test/testwindow.cc b/client/test/testwindow.cc new file mode 100644 index 0000000..72f5533 --- /dev/null +++ b/client/test/testwindow.cc @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +#include +#include "util.h" +#include "widgets/window.h" + +static QString xml = "\n"; +static QString xml2 = "\n" + "\n" + ""; + +class TestWindow: public QObject +{ +Q_OBJECT +private slots: + void memleak() { + QDomDocument doc; doc.setContent(xml); + QDomElement e = doc.documentElement(); + MacroWindow *w = createMacroWindow(); + TEST_MEMLEAK(Window le(e, w)); + delete w; + } + + void memleak2() { + QDomDocument doc; doc.setContent(xml2); + QDomElement e = doc.documentElement(); + MacroWindow *w = createMacroWindow(); + TEST_MEMLEAK(Window le(e, w)); + delete w; + } +}; + +QTEST_MAIN(TestWindow) +#include "testwindow.moc" diff --git a/client/test/util.h b/client/test/util.h index abf7df5..03b3e8a 100644 --- a/client/test/util.h +++ b/client/test/util.h @@ -31,3 +31,16 @@ QDomElement getWidgetElement(QString type = "", QCOMPARE(wdg.value(), QString("")); \ wdg.setValue("hello", "source"); \ QCOMPARE(wdg.value(), QString("hello")); + +#define TEST_MEMLEAK(C) { \ + FILE *memlk_fp = fopen("/proc/self/statm", "r"); \ + int memlk_before; \ + int memlk_after; \ + fscanf(memlk_fp, "%d", &memlk_before); \ + { C; } \ + rewind(memlk_fp); \ + fscanf(memlk_fp, "%d", &memlk_after); \ + fclose(memlk_fp); \ + QCOMPARE(memlk_before, memlk_after); \ + } + -- cgit v1.2.3