xref: /aoo42x/main/comphelper/qa/test_weakbag.cxx (revision e92f3138)
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 "gtest/gtest.h"
32 
33 namespace {
34 
35 namespace css = com::sun::star;
36 
37 class Test: public ::testing::Test {
38 public:
39 };
40 
TEST_F(Test,test)41 TEST_F(Test, test) {
42     css::uno::Reference< css::uno::XInterface > ref1(new cppu::OWeakObject);
43     css::uno::Reference< css::uno::XInterface > ref2(new cppu::OWeakObject);
44     css::uno::Reference< css::uno::XInterface > ref3(new cppu::OWeakObject);
45     comphelper::WeakBag< css::uno::XInterface > bag;
46     bag.add(ref1);
47     bag.add(ref1);
48     bag.add(ref2);
49     bag.add(ref2);
50     ref1.clear();
51     bag.add(ref3);
52     ref3.clear();
53     ASSERT_TRUE(bag.remove() == ref2) << "remove first ref2";
54     ASSERT_TRUE(bag.remove() == ref2) << "remove second ref2";
55     ASSERT_TRUE(!bag.remove().is()) << "remove first null";
56     ASSERT_TRUE(!bag.remove().is()) << "remove second null";
57 }
58 
59 
60 }
61 
main(int argc,char ** argv)62 int main(int argc, char **argv)
63 {
64     ::testing::InitGoogleTest(&argc, argv);
65     return RUN_ALL_TESTS();
66 }
67