1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. 22 */ 23 package org.opengrok.indexer.analysis; 24 25 import org.junit.jupiter.api.Test; 26 import org.opengrok.indexer.analysis.Scopes.Scope; 27 28 import java.io.IOException; 29 30 import static org.junit.jupiter.api.Assertions.assertEquals; 31 32 /** 33 * 34 * @author Tomas Kotal 35 */ 36 public class ScopesTest { 37 38 /** 39 * Test of getScope method, of class Scopes. 40 */ 41 @Test testGetScope()42 public void testGetScope() { 43 Scopes instance = new Scopes(); 44 Scope globalScope = instance.getScope(0); 45 46 instance.addScope(new Scope(10, 20, "scope1", "ns")); 47 instance.addScope(new Scope(25, 30, "scope2", "ns")); 48 instance.addScope(new Scope(40, 40, "scope3", "ns")); 49 instance.addScope(new Scope(60, 70, "scope4", "ns")); 50 instance.addScope(new Scope(80, 90, "scope5", "ns")); 51 instance.addScope(new Scope(91, 100, "scope6", "ns")); 52 53 assertEquals(instance.size(), 6); 54 assertEquals(instance.getScope(1), globalScope); 55 assertEquals(instance.getScope(10).getName(), "scope1"); 56 assertEquals(instance.getScope(15).getName(), "scope1"); 57 assertEquals(instance.getScope(20).getName(), "scope1"); 58 assertEquals(instance.getScope(21), globalScope); 59 assertEquals(instance.getScope(24), globalScope); 60 assertEquals(instance.getScope(39), globalScope); 61 assertEquals(instance.getScope(40).getName(), "scope3"); 62 assertEquals(instance.getScope(41), globalScope); 63 assertEquals(instance.getScope(90).getName(), "scope5"); 64 assertEquals(instance.getScope(100).getName(), "scope6"); 65 assertEquals(instance.getScope(101), globalScope); 66 assertEquals(instance.getScope(500), globalScope); 67 } 68 69 @Test testSerialize()70 void testSerialize() throws IOException, ClassNotFoundException { 71 Scopes scopes = new Scopes(); 72 scopes.addScope(new Scope(1, 100, "name", "namespace", "signature")); 73 byte[] bytes = scopes.serialize(); 74 Scopes deserialized = Scopes.deserialize(bytes); 75 assertEquals(1, deserialized.size()); 76 } 77 78 } 79