1
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 "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 |
|
|
18 |
package com.nokia.s60tools.imaker.internal.impmodel.tests;
|
|
19 |
|
|
20 |
import java.io.BufferedWriter;
|
|
21 |
import java.io.File;
|
|
22 |
import java.io.FileWriter;
|
|
23 |
import java.io.IOException;
|
|
24 |
import java.io.Writer;
|
|
25 |
import java.util.Map;
|
|
26 |
|
|
27 |
import junit.framework.TestCase;
|
|
28 |
|
|
29 |
import org.eclipse.emf.common.util.EList;
|
|
30 |
import org.eclipse.emf.common.util.URI;
|
|
31 |
import org.eclipse.emf.ecore.EObject;
|
|
32 |
import org.eclipse.emf.ecore.resource.Resource;
|
|
33 |
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
|
34 |
|
|
35 |
import com.nokia.s60tools.imaker.internal.impmodel.Comment;
|
|
36 |
import com.nokia.s60tools.imaker.internal.impmodel.ConfigEntry;
|
|
37 |
import com.nokia.s60tools.imaker.internal.impmodel.FileListEntry;
|
|
38 |
import com.nokia.s60tools.imaker.internal.impmodel.ImpDocument;
|
|
39 |
import com.nokia.s60tools.imaker.internal.impmodel.OverrideConfiguration;
|
|
40 |
import com.nokia.s60tools.imaker.internal.impmodel.OverrideFiles;
|
|
41 |
import com.nokia.s60tools.imaker.internal.impmodel.Variable;
|
|
42 |
import com.nokia.s60tools.imaker.internal.impmodel.util.ImpResourceFactoryImpl;
|
|
43 |
|
|
44 |
/**
|
|
45 |
* <!-- begin-user-doc -->
|
|
46 |
* A test suite for the '<em><b>impmodel</b></em>' package.
|
|
47 |
* <!-- end-user-doc -->
|
|
48 |
* @generated
|
|
49 |
*/
|
|
50 |
public class ImpResourceLoadTests extends TestCase {
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
private File testFile;
|
|
55 |
|
|
56 |
@Override
|
|
57 |
protected void setUp() throws Exception {
|
|
58 |
testFile = getTestFile();
|
|
59 |
}
|
|
60 |
|
|
61 |
@Override
|
|
62 |
protected void tearDown() throws Exception {
|
|
63 |
testFile.delete();
|
|
64 |
}
|
|
65 |
|
|
66 |
private File getTestFile() throws IOException {
|
|
67 |
File file = File.createTempFile("test", ".imp");
|
|
68 |
return file;
|
|
69 |
}
|
|
70 |
|
|
71 |
public void testLoadingEmptyFile() throws Exception {
|
|
72 |
EObject contents = loadContents();
|
|
73 |
assertNotNull(contents);
|
|
74 |
assertTrue(contents instanceof ImpDocument);
|
|
75 |
}
|
|
76 |
|
|
77 |
|
|
78 |
public void testLoadingComments() throws Exception {
|
|
79 |
String comments = "#comment1\n#comment2\nhuuhaa";
|
|
80 |
populateTestFile(comments);
|
|
81 |
ImpDocument doc = (ImpDocument) loadContents();
|
|
82 |
assertTrue("Not desired amount of comments found!",doc.getComments().size()==2);
|
|
83 |
Comment cm = doc.getComments().get(0);
|
|
84 |
assertEquals("comment1", cm.getComment());
|
|
85 |
}
|
|
86 |
|
|
87 |
public void testLoadingVariables() throws Exception {
|
|
88 |
String content = "#comment1\nvar1 = foo\nvar1 = bar";
|
|
89 |
populateTestFile(content);
|
|
90 |
ImpDocument doc = (ImpDocument) loadContents();
|
|
91 |
assertTrue("Not desired amount of variables found!",doc.getVariables().size()==2);
|
|
92 |
Variable var = doc.getVariables().get(0);
|
|
93 |
assertEquals("var1", var.getName());
|
|
94 |
assertEquals("foo", var.getValue());
|
|
95 |
}
|
|
96 |
|
|
97 |
public void testLoadingOverrideFiles() throws Exception {
|
|
98 |
String content = "#comment1\nvar1 = foo\n" +
|
|
99 |
"define IMAGE_ORIDEFILES\n" +
|
|
100 |
"\ttarget1 source1\n" +
|
|
101 |
"\ttarget2 source2\n" +
|
|
102 |
"endef";
|
|
103 |
|
|
104 |
populateTestFile(content);
|
|
105 |
ImpDocument doc = (ImpDocument) loadContents();
|
|
106 |
assertTrue("Not desired amount of override files found!",doc.getOrideFiles().size()==1);
|
|
107 |
|
|
108 |
OverrideFiles of = doc.getOrideFiles().get(0);
|
|
109 |
assertTrue("Not desired amount of entries in the list!",of.getEntries().size()==2);
|
|
110 |
}
|
|
111 |
|
|
112 |
public void testLoadingOverrideFilesWithSpace() throws Exception {
|
|
113 |
String content = "#comment1\nvar1 = foo\n" +
|
|
114 |
"define IMAGE_ORIDEFILES\n" +
|
|
115 |
"\t\"source file1\" target1\n" +
|
|
116 |
"\tsource2 \"target file2\"\n" +
|
|
117 |
"endef";
|
|
118 |
|
|
119 |
populateTestFile(content);
|
|
120 |
ImpDocument doc = (ImpDocument) loadContents();
|
|
121 |
assertTrue("Not desired amount of override files found!",doc.getOrideFiles().size()==1);
|
|
122 |
|
|
123 |
OverrideFiles of = doc.getOrideFiles().get(0);
|
|
124 |
assertTrue("Not desired amount of entries in the list!",of.getEntries().size()==2);
|
|
125 |
FileListEntry entry = of.getEntries().get(0);
|
|
126 |
assertEquals("\"source file1\"", entry.getSource());
|
|
127 |
entry = of.getEntries().get(1);
|
|
128 |
assertEquals("\"target file2\"", entry.getTarget());
|
|
129 |
|
|
130 |
}
|
|
131 |
|
|
132 |
public void testLoadingOverrideConfs() throws Exception {
|
|
133 |
String content = "#comment1\nvar1 = foo\n" +
|
|
134 |
"define IMAGE_ORIDECONF\n" +
|
|
135 |
"\tekern.exe udeb core\n" +
|
11
|
136 |
"\tAbout.r01 hide rofs2\n" +
|
1
|
137 |
"endef";
|
|
138 |
|
|
139 |
populateTestFile(content);
|
|
140 |
ImpDocument doc = (ImpDocument) loadContents();
|
|
141 |
assertTrue("Not desired amount of override confs found!",doc.getOrideConfs().size()==1);
|
|
142 |
|
|
143 |
OverrideConfiguration oc = doc.getOrideConfs().get(0);
|
|
144 |
assertTrue("Not desired amount of entries in the list!",oc.getEntries().size()==2);
|
|
145 |
ConfigEntry entry = oc.getEntries().get(0);
|
|
146 |
assertEquals("ekern.exe", entry.getTarget());
|
|
147 |
assertEquals("udeb", entry.getAction());
|
|
148 |
assertEquals("core", entry.getLocation());
|
|
149 |
}
|
|
150 |
|
|
151 |
public void testLoadingOverrideFilesAndConfsTogether() throws Exception {
|
|
152 |
String content = "#comment1\n#variables\nvar1 = foo\n" +
|
|
153 |
"#trace files\n" +
|
|
154 |
"define IMAGE_ORIDEFILES\n" +
|
|
155 |
"\tsource1 ekern.exe\n" +
|
|
156 |
"\tsource2 About.r01\n" +
|
|
157 |
"endef\n" +
|
|
158 |
"#trace configurations\n" +
|
|
159 |
"define IMAGE_ORIDECONF\n" +
|
|
160 |
"\tekern.exe udeb core\n" +
|
11
|
161 |
"\tAbout.r01 hide rofs2\n" +
|
1
|
162 |
"endef";
|
|
163 |
|
|
164 |
populateTestFile(content);
|
|
165 |
|
|
166 |
ImpDocument doc = (ImpDocument) loadContents();
|
|
167 |
assertTrue("Not desired amount of override files found!",doc.getOrideFiles().size()==1);
|
|
168 |
assertTrue("Not desired amount of override confs found!",doc.getOrideConfs().size()==1);
|
|
169 |
|
|
170 |
OverrideFiles files = doc.getOrideFiles().get(0);
|
|
171 |
FileListEntry entry = files.getEntries().get(0);
|
|
172 |
assertFalse("File Entry has no associated action",entry.getActions().isEmpty());
|
|
173 |
ConfigEntry action = entry.getActions().get(0);
|
|
174 |
assertEquals("udeb", action.getAction());
|
|
175 |
assertEquals("core", action.getLocation());
|
|
176 |
}
|
|
177 |
|
|
178 |
public void testLoadingLineBreaks() throws Exception {
|
|
179 |
String comment = "This is a longggggg comment continued and continued";
|
|
180 |
String content = "#This is a longggggg \\\ncomment continued \\\nand continued\n";
|
|
181 |
|
|
182 |
populateTestFile(content);
|
|
183 |
ImpDocument doc = (ImpDocument) loadContents();
|
|
184 |
assertTrue(doc.getComments().size()==1);
|
|
185 |
assertEquals(comment, doc.getComments().get(0).getComment());
|
|
186 |
}
|
|
187 |
|
|
188 |
public void testLoadingLineNumbers() throws Exception {
|
|
189 |
String content = "#comment1\n" +
|
|
190 |
"var1 = foo\n" +
|
|
191 |
"#trace files\n" +
|
|
192 |
"define IMAGE_ORIDEFILES\n" +
|
|
193 |
"\ttarget1 source1\n" +
|
|
194 |
"\ttarget2 source2\n" +
|
|
195 |
"endef\n" +
|
|
196 |
"#trace configurations\n" +
|
|
197 |
"define IMAGE_ORIDECONF\n" +
|
|
198 |
"\tekern.exe udeb core\n" +
|
11
|
199 |
"\tAbout.r01 hide rofs2\n" +
|
1
|
200 |
"endef";
|
|
201 |
|
|
202 |
populateTestFile(content);
|
|
203 |
ImpDocument doc = (ImpDocument) loadContents();
|
|
204 |
assertEquals(1, doc.getComments().get(0).getLineNumber());
|
|
205 |
assertEquals(3, doc.getComments().get(1).getLineNumber());
|
|
206 |
assertEquals(8, doc.getComments().get(2).getLineNumber());
|
|
207 |
assertEquals(2, doc.getVariables().get(0).getLineNumber());
|
|
208 |
assertEquals(4, doc.getOrideFiles().get(0).getLineNumber());
|
|
209 |
assertEquals(9, doc.getOrideConfs().get(0).getLineNumber());
|
|
210 |
}
|
|
211 |
|
|
212 |
private void populateTestFile(String content) throws IOException {
|
|
213 |
Writer output = new BufferedWriter(new FileWriter(testFile));
|
|
214 |
try {
|
|
215 |
output.write( content );
|
|
216 |
}
|
|
217 |
finally {
|
|
218 |
output.close();
|
|
219 |
}
|
|
220 |
}
|
|
221 |
|
|
222 |
private EObject loadContents() throws IOException {
|
|
223 |
ResourceSetImpl rs = new ResourceSetImpl();
|
|
224 |
Map<String, Object> factoryMap = rs.getResourceFactoryRegistry().getExtensionToFactoryMap();
|
|
225 |
factoryMap.put("imp", new ImpResourceFactoryImpl());
|
|
226 |
|
|
227 |
URI uri = URI.createFileURI(testFile.getAbsolutePath());
|
|
228 |
Resource resource = rs.createResource(uri);
|
|
229 |
assertNotNull(resource);
|
|
230 |
resource.load(null);
|
|
231 |
EList<EObject> contents = resource.getContents();
|
|
232 |
assertFalse("resource is empty",contents.isEmpty());
|
|
233 |
return contents.get(0);
|
|
234 |
}
|
|
235 |
|
|
236 |
} //ImpResourceLoadTests
|