update dev300-m58
[ooovba.git] / testshl2 / workben / test_filter.cxx
blob74923a5cbbbcb9fe56d2bf30322d79d62fb97c2e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_filter.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_testshl2.hxx"
34 #include <vector>
35 #include <string>
36 #include <iostream>
37 #include <rtl/string.hxx>
39 typedef std::vector<std::string> StringList;
40 typedef std::vector<rtl::OString> OStringList;
42 void split( const rtl::OString& opt,
43 const rtl::OString& _sSeparator,
44 OStringList& optLine )
46 optLine.clear();
47 // const sal_Int32 cSetLen = cSet.getLength();
48 sal_Int32 index = 0;
49 sal_Int32 oldIndex = 0;
51 // sal_Int32 i;
52 // sal_Int32 j = 0;
53 while ( opt.getLength() > 0)
55 // for ( i = 0; i < cSetLen; i++ )
56 // {
57 index = opt.indexOf( _sSeparator, oldIndex);
58 if( index != -1 )
60 optLine.push_back( opt.copy( oldIndex, index - oldIndex ) );
61 oldIndex = index + _sSeparator.getLength();
63 // }
64 else // if (index == -1)
66 optLine.push_back( opt.copy( oldIndex ) );
67 break;
70 } ///< split
72 // -----------------------------------------------------------------------------
74 StringList splitNameAtDot(rtl::OString const& _sName)
76 StringList aList;
77 int nIndex = 0;
78 // int nLastIndex = 0;
79 while ((nIndex = _sName.indexOf(".")) != -1)
81 rtl::OString nValue;
84 return aList;
87 // -----------------------------------------------------------------------------
89 bool checkFilter(JobList m_aJobFilter, std::string const& _sNodeName, std::string const& _sName)
91 std::string sFilter = m_aJobFilter.m_aJobList.begin();
93 StringList aFilter;
94 aFilter.push_back("rtl_OUString");
95 aFilter.push_back("ctors");
96 aFilter.push_back("*");
98 StringList aMyName;
99 aMyName.push_back("rtl_OUString");
100 aMyName.push_back("ctors");
101 aMyName.push_back("ctor_001");
106 void showList(OStringList const& _sList)
108 for(OStringList::const_iterator it = _sList.begin();
109 it != _sList.end();
110 ++it)
112 rtl::OString aStr = *it;
113 std::cout << aStr.getStr() << std::endl;
117 bool match(OStringList const& _aFilter, OStringList const& _aName)
119 OStringList::const_iterator aFilterIter = _aFilter.begin();
120 OStringList::const_iterator aValueIter = _aName.begin();
122 bool bMatch = false;
124 while (aFilterIter != _aFilter.end() && aValueIter != _aName.end())
126 rtl::OString sFilter = *aFilterIter;
127 rtl::OString sName = *aValueIter;
129 if (sFilter == sName)
131 bMatch = true;
132 ++aFilterIter;
133 ++aValueIter;
135 else if (sFilter == "*")
137 bMatch = true;
138 break;
140 else
142 // Filter does not match
143 bMatch = false;
144 break;
147 return bMatch;
150 // -----------------------------------------------------------------------------
151 void test_normal_filter()
153 OStringList aFilter;
154 split("rtl_OUString.ctors.*", ".", aFilter);
155 showList(aFilter);
157 OStringList aName;
158 split("rtl_OUString.ctors.ctor_001", ".", aName);
159 showList(aName);
161 if (match(aFilter, aName))
163 std::cout << "Name matches filter." << std::endl;
167 void test_normal_filter_other_sep()
169 OStringList aFilter;
170 split("rtl_OUString::ctors::*", "::", aFilter);
171 showList(aFilter);
173 OStringList aName;
174 split("rtl_OUString::ctors::ctor_001", "::", aName);
175 showList(aName);
177 if (match(aFilter, aName))
179 std::cout << "Name matches filter." << std::endl;
183 void test_no_name()
185 OStringList aFilter;
186 split("rtl_OUString.*", ".", aFilter);
187 showList(aFilter);
189 OStringList aName;
190 split("", ".", aName);
191 showList(aName);
193 if (match(aFilter, aName))
195 std::cout << "Name matches filter." << std::endl;
199 void test_name_longer_filter()
201 OStringList aFilter;
202 split("rtl_OUString.*", ".", aFilter);
203 showList(aFilter);
205 OStringList aName;
206 split("rtl_OUString.ctor.ctor_001", ".", aName);
207 showList(aName);
209 if (match(aFilter, aName))
211 std::cout << "Name matches filter." << std::endl;
215 // ----------------------------------- Main -----------------------------------
216 #if (defined UNX) || (defined OS2)
217 int main( int /* argc */ , char* /* argv */ [] )
218 #else
219 int _cdecl main( int /* argc */, char* /* argv */ [] )
220 #endif
222 test_normal_filter();
223 test_normal_filter_other_sep();
224 test_no_name();
225 test_name_longer_filter();
227 // split("rtl_OUString.*", ".", aFilter);
228 // showList(aFilter);
231 // test_autoptr();
232 return 0;