xref: /aoo41x/main/comphelper/qa/test_weakbag.cxx (revision dde7d3fa)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_comphelper.hxx"
25 #include "sal/config.h"
26 
27 #include "com/sun/star/uno/Reference.hxx"
28 #include "com/sun/star/uno/XInterface.hpp"
29 #include "comphelper/weakbag.hxx"
30 #include "cppuhelper/weak.hxx"
31 #include "testshl/simpleheader.hxx"
32 
33 namespace {
34 
35 namespace css = com::sun::star;
36 
37 class Test: public CppUnit::TestFixture {
38 public:
test()39     void test() {
40         css::uno::Reference< css::uno::XInterface > ref1(new cppu::OWeakObject);
41         css::uno::Reference< css::uno::XInterface > ref2(new cppu::OWeakObject);
42         css::uno::Reference< css::uno::XInterface > ref3(new cppu::OWeakObject);
43         comphelper::WeakBag< css::uno::XInterface > bag;
44         bag.add(ref1);
45         bag.add(ref1);
46         bag.add(ref2);
47         bag.add(ref2);
48         ref1.clear();
49         bag.add(ref3);
50         ref3.clear();
51         CPPUNIT_ASSERT_MESSAGE("remove first ref2", bag.remove() == ref2);
52         CPPUNIT_ASSERT_MESSAGE("remove second ref2", bag.remove() == ref2);
53         CPPUNIT_ASSERT_MESSAGE("remove first null", !bag.remove().is());
54         CPPUNIT_ASSERT_MESSAGE("remove second null", !bag.remove().is());
55     }
56 
57     CPPUNIT_TEST_SUITE(Test);
58     CPPUNIT_TEST(test);
59     CPPUNIT_TEST_SUITE_END();
60 };
61 
62 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests");
63 
64 }
65 
66 NOADDITIONAL;
67