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
1220N/Aimport java.io.File;
1214N/Aimport java.util.ArrayList;
1127N/Aimport org.junit.AfterClass;
1127N/Aimport org.junit.BeforeClass;
1127N/Aimport org.junit.Test;
1127N/Aimport org.opensolaris.opengrok.analysis.Definitions;
1470N/Aimport org.opensolaris.opengrok.configuration.Configuration;
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
1470N/A @SuppressWarnings("javadoc")
1127N/A @BeforeClass
1127N/A public static void setUpClass() throws Exception {
1470N/A Configuration cfg = RuntimeEnvironment.getConfig();
1470N/A assertTrue("No ctags available", RuntimeEnvironment.validateExuberantCtags());
1127N/A
1127N/A repository = new TestRepository();
1470N/A repository.create(IndexDatabase.class.getResourceAsStream("source.zip"));
1127N/A
1470N/A cfg.setSourceRoot(repository.getSourceRoot());
1470N/A cfg.setDataRoot(repository.getDataRoot());
1470N/A
1470N/A Indexer.prepareIndexer(true, true, "/c", null, false, false, false,
1470N/A null, null, new ArrayList<String>(), false);
1470N/A Indexer.doIndexerExecution(true, 1, null, null);
1127N/A }
1127N/A
1470N/A @SuppressWarnings("javadoc")
1127N/A @AfterClass
1470N/A public static void tearDownClass() {
1127N/A repository.destroy();
1127N/A }
1127N/A
1470N/A @SuppressWarnings({ "static-method", "javadoc" })
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}