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