Commit | Line | Data |
---|---|---|
e11e382c FW |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 École Polytechnique de Montréal | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common; |
e11e382c | 14 | |
9a0aa59e GB |
15 | import static org.junit.Assert.fail; |
16 | ||
e11e382c | 17 | import java.io.File; |
9a0aa59e GB |
18 | import java.io.IOException; |
19 | ||
9a0aa59e GB |
20 | import javax.xml.parsers.ParserConfigurationException; |
21 | ||
22 | import org.eclipse.core.runtime.IPath; | |
23 | import org.eclipse.core.runtime.Path; | |
f10786aa | 24 | import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils; |
9a0aa59e GB |
25 | import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.Activator; |
26 | import org.w3c.dom.Document; | |
27 | import org.xml.sax.SAXException; | |
e11e382c FW |
28 | |
29 | /** | |
30 | * Provides some test XML files to use | |
31 | * | |
32 | * @author Geneviève Bastien | |
33 | */ | |
34 | public enum TmfXmlTestFiles { | |
35 | /** A valid XML test file */ | |
9a0aa59e | 36 | VALID_FILE("test_xml_files/test_valid/test_valid.xml"), |
e11e382c | 37 | /** An invalid test file */ |
d2e62865 GB |
38 | INVALID_FILE("test_xml_files/test_invalid/test_invalid.xml"), |
39 | /** A valid file for state attribute tests */ | |
900cbf89 JCK |
40 | ATTRIBUTE_FILE("test_xml_files/test_valid/test_attributes.xml"), |
41 | /** A valid file for conditions tests */ | |
74f8a7ec | 42 | CONDITION_FILE("test_xml_files/test_valid/test_conditions.xml"), |
8765f95a MK |
43 | /** A valid file for doubles tests */ |
44 | DOUBLES_FILE("test_xml_files/test_valid/test_doubles.xml"), | |
74f8a7ec | 45 | /** A valid file for pattern tests */ |
2fd6b087 JCK |
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"); | |
e11e382c FW |
49 | |
50 | private final String fPath; | |
51 | ||
52 | private TmfXmlTestFiles(String file) { | |
53 | fPath = file; | |
54 | } | |
55 | ||
56 | /** | |
9a0aa59e | 57 | * Get the absolute path of this test file |
e11e382c | 58 | * |
9a0aa59e | 59 | * @return The absolute path of this test file |
e11e382c | 60 | */ |
9a0aa59e GB |
61 | public IPath getPath() { |
62 | IPath absPath = Activator.getAbsolutePath(new Path(fPath)); | |
63 | if (absPath == null) { | |
64 | fail("Cannot find file path for '" + fPath + "'"); | |
65 | } | |
66 | return absPath; | |
e11e382c FW |
67 | } |
68 | ||
69 | /** | |
70 | * Returns the file object corresponding to the test XML file | |
71 | * | |
72 | * @return The file object for this test file | |
73 | */ | |
74 | public File getFile() { | |
9a0aa59e GB |
75 | return getPath().toFile(); |
76 | } | |
77 | ||
78 | /** | |
79 | * Get the XML {@link Document} for this test xml file | |
80 | * | |
81 | * @return The XML {@link Document} | |
82 | */ | |
83 | public Document getXmlDocument() { | |
84 | /* Initialize the state provider module */ | |
85 | Document doc = null; | |
86 | try { | |
f10786aa | 87 | doc = XmlUtils.getDocumentFromFile(getFile()); |
9a0aa59e GB |
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"); | |
94 | } | |
95 | return doc; | |
e11e382c FW |
96 | } |
97 | ||
98 | } |