-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#268: Fix deserialization of polymorphic types when base class is specified as a template parameter. #362
Open
thearusable
wants to merge
14
commits into
develop
Choose a base branch
from
268-deserialize-polymorphic-type
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+247
−4
Open
#268: Fix deserialization of polymorphic types when base class is specified as a template parameter. #362
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bba1f26
#268: Add tests for deserialization of the polymorphic types
thearusable 2927fc3
#268: Add support for deserialization when called from the base type
thearusable d1a6d6c
#268: Add comments in the deserializeType method
thearusable de50583
#268: Remove default parameters from Prefixed::unpack method
thearusable 57a77ba
#268: Add prefix validation to protect against requests with invalid …
thearusable 0aab792
#268: Refactor dispatcher to properly deserialize polymorphic types w…
thearusable 468af6a
#268: Add check for type id in virtual serialize tests
thearusable a2e7abe
#268: Add validate parameter to all constructors in Unpacker
thearusable 35e050c
#268: Add check for type id in virtual serialize test
thearusable 7f78f73
#268: Move delete to the bottom of deserializeType function
thearusable 148b93c
#268: Remove the need for the second pass when deserializing a polymo…
thearusable 03df7fa
#268: Remove validate_memory_ member from UnpackerBuffer
thearusable 639fea0
#268: Update license in the test_polymorphic file
thearusable 6fec221
#268: Add check for type ID in tests for polymorphic types
thearusable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,129 @@ | ||
/* | ||
//@HEADER | ||
// ***************************************************************************** | ||
// | ||
// test_polymorphic.cc | ||
// DARMA/magistrate => Serialization Library | ||
// | ||
// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC | ||
// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. | ||
// Government retains certain rights in this software. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are met: | ||
// | ||
// * Redistributions of source code must retain the above copyright notice, | ||
// this list of conditions and the following disclaimer. | ||
// | ||
// * Redistributions in binary form must reproduce the above copyright notice, | ||
// this list of conditions and the following disclaimer in the documentation | ||
// and/or other materials provided with the distribution. | ||
// | ||
// * Neither the name of the copyright holder nor the names of its | ||
// contributors may be used to endorse or promote products derived from this | ||
// software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
// Questions? Contact [email protected] | ||
// | ||
// ***************************************************************************** | ||
//@HEADER | ||
*/ | ||
#include <gtest/gtest.h> | ||
|
||
#include "test_harness.h" | ||
|
||
#include <checkpoint/checkpoint.h> | ||
#include <checkpoint/dispatch/vrt/base.h> | ||
|
||
namespace checkpoint { namespace tests { namespace unit { | ||
|
||
using TestPolymorphic = TestHarness; | ||
|
||
struct Base { | ||
explicit Base() = default; | ||
explicit Base(int val_in): base_val_(val_in) {}; | ||
virtual ~Base() = default; | ||
|
||
checkpoint_virtual_serialize_root() | ||
|
||
int base_val_; | ||
virtual int getVal() { | ||
return base_val_; | ||
} | ||
|
||
template <typename Serializer> | ||
void serialize(Serializer& s) { | ||
s | base_val_; | ||
} | ||
}; | ||
|
||
struct Derived1: public Base { | ||
explicit Derived1() = default; | ||
explicit Derived1(int val_in): Base(0), derived_val_(val_in) {}; | ||
virtual ~Derived1() = default; | ||
|
||
checkpoint_virtual_serialize_derived_from(Base) | ||
|
||
int derived_val_; | ||
int getVal() override { | ||
return derived_val_; | ||
} | ||
|
||
template <typename Serializer> | ||
void serialize(Serializer& s) { | ||
s | derived_val_; | ||
} | ||
}; | ||
|
||
struct Derived2: public Derived1 { | ||
explicit Derived2() = default; | ||
explicit Derived2(int val_in): Derived1(0), derived_val_2_(val_in) {}; | ||
virtual ~Derived2() = default; | ||
|
||
checkpoint_virtual_serialize_derived_from(Derived1) | ||
|
||
int derived_val_2_; | ||
int getVal() override { | ||
return derived_val_2_; | ||
} | ||
|
||
template <typename Serializer> | ||
void serialize(Serializer& s) { | ||
s | derived_val_2_; | ||
} | ||
}; | ||
|
||
template<typename Base, typename Derived> | ||
void testPolymorphicTypes(int val) { | ||
std::unique_ptr<Base> task(new Derived(val)); | ||
auto ret = checkpoint::serialize(*task); | ||
auto out = checkpoint::deserialize<Base>(std::move(ret)); | ||
|
||
EXPECT_TRUE(nullptr != out); | ||
EXPECT_EQ(typeid(*task), typeid(*out)); | ||
EXPECT_TRUE(nullptr != dynamic_cast<Derived*>(out.get())); | ||
EXPECT_EQ(val, out->getVal()); | ||
} | ||
|
||
TEST_F(TestPolymorphic, test_polymorphic_type) { | ||
testPolymorphicTypes<Derived2, Derived2>(5); | ||
testPolymorphicTypes<Derived1, Derived2>(50); | ||
testPolymorphicTypes<Base, Derived2>(500); | ||
testPolymorphicTypes<Derived1, Derived1>(10); | ||
testPolymorphicTypes<Base, Derived1>(100); | ||
testPolymorphicTypes<Base, Base>(1); | ||
} | ||
|
||
}}} // end namespace checkpoint::tests::unit |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should probably include an ID check here to ensure we are getting the right type instead of just checking that it's not null and the output value is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the check for typeid.