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 state value tests */
42 STATE_VALUE_FILE("test_xml_files/test_valid/test_state_values.xml"),
43 /** A valid file for conditions tests */
44 CONDITION_FILE("test_xml_files/test_valid/test_conditions.xml"),
45 /** A valid file for doubles tests */
46 DOUBLES_FILE("test_xml_files/test_valid/test_doubles.xml"),
47 /** A valid file for pattern tests */
48 VALID_PATTERN_FILE("test_xml_files/test_valid/test_valid_pattern.xml"),
49 /** A valid pattern file to test the pattern segment **/
50 VALID_PATTERN_SEGMENT("test_xml_files/test_valid/test_pattern_segment.xml"),
51 /** A valid file for consuming fsm test */
52 CONSUMING_FSM_TEST("test_xml_files/test_valid/test_consuming_fsm.xml");
54 private final String fPath
;
56 private TmfXmlTestFiles(String file
) {
61 * Get the absolute path of this test file
63 * @return The absolute path of this test file
65 public IPath
getPath() {
66 IPath absPath
= Activator
.getAbsolutePath(new Path(fPath
));
67 if (absPath
== null) {
68 fail("Cannot find file path for '" + fPath
+ "'");
74 * Returns the file object corresponding to the test XML file
76 * @return The file object for this test file
78 public File
getFile() {
79 return getPath().toFile();
83 * Get the XML {@link Document} for this test xml file
85 * @return The XML {@link Document}
87 public Document
getXmlDocument() {
88 /* Initialize the state provider module */
91 doc
= XmlUtils
.getDocumentFromFile(getFile());
92 } catch (ParserConfigurationException e
) {
93 fail("Xml document parse exception");
94 } catch (SAXException e
) {
95 fail("Exception parsing xml file");
96 } catch (IOException e
) {
97 fail("File io exception");