1 /*
2
3 Firewall Builder
4
5 Copyright (C) 2010 NetCitadel, LLC
6
7 Author: Roman Bovsunivskiy a2k0001@gmail.com
8
9 $Id: TagServiceDialogTest.cpp 2723 2010-03-16 17:32:18Z a2k $
10
11 This program is free software which we release under the GNU General Public
12 License. You may redistribute and/or modify this program under the terms
13 of that license as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 To get a copy of the GNU General Public License, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
24 */
25
26 #include "TagServiceDialogTest.h"
27
28 #include "../../../../config.h"
29 //#include "../../global.h"
30
31 #include <qapplication.h>
32 #include <qfile.h>
33 #include <qtextstream.h>
34 #include <QTest>
35 #include <iostream>
36
37 #include <QProcess>
38 #include <QRegExp>
39 #include <QDebug>
40
41 #include <QToolButton>
42 #include <QMessageBox>
43 #include <QWidget>
44 #include <QLineEdit>
45 #include "FWWindow.h"
46 #include "ProjectPanel.h"
47 #include "ObjectTreeView.h"
48 #include "ObjectTreeViewItem.h"
49 #include "ObjectEditor.h"
50 #include "FWObjectClipboard.h"
51 #include "TextEditWidget.h"
52 #include "fwbuilder/Address.h"
53 #include "fwbuilder/IPv4.h"
54 #include "fwbuilder/IPv6.h"
55 #include "FWBTree.h"
56 #include "fwbuilder/Library.h"
57 #include "fwbuilder/FWObjectDatabase.h"
58 #include "TagServiceDialogTest.h"
59 #include "StartTipDialog.h"
60 #include "fwbuilder/FWObjectDatabase.h"
61 #include "fwbuilder/Interface.h"
62 #include "IPServiceDialog.h"
63 #include "fwbuilder/IPService.h"
64 #include "fwbuilder/TagService.h"
65 #include "TagServiceDialog.h"
66
67 using namespace std;
68 using namespace libfwbuilder;
69
initTestCase()70 void TagServiceDialogTest::initTestCase()
71 {
72 new FWObjectClipboard();
73 mw = new FWWindow();
74 mw->show();
75 mw->startupLoad();
76 StartTipDialog *d = mw->findChild<StartTipDialog*>();
77 if (d!=NULL) d->close();
78 om = dynamic_cast<ObjectManipulator*>(mw->getCurrentObjectTree()->parent()->parent());
79 QTest::qWait(1000);
80 }
81
findUserLibrary()82 Library* TagServiceDialogTest::findUserLibrary()
83 {
84 Library *lib = NULL;
85 foreach (FWObject *obj, mw->db()->getByType(Library::TYPENAME))
86 {
87 if (obj->getName() == "User")
88 {
89 lib = Library::cast(obj);
90 break;
91 }
92 }
93 return lib;
94 }
95
96
testDialog()97 void TagServiceDialogTest::testDialog()
98 {
99 TagService *service = TagService::cast(om->createObject(FWBTree().getStandardSlotForObject(findUserLibrary(), TagService::TYPENAME), TagService::TYPENAME, "testTagService"));
100 om->editObject(service);
101
102 TagServiceDialog *dialog = mw->findChild<TagServiceDialog*>("w_TagServiceDialog");
103 QLineEdit *obj_name = dialog->findChild<QLineEdit*>("obj_name");
104 QLineEdit *tagcode = dialog->findChild<QLineEdit*>("tagcode");
105 TextEditWidget *comment = dialog->findChild<TextEditWidget*>("comment");
106
107 obj_name->clear();
108 QTest::keyClicks(obj_name, "TestTagService");
109 QTest::keyClick(obj_name, Qt::Key_Enter);
110 QVERIFY(service->getName() == "TestTagService");
111
112 tagcode->clear();
113 QTest::keyClicks(tagcode, "45");
114 QTest::keyClick(tagcode, Qt::Key_Enter);
115 QVERIFY(service->getCode() == "45");
116
117 comment->clear();
118 QTest::mouseClick(comment, Qt::LeftButton);
119 QTest::keyClicks(comment, "Test comment");
120 QTest::mouseClick(comment, Qt::LeftButton);
121 QTest::keyClick(comment, Qt::Key_Tab);
122 QTest::qWait(100);
123 QVERIFY (service->getComment() == "Test comment");
124
125 }
126