File indexing completed on 2024-12-22 04:10:14
0001 /* 0002 * SPDX-FileCopyrightText: 2007 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_count_visitor_test.h" 0008 #include <simpletest.h> 0009 #include <QStringList> 0010 #include <KoProperties.h> 0011 0012 #include "kis_node_facade.h" 0013 0014 #include "kis_types.h" 0015 #include "kis_count_visitor.h" 0016 #include "kis_image.h" 0017 /* 0018 0019 root 0020 TestNodeA 0021 TestNodeA 0022 TestNodeA 0023 TestNodeB 0024 TestNodeB 0025 TestNodeB 0026 TestNodeC 0027 TestNodeC 0028 TestNodeC 0029 0030 */ 0031 void KisCountVisitorTest::testCounting() 0032 { 0033 0034 KisNodeSP root = new RootNode(); 0035 KisNodeFacade facade(root); 0036 0037 facade.addNode(new TestNodeA()); 0038 facade.addNode(new TestNodeB()); 0039 facade.addNode(new TestNodeC()); 0040 0041 QVERIFY(root->at(0)->inherits("TestNodeA")); 0042 root->at(0)->setName("TestNodeA 0"); 0043 QVERIFY(root->at(1)->inherits("TestNodeB")); 0044 root->at(1)->setName("TestNodeB 1"); 0045 QVERIFY(root->at(2)->inherits("TestNodeC")); 0046 root->at(2)->setName("TestNodeC 2"); 0047 0048 facade.addNode(new TestNodeA(), root->at(0)); 0049 root->at(0)->at(0)->setName("TestNodeA 0.0"); 0050 facade.addNode(new TestNodeB(), root->at(1)); 0051 root->at(1)->at(0)->setName("TestNodeB 1.0"); 0052 facade.addNode(new TestNodeC(), root->at(2)); 0053 root->at(2)->at(0)->setName("TestNodeC 2.0"); 0054 0055 facade.addNode(new TestNodeA(), root->at(0)->at(0)); 0056 root->at(0)->at(0)->at(0)->setName("TestNodeA 0.0.0"); 0057 facade.addNode(new TestNodeB(), root->at(1)->at(0)); 0058 root->at(1)->at(0)->at(0)->setName("TestNodeB 1.0.0"); 0059 facade.addNode(new TestNodeC(), root->at(2)->at(0)); 0060 root->at(2)->at(0)->at(0)->setName("TestNodeC 2.0.0"); 0061 0062 facade.addNode(new TestNodeA(), root->at(0)->at(0)->at(0)); 0063 root->at(0)->at(0)->at(0)->at(0)->setName("TestNodeA 0.0.0.0"); 0064 facade.addNode(new TestNodeB(), root->at(1)->at(0)->at(0)); 0065 root->at(1)->at(0)->at(0)->at(0)->setName("TestNodeB 1.0.0.0"); 0066 facade.addNode(new TestNodeC(), root->at(2)->at(0)->at(0)); 0067 root->at(2)->at(0)->at(0)->at(0)->setName("TestNodeC 2.0.0.0"); 0068 0069 // Count all nodes 0070 { 0071 KisCountVisitor v = KisCountVisitor(QStringList(), KoProperties()); 0072 root->accept(v); 0073 QVERIFY(v.count() == 13); 0074 } 0075 0076 // Count all nodes of type A without taking properties in mind 0077 { 0078 QStringList types; 0079 types << "TestNodeA"; 0080 KisCountVisitor v(types, KoProperties()); 0081 root->accept(v); 0082 QVERIFY(v.count() == 4); 0083 } 0084 0085 // Count all nodes of type A and B 0086 { 0087 QStringList types; 0088 types << "TestNodeA" << "TestNodeB"; 0089 KisCountVisitor v(types, KoProperties()); 0090 root->accept(v); 0091 QVERIFY(v.count() == 8); 0092 } 0093 0094 // Count all nodes of type A and B and C 0095 { 0096 QStringList types; 0097 types << "TestNodeA" << "TestNodeB" << "TestNodeC"; 0098 KisCountVisitor v(types, KoProperties()); 0099 root->accept(v); 0100 QVERIFY(v.count() == 12); 0101 } 0102 0103 // Count all nodes of type A that are visible. 0104 root->at(0)->setVisible(true); 0105 root->at(0)->at(0)->setVisible(true); 0106 root->at(0)->at(0)->at(0)->setVisible(true); 0107 root->at(0)->at(0)->at(0)->at(0)->setVisible(true); 0108 0109 // Count all nodes of type A that are visible 0110 { 0111 QStringList types; 0112 types << "TestNodeA"; 0113 KoProperties props; 0114 props.setProperty("visible", true); 0115 KisCountVisitor v(types, props); 0116 root->accept(v); 0117 QCOMPARE((int)v.count(), 4); 0118 } 0119 0120 // Count all nodes of type A that are visible 0121 { 0122 root->at(0)->at(0)->setVisible(false); 0123 QStringList types; 0124 types << "TestNodeA"; 0125 KoProperties props; 0126 props.setProperty("visible", true); 0127 KisCountVisitor v(types, props); 0128 root->accept(v); 0129 QCOMPARE((int)v.count(), 3); 0130 } 0131 } 0132 0133 SIMPLE_TEST_MAIN(KisCountVisitorTest) 0134 0135