1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="linguistic2_XDictionaryList" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31' Be sure that all variables are dimensioned:
32option explicit
33
34Dim bCB1 As Long, bCB2 As Long
35
36
37Sub RunTest()
38
39'*************************************************************************
40' INTERFACE:
41' com.sun.star.linguistic2.XDictionaryList
42'*************************************************************************
43On Error Goto ErrHndl
44    Dim bOK As Boolean
45
46    Dim vGetDics As Variant
47    Dim oNegative As Object
48    Dim vLocale As new com.sun.star.lang.Locale
49    Dim nPrevious As Integer
50    Dim oAddDic As Object
51    Dim oNewDic As Object
52    Dim oListenDic1 As Object
53    Dim oListenDic As Object
54    Dim oListener1 As Object
55    Dim oListener2 As Object
56
57    oListener1 = createUNOListener("CB1_", "com.sun.star.linguistic2.XDictionaryListEventListener")
58    oListener2 = createUNOListener("CB2_", "com.sun.star.linguistic2.XDictionaryListEventListener")
59    bCB1 = 0
60    bCB2 = 0
61    vLocale.Language = "en"
62    vLocale.Country = "US"
63    vLocale.Variant = "WIN"
64
65    Test.StartMethod("getCount()")
66    bOK = true
67    Out.Log("getCouint retunrs " + oObj.getCount())
68    bOK = bOK AND (oObj.getCount() &gt; 0)
69    Test.MethodTested("getCount()", bOK)
70
71    Test.StartMethod("getDictionaries()")
72    bOK = true
73    vGetDics = oObj.getDictionaries()
74    Out.Log("oObj.getDictionaries returned " + (uBound(vGetDics) + 1) + " elements")
75    bOK = bOK AND ((uBound(vGetDics) + 1) = oObj.getCount())
76    Test.MethodTested("getDictionaries()", bOK)
77
78    Test.StartMethod("getDictionaryByName()")
79    bOK = true
80    Out.Log("Try to get 'NegativDic' which should created in ObjCreation()"
81    oNegative = oObj.getDictionaryByName("NegativDic")
82    bOK = bOK AND hasUnoInterfaces(oNegative, "com.sun.star.linguistic2.XDictionary")
83    Test.MethodTested("getDictionaryByName()", bOK)
84
85    Test.StartMethod("createDictionary()")
86    bOK = true
87    oAddDic = oObj.createDictionary("AddedDicBasic", vLocale,_
88                     com.sun.star.linguistic2.DictionaryType.POSITIVE,"")
89    bOK = bOK AND hasUnoInterfaces(oAddDic, "com.sun.star.linguistic2.XDictionary")
90    Test.MethodTested("createDictionary()", bOK)
91
92    Test.StartMethod("addDictionary()")
93    bOK = true
94    nPrevious = oObj.getCount()
95    oObj.addDictionary(oAddDic)
96    Out.Log("Dictionaries before: " + nPrevious + ", after: " + oObj.getCount())
97    bOK = bOK AND ((nPrevious + 1) = oObj.getCount())
98    Test.MethodTested("addDictionary()", bOK)
99
100    Test.StartMethod("removeDictionary()")
101    bOK = true
102    oObj.removeDictionary(oAddDic)
103    bOK = bOK AND (nPrevious = oObj.getCount())
104    Test.MethodTested("removeDictionary()", bOK)
105
106    Test.StartMethod("addDictionaryListEventListener()")
107    Dim bListOK As Boolean
108
109    bOK = true
110    bCB1 = false
111    bCB2 = false
112    oListenDic = oObj.createDictionary("ListenDicBasic", vLocale,_
113                     com.sun.star.linguistic2.DictionaryType.POSITIVE,"")
114    bListOK = oObj.addDictionaryListEventListener(oListener1, false)
115    Out.Log("First listener was added: " + bListOK)
116    bListOK = oObj.addDictionaryListEventListener(oListener2, false)
117    Out.Log("Second listener was added: " + bListOK)
118
119    Test.StartMethod("flushEvents()")
120
121    Out.Log("The level of buffer returned by flushEvents() is " + oObj.flushEvents())
122
123    oObj.addDictionary(oListenDic)
124    oListenDic.setActive(true)
125'    oListenDic.add("AWord", false, "")
126
127    Out.Log("The level of buffer returned by flushEvents() is " + oObj.flushEvents())
128
129    bOK = bOK AND bCB1 AND bCB2
130    oObj.removeDictionary(oListenDic)
131
132    Test.MethodTested("addDictionaryListEventListener()", bOK)
133    Test.MethodTested("flushEvents()", bOK)
134
135    Test.StartMethod("removeDictionaryListEventListener()")
136    bOK = true
137    bCB1 = 0
138    bCB2 = 0
139    oObj.removeDictionaryListEventListener(oListener2)
140    oListenDic1 = oObj.createDictionary("ListenDicBasic1", vLocale,_
141                     com.sun.star.linguistic2.DictionaryType.POSITIVE,"")
142    oObj.flushEvents()
143    oObj.addDictionary(oListenDic)
144    oListenDic.setActive(true)
145    oObj.flushEvents()
146    oObj.removeDictionary(oListenDic)
147    bOK = bOK AND bCB1 AND NOT bCB2
148    Test.MethodTested("removeDictionaryListEventListener()", bOK)
149
150    Test.StartMethod("beginCollectEvents()")
151    bOK = true
152    Dim bufSize1 As Integer, bufSize2 As Integer
153
154    bufSize1 = oObj.beginCollectEvents()
155    bufSize2 = oObj.beginCollectEvents()
156
157    bOK = bOK AND (bufSize2 = bufSize1 + 1)
158    Test.MethodTested("beginCollectEvents()", bOK)
159
160    Test.StartMethod("endCollectEvents()")
161    bufSize1 = oObj.endCollectEvents()
162
163    bOK = bOK AND (bufSize2 = bufSize1 + 1)
164    Test.MethodTested("endCollectEvents()", bOK)
165
166
167Exit Sub
168ErrHndl:
169    Test.Exception()
170    bOK = false
171    resume next
172End Sub
173Sub CB1_processDictionaryListEvent
174    Out.Log("CallBack for Listener1 was called.")
175    bCB1 = bCB1 + 1
176End Sub
177Sub CB1_disposing
178End Sub
179
180Sub CB2_processDictionaryListEvent
181    Out.Log("CallBack for Listener2 was called.")
182    bCB2 = bCB2 + 1
183End Sub
184Sub CB2_disposing
185End Sub
186</script:module>
187