SheetBasicTest.java (b554e61d) SheetBasicTest.java (916729d0)
1/* Licensed to the Apache Software Foundation (ASF) under one
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
2 * or more contributor license agreements. See the NOTICE file
3 * distributed with this work for additional information
4 * regarding copyright ownership. The ASF licenses this file
5 * to you under the Apache License, Version 2.0 (the
6 * "License"); you may not use this file except in compliance
7 * with the License. You may obtain a copy of the License at
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
8 *
10 *
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * http://www.apache.org/licenses/LICENSE-2.0
10 *
12 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
17 *
19 *
18 *************************************************************/
19
20package fvt.uno.sc.sheet;
21
22import static org.junit.Assert.*;
23import org.junit.After;
24import org.junit.AfterClass;
25import org.junit.Before;

--- 55 unchanged lines hidden (view full) ---

81 XSpreadsheets spreadsheets = scDocument.getSheets();
82 spreadsheets.insertNewByName(sheetname, (short) 1);
83
84 // active the sheet second sheet aa
85 XSpreadsheet newSpreadSheet = SCUtil.getSCSheetByIndex(scDocument,
86 (short) 1);
87 SCUtil.setCurrentSheet(scDocument, newSpreadSheet);
88
20 *************************************************************/
21
22package fvt.uno.sc.sheet;
23
24import static org.junit.Assert.*;
25import org.junit.After;
26import org.junit.AfterClass;
27import org.junit.Before;

--- 55 unchanged lines hidden (view full) ---

83 XSpreadsheets spreadsheets = scDocument.getSheets();
84 spreadsheets.insertNewByName(sheetname, (short) 1);
85
86 // active the sheet second sheet aa
87 XSpreadsheet newSpreadSheet = SCUtil.getSCSheetByIndex(scDocument,
88 (short) 1);
89 SCUtil.setCurrentSheet(scDocument, newSpreadSheet);
90
89 // get the new speadsheet name
91 // get the new spreadsheet name
90 assertEquals("actual should equals aa", sheetname,
91 SCUtil.getSCSheetNameByIndex(scDocument, (short) 1));
92
93 // Change the Spreadsheet name
94 String changedname = "SpeadsheetAfterChange";
95 SCUtil.setSCSheetNameByIndex(scDocument, (short) 1, changedname);
96
97 // Save and reload document

--- 12 unchanged lines hidden (view full) ---

