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