IndexDatabaseTest.java revision 1220
159N/A/*
159N/A * CDDL HEADER START
606N/A *
159N/A * The contents of this file are subject to the terms of the
935N/A * Common Development and Distribution License (the "License").
159N/A * You may not use this file except in compliance with the License.
159N/A *
919N/A * See LICENSE.txt included in this distribution for the specific
919N/A * language governing permissions and limitations under the License.
919N/A *
919N/A * When distributing Covered Code, include this CDDL HEADER in each
919N/A * file and include the License file at LICENSE.txt.
919N/A * If applicable, add the following below this CDDL HEADER, with the
919N/A * fields enclosed by brackets "[]" replaced with your own identifying
919N/A * information: Portions Copyright [yyyy] [name of copyright owner]
919N/A *
919N/A * CDDL HEADER END
919N/A */
919N/A
919N/A/*
919N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
919N/A */
919N/A
919N/Apackage org.opensolaris.opengrok.index;
159N/A
159N/Aimport java.io.File;
159N/Aimport java.util.ArrayList;
159N/Aimport org.junit.AfterClass;
493N/Aimport org.junit.BeforeClass;
159N/Aimport org.junit.Test;
159N/Aimport org.opensolaris.opengrok.analysis.Definitions;
851N/Aimport org.opensolaris.opengrok.configuration.RuntimeEnvironment;
159N/Aimport org.opensolaris.opengrok.util.TestRepository;
911N/Aimport static org.junit.Assert.*;
911N/A
911N/A/**
911N/A * Unit tests for the {@code IndexDatabase} class.
159N/A */
851N/Apublic class IndexDatabaseTest {
606N/A private static TestRepository repository;
705N/A
705N/A public IndexDatabaseTest() {
705N/A }
159N/A
159N/A @BeforeClass
159N/A public static void setUpClass() throws Exception {
493N/A RuntimeEnvironment env = RuntimeEnvironment.getInstance();
493N/A assertTrue("No ctags available", env.validateExuberantCtags());
159N/A
606N/A repository = new TestRepository();
606N/A repository.create(
606N/A IndexDatabase.class.getResourceAsStream("source.zip"));
606N/A
891N/A env.setSourceRoot(repository.getSourceRoot());
891N/A env.setDataRoot(repository.getDataRoot());
606N/A
606N/A Indexer indexer = Indexer.getInstance();
159N/A indexer.prepareIndexer(
env, true, true, "/c", null,
false, false, false, null, null, new ArrayList<String>(), false);
indexer.doIndexerExecution(true, 1, null, null);
}
@AfterClass
public static void tearDownClass() throws Exception {
repository.destroy();
}
@Test
public void testGetDefinitions() throws Exception {
// Test that we can get definitions for one of the files in the
// repository.
File f1 = new File(repository.getSourceRoot() + "/c/foobar.c");
Definitions defs1 = IndexDatabase.getDefinitions(f1);
assertNotNull(defs1);
assertTrue(defs1.hasSymbol("foobar"));
assertTrue(defs1.hasSymbol("a"));
assertFalse(defs1.hasSymbol("b"));
assertTrue(defs1.hasDefinitionAt("foobar", 1, new String[1]));
// Test that we get null back if we request definitions for a file
// that's not in the repository.
File f2 = new File(repository.getSourceRoot() + "/c/foobar.d");
Definitions defs2 = IndexDatabase.getDefinitions(f2);
assertNull(defs2);
}
}