project/com.nokia.carbide.cpp.epoc.engine.tests/src/com/nokia/carbide/cpp/epoc/engine/tests/model/TestMMPView.java
changeset 610 bfb3ab3f70f2
parent 0 fb279309251b
child 684 8e7900690341
equal deleted inserted replaced
609:bf7dbec89c47 610:bfb3ab3f70f2
    24 import com.nokia.carbide.cpp.epoc.engine.preprocessor.DefineFactory;
    24 import com.nokia.carbide.cpp.epoc.engine.preprocessor.DefineFactory;
    25 import com.nokia.carbide.internal.api.cpp.epoc.engine.dom.IASTListNode;
    25 import com.nokia.carbide.internal.api.cpp.epoc.engine.dom.IASTListNode;
    26 import com.nokia.carbide.internal.api.cpp.epoc.engine.dom.IASTTopLevelNode;
    26 import com.nokia.carbide.internal.api.cpp.epoc.engine.dom.IASTTopLevelNode;
    27 import com.nokia.carbide.internal.api.cpp.epoc.engine.dom.mmp.IASTMMPListArgumentStatement;
    27 import com.nokia.carbide.internal.api.cpp.epoc.engine.dom.mmp.IASTMMPListArgumentStatement;
    28 import com.nokia.carbide.internal.cpp.epoc.engine.model.ViewASTBase;
    28 import com.nokia.carbide.internal.cpp.epoc.engine.model.ViewASTBase;
       
    29 import com.nokia.cpp.internal.api.utils.core.HostOS;
    29 import com.nokia.cpp.internal.api.utils.core.IMessage;
    30 import com.nokia.cpp.internal.api.utils.core.IMessage;
    30 
    31 
    31 import org.eclipse.core.runtime.IPath;
    32 import org.eclipse.core.runtime.IPath;
    32 import org.eclipse.core.runtime.Path;
    33 import org.eclipse.core.runtime.Path;
    33 
    34 
  1047 		
  1048 		
  1048 		assertEquals(new Path("data/foo.rss"), resource.getSource());
  1049 		assertEquals(new Path("data/foo.rss"), resource.getSource());
  1049 		assertEquals(2, resource.getDependsFiles().size());
  1050 		assertEquals(2, resource.getDependsFiles().size());
  1050 		assertEquals("foo1.rsg", resource.getDependsFiles().get(0));
  1051 		assertEquals("foo1.rsg", resource.getDependsFiles().get(0));
  1051 		assertEquals("foo2.rsg", resource.getDependsFiles().get(1));
  1052 		assertEquals("foo2.rsg", resource.getDependsFiles().get(1));
  1052 		assertEquals(new Path("\\sys\\bin"), resource.getTargetPath());
  1053 		assertEquals(new Path("/sys/bin"), resource.getTargetPath());
  1053 		assertEquals("foo.rsc", resource.getTargetFile());
  1054 		assertEquals("foo.rsc", resource.getTargetFile());
  1054 		assertEquals(2, resource.getLanguages().size());
  1055 		assertEquals(2, resource.getLanguages().size());
  1055 		assertEquals(EGeneratedHeaderFlags.Header, resource.getHeaderFlags());
  1056 		assertEquals(EGeneratedHeaderFlags.Header, resource.getHeaderFlags());
  1056 		assertEquals("0x1000", resource.getUid2());
  1057 		assertEquals("0x1000", resource.getUid2());
  1057 		assertEquals("0x2000", resource.getUid3());
  1058 		assertEquals("0x2000", resource.getUid3());
  1099 		_testNewResourcesParsing2a(view);
  1100 		_testNewResourcesParsing2a(view);
  1100 		_testNewResourcesParsing2a(view.getData());
  1101 		_testNewResourcesParsing2a(view.getData());
  1101 	}
  1102 	}
  1102 
  1103 
  1103 	private void _testNewResourcesParsing2a(IMMPData data) {
  1104 	private void _testNewResourcesParsing2a(IMMPData data) {
  1104 		assertEquals(new Path("\\sys\\target\\foo"), data.getTargetFilePath());
  1105 		assertEquals(new Path("/sys/target/foo"), data.getTargetFilePath());
  1105 		assertEquals("0x1", data.getUid2());
  1106 		assertEquals("0x1", data.getUid2());
  1106 		assertEquals("0x2", data.getUid3());
  1107 		assertEquals("0x2", data.getUid3());
  1107 		
  1108 		
  1108 		List<IMMPResource> resources = data.getResourceBlocks();
  1109 		List<IMMPResource> resources = data.getResourceBlocks();
  1109 		assertEquals(1, resources.size());
  1110 		assertEquals(1, resources.size());
  1110 		IMMPResource resource = resources.get(0);
  1111 		IMMPResource resource = resources.get(0);
  1111 
  1112 
  1112 		assertEquals("foo1.rsg", resource.getDependsFiles().get(0));
  1113 		assertEquals("foo1.rsg", resource.getDependsFiles().get(0));
  1113 		assertEquals("foo2.rsg", resource.getDependsFiles().get(1));
  1114 		assertEquals("foo2.rsg", resource.getDependsFiles().get(1));
  1114 		assertEquals(new Path("\\sys\\bin"), resource.getTargetPath());
  1115 		assertEquals(new Path("/sys/bin"), resource.getTargetPath());
  1115 		assertEquals("0x3", resource.getUid2());
  1116 		assertEquals("0x3", resource.getUid2());
  1116 		assertEquals("0x4", resource.getUid3());
  1117 		assertEquals("0x4", resource.getUid3());
  1117 	}
  1118 	}
  1118 
  1119 
  1119 	public void testNewResourcesParsing2b() {
  1120 	public void testNewResourcesParsing2b() {
  1140 		assertEquals(1, resources.size());
  1141 		assertEquals(1, resources.size());
  1141 		IMMPResource resource = resources.get(0);
  1142 		IMMPResource resource = resources.get(0);
  1142 
  1143 
  1143 		assertEquals("foo1.rsg", resource.getDependsFiles().get(0));
  1144 		assertEquals("foo1.rsg", resource.getDependsFiles().get(0));
  1144 		assertEquals("foo2.rsg", resource.getDependsFiles().get(1));
  1145 		assertEquals("foo2.rsg", resource.getDependsFiles().get(1));
  1145 		assertEquals(new Path("\\sys\\bin"), resource.getTargetPath());
  1146 		assertEquals(new Path("/sys/bin"), resource.getTargetPath());
  1146 		assertEquals("0x3", resource.getUid2());
  1147 		assertEquals("0x3", resource.getUid2());
  1147 		assertEquals("0x4", resource.getUid3());
  1148 		assertEquals("0x4", resource.getUid3());
  1148 	}
  1149 	}
  1149 
  1150 
  1150 	public void testNewResourcesParsing2c() {
  1151 	public void testNewResourcesParsing2c() {
  1200 		
  1201 		
  1201 		List<IMMPResource> resources = view.getResourceBlocks();
  1202 		List<IMMPResource> resources = view.getResourceBlocks();
  1202 		assertEquals(1, resources.size());
  1203 		assertEquals(1, resources.size());
  1203 		IMMPResource resource = resources.get(0);
  1204 		IMMPResource resource = resources.get(0);
  1204 		
  1205 		
  1205 		resource.setTargetPath(new Path("\\sys\\data\\myapp"));
  1206 		resource.setTargetPath(new Path("/sys/data/myapp"));
  1206 		resource.getLanguages().add(EMMPLanguage.American);
  1207 		resource.getLanguages().add(EMMPLanguage.American);
  1207 		
  1208 		
  1208 		commitTest(view,
  1209 		commitTest(view,
  1209 				"START RESOURCE ..\\data\\foo.rss\n"+
  1210 				"START RESOURCE ..\\data\\foo.rss\n"+
  1210 				"\tTARGETPATH \\sys\\data\\myapp\n"+
  1211 				"\tTARGETPATH \\sys\\data\\myapp\n"+
  1219 				);
  1220 				);
  1220 		IMMPView view = getView(mmpConfig);
  1221 		IMMPView view = getView(mmpConfig);
  1221 		assertNotNull(view);
  1222 		assertNotNull(view);
  1222 		
  1223 		
  1223 		IMMPResource resource = view.createMMPResource();
  1224 		IMMPResource resource = view.createMMPResource();
  1224 		resource.setTargetPath(new Path("\\where"));
  1225 		resource.setTargetPath(new Path("/where"));
  1225 		resource.setTargetFile("targ.rsc");
  1226 		resource.setTargetFile("targ.rsc");
  1226 		assertFalse(resource.isValid());
  1227 		assertFalse(resource.isValid());
  1227 		resource.setSource(new Path("/foo/bar/data/uidesign.rss"));
  1228 		resource.setSource(new Path("/foo/bar/data/uidesign.rss"));
  1228 		assertTrue(resource.isValid());
  1229 		assertTrue(resource.isValid());
  1229 		ArrayList<String> depends = new ArrayList<String>();
  1230 		ArrayList<String> depends = new ArrayList<String>();
  1377 
  1378 
  1378 	public void testTargetFilePath() {
  1379 	public void testTargetFilePath() {
  1379 		makeModel("TARGETPATH \\foo\\bar\n"+
  1380 		makeModel("TARGETPATH \\foo\\bar\n"+
  1380 				"TARGET file.exe\n");
  1381 				"TARGET file.exe\n");
  1381 		IMMPView view = getView(mmpConfig);
  1382 		IMMPView view = getView(mmpConfig);
  1382 		assertEquals(new Path("\\foo\\bar\\file.exe"), view.getTargetFilePath());
  1383 		assertEquals(new Path("/foo/bar/file.exe"), view.getTargetFilePath());
  1383 		
  1384 		
  1384 		// keep predom slash fmt
  1385 		// keep predom slash fmt
  1385 		view.setTargetFilePath(new Path("\\sys\\bin\\nasty.exe"));
  1386 		view.setTargetFilePath(new Path("/sys/bin/nasty.exe"));
  1386 		commitTest(view, "TARGETPATH \\sys\\bin\n"+
  1387 		commitTest(view, "TARGETPATH \\sys\\bin\n"+
  1387 			"TARGET nasty.exe\n");
  1388 			"TARGET nasty.exe\n");
  1388 		
  1389 		
  1389 		view.getSingleArgumentSettings().put(EMMPStatement.TARGETPATH, "\\sys\\dll");
  1390 		view.getSingleArgumentSettings().put(EMMPStatement.TARGETPATH, "\\sys\\dll");
  1390 		commitTest(view, "TARGETPATH \\sys\\dll\n"+
  1391 		commitTest(view, "TARGETPATH \\sys\\dll\n"+
  1406 	}
  1407 	}
  1407 
  1408 
  1408 	private void _testAIFParsing0(IMMPData data) {
  1409 	private void _testAIFParsing0(IMMPData data) {
  1409 		assertEquals(1, data.getAifs().size());
  1410 		assertEquals(1, data.getAifs().size());
  1410 		IMMPAIFInfo info = data.getAifs().get(0);
  1411 		IMMPAIFInfo info = data.getAifs().get(0);
  1411 		assertEquals(new Path("data\\aiffile.rss"), info.getResource());
  1412 		assertEquals(new Path("data/aiffile.rss"), info.getResource());
  1412 		// TARGETPATH not represented
  1413 		// TARGETPATH not represented
  1413 		assertEquals(new Path("targetfile.aif"), info.getTarget());
  1414 		assertEquals(new Path("targetfile.aif"), info.getTarget());
  1414 		
  1415 		
  1415 		assertEquals(0, info.getColorDepth());
  1416 		assertEquals(0, info.getColorDepth());
  1416 		assertEquals(0, info.getMaskDepth());
  1417 		assertEquals(0, info.getMaskDepth());
  1430 	}
  1431 	}
  1431 
  1432 
  1432 	private void _testAIFParsing1(IMMPData data) {
  1433 	private void _testAIFParsing1(IMMPData data) {
  1433 		assertEquals(1, data.getAifs().size());
  1434 		assertEquals(1, data.getAifs().size());
  1434 		IMMPAIFInfo info = data.getAifs().get(0);
  1435 		IMMPAIFInfo info = data.getAifs().get(0);
  1435 		assertEquals(new Path("data\\aiffile.rss"), info.getResource());
  1436 		assertEquals(new Path("data/aiffile.rss"), info.getResource());
  1436 		// TARGETPATH not represented
  1437 		// TARGETPATH not represented
  1437 		assertEquals(new Path("targetfile.aif"), info.getTarget());
  1438 		assertEquals(new Path("targetfile.aif"), info.getTarget());
  1438 
  1439 
  1439 		assertEquals(12, info.getColorDepth());
  1440 		assertEquals(12, info.getColorDepth());
  1440 		assertEquals(1, info.getMaskDepth());
  1441 		assertEquals(1, info.getMaskDepth());
  1636 		List<IMMPBitmap> bitmaps = data.getBitmaps();
  1637 		List<IMMPBitmap> bitmaps = data.getBitmaps();
  1637 		assertEquals(1, bitmaps.size());
  1638 		assertEquals(1, bitmaps.size());
  1638 		
  1639 		
  1639 		IMMPBitmap bitmap = bitmaps.get(0);
  1640 		IMMPBitmap bitmap = bitmaps.get(0);
  1640 		assertEquals("foo.mbm", bitmap.getTargetFile());
  1641 		assertEquals("foo.mbm", bitmap.getTargetFile());
  1641 		assertEquals(new Path("\\sys\\pix"), bitmap.getTargetPath());
  1642 		assertEquals(new Path("/sys/pix"), bitmap.getTargetPath());
  1642 		assertEquals(EGeneratedHeaderFlags.Header, bitmap.getHeaderFlags());
  1643 		assertEquals(EGeneratedHeaderFlags.Header, bitmap.getHeaderFlags());
  1643 		assertEquals(3, bitmap.getSources().size());
  1644 		assertEquals(3, bitmap.getSources().size());
  1644 		
  1645 		
  1645 		List<IBitmapSource> sources = bitmap.getBitmapSources();
  1646 		List<IBitmapSource> sources = bitmap.getBitmapSources();
  1646 		IBitmapSource bm = sources.get(0);
  1647 		IBitmapSource bm = sources.get(0);
  1671 		IMMPView view = getView(mmpConfig);
  1672 		IMMPView view = getView(mmpConfig);
  1672 		assertNotNull(view);
  1673 		assertNotNull(view);
  1673 		IMMPBitmap bitmap = view.createMMPBitmap();
  1674 		IMMPBitmap bitmap = view.createMMPBitmap();
  1674 
  1675 
  1675 		bitmap.setTargetFile("target.mbm");
  1676 		bitmap.setTargetFile("target.mbm");
  1676 		bitmap.setTargetPath(new Path("e:\\foo\\bar"));
  1677 		if (HostOS.IS_WIN32)
       
  1678 			bitmap.setTargetPath(new Path("e:\\foo\\bar"));
       
  1679 		else
       
  1680 			bitmap.setTargetPath(new Path("e:/foo/bar"));
  1677 		bitmap.setHeaderFlags(EGeneratedHeaderFlags.Header);
  1681 		bitmap.setHeaderFlags(EGeneratedHeaderFlags.Header);
  1678 
  1682 
  1679 		IBitmapSource source = bitmap.createBitmapSource();
  1683 		IBitmapSource source = bitmap.createBitmapSource();
  1680 
  1684 
  1681 		source.setDepth(8);
  1685 		source.setDepth(8);
  1699 				"END\n");
  1703 				"END\n");
  1700 				
  1704 				
  1701 	}
  1705 	}
  1702 	
  1706 	
  1703 	public void testBitmapChanging1() {
  1707 	public void testBitmapChanging1() {
       
  1708 		String nativePath;
       
  1709 		if (HostOS.IS_WIN32)
       
  1710 			nativePath = "e:\\foo\\bar";
       
  1711 		else
       
  1712 			nativePath = "e:/foo/bar";
  1704 		makeModel(
  1713 		makeModel(
  1705 				"START BITMAP target.mbm\n"+
  1714 				"START BITMAP target.mbm\n"+
  1706 				"// comment 1\n"+
  1715 				"// comment 1\n"+
  1707 				"\tTARGETPATH e:\\foo\\bar\n"+
  1716 				"\tTARGETPATH "+ nativePath + "\n"+
  1708 				"// comment 2\n"+
  1717 				"// comment 2\n"+
  1709 				"\tHEADER\n"+
  1718 				"\tHEADER\n"+
  1710 				"// comment 3\n"+
  1719 				"// comment 3\n"+
  1711 				"\tSOURCEPATH ..\\data\\pix\n"+
  1720 				"\tSOURCEPATH ..\\data\\pix\n"+
  1712 				"// comment 4\n"+
  1721 				"// comment 4\n"+
  1717 		assertNotNull(view);
  1726 		assertNotNull(view);
  1718 		
  1727 		
  1719 		IMMPBitmap bitmap = view.getBitmaps().get(0);
  1728 		IMMPBitmap bitmap = view.getBitmaps().get(0);
  1720 
  1729 
  1721 		bitmap.setTargetFile("target.mbm");
  1730 		bitmap.setTargetFile("target.mbm");
  1722 		bitmap.setTargetPath(new Path("e:\\foo\\bar"));
  1731 		bitmap.setTargetPath(new Path(nativePath));
  1723 		bitmap.setHeaderFlags(EGeneratedHeaderFlags.Header);
  1732 		bitmap.setHeaderFlags(EGeneratedHeaderFlags.Header);
  1724 
  1733 
  1725 		IBitmapSource source = (IBitmapSource) bitmap.getSources().get(0);
  1734 		IBitmapSource source = (IBitmapSource) bitmap.getSources().get(0);
  1726 
  1735 
  1727 		source.setDepth(8);
  1736 		source.setDepth(8);
  1731 
  1740 
  1732 		// should be no change
  1741 		// should be no change
  1733 		commitTest(view,
  1742 		commitTest(view,
  1734 				"START BITMAP target.mbm\n"+
  1743 				"START BITMAP target.mbm\n"+
  1735 				"// comment 1\n"+
  1744 				"// comment 1\n"+
  1736 				"\tTARGETPATH e:\\foo\\bar\n"+
  1745 				"\tTARGETPATH " + nativePath + "\n"+
  1737 				"// comment 2\n"+
  1746 				"// comment 2\n"+
  1738 				"\tHEADER\n"+
  1747 				"\tHEADER\n"+
  1739 				"// comment 3\n"+
  1748 				"// comment 3\n"+
  1740 				"\tSOURCEPATH ..\\data\\pix\n"+
  1749 				"\tSOURCEPATH ..\\data\\pix\n"+
  1741 				"// comment 4\n"+
  1750 				"// comment 4\n"+
  1744 	
  1753 	
  1745 		///
  1754 		///
  1746 		bitmap = view.getBitmaps().get(0);
  1755 		bitmap = view.getBitmaps().get(0);
  1747 		bitmap.setHeaderFlags(EGeneratedHeaderFlags.HeaderOnly);
  1756 		bitmap.setHeaderFlags(EGeneratedHeaderFlags.HeaderOnly);
  1748 		
  1757 		
  1749 		// unfortunately we have to rewrite and lose comments here
  1758 		// unfortunately we have to rewrite, reslash, and lose comments here 
       
  1759 		String nativePix;
       
  1760 		if (HostOS.IS_WIN32)
       
  1761 			nativePix = "..\\data\\pix";
       
  1762 		else
       
  1763 			nativePix = "../data/pix";
  1750 		commitTest(view,
  1764 		commitTest(view,
  1751 				"START BITMAP target.mbm\n"+
  1765 				"START BITMAP target.mbm\n"+
  1752 				"\tTARGETPATH e:\\foo\\bar\n"+
  1766 				"\tTARGETPATH " +  nativePath + "\n"+
  1753 				"\tSOURCEPATH ..\\data\\pix\n"+
  1767 				"\tSOURCEPATH " + nativePix + "\n"+
  1754 				"\tSOURCE 8,8 icon.bmp icon_mask_soft.bmp\n"+
  1768 				"\tSOURCE 8,8 icon.bmp icon_mask_soft.bmp\n"+
  1755 				"\tHEADERONLY\n"+
  1769 				"\tHEADERONLY\n"+
  1756 				"END\n");
  1770 				"END\n");
  1757 
  1771 
  1758 	}
  1772 	}