/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
*/
package org.opensolaris.opengrok.index;
import java.io.File;
import java.util.ArrayList;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opensolaris.opengrok.analysis.Definitions;
import org.opensolaris.opengrok.configuration.Configuration;
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
import org.opensolaris.opengrok.util.TestRepository;
import static org.junit.Assert.*;
/**
* Unit tests for the {@code IndexDatabase} class.
*/
public class IndexDatabaseTest {
private static TestRepository repository;
@SuppressWarnings("javadoc")
@BeforeClass
public static void setUpClass() throws Exception {
Configuration cfg = RuntimeEnvironment.getConfig();
assertTrue("No ctags available", RuntimeEnvironment.validateExuberantCtags());
repository = new TestRepository();
repository.create(IndexDatabase.class.getResourceAsStream("source.zip"));
cfg.setSourceRoot(repository.getSourceRoot());
cfg.setDataRoot(repository.getDataRoot());
Indexer.prepareIndexer(true, true, "/c", null, false, false, false,
null, null, new ArrayList<String>(), false);
Indexer.doIndexerExecution(true, 1, null, null);
}
@SuppressWarnings("javadoc")
@AfterClass
public static void tearDownClass() {
repository.destroy();
}
@SuppressWarnings({ "static-method", "javadoc" })
@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);
}
}