-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
365b0ab
commit c509fec
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* (C) Copyright 1996- ECMWF. | ||
* | ||
* This software is licensed under the terms of the Apache Licence Version 2.0 | ||
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
* In applying this licence, ECMWF does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an intergovernmental organisation nor | ||
* does it submit to any jurisdiction. | ||
*/ | ||
|
||
#include "fdb5/database/FieldLocation.h" | ||
|
||
#include "eckit/filesystem/URI.h" | ||
#include "eckit/testing/Test.h" | ||
|
||
#include <memory> | ||
|
||
using namespace eckit; | ||
using namespace eckit::testing; | ||
|
||
namespace fdb::test { | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- | ||
|
||
CASE("FieldLocation - shared_ptr") { | ||
URI uri {"dummy_uri"}; | ||
|
||
// GOOD (not best) | ||
{ | ||
auto location = std::shared_ptr<fdb5::FieldLocation>(fdb5::FieldLocationFactory::instance().build("file", uri)); | ||
|
||
auto loc1 = location->sharedPtr(); | ||
EXPECT_EQUAL(loc1.use_count(), 2); | ||
|
||
auto loc2 = location->sharedPtr(); | ||
EXPECT_EQUAL(loc2.use_count(), 3); | ||
|
||
// check that the shared pointers are the same | ||
EXPECT_EQUAL(loc2, loc1); | ||
|
||
{ | ||
auto loc3 = location->sharedPtr(); | ||
EXPECT_EQUAL(loc3.use_count(), 4); | ||
EXPECT_EQUAL(loc3, loc1); | ||
} | ||
|
||
auto loc4 = location->sharedPtr(); | ||
EXPECT_EQUAL(loc4.use_count(), 4); | ||
EXPECT_EQUAL(loc4, loc1); | ||
} | ||
|
||
// BAD: this is a how NOT to use shared_ptr on FieldLocation | ||
{ | ||
auto location = std::unique_ptr<fdb5::FieldLocation>(fdb5::FieldLocationFactory::instance().build("file", uri)); | ||
EXPECT_THROWS_AS(location->sharedPtr(), std::bad_weak_ptr); | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------------------------------- | ||
|
||
} // namespace fdb::test | ||
|
||
int main(int argc, char** argv) { | ||
return run_tests(argc, argv); | ||
} |