CommandLineOptionsTest.java revision f0ca07e08967a974684daffd32316cc9f9b98150
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/*
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * CDDL HEADER START
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen *
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen * The contents of this file are subject to the terms of the
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen * Common Development and Distribution License (the "License").
e015e2f7e7f48874495f9df8b0dd192b7ffcb5ccTimo Sirainen * You may not use this file except in compliance with the License.
58be9d6bcc3800f5b3d76a064ee767fbe31a5a8aTimo Sirainen *
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen * See LICENSE.txt included in this distribution for the specific
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * language governing permissions and limitations under the License.
18d92dbbb752c79dc461514e52f7ef11847e636bTimo Sirainen *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * When distributing Covered Code, include this CDDL HEADER in each
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * file and include the License file at LICENSE.txt.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * If applicable, add the following below this CDDL HEADER, with the
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * fields enclosed by brackets "[]" replaced with your own identifying
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * information: Portions Copyright [yyyy] [name of copyright owner]
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen *
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * CDDL HEADER END
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen */
e8fd7988ec183fb6c104aed19a61f1a096c51d34Timo Sirainen
e8fd7988ec183fb6c104aed19a61f1a096c51d34Timo Sirainen/*
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * Use is subject to license terms.
6bc0f424bcdb9119d8159874cf98adfa53eefd9aTimo Sirainen */
6bc0f424bcdb9119d8159874cf98adfa53eefd9aTimo Sirainenpackage org.opensolaris.opengrok.index;
6bc0f424bcdb9119d8159874cf98adfa53eefd9aTimo Sirainen
6bc0f424bcdb9119d8159874cf98adfa53eefd9aTimo Sirainenimport java.io.IOException;
6bc0f424bcdb9119d8159874cf98adfa53eefd9aTimo Sirainenimport java.util.Iterator;
6bc0f424bcdb9119d8159874cf98adfa53eefd9aTimo Sirainenimport org.junit.After;
d35fee8d1e5e31614dba5e64d45ed23c7d6bfa53Timo Sirainenimport org.junit.AfterClass;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenimport org.junit.Before;
6bc0f424bcdb9119d8159874cf98adfa53eefd9aTimo Sirainenimport org.junit.BeforeClass;
ad850190d946d34966a56838cfdb216e021b5b5fTimo Sirainenimport org.junit.Test;
ad850190d946d34966a56838cfdb216e021b5b5fTimo Sirainenimport static org.junit.Assert.*;
d35fee8d1e5e31614dba5e64d45ed23c7d6bfa53Timo Sirainen
d35fee8d1e5e31614dba5e64d45ed23c7d6bfa53Timo Sirainen/**
d35fee8d1e5e31614dba5e64d45ed23c7d6bfa53Timo Sirainen * Check the CommandLineOption class
d35fee8d1e5e31614dba5e64d45ed23c7d6bfa53Timo Sirainen *
d35fee8d1e5e31614dba5e64d45ed23c7d6bfa53Timo Sirainen * @author Trond Norbye
d35fee8d1e5e31614dba5e64d45ed23c7d6bfa53Timo Sirainen */
d35fee8d1e5e31614dba5e64d45ed23c7d6bfa53Timo Sirainenpublic class CommandLineOptionsTest {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen public CommandLineOptionsTest() {
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainen }
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen @BeforeClass
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen public static void setUpClass() throws Exception {
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen }
19e8adccba16ff419f5675b1575358c2956dce83Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen @AfterClass
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen public static void tearDownClass() throws Exception {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen }
8aacc9e7c84f8376822823ec98c2f551d4919b2eTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen @Before
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen public void setUp() {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen @After
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen public void tearDown() {
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen }
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen
1098fc409a45e7603701dc94635927a673bee0c1Timo Sirainen /**
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen * Test of getCommandString method, of class CommandLineOptions.
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen @Test
6e235046e1d8e9d89fc948f5c623676c20421a28Timo Sirainen public void testCommandLineOptions() throws IOException {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen CommandLineOptions instance = new CommandLineOptions();
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen String cmdString = instance.getCommandString();
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen assertNotNull(cmdString);
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen int ii = 0;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen while (ii < cmdString.length()) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen char c = cmdString.charAt(ii);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (c != ':') {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen assertNotNull(instance.getCommandUsage(c));
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ++ii;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen }
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen Iterator<CommandLineOptions.Option> iter = instance.getOptionsIterator();
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen while (iter.hasNext()) {
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen CommandLineOptions.Option o = iter.next();
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen assertNotNull(o.description);
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen }
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen assertNotNull(instance.getUsage());
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen assertNotNull(instance.getManPage());
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen }
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen
85da8c055280cd45553b6b335e9fb226d6e2801eTimo Sirainen @Test
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen public void bug3042() {
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen CommandLineOptions instance = new CommandLineOptions();
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen String cmdString = instance.getCommandString();
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen int idx = cmdString.indexOf("?");
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen assertTrue(idx != -1);
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen assertEquals("-?\n\tHelp", instance.getCommandUsage('?'));
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen }
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen
2131ef7a3390f15ea6a958256ea54908f1096350Timo Sirainen @Test
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen public void rfe3041() {
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen CommandLineOptions instance = new CommandLineOptions();
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen String cmdString = instance.getCommandString();
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen int idx = cmdString.indexOf("V");
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen assertTrue(idx != -1);
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen assertEquals("-V\n\tPrint version and quit", instance.getCommandUsage('V'));
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen }
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen}