project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestMakefileView.java
changeset 610 bfb3ab3f70f2
parent 0 fb279309251b
child 684 8e7900690341
equal deleted inserted replaced
609:bf7dbec89c47 610:bfb3ab3f70f2
    25 import com.nokia.carbide.cpp.epoc.engine.model.makefile.IMakefileViewConfiguration;
    25 import com.nokia.carbide.cpp.epoc.engine.model.makefile.IMakefileViewConfiguration;
    26 import com.nokia.carbide.cpp.epoc.engine.preprocessor.AcceptedNodesViewFilter;
    26 import com.nokia.carbide.cpp.epoc.engine.preprocessor.AcceptedNodesViewFilter;
    27 import com.nokia.carbide.cpp.epoc.engine.preprocessor.IDefine;
    27 import com.nokia.carbide.cpp.epoc.engine.preprocessor.IDefine;
    28 import com.nokia.carbide.cpp.epoc.engine.preprocessor.IViewFilter;
    28 import com.nokia.carbide.cpp.epoc.engine.preprocessor.IViewFilter;
    29 import com.nokia.carbide.cpp.epoc.engine.tests.BaseTest;
    29 import com.nokia.carbide.cpp.epoc.engine.tests.BaseTest;
       
    30 import com.nokia.cpp.internal.api.utils.core.HostOS;
    30 import com.nokia.cpp.internal.api.utils.core.IMessage;
    31 import com.nokia.cpp.internal.api.utils.core.IMessage;
    31 
    32 
    32 import org.eclipse.cdt.make.core.makefile.ICommand;
    33 import org.eclipse.cdt.make.core.makefile.ICommand;
    33 import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
    34 import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
    34 import org.eclipse.cdt.make.core.makefile.IMakefile;
    35 import org.eclipse.cdt.make.core.makefile.IMakefile;
    84 		};
    85 		};
    85 
    86 
    86 	}
    87 	}
    87 	
    88 	
    88 	protected void makeModel(String text) {
    89 	protected void makeModel(String text) {
       
    90 		// TODO: tests should work with both slash directions on both OSes
       
    91 		if (HostOS.IS_UNIX)
       
    92 			text = text.replaceAll("\\\\(?!\r|\n)", "/");
    89 		IDocument document = DocumentFactory.createDocument(text);
    93 		IDocument document = DocumentFactory.createDocument(text);
    90 		model = new MakefileModelFactory().createModel(path, document);
    94 		model = new MakefileModelFactory().createModel(path, document);
    91 
    95 
    92 		model.parse();
    96 		model.parse();
    93 	}
    97 	}
    97 		assertNotNull(view);
   101 		assertNotNull(view);
    98 		return view;
   102 		return view;
    99 	}
   103 	}
   100 	
   104 	
   101 	protected void commitTest(IMakefileView view, String refText) {
   105 	protected void commitTest(IMakefileView view, String refText) {
       
   106 		// TODO: tests should work with both slash directions on both OSes
       
   107 		if (HostOS.IS_UNIX)
       
   108 			refText = refText.replaceAll("\\\\(?!\r|\n)", "/");
   102 		commitTest(model, view, refText);
   109 		commitTest(model, view, refText);
   103 	}
   110 	}
   104 	
   111 	
   105 	final String TEST_1 =
   112 	final String TEST_1 =
   106 		"# Very special makefile\n"+
   113 		"# Very special makefile\n"+
   180 
   187 
   181 		ICommand[] commands = view.findCommandsInvoking("ld");
   188 		ICommand[] commands = view.findCommandsInvoking("ld");
   182 		assertEquals(1, commands.length);
   189 		assertEquals(1, commands.length);
   183 		assertNotNull(commands[0].getParent());
   190 		assertNotNull(commands[0].getParent());
   184 	
   191 	
       
   192 		String mifconvEXELine = "MIFCONV=$(TOOLDIR)\\mifconv"+ (HostOS.IS_WIN32 ? ".exe" : "") + "\n";  
   185 		makeModel("TOOLSDIR=c:\\my\\tools\n"+
   193 		makeModel("TOOLSDIR=c:\\my\\tools\n"+
   186 				"MIFCONV=$(TOOLDIR)\\mifconv.exe\n"+
   194 				mifconvEXELine +
   187 				"\n"+
   195 				"\n"+
   188 				"all: mytool\n"+
   196 				"all: mytool\n"+
   189 				"\n"+
   197 				"\n"+
   190 				"foo.mif: foo.svg\n"+
   198 				"foo.mif: foo.svg\n"+
   191 				"\t$(MIFCONV) -o $@ $^\n"+
   199 				"\t$(MIFCONV) -o $@ $^\n"+
   204 		+ oldRule.getCommands()[0];
   212 		+ oldRule.getCommands()[0];
   205 		
   213 		
   206 		view.replaceDirective(oldRule, newRule);
   214 		view.replaceDirective(oldRule, newRule);
   207 
   215 
   208 		commitTest(view, "TOOLSDIR=c:\\my\\tools\n"+
   216 		commitTest(view, "TOOLSDIR=c:\\my\\tools\n"+
   209 				"MIFCONV=$(TOOLDIR)\\mifconv.exe\n"+
   217 				mifconvEXELine +
   210 				"\n"+
   218 				"\n"+
   211 				"all: mytool\n"+
   219 				"all: mytool\n"+
   212 				"\n"+
   220 				"\n"+
   213 				"foo.mif: foo.svg foo.h\n"+
   221 				"foo.mif: foo.svg foo.h\n"+
   214 				"\t$(MIFCONV) -o $@ $^\n");
   222 				"\t$(MIFCONV) -o $@ $^\n");
   363 
   371 
   364 		commitTest(view, TEST_2_a);
   372 		commitTest(view, TEST_2_a);
   365 
   373 
   366 	}
   374 	}
   367 	
   375 	
   368 	public void testUnexpand() {
   376 	public void testUnexpand1() {
   369 		makeModel("ZDIR=$(EPOCROOT)\\release\\winscw\n"+
   377 		makeModel("ZDIR=$(EPOCROOT)\\release\\winscw\n"+
   370 				"TARGETDIR=$(ZDIR)\\data\n"+
   378 				"TARGETDIR=$(ZDIR)\\data\n"+
   371 				"ICONTARGETFILENAME=$(TARGETDIR)\\foo.mif\n");
   379 				"ICONTARGETFILENAME=$(TARGETDIR)\\foo.mif\n");
   372 		IMakefileView view = getView(viewConfig);
   380 		IMakefileView view = getView(viewConfig);
   373 
   381 
   374 		String repl = view.unexpandMacros("$(EPOCROOT)\\release\\winscw\\data\\more.mif", 
   382 		doUnexpandTest(view, "$(EPOCROOT)\\release\\winscw\\data\\more.mif", 
   375 				new String[] {  "TARGETDIR", "ZDIR" });
   383 				"$(TARGETDIR)\\more.mif");
   376 		assertEquals("$(TARGETDIR)\\more.mif", repl);
   384 
   377 
   385 		doUnexpandTest(view, "1 2 $(EPOCROOT)\\release\\winscw\\data\\more.mif 3 4", 
   378 		String repl1 = view.unexpandMacros("1 2 $(EPOCROOT)\\release\\winscw\\data\\more.mif 3 4", 
   386 			"1 2 $(TARGETDIR)\\more.mif 3 4");
   379 				new String[] {  "TARGETDIR", "ZDIR" });
   387 
   380 		assertEquals("1 2 $(TARGETDIR)\\more.mif 3 4", repl1);
   388 		doUnexpandTest(view, "$(EPOCROOT)\\release\\winscw\\more.mif", 
   381 
   389 			"$(ZDIR)\\more.mif");
   382 		String repl2 = view.unexpandMacros("$(EPOCROOT)\\release\\winscw\\more.mif", 
   390 
   383 				new String[] {  "TARGETDIR", "ZDIR" });
   391 		doUnexpandTest(view, "$(EPOCROOT)\\release\\foo\\data\\more.mif", 
   384 		assertEquals("$(ZDIR)\\more.mif", repl2);
   392 			"$(EPOCROOT)\\release\\foo\\data\\more.mif");
   385 
   393 
   386 		String repl3 = view.unexpandMacros("$(EPOCROOT)\\release\\foo\\data\\more.mif", 
   394 		doUnexpandTest(view, "\\release\\winscw\\data\\more.mif", 
   387 				new String[] {  "TARGETDIR", "ZDIR" });
   395 			"\\release\\winscw\\data\\more.mif");
   388 		assertEquals("$(EPOCROOT)\\release\\foo\\data\\more.mif", repl3);
   396 
   389 
   397 	}
   390 		String repl4 = view.unexpandMacros("\\release\\winscw\\data\\more.mif", 
   398 	
   391 				new String[] {  "TARGETDIR", "ZDIR" });
   399 	
   392 		assertEquals("\\release\\winscw\\data\\more.mif", repl4);
   400 	private void doUnexpandTest(IMakefileView view, String expanded,
   393 
   401 			String unexpanded) {
   394 	}
   402 
   395 	
   403 		// TODO: tests should ideally work with both slash directions on both OSes
       
   404 		if (HostOS.IS_WIN32) {
       
   405 			String repl = view.unexpandMacros(expanded, 
       
   406 					new String[] {  "TARGETDIR", "ZDIR" });
       
   407 			assertEquals(unexpanded, repl);
       
   408 		} else {
       
   409 			expanded = HostOS.convertPathToUnix(expanded);
       
   410 			unexpanded = HostOS.convertPathToUnix(unexpanded);
       
   411 			String repl = view.unexpandMacros(expanded, 
       
   412 					new String[] {  "TARGETDIR", "ZDIR" });
       
   413 			assertEquals(unexpanded, repl);
       
   414 		}
       
   415 		
       
   416 	}
       
   417 
   396 	public void testProblems() {
   418 	public void testProblems() {
   397 		makeModel("\n\n)ZDIR@foo{\n"+
   419 		makeModel("\n\n)ZDIR@foo{\n"+
   398 				"^^ placate ^^\n");
   420 				"^^ placate ^^\n");
   399 		IMakefileView view = getView(viewConfig);
   421 		IMakefileView view = getView(viewConfig);
   400 		IMessage[] messages = view.getMessages();
   422 		IMessage[] messages = view.getMessages();