1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.common
;
15 import static org
.junit
.Assert
.fail
;
18 import java
.io
.IOException
;
20 import javax
.xml
.parsers
.ParserConfigurationException
;
22 import org
.eclipse
.core
.runtime
.IPath
;
23 import org
.eclipse
.core
.runtime
.Path
;
24 import org
.eclipse
.tracecompass
.internal
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
25 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.Activator
;
26 import org
.w3c
.dom
.Document
;
27 import org
.xml
.sax
.SAXException
;
30 * Provides some test XML files to use
32 * @author Geneviève Bastien
34 public enum TmfXmlTestFiles
{
35 /** A valid XML test file */
36 VALID_FILE("test_xml_files/test_valid/test_valid.xml"),
37 /** An invalid test file */
38 INVALID_FILE("test_xml_files/test_invalid/test_invalid.xml"),
39 /** A valid file for state attribute tests */
40 ATTRIBUTE_FILE("test_xml_files/test_valid/test_attributes.xml"),
41 /** A valid file for conditions tests */
42 CONDITION_FILE("test_xml_files/test_valid/test_conditions.xml"),
43 /** A valid file for doubles tests */
44 DOUBLES_FILE("test_xml_files/test_valid/test_doubles.xml"),
45 /** A valid file for pattern tests */
46 VALID_PATTERN_FILE("test_xml_files/test_valid/test_valid_pattern.xml"),
47 /** A valid pattern file to test the pattern segment **/
48 VALID_PATTERN_SEGMENT("test_xml_files/test_valid/test_pattern_segment.xml");
50 private final String fPath
;
52 private TmfXmlTestFiles(String file
) {
57 * Get the absolute path of this test file
59 * @return The absolute path of this test file
61 public IPath
getPath() {
62 IPath absPath
= Activator
.getAbsolutePath(new Path(fPath
));
63 if (absPath
== null) {
64 fail("Cannot find file path for '" + fPath
+ "'");
70 * Returns the file object corresponding to the test XML file
72 * @return The file object for this test file
74 public File
getFile() {
75 return getPath().toFile();
79 * Get the XML {@link Document} for this test xml file
81 * @return The XML {@link Document}
83 public Document
getXmlDocument() {
84 /* Initialize the state provider module */
87 doc
= XmlUtils
.getDocumentFromFile(getFile());
88 } catch (ParserConfigurationException e
) {
89 fail("Xml document parse exception");
90 } catch (SAXException e
) {
91 fail("Exception parsing xml file");
92 } catch (IOException e
) {
93 fail("File io exception");