javauis/lcdui_qt/tsrc/src/com/nokia/openlcdui/mt/graphics/CommandBufferingTest.java
changeset 76 4ad59aaee882
parent 61 bf7ee68962da
equal deleted inserted replaced
69:773449708c84 76:4ad59aaee882
   107         methodNames.addElement("testDrawString");
   107         methodNames.addElement("testDrawString");
   108         methodNames.addElement("testFillArc");
   108         methodNames.addElement("testFillArc");
   109         methodNames.addElement("testFillRect");
   109         methodNames.addElement("testFillRect");
   110         methodNames.addElement("testFillRoundRect");
   110         methodNames.addElement("testFillRoundRect");
   111         methodNames.addElement("testFillTriangle");
   111         methodNames.addElement("testFillTriangle");
       
   112         
   112 
   113 
   113         return methodNames;
   114         return methodNames;
   114     }
   115     }
   115 
   116 
   116     protected void runTest() throws Throwable
   117     protected void runTest() throws Throwable
   127     	else if(getName().equals("testDrawString")) testDrawString();
   128     	else if(getName().equals("testDrawString")) testDrawString();
   128     	else if(getName().equals("testFillArc")) testFillArc();
   129     	else if(getName().equals("testFillArc")) testFillArc();
   129     	else if(getName().equals("testFillRect")) testFillRect();
   130     	else if(getName().equals("testFillRect")) testFillRect();
   130     	else if(getName().equals("testFillRoundRect")) testFillRoundRect();
   131     	else if(getName().equals("testFillRoundRect")) testFillRoundRect();
   131     	else if(getName().equals("testFillTriangle")) testFillTriangle();
   132     	else if(getName().equals("testFillTriangle")) testFillTriangle();
   132 
       
   133         else super.runTest();
   133         else super.runTest();
   134     }
   134     }
   135 
   135 
   136     /**
   136     /**
   137      * Tests the default value of a newly created Graphics object
   137      * Tests the default value of a newly created Graphics object
   763     	{
   763     	{
   764     		fail(errorMsg);
   764     		fail(errorMsg);
   765     	}	
   765     	}	
   766 	}
   766 	}
   767 	
   767 	
       
   768 	/**
       
   769 	 * Test drawString with two graphics
       
   770 	 */
   768 	void testDrawString()
   771 	void testDrawString()
   769 	{
   772 	{
   770 		
   773 	 	boolean pass = true;
       
   774     	String errorMsg = "Pixel check failed at: ";
       
   775     	
       
   776     	Graphics g1 = testImage.getGraphics();
       
   777     	Graphics g2 = testImage.getGraphics();
       
   778     	
       
   779     	// run different settings in the graphics instances
       
   780     	applyGraphicsSettings(g1, GRAPHICS_SETTINGS_1);
       
   781     	applyGraphicsSettings(g2, GRAPHICS_SETTINGS_2);
       
   782     	
       
   783     	final int anchor = Graphics.TOP | Graphics.LEFT;
       
   784     	
       
   785     	g1.drawString("I", 0, -9, anchor);
       
   786     	g2.drawString("I", -2, -3, anchor);
       
   787     	g1.drawString("I", 11, -9, anchor);
       
   788 
       
   789      	// read image pixels to member array
       
   790     	readTestImagePixels();
       
   791     	
       
   792     	//print(pixelData, testImageWidth);
       
   793     	
       
   794     	// Most of the points to validate are based on the values 
       
   795     	// set by applyGraphicsSettings() -method
       
   796     	final int[] spotsToValidate = {
       
   797     			// "I" with large font 1
       
   798     		  3, 1, BLUE,  // top inside 
       
   799     		  3, 19, BLUE, // bottom inside
       
   800     		  3, 0, WHITE, // top outside
       
   801     		    
       
   802     		  // "I" with small font
       
   803     		  10, 4, RED, // top inside
       
   804     		  10, 15, RED, // bottom inside
       
   805     		  10,  3, WHITE, // top outside
       
   806     		  10,  16, WHITE, // bottom outside
       
   807     		    
       
   808     		  // "I" with large font 2
       
   809     		  15, 1, BLUE,  // top inside 
       
   810     		  15, 19, BLUE, // bottom inside
       
   811     		  15, 0, WHITE // top outside
       
   812     	};
       
   813     	
       
   814     	// Validate test points against reference color
       
   815     	for(int i = 0; i < spotsToValidate.length ; i=i+3) 
       
   816     	{
       
   817     		if(!validatePixel(spotsToValidate[i], spotsToValidate[i+1], spotsToValidate[i+2]))
       
   818         	{
       
   819         		pass = false;
       
   820         		errorMsg += "("+spotsToValidate[i]+","+spotsToValidate[i+1]+"), expected "+colorToString(spotsToValidate[i+2])+
       
   821         		            ", got "+ colorToString(getPixelIgnoreAlpha(spotsToValidate[i], spotsToValidate[i+1]))+" : ";
       
   822         	}
       
   823     	}
       
   824     	
       
   825     	if(!pass) 
       
   826     	{
       
   827     		fail(errorMsg);
       
   828     	}
   771 	}
   829 	}
   772 	
   830 	
       
   831 	/**
       
   832 	 * Test fillArc with two graphics
       
   833 	 */
   773 	void testFillArc()
   834 	void testFillArc()
   774 	{
   835 	{
   775 		
   836     	boolean pass = true;
       
   837     	String errorMsg = "Pixel check failed at: ";
       
   838     	Graphics g1 = testImage.getGraphics();
       
   839     	Graphics g2 = testImage.getGraphics();
       
   840     	
       
   841     	// run different settings in the graphics instances
       
   842     	applyGraphicsSettings(g1, GRAPHICS_SETTINGS_1);
       
   843     	applyGraphicsSettings(g2, GRAPHICS_SETTINGS_2);
       
   844     	
       
   845     	g1.fillArc(0, 0, 8, 8, 0, 180);
       
   846     	g2.fillArc(0, 0, 8, 8, 0, 180);
       
   847     	g1.fillArc(0, 8, 8, 8, 0, 180);
       
   848     	
       
   849      	// read image pixels to member array
       
   850     	readTestImagePixels();
       
   851     	
       
   852     	// Most of the points to validate are based on the values 
       
   853     	// set by applyGraphicsSettings() -method
       
   854     	final int[] spotsToValidate = {
       
   855     			2,  8, BLUE, // Starting point of the first arc 
       
   856     			8,  8, BLUE, // end point
       
   857     			5,  6, BLUE, // tip of the arc 
       
   858     			11, 7, RED,  // start arc 2
       
   859     			17, 7, RED,  // end arc 2
       
   860     			14, 5, RED,  // tip of arc 2
       
   861     			2,  16, BLUE, // start arc 3
       
   862     			8,  16, BLUE, // end arc 3
       
   863     			5,  14, BLUE, // tip of arc 3	
       
   864     			1,  1, WHITE // one point to validate that whole image is not filled
       
   865     	};
       
   866     	
       
   867     	// Validate test points against reference color
       
   868     	for(int i = 0; i < spotsToValidate.length ; i=i+3) 
       
   869     	{
       
   870     		if(!validatePixel(spotsToValidate[i], spotsToValidate[i+1], spotsToValidate[i+2]))
       
   871         	{
       
   872         		pass = false;
       
   873         		errorMsg += "("+spotsToValidate[i]+","+spotsToValidate[i+1]+"), expected "+colorToString(spotsToValidate[i+2])+
       
   874         		            ", got "+ colorToString(getPixelIgnoreAlpha(spotsToValidate[i], spotsToValidate[i+1]))+" : ";
       
   875         	}
       
   876     	}
       
   877     	
       
   878     	if(!pass) 
       
   879     	{
       
   880     		fail(errorMsg);
       
   881     	}
   776 	}
   882 	}
   777 	
   883 	
       
   884 	/**
       
   885 	 * Test fillRect with two graphics
       
   886 	 */
   778 	void testFillRect()
   887 	void testFillRect()
   779 	{
   888 	{
   780 		
   889 		boolean pass = true;
       
   890     	String errorMsg = "Pixel check failed at: ";
       
   891     	
       
   892     	Graphics g1 = testImage.getGraphics();
       
   893     	Graphics g2 = testImage.getGraphics();
       
   894     	
       
   895     	// run different settings in the graphics instances
       
   896     	applyGraphicsSettings(g1, GRAPHICS_SETTINGS_1);
       
   897     	applyGraphicsSettings(g2, GRAPHICS_SETTINGS_2);
       
   898     	
       
   899     	g1.fillRect(0, 0, 6, 6);
       
   900     	g2.fillRect(0, 0, 6, 6);
       
   901     	g1.fillRect(0, 8, 3, 3);
       
   902     	
       
   903      	// read image pixels to member array
       
   904     	readTestImagePixels();
       
   905     	
       
   906     	// Most of the points to validate are based on the values 
       
   907     	// set by applyGraphicsSettings() -method
       
   908     	final int[] spotsToValidate = {
       
   909     			// filled rectangle 1
       
   910     			1, 5, BLUE,  // top-left corner of rectangle 1
       
   911     			6, 5, BLUE,  // top-right corner of rectangle 1
       
   912     			1, 10, BLUE, // bottom-left corner of rectangle 1 
       
   913     		    6, 10, BLUE, // bottom-right corner of rectangle 1
       
   914     		    
       
   915     		    0, 7, WHITE, // Left border (outside) of rectangle 1
       
   916     		    7, 7, WHITE, // Right border (outside) of rectangle 1
       
   917     		    3, 4, WHITE, // Top border (outside) of rectangle 1
       
   918     		    3, 11, WHITE, // Bottom border (outside) of rectangle 1
       
   919     		    
       
   920     		    // filled rectangle 2
       
   921     			10, 4, RED,  // top-left corner of rectangle 2
       
   922     			15, 4, RED,  // top-right corner of rectangle 2
       
   923     			10, 9, RED, // bottom-left corner of rectangle 2 
       
   924     		    15, 9, RED, // bottom-right corner of rectangle 2
       
   925     		    
       
   926     		    9, 6, WHITE, // Left border (outside) of rectangle 2
       
   927     		    16, 6, WHITE, // Right border (outside) of rectangle 2
       
   928     		    12, 3, WHITE, // Top border (outside) of rectangle 2
       
   929     		    14, 10, WHITE, // Bottom border (outside) of rectangle 2
       
   930     		    
       
   931     		    // filled rectangle 3
       
   932     			1, 13, BLUE,  // top-left corner of rectangle 3
       
   933     			3, 13, BLUE,  // top-right corner of rectangle 3
       
   934     			1, 15, BLUE, // bottom-left corner of rectangle 3 
       
   935     		    3, 15, BLUE, // bottom-right corner of rectangle 3
       
   936     		    
       
   937     		    0, 14, WHITE, // Left border (outside) of rectangle 3
       
   938     		    4, 14, WHITE, // Right border (outside) of rectangle 3
       
   939     		    3, 12, WHITE, // Top border (outside) of rectangle 3
       
   940     		    3, 16, WHITE, // Bottom border (outside) of rectangle 3
       
   941     	};
       
   942     	
       
   943     	// Validate test points against reference color
       
   944     	for(int i = 0; i < spotsToValidate.length ; i=i+3) 
       
   945     	{
       
   946     		if(!validatePixel(spotsToValidate[i], spotsToValidate[i+1], spotsToValidate[i+2]))
       
   947         	{
       
   948         		pass = false;
       
   949         		errorMsg += "("+spotsToValidate[i]+","+spotsToValidate[i+1]+"), expected "+colorToString(spotsToValidate[i+2])+
       
   950         		            ", got "+ colorToString(getPixelIgnoreAlpha(spotsToValidate[i], spotsToValidate[i+1]))+" : ";
       
   951         	}
       
   952     	}
       
   953     	
       
   954     	if(!pass) 
       
   955     	{
       
   956     		fail(errorMsg);
       
   957     	}	
   781 	}
   958 	}
   782 	
   959 	
       
   960 	/**
       
   961 	 * Test fillRoundRect with two graphics
       
   962 	 */
   783 	void testFillRoundRect()
   963 	void testFillRoundRect()
   784 	{
   964 	{
   785 		
   965 	 	boolean pass = true;
       
   966     	String errorMsg = "Pixel check failed at: ";
       
   967     	
       
   968     	Graphics g1 = testImage.getGraphics();
       
   969     	Graphics g2 = testImage.getGraphics();
       
   970     	
       
   971     	// run different settings in the graphics instances
       
   972     	applyGraphicsSettings(g1, GRAPHICS_SETTINGS_1);
       
   973     	applyGraphicsSettings(g2, GRAPHICS_SETTINGS_2);
       
   974     	
       
   975     	g1.fillRoundRect(0, 0, 6, 6, 2, 2);
       
   976     	g2.fillRoundRect(0, 0, 6, 6, 2, 2);
       
   977     	g1.fillRoundRect(0, 8, 5, 5, 2, 2);
       
   978     	
       
   979      	// read image pixels to member array
       
   980     	readTestImagePixels();
       
   981     	
       
   982     	// Most of the points to validate are based on the values 
       
   983     	// set by applyGraphicsSettings() -method
       
   984     	final int[] spotsToValidate = {
       
   985     			// rectangle 1
       
   986     			1, 6, BLUE,  // left side of rectangle 1
       
   987     			6, 6, BLUE,  // right side of rectangle 1
       
   988     			3, 5, BLUE, // top side of rectangle 1 
       
   989     		    3, 10, BLUE, // bottom side of rectangle 1
       
   990     		    
       
   991     		    0, 7, WHITE, // Left border (outside) of rectangle 1
       
   992     		    7, 7, WHITE, // Right border (outside) of rectangle 1
       
   993     		    3, 4, WHITE, // Top border (outside) of rectangle 1
       
   994     		    3, 11, WHITE, // Bottom border (outside) of rectangle 1
       
   995     		    
       
   996     		    // rectangle 2
       
   997     			10, 6, RED,  // left side of rectangle 2
       
   998     			15, 5, RED,  // right side of rectangle 2
       
   999     			12, 4, RED, // top side of rectangle 2 
       
  1000     		    12, 9, RED, // bottom side corner of rectangle 2
       
  1001     		    
       
  1002     		    9, 6, WHITE, // Left border (outside) of rectangle 2
       
  1003     		    16, 6, WHITE, // Right border (outside) of rectangle 2
       
  1004     		    12, 3, WHITE, // Top border (outside) of rectangle 2
       
  1005     		    14, 10, WHITE, // Bottom border (outside) of rectangle 2
       
  1006     		    
       
  1007     		    // rectangle 3
       
  1008     			1, 15, BLUE,  // left side of of rectangle 3
       
  1009     			5, 14, BLUE,  // right side of of rectangle 3
       
  1010     			2, 13, BLUE, // top side of rectangle 3 
       
  1011     		    3, 17, BLUE, // bottom side of rectangle 3
       
  1012     		    
       
  1013     		    0, 14, WHITE, // Left border (outside) of rectangle 3
       
  1014     		    6, 14, WHITE, // Right border (outside) of rectangle 3
       
  1015     		    3, 12, WHITE, // Top border (outside) of rectangle 3
       
  1016     		    3, 18, WHITE, // Bottom border (outside) of rectangle 3
       
  1017     	};
       
  1018     	
       
  1019     	// Validate test points against reference color
       
  1020     	for(int i = 0; i < spotsToValidate.length ; i=i+3) 
       
  1021     	{
       
  1022     		if(!validatePixel(spotsToValidate[i], spotsToValidate[i+1], spotsToValidate[i+2]))
       
  1023         	{
       
  1024         		pass = false;
       
  1025         		errorMsg += "("+spotsToValidate[i]+","+spotsToValidate[i+1]+"), expected "+colorToString(spotsToValidate[i+2])+
       
  1026         		            ", got "+ colorToString(getPixelIgnoreAlpha(spotsToValidate[i], spotsToValidate[i+1]))+" : ";
       
  1027         	}
       
  1028     	}
       
  1029     	
       
  1030     	if(!pass) 
       
  1031     	{
       
  1032     		fail(errorMsg);
       
  1033     	}	
   786 	}
  1034 	}
   787 	
  1035 	
       
  1036 	/**
       
  1037 	 * Test fillTriangle with two graphics
       
  1038 	 */
   788 	void testFillTriangle()
  1039 	void testFillTriangle()
   789 	{
  1040 	{
   790 		
  1041 	 	boolean pass = true;
       
  1042     	String errorMsg = "Pixel check failed at: ";
       
  1043     	
       
  1044     	Graphics g1 = testImage.getGraphics();
       
  1045     	Graphics g2 = testImage.getGraphics();
       
  1046     	
       
  1047     	// run different settings in the graphics instances
       
  1048     	applyGraphicsSettings(g1, GRAPHICS_SETTINGS_1);
       
  1049     	applyGraphicsSettings(g2, GRAPHICS_SETTINGS_2);
       
  1050     	
       
  1051     	g1.fillTriangle(0, 0, 5, 6, 5, 0);
       
  1052     	g2.fillTriangle(0, 0, 5, 6, 5, 0);
       
  1053     	g1.fillTriangle(0, 8, 5, 14, 5, 8);
       
  1054     	
       
  1055      	// read image pixels to member array
       
  1056     	readTestImagePixels();
       
  1057     	
       
  1058     	// Most of the points to validate are based on the values 
       
  1059     	// set by applyGraphicsSettings() -method
       
  1060     	final int[] spotsToValidate = {
       
  1061     			// triangle 1
       
  1062     			1, 5, BLUE,  // top-left
       
  1063     			6, 5, BLUE,  // top-right
       
  1064     			4, 4, WHITE, // outside near triangle 1
       
  1065     		    
       
  1066     			// triangle 2
       
  1067     			10, 4, RED,  // top-left
       
  1068     			15, 4, RED,  // top-right
       
  1069     			13, 3, WHITE, // outside near triangle 1
       
  1070     		    
       
  1071     			// triangle 3
       
  1072     			1, 13, BLUE,  // top-left
       
  1073     			6, 13, BLUE,  // top-right
       
  1074     			4, 12, WHITE, // outside near triangle 1
       
  1075     	};
       
  1076     	
       
  1077     	// Validate test points against reference color
       
  1078     	for(int i = 0; i < spotsToValidate.length ; i=i+3) 
       
  1079     	{
       
  1080     		if(!validatePixel(spotsToValidate[i], spotsToValidate[i+1], spotsToValidate[i+2]))
       
  1081         	{
       
  1082         		pass = false;
       
  1083         		errorMsg += "("+spotsToValidate[i]+","+spotsToValidate[i+1]+"), expected "+colorToString(spotsToValidate[i+2])+
       
  1084         		            ", got "+ colorToString(getPixelIgnoreAlpha(spotsToValidate[i], spotsToValidate[i+1]))+" : ";
       
  1085         	}
       
  1086     	}
       
  1087     	
       
  1088     	if(!pass) 
       
  1089     	{
       
  1090     		fail(errorMsg);
       
  1091     	}
   791 	}
  1092 	}
   792   
  1093   
   793     
       
   794 	private void applyGraphicsSettings(Graphics g, int settings) 
  1094 	private void applyGraphicsSettings(Graphics g, int settings) 
   795 	{
  1095 	{
   796 		
  1096 		
   797 		Font defaultFont = Font.getDefaultFont();
  1097 		Font defaultFont = Font.getDefaultFont();
   798 		if(settings == GRAPHICS_SETTINGS_1)
  1098 		if(settings == GRAPHICS_SETTINGS_1)
   799 		{
  1099 		{
   800 			Font font = Font.getFont(defaultFont.getFace(), defaultFont.getStyle(), Font.SIZE_LARGE);
  1100 			Font font = Font.getFont(defaultFont.getFace(), defaultFont.getStyle(), Font.SIZE_LARGE);
   801 			g.setColor(BLUE);
  1101 			g.setColor(BLUE);
   802 			g.translate(1, 5);
  1102 			g.translate(1, 5);
   803 			g.setStrokeStyle(Graphics.DOTTED);
  1103 			g.setStrokeStyle(Graphics.DOTTED);
       
  1104 			g.setFont(font);
   804 		}
  1105 		}
   805 		else if(settings == GRAPHICS_SETTINGS_2)
  1106 		else if(settings == GRAPHICS_SETTINGS_2)
   806 		{
  1107 		{
   807 			Font font = Font.getFont(defaultFont.getFace(), defaultFont.getStyle(), Font.SIZE_SMALL);
  1108 			Font font = Font.getFont(defaultFont.getFace(), defaultFont.getStyle(), Font.SIZE_SMALL);
   808 			g.setColor(RED);
  1109 			g.setColor(RED);
   809 			g.translate(10, 4);
  1110 			g.translate(10, 4);
   810 			g.setStrokeStyle(Graphics.SOLID);
  1111 			g.setStrokeStyle(Graphics.SOLID);
       
  1112 			g.setFont(font);
   811 		}
  1113 		}
   812 	}
  1114 	}
   813 	
  1115 	
   814     /**
  1116     /**
   815      * Reads all pixels of the testImage to the class member array pixelData
  1117      * Reads all pixels of the testImage to the class member array pixelData