buildframework/helium/sf/java/checktools/tests/src/com/nokia/helium/checktools/tests/TestOSResolver.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
parent 587 85df38eb4012
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     1
/*
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     3
 * All rights reserved.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     8
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
     9
 * Initial Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    11
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    12
 * Contributors:
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    13
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    14
 * Description: 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    15
 *
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    16
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    17
package com.nokia.helium.checktools.tests;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    19
import java.util.Locale;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    20
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    21
import junit.framework.TestCase;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import com.nokia.helium.checktools.CheckToolException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import com.nokia.helium.checktools.OSResolver;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
/**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
 * Test class for OSResolver.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
 * 
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
public class TestOSResolver extends TestCase {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
     * Method to test getCommand.
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    34
     * @throws CheckToolException 
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    36
    public void testGetCommand() throws CheckToolException {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
        String result = OSResolver.getCommand("test");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
        String osName = System.getProperty("os.name").toLowerCase(Locale.US);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
        boolean isWindows = osName.indexOf("windows") > -1;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
        boolean is9x = (osName.indexOf("95") >= 0 || osName.indexOf("98") >= 0
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
                || osName.indexOf("me") >= 0 || osName.indexOf("ce") >= 0);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
        if (isWindows && is9x) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
            assertEquals("command /c test", result);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
        } else if (isWindows && !is9x) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
            assertEquals("cmd /c test", result);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        } else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
            assertEquals("test", result);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    48
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    49
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    50
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
     * Method to test whether the given os is of Windows family or not.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    54
    public void testIsOSWindowsFamily() throws CheckToolException  {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        String osName = System.getProperty("os.name").toLowerCase(Locale.US);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
        boolean isWindows = osName.indexOf("windows") > -1;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
        boolean result = OSResolver.isOs("windows");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
        if (isWindows) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
            assertEquals(true, result);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
        } else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
            assertEquals(false, result);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
     * Method to test whether the given os is of unix family or not.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
     */
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    68
    public void testIsOSUnixFamily() throws CheckToolException  {
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
        String osName = System.getProperty("os.name").toLowerCase(Locale.US);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
        String pathSeparator = System.getProperty("path.separator");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
        boolean isUnix = pathSeparator.equals(":")
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
                && (osName.indexOf("mac") == -1 || osName.endsWith("x"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
        boolean result = OSResolver.isOs("unix");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
        if (isUnix) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
            assertEquals(true, result);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        } else {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
            assertEquals(false, result);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    78
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    79
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    80
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
     * Method to test whether the given os is invalid or not.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
    public void testIsOSInvalidFamily() {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
        CheckToolException cte = null;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
            OSResolver.isOs("invalid");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
        } catch (CheckToolException ex) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
            cte = ex;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
        assertNotNull(cte);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
        String expected = "Don\'t know how to detect os family \"invalid\"";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
        assertEquals(expected, cte.getMessage());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
}