1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // https://developers.google.com/protocol-buffers/ 4 // 5 // Redistribution and use in source and binary forms, with or without 6 // modification, are permitted provided that the following conditions are 7 // met: 8 // 9 // * Redistributions of source code must retain the above copyright 10 // notice, this list of conditions and the following disclaimer. 11 // * Redistributions in binary form must reproduce the above 12 // copyright notice, this list of conditions and the following disclaimer 13 // in the documentation and/or other materials provided with the 14 // distribution. 15 // * Neither the name of Google Inc. nor the names of its 16 // contributors may be used to endorse or promote products derived from 17 // this software without specific prior written permission. 18 // 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31 package com.google.protobuf; 32 33 import junit.framework.TestCase; 34 35 /** Test @{link TextFormatParseLocation}. */ 36 public class TextFormatParseLocationTest extends TestCase { 37 testCreateEmpty()38 public void testCreateEmpty() { 39 TextFormatParseLocation location = TextFormatParseLocation.create(-1, -1); 40 assertEquals(TextFormatParseLocation.EMPTY, location); 41 } 42 testCreate()43 public void testCreate() { 44 TextFormatParseLocation location = TextFormatParseLocation.create(2, 1); 45 assertEquals(2, location.getLine()); 46 assertEquals(1, location.getColumn()); 47 } 48 testCreateThrowsIllegalArgumentExceptionForInvalidIndex()49 public void testCreateThrowsIllegalArgumentExceptionForInvalidIndex() { 50 try { 51 TextFormatParseLocation.create(-1, 0); 52 fail("Should throw IllegalArgumentException if line is less than 0"); 53 } catch (IllegalArgumentException unused) { 54 // pass 55 } 56 try { 57 TextFormatParseLocation.create(0, -1); 58 fail("Should throw, column < 0"); 59 } catch (IllegalArgumentException unused) { 60 // pass 61 } 62 } 63 testHashCode()64 public void testHashCode() { 65 TextFormatParseLocation loc0 = TextFormatParseLocation.create(2, 1); 66 TextFormatParseLocation loc1 = TextFormatParseLocation.create(2, 1); 67 68 assertEquals(loc0.hashCode(), loc1.hashCode()); 69 assertEquals( 70 TextFormatParseLocation.EMPTY.hashCode(), TextFormatParseLocation.EMPTY.hashCode()); 71 } 72 testEquals()73 public void testEquals() { 74 TextFormatParseLocation loc0 = TextFormatParseLocation.create(2, 1); 75 TextFormatParseLocation loc1 = TextFormatParseLocation.create(1, 2); 76 TextFormatParseLocation loc2 = TextFormatParseLocation.create(2, 2); 77 TextFormatParseLocation loc3 = TextFormatParseLocation.create(2, 1); 78 79 assertEquals(loc0, loc3); 80 assertNotSame(loc0, loc1); 81 assertNotSame(loc0, loc2); 82 assertNotSame(loc1, loc2); 83 } 84 } 85