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="util_XSearchable" 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'*************************************************************************
32' This Interface/Service test depends on the following GLOBAL variables,
33' which must be specified in the object creation:
34
35'     - Global cStringToSearch As String
36'	 should appears more than once
37'     - Global nSearchedEntriesAmount As Integer
38
39'*************************************************************************
40
41
42
43
44
45Sub RunTest()
46
47'*************************************************************************
48' INTERFACE:
49' com.sun.star.util.XSearchable
50'*************************************************************************
51On Error Goto ErrHndl
52    Dim bOK As Boolean
53
54    Dim oMatch As Object
55    Dim oAllMatch As Object
56    Dim oSearchDescriptor As Object
57    Dim nCount As Long
58
59    Test.StartMethod("createSearchDescriptor()")
60    bOK = true
61    oSearchDescriptor = oObj.createSearchDescriptor()
62    bOK = bOK AND NOT isNULL(oSearchDescriptor)
63    bOK = bOK AND hasUnoInterfaces(oSearchDescriptor, "com.sun.star.util.XSearchDescriptor")
64    Test.MethodTested("createSearchDescriptor()", bOK)
65
66    Out.Log("Setting values to search descriptor")
67    oSearchDescriptor.SearchString = cStringToSearch
68    oSearchDescriptor.SearchWords = false
69    oSearchDescriptor.SearchCaseSensitive = true
70
71    Test.StartMethod("findAll()")
72    bOK = true
73    oAllMatch = oObj.findAll(oSearchDescriptor)
74    bOK = bOK AND hasUnoInterfaces(oAllMatch, "com.sun.star.container.XIndexAccess")
75    for i = 0 to oAllMatch.count - 1
76        bOK = bOK AND oAllMatch.getByIndex(i).String = cStringToSearch
77    next i
78    bOK = bOK AND oAllMatch.count = nSearchedEntriesAmount
79    Test.MethodTested("findAll()", bOK)
80
81    Test.StartMethod("findFirst()")
82    bOK = true
83    oMatch = oObj.findFirst(oSearchDescriptor)
84    bOK = bOK AND oMatch.String = cStringToSearch
85    Test.MethodTested("findFirst()", bOK)
86
87    Test.StartMethod("findNext()")
88    bOK = true
89    nCount = 0
90
91    While NOT isNULL(oMatch)
92        nCount = nCount + 1
93        bOK = bOK AND oMatch.String = cStringToSearch
94        oMatch = oObj.findNext(oMatch.end, oSearchDescriptor)
95    wend
96
97    bOK = bOK AND nSearchedEntriesAmount = nCount
98    Test.MethodTested("findNext()", bOK)
99
100Exit Sub
101ErrHndl:
102    Test.Exception()
103    bOK = false
104    resume next
105End Sub
106</script:module>
107