imakerplugin/com.nokia.s60tools.imaker.tests/src/com/nokia/s60tools/imaker/internal/tests/ProjectManagerTest.java
author dpodwall
Tue, 12 Jan 2010 13:17:53 -0600
changeset 0 61163b28edca
child 1 7ff23301fe22
permissions -rw-r--r--
initial EPL conversion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     1
/*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     2
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     3
* All rights reserved.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     4
* This component and the accompanying materials are made available
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     6
* which accompanies this distribution, and is available
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     8
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
     9
* Initial Contributors:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    11
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    12
* Contributors:
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    13
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    14
* Description: 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    15
*
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    16
*/
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    17
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    18
package com.nokia.s60tools.imaker.internal.tests;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    19
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    20
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    21
import java.io.BufferedReader;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    22
import java.io.File;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    23
import java.io.FileInputStream;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    24
import java.io.IOException;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    25
import java.io.InputStream;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    26
import java.io.InputStreamReader;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    27
import java.util.ArrayList;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    28
import java.util.List;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    29
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    30
import org.eclipse.core.runtime.IPath;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    31
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    32
import com.nokia.s60tools.imaker.internal.managers.ProjectManager;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    33
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    34
public class ProjectManagerTest extends ProjectBuilder  {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    35
	private final String CONTENT  = "sample content";
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    36
	private final String LOCATION = "rofs3";
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    37
	private final String FILENAME = ProjectManager.IBY_FILENAME_PREFIX+LOCATION;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    38
	private ProjectManager projectManager;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    39
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    40
	public void setUp() throws Exception {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    41
		createDefaultProject();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    42
		addImakerImpFiles();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    43
		assertTrue(project.isAccessible());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    44
		projectManager = new ProjectManager(project);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    45
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    46
	
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    47
    public void tearDown() throws Exception {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    48
//        closeAndDeleteDefaultProject();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    49
    }
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    50
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    51
    public void testLocation() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    52
    	assertTrue(!projectManager.getRoot().equals(""));
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    53
    }
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    54
	public void testImplFiles() throws Exception {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    55
		assertTrue("No impl files found. There shoud be some in the testdata folder!",!projectManager.getImakerFiles().isEmpty());		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    56
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    57
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    58
	public void testIbyFiles() {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    59
		IPath path = project.getLocation(); 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    60
		IPath filePath = projectManager.createIbyFile(FILENAME, CONTENT, path);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    61
		File file = filePath.toFile();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    62
		assertTrue("Coudn't create iby file under test projec!", file.exists());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    63
		try {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    64
			FileInputStream fs = new FileInputStream(file);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    65
			String line = getContents(fs);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    66
			assertEquals(CONTENT, line);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    67
		} catch (IOException e) {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    68
			e.printStackTrace();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    69
		}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    70
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    71
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    72
	private String getContents(InputStream contents) throws IOException {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    73
		BufferedReader br = new BufferedReader(new InputStreamReader(contents));
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    74
		String line = br.readLine();
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    75
		return line;
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    76
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    77
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    78
	public void testMakefile() throws Exception {
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    79
		List<IPath> ifiles = new ArrayList<IPath>();		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    80
		IPath path = project.getLocation(); 
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    81
		IPath filePath = projectManager.createIbyFile(FILENAME, CONTENT, path);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    82
		ifiles.add(filePath);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    83
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    84
		IPath mk = projectManager.createAdditionsMakefile(ifiles,path);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    85
		
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    86
		assertNotNull("Makefile creation failled!",mk);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    87
		assertTrue("Makefile creation failled!", mk.toFile().exists());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    88
		FileInputStream fs = new FileInputStream(mk.toFile());
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    89
		String cons = getContents(fs);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    90
		assertNotNull(cons);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    91
		assertEquals(LOCATION.toUpperCase()+"_OBY += "+ filePath.toFile().getAbsolutePath(),cons);
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    92
	}
61163b28edca initial EPL conversion
dpodwall
parents:
diff changeset
    93
}