buildframework/helium/sf/java/imaker/tests/src/com/nokia/helium/imaker/tests/TestIMaker.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.imaker.tests;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    18
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    19
import static org.junit.Assert.assertArrayEquals;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    20
import static org.junit.Assert.assertEquals;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents: 587
diff changeset
    21
import static org.junit.Assert.fail;
587
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    22
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    23
import java.io.File;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    24
import java.util.List;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    25
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    26
import org.junit.Test;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    27
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    28
import com.nokia.helium.imaker.IMaker;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    29
import com.nokia.helium.imaker.IMakerException;
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    30
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    31
/**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    32
 * Testing IMaker class.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    33
 */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    34
public class TestIMaker {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    35
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    36
    private File epocroot = new File(System.getProperty("testdir"), "tests/epocroot");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    37
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    38
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    39
     * Test the getVersion is retrieving the output from imaker correctly.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    40
     * @throws IMakerException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    41
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    42
    @Test
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    43
    public void testGetVersion() throws IMakerException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    44
        String expectedVersion = "iMaker 09.24.01, 10-Jun-2009.";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    45
        IMaker imaker = new IMaker(epocroot);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    46
        assertEquals(expectedVersion, imaker.getVersion());
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    47
    }
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
     * Test the introspection of an existing variable.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    51
     * @throws IMakerException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    52
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    53
    @Test
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    54
    public void testGetVariable() throws IMakerException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    55
        IMaker imaker = new IMaker(epocroot);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    56
        assertEquals("VALUE", imaker.getVariable("VARIABLE"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    57
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    58
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    59
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    60
     * Test the introspection of an existing variable.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    61
     * @throws IMakerException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    62
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    63
    @Test
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    64
    public void testGetVariableFromConfiguration() throws IMakerException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    65
        IMaker imaker = new IMaker(epocroot);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    66
        assertEquals("PRODUCT_VALUE", imaker.getVariable("VARIABLE", new File("/epoc32/rom/config/platform/product/image_conf_product.mk")));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    67
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    68
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    69
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    70
     * Test the introspection of a non-existing variable.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    71
     * @throws IMakerException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    72
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    73
    @Test
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    74
    public void testGetNotExistingVariable() throws IMakerException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    75
        IMaker imaker = new IMaker(epocroot);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    76
        assertEquals(null, imaker.getVariable("NOTEXISTINGVARIABLE"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    77
    }
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
     * Test the introspection of existing configurations.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    81
     * @throws IMakerException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    82
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    83
    @Test
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    84
    public void testGetConfigurations() throws IMakerException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    85
        IMaker imaker = new IMaker(epocroot);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    86
        String[] expected = new String[2];
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    87
        expected[0] = "/epoc32/rom/config/platform/product/image_conf_product.mk";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    88
        expected[1] = "/epoc32/rom/config/platform/product/image_conf_product_ui.mk";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    89
        assertArrayEquals(expected, imaker.getConfigurations().toArray(new String[2]));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    90
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    91
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    92
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    93
     * Test the introspection of existing target for a configuration.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    94
     * @throws IMakerException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    95
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    96
    @Test
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    97
    public void testGetTargets() throws IMakerException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    98
        IMaker imaker = new IMaker(epocroot);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
    99
        List<String> targets = imaker.getTargets("/epoc32/rom/config/platform/product/image_conf_product.mk");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   100
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   101
        String[] expected = new String[5];
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   102
        expected[0] = "all";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   103
        expected[1] = "core";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   104
        expected[2] = "core-dir";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   105
        expected[3] = "help-%-list";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   106
        expected[4] = "langpack_01";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   107
        assertArrayEquals(expected, targets.toArray(new String[5]));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   108
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   109
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   110
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   111
     * Test the introspection of existing target for a configuration using file
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   112
     * object.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   113
     * @throws IMakerException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   114
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   115
    @Test
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   116
    public void testGetTargetsFromFile() throws IMakerException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   117
        IMaker imaker = new IMaker(epocroot);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   118
        List<String> targets = imaker.getTargets(new File("/epoc32/rom/config/platform/product/image_conf_product.mk"));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   119
        
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   120
        String[] expected = new String[5];
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   121
        expected[0] = "all";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   122
        expected[1] = "core";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   123
        expected[2] = "core-dir";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   124
        expected[3] = "help-%-list";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   125
        expected[4] = "langpack_01";
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   126
        assertArrayEquals(expected, targets.toArray(new String[5]));
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   127
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   128
    
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   129
    /**
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   130
     * Test the introspection of existing target for a configuration.
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   131
     * @throws IMakerException
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   132
     */
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   133
    @Test
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   134
    public void testGetTargetsWithInvalidProductConf() throws IMakerException {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   135
        IMaker imaker = new IMaker(epocroot);
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   136
        try {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   137
            imaker.getTargets("/epoc32/rom/config/platform/product/image_conf_invalid.mk");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   138
            fail("We should catch a failure from iMaker.");
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   139
        } catch(IMakerException e) {
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   140
            // Exception should be raised
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   141
        }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   142
    }
85df38eb4012 helium_9.0-a7879c935424
wbernard
parents:
diff changeset
   143
}