110 scDocument.getSheets().removeByName(changedname);
111
112 assertFalse("actual should equals false",
113 spreadsheets.hasByName(changedname));
114 SCUtil.save(scDocumentTemp);
115 }
116
117 /**
92 assertEquals("actual should equals aa", sheetname,
93 SCUtil.getSCSheetNameByIndex(scDocument, (short) 1));
94
95 // Change the Spreadsheet name
96 String changedname = "SpeadsheetAfterChange";
97 SCUtil.setSCSheetNameByIndex(scDocument, (short) 1, changedname);
98
99 // Save and reload document

--- 12 unchanged lines hidden (view full) ---

112 scDocument.getSheets().removeByName(changedname);
113
114 assertFalse("actual should equals false",
115 spreadsheets.hasByName(changedname));
116 SCUtil.save(scDocumentTemp);
117 }
118
119 /**
118 * Test copy and past sheet
120 * Test copy and paste sheet
119 */
120 @Test
121 public void copypastesheet() throws Exception {
122 // Insert some value into cells
123 scDocument = SCUtil.getSCDocument(scComponent);
124 String souceSheetName = "sourcesheet";
125 SCUtil.setSCSheetNameByIndex(scDocument, (short) 0, souceSheetName);
126 String[][] stringValues = { { "", "Jan", "Feb", "Mar", "Apr", "Mai" },

--- 163 unchanged lines hidden (view full) ---

290
291 // Get first sheet color
292 sheet1PropertySet = (XPropertySet) UnoRuntime.queryInterface(
293 XPropertySet.class,
294 SCUtil.getSCSheetByIndex(scDocument, (short) 0));
295 int firstSheetcolorid = (Integer) sheet1PropertySet
296 .getPropertyValue("TabColor");
297
121 */
122 @Test
123 public void copypastesheet() throws Exception {
124 // Insert some value into cells
125 scDocument = SCUtil.getSCDocument(scComponent);
126 String souceSheetName = "sourcesheet";
127 SCUtil.setSCSheetNameByIndex(scDocument, (short) 0, souceSheetName);
128 String[][] stringValues = { { "", "Jan", "Feb", "Mar", "Apr", "Mai" },

--- 163 unchanged lines hidden (view full) ---

292
293 // Get first sheet color
294 sheet1PropertySet = (XPropertySet) UnoRuntime.queryInterface(
295 XPropertySet.class,
296 SCUtil.getSCSheetByIndex(scDocument, (short) 0));
297 int firstSheetcolorid = (Integer) sheet1PropertySet
298 .getPropertyValue("TabColor");
299
298 // Get the copyed sheet color
300 // Get the copied sheet color
299 XPropertySet newsheetPropertySet = (XPropertySet) UnoRuntime
300 .queryInterface(XPropertySet.class,
301 SCUtil.getSCSheetByIndex(scDocument, (short) 3));
302 int copySheetcolorid = (Integer) newsheetPropertySet
303 .getPropertyValue("TabColor");
304
305 // Verify first sheet color changed successfully
306 assertEquals("Expect color should be 111", 111, firstSheetcolorid);

--- 104 unchanged lines hidden (view full) ---

411 SCUtil.getTextFromCell(secondexternalsheet, 1, 2));
412
413 // Verify thirdexternalsheet
414 assertEquals("Expect formula should be blank", "",
415 SCUtil.getFormulaFromCell(thirdexternalsheet, 1, 2));
416 assertEquals("Expect formula result should be blank", "",
417 SCUtil.getTextFromCell(thirdexternalsheet, 1, 2));
418
301 XPropertySet newsheetPropertySet = (XPropertySet) UnoRuntime
302 .queryInterface(XPropertySet.class,
303 SCUtil.getSCSheetByIndex(scDocument, (short) 3));
304 int copySheetcolorid = (Integer) newsheetPropertySet
305 .getPropertyValue("TabColor");
306
307 // Verify first sheet color changed successfully
308 assertEquals("Expect color should be 111", 111, firstSheetcolorid);

--- 104 unchanged lines hidden (view full) ---

413 SCUtil.getTextFromCell(secondexternalsheet, 1, 2));
414
415 // Verify thirdexternalsheet
416 assertEquals("Expect formula should be blank", "",
417 SCUtil.getFormulaFromCell(thirdexternalsheet, 1, 2));
418 assertEquals("Expect formula result should be blank", "",
419 SCUtil.getTextFromCell(thirdexternalsheet, 1, 2));
420
419 //save and close document
421 // save and close document
420 SCUtil.save(scDocument);
421 SCUtil.closeFile(scDocument);
422
422 SCUtil.save(scDocument);
423 SCUtil.closeFile(scDocument);
424
423 //Open souce document and change the value in souce document
425 // Open source document and change the value in source document
424 XSpreadsheetDocument sourcescDocument = SCUtil.reloadFile(unoApp,
425 scDocument, "source.xls");
426 firstSheet = SCUtil.getSCSheetByIndex(sourcescDocument, (short) 0);
427 secondSheet = SCUtil.getSCSheetByIndex(sourcescDocument, (short) 1);
428 thirdSheet = SCUtil.getSCSheetByIndex(sourcescDocument, (short) 2);
429 SCUtil.setFormulaToCell(firstSheet, 1, 2, "=3*3");
430 SCUtil.setFormulaToCell(secondSheet, 1, 2, "=3*3");
431 SCUtil.setFormulaToCell(thirdSheet, 1, 2, "=3*3");
432 SCUtil.save(sourcescDocument);
433 SCUtil.closeFile(sourcescDocument);
434
426 XSpreadsheetDocument sourcescDocument = SCUtil.reloadFile(unoApp,
427 scDocument, "source.xls");
428 firstSheet = SCUtil.getSCSheetByIndex(sourcescDocument, (short) 0);
429 secondSheet = SCUtil.getSCSheetByIndex(sourcescDocument, (short) 1);
430 thirdSheet = SCUtil.getSCSheetByIndex(sourcescDocument, (short) 2);
431 SCUtil.setFormulaToCell(firstSheet, 1, 2, "=3*3");
432 SCUtil.setFormulaToCell(secondSheet, 1, 2, "=3*3");
433 SCUtil.setFormulaToCell(thirdSheet, 1, 2, "=3*3");
434 SCUtil.save(sourcescDocument);
435 SCUtil.closeFile(sourcescDocument);
436
435 //Open link document
437 // Open link document
436 tempscDocument = SCUtil.reloadFile(unoApp, scDocument, "linked.ods");
437 scDocument = tempscDocument;
438 spreadsheets = scDocument.getSheets();
439
440 firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 3);
441 secondexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 4);
442 thirdexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 5);
443
438 tempscDocument = SCUtil.reloadFile(unoApp, scDocument, "linked.ods");
439 scDocument = tempscDocument;
440 spreadsheets = scDocument.getSheets();
441
442 firstexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 3);
443 secondexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 4);
444 thirdexternalsheet = SCUtil.getSCSheetByIndex(scDocument, (short) 5);
445
444 //get Object SheetLinks for document
446 // get Object SheetLinks for document
445 XPropertySet sheetpropertyset = (XPropertySet) UnoRuntime
446 .queryInterface(XPropertySet.class, scDocument);
447 Object sheetLinks = sheetpropertyset.getPropertyValue("SheetLinks");
448
449 XIndexAccess xsheetlinks = (XIndexAccess) UnoRuntime.queryInterface(
450 XIndexAccess.class, sheetLinks);
451
447 XPropertySet sheetpropertyset = (XPropertySet) UnoRuntime
448 .queryInterface(XPropertySet.class, scDocument);
449 Object sheetLinks = sheetpropertyset.getPropertyValue("SheetLinks");
450
451 XIndexAccess xsheetlinks = (XIndexAccess) UnoRuntime.queryInterface(
452 XIndexAccess.class, sheetLinks);
453
452 //Refresh all links
454 // Refresh all links
453 for (int i = 0; i < xsheetlinks.getCount(); i++) {
454 Object sheetlink = xsheetlinks.getByIndex(i);
455 XRefreshable xsheetRefreshable = (XRefreshable) UnoRuntime
456 .queryInterface(XRefreshable.class, sheetlink);
457 xsheetRefreshable.refresh();
458 }
459
460 // Verify firstexternalsheet

