1 | /* |
---|
2 | * This file is part of Modelica Development Tooling. |
---|
3 | * |
---|
4 | * Copyright (c) 2005, Link�pings universitet, Department of |
---|
5 | * Computer and Information Science, PELAB |
---|
6 | * |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * (The new BSD license, see also |
---|
10 | * http://www.opensource.org/licenses/bsd-license.php) |
---|
11 | * |
---|
12 | * |
---|
13 | * Redistribution and use in source and binary forms, with or without |
---|
14 | * modification, are permitted provided that the following conditions are |
---|
15 | * met: |
---|
16 | * |
---|
17 | * * Redistributions of source code must retain the above copyright |
---|
18 | * notice, this list of conditions and the following disclaimer. |
---|
19 | * |
---|
20 | * * Redistributions in binary form must reproduce the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer in |
---|
22 | * the documentation and/or other materials provided with the |
---|
23 | * distribution. |
---|
24 | * |
---|
25 | * * Neither the name of Link�pings universitet nor the names of its |
---|
26 | * contributors may be used to endorse or promote products derived from |
---|
27 | * this software without specific prior written permission. |
---|
28 | * |
---|
29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
32 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
33 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
34 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
35 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
36 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
37 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
40 | */ |
---|
41 | |
---|
42 | package org.modelica.mdt.test; |
---|
43 | |
---|
44 | import org.modelica.mdt.core.compiler.ICompileError; |
---|
45 | import org.modelica.mdt.core.compiler.UnexpectedReplyException; |
---|
46 | import org.modelica.mdt.omc.internal.OMCParser; |
---|
47 | |
---|
48 | import junit.framework.TestCase; |
---|
49 | |
---|
50 | /** |
---|
51 | * Test various methods in org.modelica.mdt.omc.internal.OMCParser |
---|
52 | * @author Elmir Jagudin |
---|
53 | */ |
---|
54 | public class TestProxyParser extends TestCase |
---|
55 | { |
---|
56 | |
---|
57 | /** |
---|
58 | * Test if OMCParser.parseErrorString() works as prescribed. |
---|
59 | * @throws UnexpectedReplyException |
---|
60 | */ |
---|
61 | public void testParseErrorString() throws UnexpectedReplyException |
---|
62 | { |
---|
63 | try |
---|
64 | { |
---|
65 | /* single error windows style */ |
---|
66 | String errorString = |
---|
67 | "[c:/folde/hej.mo:2:1-3:2:writable]: error: unexpected " + |
---|
68 | "tooken: muu\n"; |
---|
69 | ICompileError[] errors = OMCParser.parseErrorString(errorString); |
---|
70 | |
---|
71 | assertEquals(1, errors.length); |
---|
72 | ICompileError error = errors[0]; |
---|
73 | assertEquals(2, error.getStartLine()); |
---|
74 | assertEquals("unexpected tooken: muu", error.getErrorDescription()); |
---|
75 | |
---|
76 | /* two errors windows style */ |
---|
77 | errorString = |
---|
78 | "[c:/folder he/hej.mo:4:1-4:5:writable]: error: unexpected " + |
---|
79 | "end of file\n" + |
---|
80 | "[c:/folder he/hej.mo:15:1-16:2:writable]: error: hej remar\n"; |
---|
81 | errors = OMCParser.parseErrorString(errorString); |
---|
82 | assertEquals(2, errors.length); |
---|
83 | |
---|
84 | error = errors[0]; |
---|
85 | assertEquals(4, error.getStartLine()); |
---|
86 | assertEquals("unexpected end of file", error.getErrorDescription()); |
---|
87 | |
---|
88 | error = errors[1]; |
---|
89 | assertEquals(15, error.getStartLine()); |
---|
90 | assertEquals("hej remar", error.getErrorDescription()); |
---|
91 | |
---|
92 | /* single error unix style */ |
---|
93 | errorString = |
---|
94 | "[/usr/folde/hej.mo:12:1-13:4:writable]: error: unexpected" + |
---|
95 | " tooken: muu\n"; |
---|
96 | errors = OMCParser.parseErrorString(errorString); |
---|
97 | |
---|
98 | assertEquals(1, errors.length); |
---|
99 | error = errors[0]; |
---|
100 | assertEquals(12, error.getStartLine()); |
---|
101 | assertEquals("unexpected tooken: muu", error.getErrorDescription()); |
---|
102 | |
---|
103 | /* two errors unix style */ |
---|
104 | errorString = |
---|
105 | "[/hej/hop/hej.mo:453:1-570:3:writable]: error: unexpected " + |
---|
106 | "end of file\n" + |
---|
107 | "[/usr/local/modelica/hej.mo:715:1-864:45:writable]: error: " + |
---|
108 | "hej remar\n"; |
---|
109 | errors = OMCParser.parseErrorString(errorString); |
---|
110 | assertEquals(2, errors.length); |
---|
111 | |
---|
112 | error = errors[0]; |
---|
113 | assertEquals(453, error.getStartLine()); |
---|
114 | assertEquals("unexpected end of file", error.getErrorDescription()); |
---|
115 | |
---|
116 | error = errors[1]; |
---|
117 | assertEquals(715, error.getStartLine()); |
---|
118 | assertEquals("hej remar", error.getErrorDescription()); |
---|
119 | |
---|
120 | /* no errors aka empty error string */ |
---|
121 | errors = OMCParser.parseErrorString(""); |
---|
122 | assertEquals(0, errors.length); |
---|
123 | } |
---|
124 | catch(Exception e) |
---|
125 | { |
---|
126 | /* On any exception, fail. */ |
---|
127 | fail(e.getMessage()); |
---|
128 | } |
---|
129 | } |
---|
130 | } |
---|