Skip to content

Commit a69be97

Browse files
committed
b-169 tests for new container feature
1 parent 512dbee commit a69be97

File tree

7 files changed

+113
-2
lines changed

7 files changed

+113
-2
lines changed

src/modules/namespace/regolaprefixes.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,54 @@ void Element::collectPrefixes(PrefixInfo & info, Element * selection, const bool
182182
}
183183
}
184184

185+
void Element::collectAllPrefixes(PrefixInfo & info, Element * selection, const bool inSelection, const bool inBookmark)
186+
{
187+
QSet<QString> prefixes;
188+
QString name, prefix;
189+
XmlUtils::decodeQualifiedName(tag(), prefix, name);
190+
if(!prefix.isEmpty()) {
191+
prefixes.insert(prefix);
192+
}
193+
foreach(Attribute * attr, getAttributesList()) {
194+
XmlUtils::decodeQualifiedName(attr->name, prefix, name);
195+
if(!prefix.isEmpty() && XmlUtils::isDataAttribute(attr->name)) {
196+
prefixes.insert(prefix);
197+
} else if(!prefix.isEmpty() && XmlUtils::isDeclaringNS(attr->name)) {
198+
// handles xmlns:XXX
199+
if(!name.isEmpty()) {
200+
prefixes.insert(name);
201+
}
202+
}
203+
}
204+
bool thisBookmark = false ;
205+
bool isSelection = this == selection;
206+
if(NULL != parentRule) {
207+
if(parentRule->isBookmarked(this)) {
208+
thisBookmark = true;
209+
}
210+
}
211+
foreach(const QString & prefix, prefixes.values()) {
212+
info.allPrefixes.insert(prefix);
213+
if(isSelection) {
214+
info.selectionPrefixes.insert(prefix);
215+
}
216+
if(inSelection || isSelection) {
217+
info.selectionPrefixesRecursive.insert(prefix);
218+
}
219+
if(thisBookmark) {
220+
info.bookmarksPrefixesRecursive.insert(prefix);
221+
}
222+
if(inBookmark || thisBookmark) {
223+
info.bookmarksPrefixesRecursive.insert(prefix);
224+
}
225+
}
226+
foreach(Element * child, getChildItemsRef()) {
227+
if(child->isElement()) {
228+
child->collectAllPrefixes(info, selection, inSelection || isSelection, inBookmark || thisBookmark);
229+
}
230+
}
231+
}
232+
185233
bool Regola::removePrefix(const QString &removedPrefix, QList<Element*> elements, TargetSelection::Type targetSelection,
186234
const bool isAllPrefixes, ElementUndoObserver *observer)
187235
{

src/modules/xml/regolaContainer.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,9 @@ bool Regola::removeParentAction(Element *element, QTreeWidget *tree, int &insPos
331331

332332
QString Regola::unusedPrefixByElement(Element *element)
333333
{
334-
Utils::TEST_ME("");
335334
if(NULL != element) {
336335
PrefixInfo info;
337-
element->collectPrefixes(info, element, true, false);
336+
element->collectAllPrefixes(info, element, true, false);
338337
{
339338
const QString stdPrefix = "xsl";
340339
if(!info.allPrefixes.contains(stdPrefix)) {

test/data/container/pr_0_start.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<root>
2+
<a1><b/></a1>
3+
<a2><b/></a2>
4+
<a3><b/></a3>
5+
</root>

test/data/container/pr_1_start.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<root>
2+
<a1><b/></a1>
3+
<a2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><b/></a2>
4+
<a3><b/></a3>
5+
</root>

test/data/container/pr_3_start.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<root xmlns:xsl="xxcvxcvxcvxcbv" xmlns:xsl3="xxcvxcvxcvxcbv">
2+
<a1><b/></a1>
3+
<a2 xmlns:xsl="xxcvxcvxcvxcbv" xmlns:xsl0="xxcvxcvxcvxcbv" xmlns:xsl4="xxcvxcvxcvxcbv" ><b xmlns:xsl1="xxcvxcvxcvxcbv" /></a2>
4+
<a3><b/></a3>
5+
</root>

test/testcontainer.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,31 @@ bool TestContainer::testEnable(const bool isInsert, const QString &fileStart, co
865865
#define ISP_NRIS_START "../test/data/container/dp_4_start.xml"
866866
#define ISP_NRIS_END "../test/data/container/dp_4_end.xml"
867867

868+
#define PR_0_START "../test/data/container/pr_0_start.xml"
869+
#define PR_1_START "../test/data/container/pr_1_start.xml"
870+
#define PR_2_START "../test/data/container/pr_3_start.xml"
871+
868872
bool TestContainer::testInsertDisablingParent()
869873
{
870874
_testName = "testInsertDisablingParent";
875+
876+
{
877+
QList<int> selectPath;
878+
selectPath << 0 << 1 ;
879+
// none
880+
if( !testUnusedPrefix("testUnusedPrefix0", PR_0_START, selectPath, "xsl") ) {
881+
return false;
882+
}
883+
// exists
884+
if( !testUnusedPrefix("testUnusedPrefix1", PR_1_START, selectPath, "xsl0") ) {
885+
return false;
886+
}
887+
// exists, but other
888+
if( !testUnusedPrefix("testUnusedPrefix2", PR_2_START, selectPath, "xsl2") ) {
889+
return false;
890+
}
891+
}
892+
871893
QList<int> selectPath;
872894
selectPath.clear();
873895
selectPath << 0 << 1 ;
@@ -988,3 +1010,29 @@ bool TestContainer::testGeneric2(const QString &testName, const QString &fileSta
9881010
}
9891011
return true;
9901012
}
1013+
1014+
bool TestContainer::testUnusedPrefix(const QString &testName, const QString &fileStart, QList<int> selectPath, const QString &expectedPrefix)
1015+
{
1016+
_testName = testName ;
1017+
QString actionName = "testUnusedPrefix" ;
1018+
QString msgFile = QString(" file:'%1'").arg(fileStart);
1019+
1020+
App app;
1021+
if(!app.init()) {
1022+
return error(QString("init app %1").arg(msgFile));
1023+
}
1024+
if( !app.mainWindow()->loadFile(fileStart) ){
1025+
return error(QString("Unable to load file:%1").arg(fileStart));
1026+
}
1027+
Regola *regola = app.mainWindow()->getRegola();
1028+
Element *selectedElement = NULL ;
1029+
selectedElement = regola->findElementByArray(selectPath);
1030+
if( NULL == selectedElement ) {
1031+
return error(QString("Unable to find element for path:'%1' file:'%2'").arg(listIntToString(selectPath)).arg(fileStart));
1032+
}
1033+
const QString resultingPrefix = regola->unusedPrefixByElement(selectedElement);
1034+
if( resultingPrefix != expectedPrefix ) {
1035+
return error(QString("Expecting '%1', found:'%2'").arg(expectedPrefix).arg(resultingPrefix));
1036+
}
1037+
return true;
1038+
}

test/testcontainer.h

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class TestContainer : public TestBase
3333
bool testGeneric(const bool isInsert, const QString &testName, const QString &fileStart, const QString &fileEnd , QList<int> selectPath, const bool expected);
3434
bool testGeneric2(const QString &testName, const QString &fileStart, const QString &fileEnd, QList<int> selectPath);
3535
bool testEnableRegola(MainWindow *window, const QString &fileName, QList<int> &selectPath, const bool expected, const QString &actionName, Element *&selectedElement);
36+
bool testUnusedPrefix(const QString &testName, const QString &fileStart, QList<int> selectPath, const QString &expectedPrefix);
3637
public:
3738
TestContainer();
3839
~TestContainer();

0 commit comments

Comments
 (0)