1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_filter.cxx,v $
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"
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
)
47 // const sal_Int32 cSetLen = cSet.getLength();
49 sal_Int32 oldIndex
= 0;
53 while ( opt
.getLength() > 0)
55 // for ( i = 0; i < cSetLen; i++ )
57 index
= opt
.indexOf( _sSeparator
, oldIndex
);
60 optLine
.push_back( opt
.copy( oldIndex
, index
- oldIndex
) );
61 oldIndex
= index
+ _sSeparator
.getLength();
64 else // if (index == -1)
66 optLine
.push_back( opt
.copy( oldIndex
) );
72 // -----------------------------------------------------------------------------
74 StringList
splitNameAtDot(rtl::OString
const& _sName
)
78 // int nLastIndex = 0;
79 while ((nIndex
= _sName
.indexOf(".")) != -1)
87 // -----------------------------------------------------------------------------
89 bool checkFilter(JobList m_aJobFilter, std::string const& _sNodeName, std::string const& _sName)
91 std::string sFilter = m_aJobFilter.m_aJobList.begin();
94 aFilter.push_back("rtl_OUString");
95 aFilter.push_back("ctors");
96 aFilter.push_back("*");
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();
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();
124 while (aFilterIter
!= _aFilter
.end() && aValueIter
!= _aName
.end())
126 rtl::OString sFilter
= *aFilterIter
;
127 rtl::OString sName
= *aValueIter
;
129 if (sFilter
== sName
)
135 else if (sFilter
== "*")
142 // Filter does not match
150 // -----------------------------------------------------------------------------
151 void test_normal_filter()
154 split("rtl_OUString.ctors.*", ".", aFilter
);
158 split("rtl_OUString.ctors.ctor_001", ".", aName
);
161 if (match(aFilter
, aName
))
163 std::cout
<< "Name matches filter." << std::endl
;
167 void test_normal_filter_other_sep()
170 split("rtl_OUString::ctors::*", "::", aFilter
);
174 split("rtl_OUString::ctors::ctor_001", "::", aName
);
177 if (match(aFilter
, aName
))
179 std::cout
<< "Name matches filter." << std::endl
;
186 split("rtl_OUString.*", ".", aFilter
);
190 split("", ".", aName
);
193 if (match(aFilter
, aName
))
195 std::cout
<< "Name matches filter." << std::endl
;
199 void test_name_longer_filter()
202 split("rtl_OUString.*", ".", aFilter
);
206 split("rtl_OUString.ctor.ctor_001", ".", 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 */ [] )
219 int _cdecl
main( int /* argc */, char* /* argv */ [] )
222 test_normal_filter();
223 test_normal_filter_other_sep();
225 test_name_longer_filter();
227 // split("rtl_OUString.*", ".", aFilter);
228 // showList(aFilter);