/************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ package ifc.linguistic2; import lib.MultiMethodTest; import com.sun.star.lang.EventObject; import com.sun.star.lang.Locale; import com.sun.star.linguistic2.DictionaryListEvent; import com.sun.star.linguistic2.XDictionary; import com.sun.star.linguistic2.XDictionaryList; import com.sun.star.linguistic2.XDictionaryListEventListener; /** * Testing com.sun.star.linguistic2.XDictionaryList * interface methods: *

* @see com.sun.star.linguistic2.XDictionaryList */ public class _XDictionaryList extends MultiMethodTest { public XDictionaryList oObj = null; public XDictionary addedDic = null; /** * Flag for testing of listeners. */ public boolean listenerCalled = false; /** * Class implements interface XDictionaryListEventListener * for test method addDictionaryListEventListener. * @see com.sun.star.linguistic2.XDictionaryListEventListener */ public class MyDictionaryListEventListener implements XDictionaryListEventListener { public void disposing ( EventObject oEvent ) { log.println("Listener has been disposed"); } public void processDictionaryListEvent( DictionaryListEvent aDicEvent) { listenerCalled = true; } }; XDictionaryListEventListener listener = new MyDictionaryListEventListener(); short count = 0; /** * Test calls the method and checks returned value.

* Has OK status if returned value is greater than zero.

*/ public void _getCount() { count = oObj.getCount(); tRes.tested("getCount()",(count > 0) ); } /** * Test calls the method and checks number of obtained dictionaries * with value that was returned by method getCount.

* Has OK status if values are equal.

* The following method tests are to be completed successfully before : *

*/ public void _getDictionaries() { requiredMethod("getCount()"); XDictionary[] dics = oObj.getDictionaries(); boolean res = (dics.length == count); if (!res) { log.println("Expected: " + oObj.getCount()); log.println("Gained: " + dics.length); } tRes.tested("getDictionaries()", res); } /** * Test calls the method, makes some actions that leads to event * processDictionaryListEvent, removes listener, checks flag * listenerCalled and checks returned value.

* Has OK status if returned value is true and value of flag * listenerCallled is true.

*/ public void _addDictionaryListEventListener() { listenerCalled = false; XDictionary xDic = oObj.createDictionary("ListenDic", new Locale("en","US","WIN"), com.sun.star.linguistic2.DictionaryType.POSITIVE,""); boolean res = oObj.addDictionaryListEventListener(listener, false); oObj.flushEvents(); oObj.addDictionary(xDic); xDic.add("Positiv", false, ""); xDic.setActive(true); oObj.flushEvents(); oObj.removeDictionary(xDic); oObj.removeDictionaryListEventListener(listener); tRes.tested("addDictionaryListEventListener()",listenerCalled && res); } /** * Test calls the method, makes some actions that leads to event * processDictionaryListEvent, checks flag * listenerCalled and checks returned value.

* Has OK status if returned value is false and value of flag * listenerCallled is false.

*/ public void _removeDictionaryListEventListener() { listenerCalled = false; XDictionary xDic = oObj.createDictionary("ListenDic", new Locale("en","US","WIN"), com.sun.star.linguistic2.DictionaryType.POSITIVE,""); oObj.addDictionaryListEventListener(listener,false); oObj.flushEvents(); oObj.addDictionary(xDic); xDic.add("Positiv", false,""); xDic.setActive(true); listenerCalled = false; boolean res = oObj.removeDictionaryListEventListener(listener); oObj.flushEvents(); oObj.removeDictionary(xDic); tRes.tested( "removeDictionaryListEventListener()", listenerCalled == false && res == true ); } /** * Test creates new dictionary, adds the dictionary to list and compares * number of dictionaries after adding with number of dictionaries before.

* Has OK status if number of dictionaries after method call is * greater than number of dictionaries before method call.

*/ public void _addDictionary() { short previous = oObj.getCount(); addedDic = oObj.createDictionary("AddedDic",new Locale("en","US","WIN"), com.sun.star.linguistic2.DictionaryType.POSITIVE,""); addedDic.add("Positiv",false,""); oObj.addDictionary(addedDic); short after = oObj.getCount(); tRes.tested( "addDictionary()", (after > previous) ); } /** * Test calls the method and compares number of dictionaries * before method call and after.

* Has OK status if number of dictionaries before method call is * less than number of dictionaries after method call.

*/ public void _removeDictionary() { short previous = oObj.getCount(); oObj.removeDictionary(addedDic); short after = oObj.getCount(); tRes.tested("removeDictionary()",(after < previous) ); } /** * Test calls the method and checks returned value.

* Has OK status if returned value isn't null.

*/ public void _getDictionaryByName() { XDictionary getting = oObj.getDictionaryByName("NegativDic"); tRes.tested("getDictionaryByName()", getting != null ); } /** * Test calls the method and checks returned value.

* Has OK status if returned value isn't null.

*/ public void _createDictionary() { XDictionary tmpDic = oObj.createDictionary("AddedDic", new Locale("en","US","WIN"), com.sun.star.linguistic2.DictionaryType.POSITIVE,""); tRes.tested("createDictionary()", tmpDic != null ); } /** * Test creates dictionary, adds dictionary list event listener, * begins collect events, makes some actions that leads to event * processDictionaryListEvent, ends collect events, * removes the listener and checks the flag listenerCalled .

* Has OK status if value of the flag is true.

*/ public void _beginCollectEvents() { listenerCalled = false; XDictionary xDic = oObj.createDictionary("ListenDic", new Locale("en","US","WIN"), com.sun.star.linguistic2.DictionaryType.POSITIVE,""); oObj.addDictionaryListEventListener(listener,false); oObj.beginCollectEvents(); oObj.addDictionary(xDic); xDic.add("Positiv",false,""); xDic.setActive(true); oObj.removeDictionary(xDic); oObj.endCollectEvents(); oObj.removeDictionaryListEventListener(listener); tRes.tested("beginCollectEvents()", listenerCalled ); } /** * Test does nothing.

* Has OK status if method * addDictionaryListEventListener() was completed * successfully.

* The following method tests are to be completed successfully before : *

*/ public void _flushEvents() { requiredMethod("addDictionaryListEventListener()"); // if listener adding worked, flushEvents was already used and worked tRes.tested("flushEvents()",true); } /** * Test does nothing.

* Has OK status if method * beginCollectEvents() was completed successfully.

* The following method tests are to be completed successfully before : *

*/ public void _endCollectEvents() { requiredMethod("beginCollectEvents()"); // if beginCollectEvents() worked, endCollectEvents // was already used and worked tRes.tested("endCollectEvents()",true); } } // finish class _XDictionaryList