View | Details | Raw Unified | Return to issue 120631
Collapse All | Expand All

(-)testuno/source/testcase/uno/sd/CheckBuildInBullet.java (+158 lines)
Line 0 Link Here
1
/**
2
 * There are 8 build-in bullets. Verify those bullets can be applied successfully.
3
 * insert text into a SD
4
 * apply the 8 bullets one by one, and check
5
 */
6
package testcase.uno.sd;
7
8
import static org.junit.Assert.*;
9
import static testlib.uno.PageUtil.*;
10
import static testlib.uno.ShapeUtil.*;
11
12
import java.io.File;
13
import java.util.Arrays;
14
import java.util.Collection;
15
16
import org.junit.After;
17
import org.junit.AfterClass;
18
import org.junit.Before;
19
import org.junit.BeforeClass;
20
import org.junit.Test;
21
import org.junit.runner.RunWith;
22
import org.junit.runners.Parameterized;
23
import org.junit.runners.Parameterized.Parameters;
24
import org.openoffice.test.common.FileUtil;
25
import org.openoffice.test.common.Testspace;
26
import org.openoffice.test.uno.UnoApp;
27
28
import testlib.uno.SDUnoUtil;
29
30
import com.sun.star.beans.PropertyValue;
31
import com.sun.star.beans.XPropertySet;
32
import com.sun.star.container.XIndexReplace;
33
import com.sun.star.drawing.XShape;
34
import com.sun.star.lang.XComponent;
35
import com.sun.star.style.NumberingType;
36
import com.sun.star.uno.UnoRuntime;
37
38
39
/**
40
 * @author LouQL
41
 *
42
 */
43
@RunWith(Parameterized.class)
44
public class CheckBuildInBullet {
45
46
	private static final UnoApp app = new UnoApp();	
47
	private static final SDUnoUtil SDUtil = new SDUnoUtil();
48
	private XComponent m_xSDComponent = null;
49
	private String m_filePath = null;
50
	private XPropertySet m_xtextProps = null;
51
	private String m_BulletChar = null;
52
	private String m_expectedBulletChar = null;
53
	/**
54
	 * @throws java.lang.Exception
55
	 */
56
	
57
	public CheckBuildInBullet(String BulletChar, String expected) {
58
        this.m_BulletChar = BulletChar;
59
        m_expectedBulletChar = expected;
60
    }
61
	@Parameters
62
    public static Collection<String[]> data() {
63
        String[][] bulletChar = new String[][] {{"●","●"}, {"•","•"}, {"",""},{"",""},{"➔","➔"}, {"➢","➢"}, {"✗","✗"},{"✔","✔"}};
64
        return Arrays.asList(bulletChar);
65
    }
66
	
67
	@BeforeClass
68
	public static void setUpBeforeClass() throws Exception {
69
		app.start();
70
		File temp = new File(Testspace.getPath("temp"));
71
		temp.mkdirs();
72
	}
73
74
	/**
75
	 * @throws java.lang.Exception
76
	 */
77
	@AfterClass
78
	public static void tearDownAfterClass() throws Exception {
79
		app.close();
80
		//remove the temp file
81
		FileUtil.deleteFile(Testspace.getPath("temp"));
82
	}
83
84
	/**
85
	 * @throws java.lang.Exception
86
	 */
87
	@Before
88
	public void setUp() throws Exception {
89
		m_filePath = Testspace.getPath("temp/CheckBuildInBullet.odt");
90
//		m_filePath = "F:/aa.odp";
91
		if(FileUtil.fileExists(m_filePath))
92
		{	//load
93
			m_xtextProps = load();	  		
94
		}
95
		else{
96
			//create a sd
97
			m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress"));
98
			Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
99
			Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0);
100
			XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox);
101
			m_xtextProps = addPortion(xfirstTextBox, "test Build-in Bullet", false);
102
		}			
103
	}
104
	
105
	/**
106
	 * @throws java.lang.Exception
107
	 */
108
	@After
109
	public void tearDown() throws Exception {	
110
		app.closeDocument(m_xSDComponent);		
111
	}
112
	private XPropertySet load() throws Exception{
113
		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, 
114
				app.loadDocument(m_filePath));
115
		Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
116
		Object firstTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 0);
117
		XShape xfirstTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, firstTextBox);
118
		return getPortion(xfirstTextBox, 0);
119
	}
120
			
121
	@Test
