summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2011-04-14 15:29:52 +0200
committerKurt Zenker <kz@openoffice.org>2011-04-14 15:29:52 +0200
commitd937dc8c1151b223e085257238dc1742423bc858 (patch)
tree6a42a2d9a36e9fffe8a0136b503dbe6a6bd1f548
parent80283e1fb7c6d47afb385339dbae708805d74ca0 (diff)
parent2c1329eb2da092247e6ebf2bce192526222576bd (diff)
CWS-TOOLING: integrate CWS fs34b_OOO340
-rwxr-xr-xframework/source/fwe/helper/undomanagerhelper.cxx52
-rwxr-xr-xsfx2/JunitTest_sfx2_complex.mk3
-rwxr-xr-xsfx2/qa/complex/sfx2/DocumentEvents.java206
-rwxr-xr-xsfx2/qa/complex/sfx2/JUnitBasedTest.java55
-rwxr-xr-xsfx2/qa/complex/sfx2/UndoManager.java5
-rw-r--r--sfx2/source/dialog/filedlghelper.cxx14
6 files changed, 308 insertions, 27 deletions
diff --git a/framework/source/fwe/helper/undomanagerhelper.cxx b/framework/source/fwe/helper/undomanagerhelper.cxx
index 891504adbe71..9e3b6c7265e0 100755
--- a/framework/source/fwe/helper/undomanagerhelper.cxx
+++ b/framework/source/fwe/helper/undomanagerhelper.cxx
@@ -220,6 +220,7 @@ namespace framework
bool m_disposed;
bool m_bAPIActionRunning;
bool m_bProcessingEvents;
+ sal_Int32 m_nLockCount;
::cppu::OInterfaceContainerHelper m_aUndoListeners;
::cppu::OInterfaceContainerHelper m_aModifyListeners;
IUndoManagerImplementation& m_rUndoManagerImplementation;
@@ -241,6 +242,7 @@ namespace framework
,m_disposed( false )
,m_bAPIActionRunning( false )
,m_bProcessingEvents( false )
+ ,m_nLockCount( 0 )
,m_aUndoListeners( m_aMutex )
,m_aModifyListeners( m_aMutex )
,m_rUndoManagerImplementation( i_undoManagerImpl )
@@ -290,6 +292,9 @@ namespace framework
void clearRedo( IMutexGuard& i_instanceLock );
void reset( IMutexGuard& i_instanceLock );
+ void lock();
+ void unlock();
+
void addUndoManagerListener( const Reference< XUndoManagerListener >& i_listener )
{
m_aUndoListeners.addInterface( i_listener );
@@ -480,6 +485,37 @@ namespace framework
}
//------------------------------------------------------------------------------------------------------------------
+ void UndoManagerHelper_Impl::lock()
+ {
+ // SYNCHRONIZED --->
+ ::osl::MutexGuard aGuard( getMutex() );
+
+ if ( ++m_nLockCount == 1 )
+ {
+ IUndoManager& rUndoManager = getUndoManager();
+ rUndoManager.EnableUndo( false );
+ }
+ // <--- SYNCHRONIZED
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
+ void UndoManagerHelper_Impl::unlock()
+ {
+ // SYNCHRONIZED --->
+ ::osl::MutexGuard aGuard( getMutex() );
+
+ if ( m_nLockCount == 0 )
+ throw NotLockedException( ::rtl::OUString::createFromAscii( "Undo manager is not locked" ), getXUndoManager() );
+
+ if ( --m_nLockCount == 0 )
+ {
+ IUndoManager& rUndoManager = getUndoManager();
+ rUndoManager.EnableUndo( true );
+ }
+ // <--- SYNCHRONIZED
+ }
+
+ //------------------------------------------------------------------------------------------------------------------
void UndoManagerHelper_Impl::impl_processRequest( ::boost::function0< void > const& i_request, IMutexGuard& i_instanceLock )
{
// create the request, and add it to our queue
@@ -1100,25 +1136,13 @@ namespace framework
//------------------------------------------------------------------------------------------------------------------
void UndoManagerHelper::lock()
{
- // SYNCHRONIZED --->
- ::osl::MutexGuard aGuard( m_pImpl->getMutex() );
-
- IUndoManager& rUndoManager = m_pImpl->getUndoManager();
- rUndoManager.EnableUndo( false );
- // <--- SYNCHRONIZED
+ m_pImpl->lock();
}
//------------------------------------------------------------------------------------------------------------------
void UndoManagerHelper::unlock()
{
- // SYNCHRONIZED --->
- ::osl::MutexGuard aGuard( m_pImpl->getMutex() );
-
- IUndoManager& rUndoManager = m_pImpl->getUndoManager();
- if ( rUndoManager.IsUndoEnabled() )
- throw NotLockedException( ::rtl::OUString::createFromAscii( "Undo manager is not locked" ), m_pImpl->getXUndoManager() );
- rUndoManager.EnableUndo( true );
- // <--- SYNCHRONIZED
+ m_pImpl->unlock();
}
//------------------------------------------------------------------------------------------------------------------
diff --git a/sfx2/JunitTest_sfx2_complex.mk b/sfx2/JunitTest_sfx2_complex.mk
index 800612a6c55d..eac148a112d9 100755
--- a/sfx2/JunitTest_sfx2_complex.mk
+++ b/sfx2/JunitTest_sfx2_complex.mk
@@ -51,6 +51,8 @@ $(eval $(call gb_JunitTest_add_sourcefiles,sfx2_complex,\
sfx2/qa/complex/sfx2/DocumentInfo \
sfx2/qa/complex/sfx2/StandaloneDocumentInfo \
sfx2/qa/complex/sfx2/UndoManager \
+ sfx2/qa/complex/sfx2/JUnitBasedTest \
+ sfx2/qa/complex/sfx2/DocumentEvents \
sfx2/qa/complex/sfx2/standalonedocinfo/StandaloneDocumentInfoTest \
sfx2/qa/complex/sfx2/standalonedocinfo/TestHelper \
sfx2/qa/complex/sfx2/standalonedocinfo/Test01 \
@@ -69,6 +71,7 @@ $(eval $(call gb_JunitTest_add_classes,sfx2_complex,\
complex.sfx2.DocumentProperties \
complex.sfx2.DocumentMetadataAccess \
complex.sfx2.UndoManager \
+ complex.sfx2.DocumentEvents \
))
# #i115674# fails currently: misses some OnUnfocus event
# complex.sfx2.GlobalEventBroadcaster \
diff --git a/sfx2/qa/complex/sfx2/DocumentEvents.java b/sfx2/qa/complex/sfx2/DocumentEvents.java
new file mode 100755
index 000000000000..a38e13756551
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/DocumentEvents.java
@@ -0,0 +1,206 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package complex.sfx2;
+
+import com.sun.star.document.DocumentEvent;
+import com.sun.star.document.XDocumentEventBroadcaster;
+import com.sun.star.document.XDocumentEventListener;
+import com.sun.star.lang.EventObject;
+import com.sun.star.lang.XEventListener;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.util.CloseVetoException;
+import com.sun.star.util.XCloseListener;
+import com.sun.star.util.XCloseable;
+import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.openoffice.test.tools.OfficeDocument;
+
+/**
+ *
+ * @author frank.shoenheit@oracle.com
+ */
+public class DocumentEvents extends JUnitBasedTest
+{
+ @Before
+ public void beforeTest() throws Exception
+ {
+ m_document = OfficeDocument.blankTextDocument( this.getORB() );
+ }
+
+ @After
+ public void afterTest()
+ {
+ if ( m_document != null )
+ {
+ assertTrue( "closing the test document failed", m_document.close() );
+ m_document = null;
+ }
+ }
+
+ /**
+ * sets up the environment for a test which checks the behavior upon closing a doc
+ */
+ private void impl_setupDocCloseTest()
+ {
+ m_observedCloseEvents.clear();
+
+ final XDocumentEventBroadcaster docEventBroadcaster = UnoRuntime.queryInterface(
+ XDocumentEventBroadcaster.class, m_document.getDocument() );
+ docEventBroadcaster.addDocumentEventListener( new DocumentEventListener() );
+
+ final XCloseable docCloseable = UnoRuntime.queryInterface( XCloseable.class,
+ m_document.getDocument() );
+ docCloseable.addCloseListener( new CloseListener() );
+
+ m_document.getDocument().addEventListener( new DocDisposeListener() );
+ }
+
+ /**
+ * sets up the environment for a test which checks the behavior upon closing a doc
+ */
+ private void impl_tearDownDocCloseTest( final String i_docCloseMethod )
+ {
+ synchronized( m_document )
+ {
+ try
+ {
+ m_document.wait(10000);
+ }
+ catch (InterruptedException ex)
+ {
+ // don't continue the test if somebody interrupted us ...
+ return;
+ }
+ }
+
+ m_document = null;
+ synchronized( m_observedCloseEvents )
+ {
+ assertArrayEquals(
+ "wrong order of events when closing a doc " + i_docCloseMethod,
+ new CloseEventType[] { CloseEventType.OnUnload, CloseEventType.NotifyClosing, CloseEventType.Disposing },
+ m_observedCloseEvents.toArray( new CloseEventType[0] )
+ );
+ }
+ }
+
+ @Test
+ public void testCloseWinEvents() throws Exception
+ {
+ impl_setupDocCloseTest();
+ m_document.getCurrentView().dispatch( ".uno:CloseWin" );
+ impl_tearDownDocCloseTest( "via .uno:CloseWin" );
+ }
+
+ //@Test
+ public void testCloseDocEvents() throws Exception
+ {
+ impl_setupDocCloseTest();
+ m_document.getCurrentView().dispatch( ".uno:CloseDoc" );
+ impl_tearDownDocCloseTest( "via .uno:CloseDoc" );
+ }
+
+ //@Test
+ public void testCloseByAPI() throws Exception
+ {
+ impl_setupDocCloseTest();
+ // closing the doc by API is synchronous, so do this in a separate thread, else we will get a deadlock
+ // when the document tries to call back our listener (well, I admit I didn't understand *why* we get this
+ // deadlock ... :-\ )
+ (new DocCloser()).start();
+ impl_tearDownDocCloseTest( "by API" );
+ }
+
+ private class DocumentEventListener implements XDocumentEventListener
+ {
+
+ public void documentEventOccured( DocumentEvent i_documentEvent )
+ {
+ if ( i_documentEvent.EventName.equals( "OnUnload" ) )
+ {
+ synchronized( m_observedCloseEvents )
+ {
+ m_observedCloseEvents.add( CloseEventType.OnUnload );
+ }
+ }
+ }
+
+ public void disposing(EventObject eo)
+ {
+ // not interested in
+ }
+ };
+
+ private class CloseListener implements XCloseListener
+ {
+
+ public void queryClosing(EventObject eo, boolean bln) throws CloseVetoException
+ {
+ // not interested in
+ }
+
+ public void notifyClosing(EventObject eo)
+ {
+ synchronized( m_observedCloseEvents )
+ {
+ m_observedCloseEvents.add( CloseEventType.NotifyClosing );
+ }
+ }
+
+ public void disposing(EventObject eo)
+ {
+ // not interested in
+ }
+ };
+
+ private class DocDisposeListener implements XEventListener
+ {
+ public void disposing(EventObject eo)
+ {
+ synchronized( m_observedCloseEvents )
+ {
+ m_observedCloseEvents.add( CloseEventType.Disposing );
+ }
+ synchronized ( m_document )
+ {
+ m_document.notifyAll();
+ }
+ }
+ };
+
+ private class DocCloser extends Thread
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ final XCloseable docCloseable = UnoRuntime.queryInterface(XCloseable.class, m_document.getDocument());
+ docCloseable.close(true);
+ }
+ catch (CloseVetoException ex)
+ {
+ Logger.getLogger(DocumentEvents.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ };
+
+ private enum CloseEventType
+ {
+ OnUnload,
+ NotifyClosing,
+ Disposing
+ };
+
+ private OfficeDocument m_document = null;
+ final private Vector< CloseEventType > m_observedCloseEvents = new Vector<DocumentEvents.CloseEventType>();
+}
diff --git a/sfx2/qa/complex/sfx2/JUnitBasedTest.java b/sfx2/qa/complex/sfx2/JUnitBasedTest.java
new file mode 100755
index 000000000000..a43493712c31
--- /dev/null
+++ b/sfx2/qa/complex/sfx2/JUnitBasedTest.java
@@ -0,0 +1,55 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package complex.sfx2;
+
+import org.openoffice.test.OfficeConnection;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.XComponentContext;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ *
+ * @author Frank
+ */
+public class JUnitBasedTest
+{
+ // -----------------------------------------------------------------------------------------------------------------
+ protected XComponentContext getContext()
+ {
+ return m_connection.getComponentContext();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ protected XMultiServiceFactory getORB()
+ {
+ final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, getContext().getServiceManager() );
+ return xMSF1;
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @BeforeClass
+ public static void setUpConnection() throws Exception
+ {
+ System.out.println( "--------------------------------------------------------------------------------" );
+ System.out.println( "connecting ..." );
+ m_connection.setUp();
+ }
+
+ // -----------------------------------------------------------------------------------------------------------------
+ @AfterClass
+ public static void tearDownConnection() throws InterruptedException, com.sun.star.uno.Exception
+ {
+ System.out.println();
+ System.out.println( "tearing down connection" );
+ m_connection.tearDown();
+ System.out.println( "--------------------------------------------------------------------------------" );
+ }
+
+ private static final OfficeConnection m_connection = new OfficeConnection();
+}
diff --git a/sfx2/qa/complex/sfx2/UndoManager.java b/sfx2/qa/complex/sfx2/UndoManager.java
index f37530aba726..a50cff82a4bf 100755
--- a/sfx2/qa/complex/sfx2/UndoManager.java
+++ b/sfx2/qa/complex/sfx2/UndoManager.java
@@ -159,7 +159,7 @@ public class UndoManager
}
// -----------------------------------------------------------------------------------------------------------------
-//#i116813# disabled @Test
+ @Test
public void checkBrokenScripts() throws com.sun.star.uno.Exception, InterruptedException
{
System.out.println( "testing: broken scripts" );
@@ -221,12 +221,11 @@ public class UndoManager
events.replaceByName( "OnViewCreated", scriptDescriptor );
// The below doesn't work: event notification is broken in m96, see http://www.openoffice.org/issues/show_bug.cgi?id=116313
-/* m_callbackCalled = false;
+ m_callbackCalled = false;
m_currentDocument.getCurrentView().dispatch( ".uno:NewWindow" );
assertTrue( "triggering an event did not work as expected - basic script not called", m_callbackCalled );
// same as above: The script didn't close the context, but the OOo framework should have
assertEquals( "undo context was not auto-closed as expected", 0, m_undoListener.getCurrentUndoContextDepth() );
- */
// .............................................................................................................
// scenario 4: let the script enter an Undo context, but not close it, as usual.
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index eb6373b5b998..10ccee0cb641 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -2195,19 +2195,13 @@ void FileDialogHelper_Impl::loadConfig()
{
// respect the last "insert as link" state
sal_Bool bLink = (sal_Bool) aUserData.GetToken( 0, ' ' ).ToInt32();
- if ( !xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0 ).hasValue() )
- {
- aValue <<= bLink;
- xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, aValue );
- }
+ aValue <<= bLink;
+ xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, aValue );
// respect the last "show preview" state
sal_Bool bShowPreview = (sal_Bool) aUserData.GetToken( 1, ' ' ).ToInt32();
- if ( !xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 ).hasValue() )
- {
- aValue <<= bShowPreview;
- xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, aValue );
- }
+ aValue <<= bShowPreview;
+ xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, aValue );
if ( !maPath.getLength() )
displayFolder( getInitPath( aUserData, 2 ) );