19064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar/* 29064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * Copyright (C) 2015 The Android Open Source Project 39064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * 49064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * Licensed under the Apache License, Version 2.0 (the "License"); 59064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * you may not use this file except in compliance with the License. 69064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * You may obtain a copy of the License at 79064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * 89064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * http://www.apache.org/licenses/LICENSE-2.0 99064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * 109064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * Unless required by applicable law or agreed to in writing, software 119064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * distributed under the License is distributed on an "AS IS" BASIS, 129064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * See the License for the specific language governing permissions and 149064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * limitations under the License. 159064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar */ 169064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 179064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyarpackage android.databinding.compilationTest; 189064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 19731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyarimport android.databinding.tool.processing.ScopedErrorReport; 20731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyarimport android.databinding.tool.processing.ScopedException; 21731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar 22731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyarimport java.util.List; 23731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar 24731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyarimport static org.junit.Assert.assertEquals; 25731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar 269064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyarpublic class CompilationResult { 279064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar public final int resultCode; 289064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar public final String output; 299064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar public final String error; 309064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 319064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar public CompilationResult(int resultCode, String output, String error) { 329064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar this.resultCode = resultCode; 339064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar this.output = output; 349064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar this.error = error; 359064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar } 369064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 379064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar public boolean resultContainsText(String text) { 389064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar return resultCode == 0 && output.indexOf(text) > 0; 399064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar } 409064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 419064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar public boolean errorContainsText(String text) { 429064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar return resultCode != 0 && error.indexOf(text) > 0; 439064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar } 44731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar 45731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar public ScopedException getBindingException() { 46731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar List<ScopedException> errors = ScopedException.extractErrors(error); 47731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar if (errors.isEmpty()) { 48731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar return null; 49731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar } 5024bec1cc542de69e0e21cc774469f20d34811ad9Yigit Boyar assertEquals(error, 1, errors.size()); 51731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar return errors.get(0); 52731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar } 53731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar 54731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar public List<ScopedException> getBindingExceptions() { 55731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar return ScopedException.extractErrors(error); 56731b74f7f44e67312a1fc4161c4e0aae221b2417Yigit Boyar } 579064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar} 58