--- 9 unchanged lines hidden (view full) ---

470 SCUtil.getTextFromCell(secondexternalsheet, 1, 2));
471
472 // Verify thirdexternalsheet
473 assertEquals("Expect formula should be blank", "",
474 SCUtil.getFormulaFromCell(thirdexternalsheet, 1, 2));
475 assertEquals("Expect formula result should be blank", "",
476 SCUtil.getTextFromCell(thirdexternalsheet, 1, 2));
477
455 for (int i = 0; i < xsheetlinks.getCount(); i++) {
456 Object sheetlink = xsheetlinks.getByIndex(i);
457 XRefreshable xsheetRefreshable = (XRefreshable) UnoRuntime
458 .queryInterface(XRefreshable.class, sheetlink);
459 xsheetRefreshable.refresh();
460 }
461
462 // Verify firstexternalsheet

--- 9 unchanged lines hidden (view full) ---

472 SCUtil.getTextFromCell(secondexternalsheet, 1, 2));
473
474 // Verify thirdexternalsheet
475 assertEquals("Expect formula should be blank", "",
476 SCUtil.getFormulaFromCell(thirdexternalsheet, 1, 2));
477 assertEquals("Expect formula result should be blank", "",
478 SCUtil.getTextFromCell(thirdexternalsheet, 1, 2));
479
478 //Save the document before close
480 // Save the document before close
479 SCUtil.save(scDocument);
480
481 }
482
483}
481 SCUtil.save(scDocument);
482
483 }
484
485}