diff options
author | Murray Cumming <murrayc@murrayc.com> | 2016-12-11 20:57:37 +0100 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2017-04-07 11:03:50 +0200 |
commit | 650453a800e6c3ad0c934ce2675298a7d90cc6b8 (patch) | |
tree | 4f153fa22af19dfb08f5af3899f6b0115228b3f9 /tests/giomm_listmodel | |
parent | ff390b28885f8fdea3bb8094570d943640519d64 (diff) | |
download | glibmm-650453a800e6c3ad0c934ce2675298a7d90cc6b8.tar.gz |
Remove Glib::WeakRef
Now that RefPtr is really a std::shared_ptr<>, we should use
std::weak_ref<> instead.
Note that a std::weak_ptr<> tells you nothing about whether
the underlying GObject is still alive, which Glib::RefPtr did.
It just tells you whether our std::shared_ptr<> still holds
a reference to it. That's why I removed one of the checks in
tests/giomm_listmodel/main.cc.
Diffstat (limited to 'tests/giomm_listmodel')
-rw-r--r-- | tests/giomm_listmodel/main.cc | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/tests/giomm_listmodel/main.cc b/tests/giomm_listmodel/main.cc index cd8667da..1024a05e 100644 --- a/tests/giomm_listmodel/main.cc +++ b/tests/giomm_listmodel/main.cc @@ -39,7 +39,7 @@ void test_store_boundaries() { auto store = Gio::ListStore<Gio::MenuItem>::create(); auto item = Gio::MenuItem::create("", ""); - auto weakref_item = Glib::WeakRef<Gio::MenuItem>(item); + std::weak_ptr<Gio::MenuItem> weakref_item = item; // Remove an item from an empty list. store->remove(0); @@ -84,7 +84,7 @@ void test_store_boundaries() store.reset(); item.reset(); - if (weakref_item) + if (weakref_item.lock()) { result = EXIT_FAILURE; std::cerr << "test_store_boundaries(), 10: weakref_item is not null" << std::endl; @@ -116,16 +116,16 @@ void test_store_refcounts() const std::size_t n_items = 10; std::vector<Glib::RefPtr<Gio::MenuItem>> items; - std::vector<Glib::WeakRef<Gio::MenuItem>> weakref_items; + std::vector<std::weak_ptr<Gio::MenuItem>> weakref_items; for (std::size_t i = 0; i < n_items; ++i) { items.push_back(Gio::MenuItem::create("", "")); - weakref_items.push_back(Glib::WeakRef<Gio::MenuItem>(items[i])); + weakref_items.emplace_back(items[i]); store->append(items[i]); } check_store_refcounts_n_items(2, store, n_items); - if (store->get_item(3).operator->() != items[3].operator->()) + if (store->get_item(3).get() != items[3].get()) { result = EXIT_FAILURE; std::cerr << "test_store_refcounts(), 3: get_item(3) != items[3]" << std::endl; @@ -134,25 +134,15 @@ void test_store_refcounts() for (std::size_t i = 0; i < n_items; ++i) { items[i].reset(); - if (!weakref_items[i]) - { - result = EXIT_FAILURE; - std::cerr << "test_store_refcounts(), 4: weakref_items[" << i << "] is null" << std::endl; - } } store->remove(4); - if (weakref_items[4]) - { - result = EXIT_FAILURE; - std::cerr << "test_store_refcounts(), 5: weakref_items[4] is not null" << std::endl; - } check_store_refcounts_n_items(6, store, n_items-1); store.reset(); for (std::size_t i = 0; i < n_items; ++i) { - if (weakref_items[i]) + if (weakref_items[i].lock()) { result = EXIT_FAILURE; std::cerr << "test_store_refcounts(), 7: weakref_items[" << i << "] is not null" << std::endl; @@ -228,7 +218,7 @@ void test_store_sorted1() result = EXIT_FAILURE; std::cerr << "test_store_sorted1(), 2: i=" << i << ", items are not equal" << std::endl; } - if (a.operator->() == b.operator->()) + if (a.get() == b.get()) { result = EXIT_FAILURE; std::cerr << "test_store_sorted1(), 3: i=" << i << ", items are the same" << std::endl; @@ -237,7 +227,7 @@ void test_store_sorted1() if (i > 0) { auto c = store->get_item(i * 2 - 1); - if (c.operator->() == a.operator->() || c.operator->() == b.operator->()) + if (c.get() == a.get() || c.get() == b.get()) { result = EXIT_FAILURE; std::cerr << "test_store_sorted1(), 4: i=" << i << ", items are the same" << std::endl; @@ -311,7 +301,7 @@ void test_store_sorted2() result = EXIT_FAILURE; std::cerr << "test_store_sorted2(), 2: i=" << i << ", items are not equal" << std::endl; } - if (a.operator->() == b.operator->()) + if (a.get() == b.get()) { result = EXIT_FAILURE; std::cerr << "test_store_sorted2(), 3: i=" << i << ", items are the same" << std::endl; @@ -320,7 +310,7 @@ void test_store_sorted2() if (i > 0) { auto c = store->get_item(i * 2 - 1); - if (c.operator->() == a.operator->() || c.operator->() == b.operator->()) + if (c.get() == a.get() || c.get() == b.get()) { result = EXIT_FAILURE; std::cerr << "test_store_sorted2(), 4: i=" << i << ", items are the same" << std::endl; |