1 /*
2     SPDX-FileCopyrightText: 2011 Andi Fischer <andi.fischer@hispeed.ch>
3 
4     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5 */
6 
7 #include "testclassifier.h"
8 
9 // app include
10 #include "uml.h"
11 #include "association.h"
12 #include "classifier.h"
13 #include "datatype.h"
14 #include "operation.h"
15 #include "model_utils.h"
16 
17 //-----------------------------------------------------------------------------
18 
test_equal()19 void TEST_classifier::test_equal()
20 {
21     UMLClassifier* a = new UMLClassifier("Test A", Uml::ID::None);
22     UMLClassifier* b = a;
23     UMLClassifier* c = new UMLClassifier("Test A", Uml::ID::None);
24     UMLClassifier* d = new UMLClassifier("Test B", Uml::ID::None);
25     QCOMPARE(*a == *b, true);
26     QCOMPARE(*a == *c, true);
27     QCOMPARE(*b == *c, true);
28     QCOMPARE(*c == *d, false);
29 }
30 
test_copyInto()31 void TEST_classifier::test_copyInto()
32 {
33     UMLClassifier a("Test A", Uml::ID::None);
34     UMLClassifier b("Test B", Uml::ID::None);
35     b.copyInto(&a);
36     QCOMPARE(a == b, true);
37 }
38 
test_clone()39 void TEST_classifier::test_clone()
40 {
41     UMLClassifier* a = new UMLClassifier("Test A", Uml::ID::None);
42     UMLClassifier* b = a->clone()->asUMLClassifier();
43     QCOMPARE(*a == *b, true);
44 }
45 
test_addAttributeWithType()46 void TEST_classifier::test_addAttributeWithType()
47 {
48     UMLClassifier a("Test A", Uml::ID::None);
49     a.addAttribute("attributeA_", Uml::ID::None);
50     UMLAttribute *attrA = a.addAttribute("attributeA_", Uml::ID::None);
51     /* UMLAttribute* attrB = */ a.addAttribute("attributeB_", Uml::ID::None);
52     int num1 = a.getAttributeList().count();
53     QCOMPARE(num1, 2);
54     int num2 = a.removeAttribute(attrA);
55     QCOMPARE(num2, 1);  // one deleted
56     int num3 = a.getAttributeList().count();
57     QCOMPARE(num3, num1 - 1);
58 }
59 
test_addAttributeWithObject()60 void TEST_classifier::test_addAttributeWithObject()
61 {
62     IS_NOT_IMPL();
63 }
64 
test_addAttributeWithAttribute()65 void TEST_classifier::test_addAttributeWithAttribute()
66 {
67     IS_NOT_IMPL();
68 }
69 
test_removeAndCountAttribute()70 void TEST_classifier::test_removeAndCountAttribute()
71 {
72     UMLClassifier* a = new UMLClassifier("Test A", Uml::ID::None);
73     int num0 = a->getAttributeList().count();
74     QCOMPARE(num0, 0);  // no attributes present yet
75     /*UMLAttribute* attrA = */ a->addAttribute("attributeA_", Uml::ID::None);
76     UMLAttribute* attrB = a->addAttribute("attributeB_", Uml::ID::None);
77     UMLAttribute* attrC = a->addAttribute("attributeC_", Uml::ID::None);
78     /* UMLAttribute* attrD = */ a->addAttribute("attributeD_", Uml::ID::None);
79     int num1 = a->getAttributeList().count();
80     QCOMPARE(num1, 4);
81     int num2 = a->removeAttribute(attrB);
82     QCOMPARE(num2, 3);  // one deleted
83     num2 = a->removeAttribute(attrC);
84     QCOMPARE(num2, 2);  // one deleted
85     int num3 = a->getAttributeList().count();
86     QCOMPARE(num3, 2);
87 }
88 
test_getAttributeList()89 void TEST_classifier::test_getAttributeList()
90 {
91     IS_NOT_IMPL();
92 }
93 
test_addOperationWithPosition()94 void TEST_classifier::test_addOperationWithPosition()
95 {
96     IS_NOT_IMPL();
97 }
98 
test_addOperationWithLog()99 void TEST_classifier::test_addOperationWithLog()
100 {
101     IS_NOT_IMPL();
102 }
103 
test_checkOperationSignature()104 void TEST_classifier::test_checkOperationSignature()
105 {
106     IS_NOT_IMPL();
107 }
108 
test_removeAndCountOperation()109 void TEST_classifier::test_removeAndCountOperation()
110 {
111     IS_NOT_IMPL();
112 }
113 
test_getOperationList()114 void TEST_classifier::test_getOperationList()
115 {
116     IS_NOT_IMPL();
117 }
118 
test_addTemplateWithType()119 void TEST_classifier::test_addTemplateWithType()
120 {
121     IS_NOT_IMPL();
122 }
123 
test_addTemplateWithLog()124 void TEST_classifier::test_addTemplateWithLog()
125 {
126     IS_NOT_IMPL();
127 }
128 
test_addTemplateWithPosition()129 void TEST_classifier::test_addTemplateWithPosition()
130 {
131     IS_NOT_IMPL();
132 }
133 
test_removeAndCountTemplate()134 void TEST_classifier::test_removeAndCountTemplate()
135 {
136     IS_NOT_IMPL();
137 }
138 
test_findTemplate()139 void TEST_classifier::test_findTemplate()
140 {
141     IS_NOT_IMPL();
142 }
143 
test_getTemplateList()144 void TEST_classifier::test_getTemplateList()
145 {
146     IS_NOT_IMPL();
147 }
148 
test_takeItem()149 void TEST_classifier::test_takeItem()
150 {
151     IS_NOT_IMPL();
152 }
153 
test_getFilteredList()154 void TEST_classifier::test_getFilteredList()
155 {
156     IS_NOT_IMPL();
157 }
158 
test_resolveRef()159 void TEST_classifier::test_resolveRef()
160 {
161     qDebug() << "already tested by testumlobject";
162 }
163 
test_findOperations()164 void TEST_classifier::test_findOperations()
165 {
166     UMLClassifier c("Test A", Uml::ID::None);
167     UMLOperation o1(nullptr, "testop1");
168     c.addOperation(&o1);
169     int num1 = c.getOpList().count();
170     QCOMPARE(num1, 1);
171     UMLOperation o2(nullptr, "testop2");
172     c.addOperation(&o2);
173     int num2 = c.getOpList().count();
174     QCOMPARE(num2, 2);
175     QCOMPARE(c.findOperations("testop1").count(), 1);
176     QCOMPARE(c.findOperations("testop2").count(), 1);
177     QCOMPARE(c.findOperations("testOp1").count(), 0);
178     QCOMPARE(c.findOperations("testOp2").count(), 0);
179     // case insensitive language
180     Uml::ProgrammingLanguage::Enum lang = UMLApp::app()->activeLanguage();
181     UMLApp::app()->setActiveLanguage(Uml::ProgrammingLanguage::PostgreSQL);
182     QCOMPARE(c.findOperations("testOp1").count(), 1);
183     QCOMPARE(c.findOperations("testOp2").count(), 1);
184     UMLApp::app()->setActiveLanguage(lang);
185 }
186 
test_findChildObjectById()187 void TEST_classifier::test_findChildObjectById()
188 {
189     IS_NOT_IMPL();
190 }
191 
test_findOperation()192 void TEST_classifier::test_findOperation()
193 {
194     UMLClassifier c("Test A", Uml::ID::None);
195     UMLOperation o1(nullptr, "testop1");
196     UMLAttribute a1(nullptr, "aParam");
197     a1.setTypeName("int");
198     o1.addParm(&a1);
199     c.addOperation(&o1);
200     UMLOperation o2(nullptr, "testop1");
201     UMLAttribute a2(nullptr, "aParam");
202     a2.setTypeName("double");
203     o2.addParm(&a2);
204     c.addOperation(&o2);
205     Model_Utils::NameAndType_List searchTypes;
206     // first function
207     searchTypes << Model_Utils::NameAndType("aParam", a1.getType());
208     UMLOperation *o = c.findOperation("testop1", searchTypes);
209     QVERIFY(o);
210     // second function
211     searchTypes.clear();
212     searchTypes << Model_Utils::NameAndType("aParam", a2.getType());
213     o = c.findOperation("testop1", searchTypes);
214     QVERIFY(o);
215 
216     // unknown type
217     UMLDatatype d1("someType");
218     searchTypes.clear();
219     searchTypes << Model_Utils::NameAndType("aParam", &d1);
220     o = c.findOperation("testop1", searchTypes);
221     QVERIFY(!o);
222 
223 #if 0
224     // different param name
225     searchTypes.clear();
226     searchTypes << Model_Utils::NameAndType("otherParam", a1.getType());
227     o = c.findOperation("testop1", searchTypes);
228     QVERIFY(!o);
229 
230     // different param name
231     searchTypes.clear();
232     searchTypes << Model_Utils::NameAndType("otherParam", a2.getType());
233     o = c.findOperation("testop1", searchTypes);
234     QVERIFY(!o);
235 #else
236     qDebug() <<"finding param names is not supported";
237 #endif
238 }
239 
test_findSuperClassConcepts()240 void TEST_classifier::test_findSuperClassConcepts()
241 {
242     UMLClassifier c1("Test A");
243     UMLClassifier c2("Test B");
244     UMLAssociation a1(Uml::AssociationType::Generalization, &c1, &c2);
245     QCOMPARE(c1.findSuperClassConcepts(UMLClassifier::ALL).size(), 0);
246     c1.addAssociationEnd(&a1);
247     QCOMPARE(c1.findSuperClassConcepts(UMLClassifier::ALL).size(), 1);
248     UMLAssociation a2(Uml::AssociationType::Realization, &c1, &c2);
249     c1.addAssociationEnd(&a2);
250     QCOMPARE(c1.findSuperClassConcepts(UMLClassifier::ALL).size(), 2);
251 }
252 
test_findSubClassConcepts()253 void TEST_classifier::test_findSubClassConcepts()
254 {
255     UMLClassifier c1("Test A");
256     UMLClassifier c2("Test B");
257     UMLAssociation a1(Uml::AssociationType::Generalization, &c1, &c2);
258     QCOMPARE(c2.findSubClassConcepts(UMLClassifier::ALL).size(), 0);
259     c2.addAssociationEnd(&a1);
260     QCOMPARE(c2.findSubClassConcepts(UMLClassifier::ALL).size(), 1);
261     UMLAssociation a2(Uml::AssociationType::Realization, &c1, &c2);
262     c2.addAssociationEnd(&a2);
263     QCOMPARE(c2.findSubClassConcepts(UMLClassifier::ALL).size(), 2);
264 }
265 
test_setGetClassAssoc()266 void TEST_classifier::test_setGetClassAssoc()
267 {
268     IS_NOT_IMPL();
269 }
270 
test_isInterface()271 void TEST_classifier::test_isInterface()
272 {
273     UMLClassifier c1("Test A");
274     QCOMPARE(c1.isInterface(), false);
275     c1.setBaseType(UMLObject::ObjectType::ot_Interface);
276     QCOMPARE(c1.isInterface(), true);
277     c1.setBaseType(UMLObject::ObjectType::ot_Class);
278     QCOMPARE(c1.isInterface(), false);
279 }
280 
test_setGetOriginType()281 void TEST_classifier::test_setGetOriginType()
282 {
283     IS_NOT_IMPL();
284 }
285 
test_setGetIsReference()286 void TEST_classifier::test_setGetIsReference()
287 {
288     IS_NOT_IMPL();
289 }
290 
test_hasAbstractOps()291 void TEST_classifier::test_hasAbstractOps()
292 {
293     IS_NOT_IMPL();
294 }
295 
test_makeChildObject()296 void TEST_classifier::test_makeChildObject()
297 {
298     IS_NOT_IMPL();
299 }
300 
test_getUniAssociationToBeImplemented()301 void TEST_classifier::test_getUniAssociationToBeImplemented()
302 {
303     IS_NOT_IMPL();
304 }
305 
306 typedef TestUML<UMLClassifier, const QString&> TestUMLClassifier;
307 
test_saveAndLoad()308 void TEST_classifier::test_saveAndLoad()
309 {
310     UMLPackage parent("test package");
311     TestUMLClassifier c1("Test A");
312     c1.setUMLPackage(&parent);
313     UMLOperation o1(nullptr, "testop1");
314     c1.addOperation(&o1);
315     UMLOperation o2(nullptr, "testop2");
316     c1.addOperation(&o2);
317     QString save = c1.testSave1();
318     //c1.testDump("save");
319     TestUMLClassifier c2;
320     c2.setUMLPackage(&parent);
321     QCOMPARE(c2.testLoad1(save), true);
322     //c2.testDump("after load");
323     QCOMPARE(c2.testSave1(), save);
324 }
325 
326 QTEST_MAIN(TEST_classifier)
327