122
	public void testBuildInBullet() throws Exception {		
123
		    
124
		Object numberingrules = m_xtextProps.getPropertyValue("NumberingRules");
125
					
126
		XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
127
	             XIndexReplace.class, numberingrules);    
128
						
129
		PropertyValue[] props = new PropertyValue[2];
130
	    props[0] = new PropertyValue();
131
	    props[0].Name = "NumberingType";
132
	    props[0].Value = new Short(NumberingType.CHAR_SPECIAL );
133
	    
134
	    props[1] = new PropertyValue();
135
	    props[1].Name = "BulletChar";
136
	    props[1].Value = this.m_BulletChar;
137
		
138
	    //set numberingType
139
	    xReplace.replaceByIndex(0, props);
140
	    m_xtextProps.setPropertyValue("NumberingRules", numberingrules);
141
	  //set numbering level to 0			
142
	    m_xtextProps.setPropertyValue("NumberingLevel", new Short((short)0));
143
144
		app.saveDocument(m_xSDComponent, m_filePath);
145
		app.closeDocument(m_xSDComponent);
146
		//reopen
147
		m_xtextProps = load();
148
				    
149
		Object numberingrules2 = m_xtextProps.getPropertyValue("NumberingRules");
150
					
151
		XIndexReplace xReplace2 = (XIndexReplace) UnoRuntime.queryInterface(
152
	             XIndexReplace.class, numberingrules2);
153
		
154
		PropertyValue[] proValues2 = (PropertyValue[])xReplace2.getByIndex(0);  
155
		assertEquals("NumberingType should be CHAR_SPECIAL", NumberingType.CHAR_SPECIAL, proValues2[0].Value);
156
		assertEquals("BulletChar should be"+m_expectedBulletChar, m_expectedBulletChar, proValues2[4].Value);
157
	}
158
}
(-)testuno/source/testlib/uno/ShapeUtil.java (+28 lines)
Lines 25-30 Link Here
25
25
26
import com.sun.star.uno.Exception;
26
import com.sun.star.uno.Exception;
27
import com.sun.star.uno.UnoRuntime;
27
import com.sun.star.uno.UnoRuntime;
28
import com.sun.star.lang.WrappedTargetException;
28
import com.sun.star.lang.XComponent;
29
import com.sun.star.lang.XComponent;
29
import com.sun.star.lang.XMultiServiceFactory;
30
import com.sun.star.lang.XMultiServiceFactory;
30
31
Lines 33-38 Link Here
33
34
34
import com.sun.star.beans.XPropertySet;
35
import com.sun.star.beans.XPropertySet;
35
36
37
import com.sun.star.container.NoSuchElementException;
36
import com.sun.star.container.XEnumeration;
38
import com.sun.star.container.XEnumeration;
37
import com.sun.star.container.XEnumerationAccess;
39
import com.sun.star.container.XEnumerationAccess;
38
40
Lines 118-124 Link Here
118
				XPropertySet.class, xTextRange);
120
				XPropertySet.class, xTextRange);
119
		return xPropSet;
121
		return xPropSet;
120
	}
122
	}
123
	
124
	/**
125
	 * get a paragraph in a shape. the return value is the PropertySet of the text
126
	 * range that specified by the index
127
	 */
128
	public static XPropertySet getPortion(XShape xShape, int index) throws NoSuchElementException, WrappedTargetException {
129
		XEnumerationAccess m_paraAccess = (XEnumerationAccess)UnoRuntime.queryInterface(XEnumerationAccess.class, xShape);
130
		XEnumeration xParaEnum = m_paraAccess.createEnumeration();	
131
		XPropertySet xPropSet = null;
132
		int i=0;
133
		while(xParaEnum.hasMoreElements())
134
		{
135
			if(i == index)
136
			{
137
				Object aPortionObj = xParaEnum.nextElement();
138
				XTextRange xTextRange = (XTextRange)UnoRuntime.queryInterface(XTextRange.class, aPortionObj);
139
//				System.out.println(xTextRange.getText().getString());
140
				xPropSet = (XPropertySet) UnoRuntime.queryInterface(
141
						XPropertySet.class, xTextRange);
142
				break;				
143
			}
144
			else i++;			
145
		}	
146
		return xPropSet;
147
	}
121
148
149
122
	/**
150
	/**
123
	 * try to get text of a shape
151
	 * try to get text of a shape
124
	 * 
152
	 * 

Return to issue 120631