~ubuntu-branches/ubuntu/utopic/ardour3/utopic

« back to all changes in this revision

Viewing changes to libs/pbd/test/xpath.cc

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2013-09-21 19:05:02 UTC
  • Revision ID: package-import@ubuntu.com-20130921190502-8gsftrku6jnzhd7v
Tags: upstream-3.4~dfsg
ImportĀ upstreamĀ versionĀ 3.4~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "assert.h"
 
2
#include <iostream>
 
3
 
 
4
#include "xpath.h"
 
5
#include "pbd/xml++.h"
 
6
#include "pbd/file_utils.h"
 
7
 
 
8
#include "test_common.h"
 
9
 
 
10
CPPUNIT_TEST_SUITE_REGISTRATION (XPathTest);
 
11
 
 
12
using namespace std;
 
13
using namespace PBD;
 
14
 
 
15
void
 
16
XPathTest::testMisc ()
 
17
{
 
18
//      cout << "Test 1: RosegardenPatchFile.xml: Find all banks in the file" << endl;
 
19
 
 
20
        std::string testdata_path;
 
21
        CPPUNIT_ASSERT (find_file_in_search_path (test_search_path (), "RosegardenPatchFile.xml", testdata_path));
 
22
 
 
23
        XMLTree  doc(testdata_path);
 
24
        // "//bank" gives as last element an empty element libxml bug????
 
25
        boost::shared_ptr<XMLSharedNodeList> result = doc.find("//bank[@name]");
 
26
        
 
27
//      cout << "Found " << result->size() << " banks" << endl;
 
28
        assert(result->size() == 8);
 
29
//      int counter = 1;
 
30
        for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
 
31
                assert((*i)->name() == "bank");
 
32
                assert((*i)->property("name"));
 
33
//              cout << "Found bank number " << counter++ << " with name: " << (*i)->property("name")->value() << endl;
 
34
                for(XMLNodeList::const_iterator j = (*i)->children().begin(); j != (*i)->children().end(); ++j) {
 
35
//                      cout << "\t found program " << (*j)->property("id")->value() << 
 
36
//                              " with name: " << (*j)->property("name")->value() << endl;
 
37
                }
 
38
        }
 
39
        
 
40
//      cout << endl << endl << "Test 2: RosegardenPatchFile.xml: Find all programs whose program name contains 'Latin'" << endl;
 
41
        
 
42
        result = doc.find("/rosegarden-data/studio/device/bank/program[contains(@name, 'Latin')]");
 
43
        assert(result->size() == 5);
 
44
        
 
45
        for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
 
46
//              cout << "\t found program " << (*i)->property("id")->value() << 
 
47
//                      " with name: " << (*i)->property("name")->value() << endl;
 
48
        }
 
49
 
 
50
//      cout << endl << endl << "Test 3: TestSession.ardour: find all Sources where captured-for contains the string 'Guitar'" << endl;
 
51
        
 
52
        // We have to allocate a new document here, or we get segfaults
 
53
        std::string testsession_path;
 
54
        CPPUNIT_ASSERT (find_file_in_search_path (test_search_path (), "TestSession.ardour", testsession_path));
 
55
 
 
56
        XMLTree doc2(testsession_path);
 
57
        result = doc2.find("/Session/Sources/Source[contains(@captured-for, 'Guitar')]");
 
58
        assert(result->size() == 16);
 
59
        
 
60
        for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
 
61
//              cout << "\t found source '" << (*i)->property("name")->value() << 
 
62
//                      "' with id: " << (*i)->property("id")->value() << endl;
 
63
        }
 
64
        
 
65
//      cout << endl << endl << "Test 4: TestSession.ardour: Find all elements with an 'id' and 'name' attribute" << endl;
 
66
        
 
67
        result = doc2.find("//*[@id and @name]");
 
68
        
 
69
        for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
 
70
                assert((*i)->property("id"));
 
71
                assert((*i)->property("name"));
 
72
//              cout << "\t found element '" << (*i)->name() << 
 
73
//                      "' with id: "  << (*i)->property("id")->value() << 
 
74
//                              "' and name: " << (*i)->property("name")->value() << endl;
 
75
        }
 
76
        
 
77
//      cout << endl << endl << "Test 5: ProtoolsPatchFile.midnam: Get Banks and Patches for 'Name Set 1'" << endl;
 
78
        
 
79
        std::string testmidnam_path;
 
80
        CPPUNIT_ASSERT (find_file_in_search_path (test_search_path (), "ProtoolsPatchFile.midnam", testmidnam_path));
 
81
 
 
82
        // We have to allocate a new document here, or we get segfaults
 
83
        XMLTree doc3(testmidnam_path);
 
84
        result = doc3.find("/MIDINameDocument/MasterDeviceNames/ChannelNameSet[@Name='Name Set 1']/PatchBank");
 
85
        assert(result->size() == 16);
 
86
        
 
87
        for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
 
88
//              cout << "\t found Patchbank " << (*i)->property("Name")->value() << endl;
 
89
                boost::shared_ptr<XMLSharedNodeList> patches = doc3.find ("//Patch[@Name]", i->get());
 
90
                for(XMLSharedNodeList::const_iterator p = patches->begin(); p != patches->end(); ++p) {
 
91
//                      cout << "\t\t found patch number " << (*p)->property("Number")->value() 
 
92
//                           << " with name: " << (*p)->property("Name")->value()  << endl;
 
93
                }
 
94
        }
 
95
 
 
96
//      cout << endl << endl << "Test 5: ProtoolsPatchFile.midnam: Find attribute nodes" << endl;
 
97
        result = doc3.find("//@Value");
 
98
        
 
99
        for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
 
100
                boost::shared_ptr<XMLNode> node = (*i);
 
101
//              cout << "\t found attribute node: " << node->name()  
 
102
//                   << " value: " << node->attribute_value() << endl;
 
103
        }       
 
104
        
 
105
//      cout << endl << endl << "Test 6: ProtoolsPatchFile.midnam: Find available channels on 'Name Set 1'" << endl;
 
106
        result = doc3.find(
 
107
                "//ChannelNameSet[@Name = 'Name Set 1']//AvailableChannel[@Available = 'true']/@Channel");
 
108
        
 
109
        assert(result->size() == 15);
 
110
        for(XMLSharedNodeList::const_iterator i = result->begin(); i != result->end(); ++i) {
 
111
                boost::shared_ptr<XMLNode> node = (*i);
 
112
//              cout << "\t found available Channel: " << node->name()  
 
113
//                   << " value: " << node->attribute_value() << endl;
 
114
        }       
 
115
        
 
116
}