source: trunk/org.modelica.mdt.test/src/org/modelica/mdt/test/TestProxyParser.java @ 271

Last change on this file since 271 was 271, checked in by boris, 19 years ago
  • renaming org.modelica.mdt plugin to org.modelica.mdt.core (step 1)
File size: 4.4 KB
Line 
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
42package org.modelica.mdt.test;
43
44import org.modelica.mdt.core.compiler.ICompileError;
45import org.modelica.mdt.core.compiler.UnexpectedReplyException;
46import org.modelica.mdt.omc.internal.OMCParser;
47
48import junit.framework.TestCase;
49
50/**
51 * Test various methods in org.modelica.mdt.omc.internal.OMCParser
52 * @author Elmir Jagudin
53 */
54public 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]: error: unexpected tooken: muu\n";
68            ICompileError[] errors = OMCParser.parseErrorString(errorString);
69   
70            assertEquals(1, errors.length);     
71            ICompileError error = errors[0];
72            assertEquals(2, error.getLine());
73            assertEquals("unexpected tooken: muu", error.getErrorDescription());
74   
75            /* two errors windows style */
76            errorString = 
77                "[c:/folder he/hej.mo:4:1]: error: unexpected end of file\n" + 
78                "[c:/folder he/hej.mo:15:1]: error: hej remar\n";
79            errors = OMCParser.parseErrorString(errorString);
80            assertEquals(2, errors.length);
81           
82            error = errors[0];
83            assertEquals(4, error.getLine());
84            assertEquals("unexpected end of file", error.getErrorDescription());
85   
86            error = errors[1];
87            assertEquals(15, error.getLine());
88            assertEquals("hej remar", error.getErrorDescription());
89           
90            /* single error unix style */
91            errorString = 
92                "[/usr/folde/hej.mo:12:1]: error: unexpected tooken: muu\n";
93            errors = OMCParser.parseErrorString(errorString);
94   
95            assertEquals(1, errors.length);     
96            error = errors[0];
97            assertEquals(12, error.getLine());
98            assertEquals("unexpected tooken: muu", error.getErrorDescription());
99   
100            /* two errors unix style */
101            errorString = 
102                "[/hej/hop/hej.mo:453:1]: error: unexpected end of file\n" + 
103                "[/usr/local/modelica/hej.mo:715:1]: error: hej remar\n";
104            errors = OMCParser.parseErrorString(errorString);
105            assertEquals(2, errors.length);
106           
107            error = errors[0];
108            assertEquals(453, error.getLine());
109            assertEquals("unexpected end of file", error.getErrorDescription());
110   
111            error = errors[1];
112            assertEquals(715, error.getLine());
113            assertEquals("hej remar", error.getErrorDescription());
114   
115            /* no errors aka empty error string */
116            errors = OMCParser.parseErrorString("");
117            assertEquals(0, errors.length);
118        }
119        catch(Exception e)
120        {
121            /* On any exception, fail. */
122            fail(e.getMessage());
123        }
124    }
125}
Note: See TracBrowser for help on using the repository browser.