| 1 |
/* |
| 2 |
* Copyright (C) 2015 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
package com.android.ide.common.blame.parser; |
| 17 |
|
| 18 |
import static org.junit.Assert.assertEquals; |
| 19 |
import static org.junit.Assert.assertNotNull; |
| 20 |
|
| 21 |
import com.android.ide.common.blame.Message; |
| 22 |
import com.android.utils.StdLogger; |
| 23 |
|
| 24 |
import org.junit.Before; |
| 25 |
import org.junit.Rule; |
| 26 |
import org.junit.Test; |
| 27 |
import org.junit.rules.TemporaryFolder; |
| 28 |
|
| 29 |
import java.io.File; |
| 30 |
import java.io.IOException; |
| 31 |
import java.util.List; |
| 32 |
|
| 33 |
/** |
| 34 |
* Tests for {@link LegacyNdkOutputParser}. |
| 35 |
*/ |
| 36 |
public class LegacyNdkOutputParserTest { |
| 37 |
@Rule |
| 38 |
public TemporaryFolder mTemporaryFolder = new TemporaryFolder(); |
| 39 |
|
| 40 |
private ToolOutputParser mParser; |
| 41 |
|
| 42 |
private File mSourceFile; |
| 43 |
|
| 44 |
@Before |
| 45 |
public void setUp() throws IOException { |
| 46 |
mParser = new ToolOutputParser(new LegacyNdkOutputParser(), |
| 47 |
new StdLogger(StdLogger.Level.VERBOSE)); |
| 48 |
mSourceFile = mTemporaryFolder.newFile(); |
| 49 |
} |
| 50 |
|
| 51 |
@Test |
| 52 |
public void testParseUnresolvedInclude() { |
| 53 |
String path = mSourceFile.getAbsolutePath(); |
| 54 |
String err = path + |
| 55 |
":35:18: fatal error: fake.h: No such file or directory\n" + |
| 56 |
" #include \"fake.h\"\n" + |
| 57 |
" ^"; |
| 58 |
List<Message> messages = mParser.parseToolOutput(err); |
| 59 |
assertEquals("[message count]", 1, messages.size()); |
| 60 |
Message message = messages.iterator().next(); |
| 61 |
assertNotNull(message); |
| 62 |
|
| 63 |
assertEquals("fake.h: No such file or directory", message.getText()); |
| 64 |
assertEquals(Message.Kind.ERROR, message.getKind()); |
| 65 |
assertEquals(path, message.getSourcePath()); |
| 66 |
assertEquals(35, message.getLineNumber()); |
| 67 |
assertEquals(18, message.getColumn()); |
| 68 |
} |
| 69 |
|
| 70 |
@Test |
| 71 |
public void testParseUnknownMessage() { |
| 72 |
String path = mSourceFile.getAbsolutePath(); |
| 73 |
String err = "In file included from " + path + ":35:18,"; |
| 74 |
List<Message> messages = mParser.parseToolOutput(err); |
| 75 |
assertEquals("[message count]", 1, messages.size()); |
| 76 |
Message message = messages.iterator().next(); |
| 77 |
assertNotNull(message); |
| 78 |
|
| 79 |
assertEquals("(Unknown) In file included", message.getText()); |
| 80 |
assertEquals(Message.Kind.INFO, message.getKind()); |
| 81 |
assertEquals(path, message.getSourcePath()); |
| 82 |
assertEquals(35, message.getLineNumber()); |
| 83 |
assertEquals(18, message.getColumn()); |
| 84 |
} |
| 85 |
|
| 86 |
@Test |
| 87 |
public void testParseUnknownMessage2() { |
| 88 |
String path = mSourceFile.getAbsolutePath(); |
| 89 |
String err = " from " + path + ":35:18:"; |
| 90 |
List<Message> messages = mParser.parseToolOutput(err); |
| 91 |
assertEquals("[message count]", 1, messages.size()); |
| 92 |
Message message = messages.iterator().next(); |
| 93 |
assertNotNull(message); |
| 94 |
|
| 95 |
assertEquals("(Unknown)", message.getText()); |
| 96 |
assertEquals(Message.Kind.INFO, message.getKind()); |
| 97 |
assertEquals(path, message.getSourcePath()); |
| 98 |
assertEquals(35, message.getLineNumber()); |
| 99 |
assertEquals(18, message.getColumn()); |
| 100 |
} |
| 101 |
} |