X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Ftests%2Fxpath.cc;h=54b844f16c2376a791f8d21d6a754ff029fe4b8b;hb=911c5717bcf8da0f59048d1fd3af0da09a21cbd7;hp=968bbd9b5fa6485e3d957399b5b98949f523153e;hpb=1401a527643c4bd8712b9612821f5df7a408481e;p=ardour.git diff --git a/libs/pbd/tests/xpath.cc b/libs/pbd/tests/xpath.cc index 968bbd9b5f..54b844f16c 100644 --- a/libs/pbd/tests/xpath.cc +++ b/libs/pbd/tests/xpath.cc @@ -7,8 +7,8 @@ using namespace std; int main() { - cout << "Test 1: Find all banks in the file" << endl; - XMLTree doc("./rosegardenpatchfile.xml"); + cout << "Test 1: RosegardenPatchFile.xml: Find all banks in the file" << endl; + XMLTree doc("./RosegardenPatchFile.xml"); // "//bank" gives as last element an empty element libxml bug???? boost::shared_ptr result = doc.root()->find("//bank[@name]"); @@ -25,7 +25,7 @@ int main() } } - cout << endl << endl << "Test 2: Find all programs whose program name contains 'Latin'" << endl; + cout << endl << endl << "Test 2: RosegardenPatchFile.xml: Find all programs whose program name contains 'Latin'" << endl; result = doc.root()->find("/rosegarden-data/studio/device/bank/program[contains(@name, 'Latin')]"); assert(result->size() == 5); @@ -35,8 +35,9 @@ int main() " with name: " << (*i)->property("name")->value() << endl; } - cout << endl << endl << "Test 3: find all Sources where captured-for contains the string 'Guitar'" << endl; + cout << endl << endl << "Test 3: TestSession.ardour: find all Sources where captured-for contains the string 'Guitar'" << endl; + // We have to allocate a new document here, or we get segfaults XMLTree doc2("./TestSession.ardour"); result = doc2.root()->find("/Session/Sources/Source[contains(@captured-for, 'Guitar')]"); assert(result->size() == 16); @@ -46,7 +47,7 @@ int main() "' with id: " << (*i)->property("id")->value() << endl; } - cout << endl << endl << "Test 4: Find all elements with an 'id' and 'name' attribute" << endl; + cout << endl << endl << "Test 4: TestSession.ardour: Find all elements with an 'id' and 'name' attribute" << endl; result = doc2.root()->find("//*[@id and @name]"); @@ -57,4 +58,41 @@ int main() "' with id: " << (*i)->property("id")->value() << "' and name: " << (*i)->property("name")->value() << endl; } + + cout << endl << endl << "Test 5: ProtoolsPatchFile.midnam: Get Banks and Patches for 'Name Set 1'" << endl; + + // We have to allocate a new document here, or we get segfaults + XMLTree doc3("./ProtoolsPatchFile.midnam"); + result = doc3.root()->find("/MIDINameDocument/MasterDeviceNames/ChannelNameSet[@Name='Name Set 1']/PatchBank"); + assert(result->size() == 16); + + for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) { + cout << "\t found Patchbank " << (*i)->property("Name")->value() << endl; + boost::shared_ptr patches = (*i)->find("//Patch[@Name]"); + for(XMLSharedNodeList::const_iterator p = patches->begin(); p != patches->end(); ++p) { + cout << "\t\t found patch number " << (*p)->property("Number")->value() + << " with name: " << (*p)->property("Name")->value() << endl; + } + } + + cout << endl << endl << "Test 5: ProtoolsPatchFile.midnam: Find attribute nodes" << endl; + result = doc3.root()->find("//@Value"); + + for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) { + boost::shared_ptr node = (*i); + cout << "\t found attribute node: " << node->name() + << " value: " << node->attribute_value() << endl; + } + + cout << endl << endl << "Test 6: ProtoolsPatchFile.midnam: Find available channels on 'Name Set 1'" << endl; + result = doc3.root()->find( + "//ChannelNameSet[@Name = 'Name Set 1']//AvailableChannel[@Available = 'true']/@Channel"); + + assert(result->size() == 15); + for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) { + boost::shared_ptr node = (*i); + cout << "\t found available Channel: " << node->name() + << " value: " << node->attribute_value() << endl; + } + }