7 CPPUNIT_TEST_SUITE_REGISTRATION (XPathTest);
11 static string const prefix = "../libs/pbd/test/";
14 XPathTest::testMisc ()
16 cout << "Test 1: RosegardenPatchFile.xml: Find all banks in the file" << endl;
17 XMLTree doc(prefix + "RosegardenPatchFile.xml");
18 // "//bank" gives as last element an empty element libxml bug????
19 boost::shared_ptr<XMLSharedNodeList> result = doc.find("//bank[@name]");
21 cout << "Found " << result->size() << " banks" << endl;
22 assert(result->size() == 8);
24 for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
25 assert((*i)->name() == "bank");
26 assert((*i)->property("name"));
27 // cout << "Found bank number " << counter++ << " with name: " << (*i)->property("name")->value() << endl;
28 for(XMLNodeList::const_iterator j = (*i)->children().begin(); j != (*i)->children().end(); ++j) {
29 // cout << "\t found program " << (*j)->property("id")->value() <<
30 // " with name: " << (*j)->property("name")->value() << endl;
34 cout << endl << endl << "Test 2: RosegardenPatchFile.xml: Find all programs whose program name contains 'Latin'" << endl;
36 result = doc.find("/rosegarden-data/studio/device/bank/program[contains(@name, 'Latin')]");
37 assert(result->size() == 5);
39 for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
40 // cout << "\t found program " << (*i)->property("id")->value() <<
41 // " with name: " << (*i)->property("name")->value() << endl;
44 // cout << endl << endl << "Test 3: TestSession.ardour: find all Sources where captured-for contains the string 'Guitar'" << endl;
46 // We have to allocate a new document here, or we get segfaults
47 XMLTree doc2(prefix + "TestSession.ardour");
48 result = doc2.find("/Session/Sources/Source[contains(@captured-for, 'Guitar')]");
49 assert(result->size() == 16);
51 for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
52 // cout << "\t found source '" << (*i)->property("name")->value() <<
53 // "' with id: " << (*i)->property("id")->value() << endl;
56 cout << endl << endl << "Test 4: TestSession.ardour: Find all elements with an 'id' and 'name' attribute" << endl;
58 result = doc2.find("//*[@id and @name]");
60 for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
61 assert((*i)->property("id"));
62 assert((*i)->property("name"));
63 // cout << "\t found element '" << (*i)->name() <<
64 // "' with id: " << (*i)->property("id")->value() <<
65 // "' and name: " << (*i)->property("name")->value() << endl;
68 cout << endl << endl << "Test 5: ProtoolsPatchFile.midnam: Get Banks and Patches for 'Name Set 1'" << endl;
70 // We have to allocate a new document here, or we get segfaults
71 XMLTree doc3(prefix + "ProtoolsPatchFile.midnam");
72 result = doc3.find("/MIDINameDocument/MasterDeviceNames/ChannelNameSet[@Name='Name Set 1']/PatchBank");
73 assert(result->size() == 16);
75 for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
76 // cout << "\t found Patchbank " << (*i)->property("Name")->value() << endl;
77 boost::shared_ptr<XMLSharedNodeList> patches = doc3.find ("//Patch[@Name]", i->get());
78 for(XMLSharedNodeList::const_iterator p = patches->begin(); p != patches->end(); ++p) {
79 // cout << "\t\t found patch number " << (*p)->property("Number")->value()
80 // << " with name: " << (*p)->property("Name")->value() << endl;
84 cout << endl << endl << "Test 5: ProtoolsPatchFile.midnam: Find attribute nodes" << endl;
85 result = doc3.find("//@Value");
87 for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
88 boost::shared_ptr<XMLNode> node = (*i);
89 // cout << "\t found attribute node: " << node->name()
90 // << " value: " << node->attribute_value() << endl;
93 cout << endl << endl << "Test 6: ProtoolsPatchFile.midnam: Find available channels on 'Name Set 1'" << endl;
95 "//ChannelNameSet[@Name = 'Name Set 1']//AvailableChannel[@Available = 'true']/@Channel");
97 assert(result->size() == 15);
98 for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
99 boost::shared_ptr<XMLNode> node = (*i);
100 // cout << "\t found available Channel: " << node->name()
101 // << " value: " << node->attribute_value() << endl;