1 /* Copyright 2009 Yorba Foundation
3 * This software is licensed under the GNU Lesser General Public License
4 * (version 2.1 or later). See the COPYING file in this distribution.
9 public class ClipFetcher {
10 public string error_string;
11 public ClipFile clipfile;
14 public ClipFetcher(string filename) {
15 this.filename = filename;
17 public string get_filename() {
20 public signal void ready(ClipFetcher fetcher);
23 public class ClipFile {
24 public string filename;
28 // Describes an XML Document and if the test should consider it a valid or an invalid document
29 struct ValidDocument {
31 public string document;
32 public ValidDocument(bool valid, string document) {
34 this.document = document;
38 ValidDocument[] project_documents; // The set of documents for building the test suite
39 int current_document; // Index of the document for the test we are currently building
41 // StateChangeFixture holds the root of an XML tree describing a project, the TreeBuilder
42 // and if the XML tree is expected to be valid or not
43 struct StateChangeFixture {
44 public Model.XmlElement root;
45 public Model.ProjectBuilder project_builder;
49 void state_change_fixture_buildup(void *fixture) {
50 StateChangeFixture* state_change_fixture = (StateChangeFixture*)fixture;
51 Model.XmlTreeLoader tree_loader = new Model.XmlTreeLoader(project_documents[current_document].document);
52 state_change_fixture->root = tree_loader.root;
53 state_change_fixture->project_builder = new Model.ProjectBuilder(new Model.LoaderHandler());
54 state_change_fixture->valid = project_documents[current_document].valid;
58 void state_change_fixture_teardown(void *fixture) {
59 StateChangeFixture* state_change_fixture = (StateChangeFixture*)fixture;
60 state_change_fixture->root = null;
61 state_change_fixture->project_builder = null;
64 bool document_valid; // if a document is invalid, on_error_occurred will set this variable to false
66 void on_error_occurred(string? message) {
67 Test.message("received error: %s", message);
68 document_valid = false;
71 // The actual test code. It builds the given document and then asserts that the result is what
73 void check_document(void *fixture) {
74 StateChangeFixture* state_change_fixture = (StateChangeFixture*)fixture;
76 Test.message("checking document expecting to be %s",
77 state_change_fixture->valid ? "valid" : "invalid");
79 Model.XmlElement root = state_change_fixture->root;
80 Model.ProjectBuilder project_builder = state_change_fixture->project_builder;
82 document_valid = true;
83 project_builder.error_occurred.connect(on_error_occurred);
85 // We call check project to check the integrity of the file skeleton.
86 // If it's good, then we can load all the pieces of the file (library, tracks).
87 if (project_builder.check_project(root))
88 project_builder.build_project(root);
89 assert(document_valid == state_change_fixture->valid);
90 Test.message("finished executing check document");
94 class ProjectLoaderSuite : TestSuite {
95 public ProjectLoaderSuite() {
96 base("ProjectLoaderSuite");
100 ValidDocument(true, "<marina><library></library><tracks><track><clip /><clip /></track>"
101 + "<track><clip /></track></tracks><preferences /></marina>"),
102 ValidDocument(true, "<marina><library /><tracks /><preferences/>"
103 + "<maps><tempo /><time_signature /></marina>"),
104 ValidDocument(true, "<marina><library /><tracks /><preferences/><maps><tempo />"
106 ValidDocument(true, "<marina><library /><tracks /><preferences/>"
107 + "<maps><time_signature /></marina>"),
108 ValidDocument(true, "<marina><library></library><tracks><track /></tracks>"
109 + "<preferences/></marina>"),
110 ValidDocument(true, "<marina><library></library><tracks><track><clip /></track>"
111 + "</tracks><preferences/></marina>"),
112 ValidDocument(true, "<marina><library/><tracks/><preferences/>"
113 + "<maps><tempo><entry></tempo></maps></marina>"),
114 ValidDocument(true, "<marina><library/><tracks/><preferences/>"
115 +"<maps><time_signature><entry></time_signature></maps></marina>"),
116 ValidDocument(true, "<marina><library/><tracks/><preferences/></marina>"),
117 ValidDocument(true, "<marina><library/><tracks/><preferences><click/></preferences>"
119 ValidDocument(true, "<marina><library/><tracks/><preferences><library/>" +
120 "</preferences></marina>"),
121 ValidDocument(true, "<marina><library/><tracks/><preferences><click/><library/>" +
122 "</preferences></marina>"),
123 ValidDocument(false, "<marina><tracks></tracks><library></library></marina>"),
124 ValidDocument(false, "<marina><library></library><track></track></marina>"),
125 ValidDocument(false, "<marina><library><clip /></library><tracks><clipfile />"
126 + "</tracks></marina>"),
127 ValidDocument(false, "<marina />"),
128 ValidDocument(false, "<library />"),
129 ValidDocument(false, "<track />"),
130 ValidDocument(false, "<clip />"),
131 ValidDocument(false, "<entry />"),
132 ValidDocument(false, "<tempo />"),
133 ValidDocument(false, "<maps />"),
134 ValidDocument(false, "<preferences />"),
135 ValidDocument(false, "<click />"),
136 ValidDocument(false, "<time_signature />"),
137 ValidDocument(false, "<marina><clip /></marina>"),
138 ValidDocument(false, "<marina><track><clip><track /></clip></track></marina>"),
139 ValidDocument(false, "<unknown />"),
140 ValidDocument(false, "<marina><foo /></marina>"),
141 ValidDocument(false, "<marina><track><foo /></track></track></marina>"),
142 ValidDocument(false, "<marina><track><clip><foo /></clip></track></marina>"),
143 ValidDocument(false, "<marina><library/><tracks/><maps><foo/></maps></marina>"),
144 ValidDocument(false, "<marina><library/><tracks/><maps><time_signature>"
145 + "<tempo/></time_signature></marina>"),
146 ValidDocument(false, "<marina><library/><tracks/><click/></marina>"),
147 ValidDocument(false, "<marina><library/><tracks/><preferences><tracks/>"
148 +"</preferences></marina>"),
149 ValidDocument(false, "<marina><library/><tracks/><maps/><preferences/></marina>")
152 int length = project_documents.length;
154 for (int i = 0; i < length; ++i) {
155 if (Test.thorough() || project_documents[i].valid) {
156 add(new TestCase("Document%d".printf(i), state_change_fixture_buildup,
157 check_document, state_change_fixture_teardown, sizeof(StateChangeFixture)));