-
Notifications
You must be signed in to change notification settings - Fork 5.5k
quiche: Implement http2_reconstruct_object_impl.h. #6717
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,10 @@ | |
| #include "quiche/http2/platform/api/http2_macros.h" | ||
| #include "quiche/http2/platform/api/http2_optional.h" | ||
| #include "quiche/http2/platform/api/http2_ptr_util.h" | ||
| #include "quiche/http2/platform/api/http2_reconstruct_object.h" | ||
| #include "quiche/http2/platform/api/http2_string.h" | ||
| #include "quiche/http2/platform/api/http2_string_piece.h" | ||
| #include "quiche/http2/test_tools/http2_random.h" | ||
|
|
||
| // Basic tests to validate functioning of the QUICHE http2 platform | ||
| // implementation. For platform APIs in which the implementation is a simple | ||
|
|
@@ -77,16 +79,30 @@ TEST(Http2PlatformTest, Http2Log) { | |
| HTTP2_DLOG_EVERY_N(ERROR, 2) << "DLOG_EVERY_N(ERROR, 2)"; | ||
| } | ||
|
|
||
| TEST(Http2PlatformTest, Http2MakeUnique) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why adding this test?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not adding this test, I just moved it up to sort the tests by name alphabetically.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, right. It was there. Thanks for doing this! |
||
| auto p = http2::Http2MakeUnique<int>(4); | ||
| EXPECT_EQ(4, *p); | ||
| } | ||
|
|
||
| TEST(Http2PlatformTest, Http2Optional) { | ||
| http2::Http2Optional<int> opt; | ||
| EXPECT_FALSE(opt.has_value()); | ||
| opt = 3; | ||
| EXPECT_TRUE(opt.has_value()); | ||
| } | ||
|
|
||
| TEST(Http2PlatformTest, Http2MakeUnique) { | ||
| auto p = http2::Http2MakeUnique<int>(4); | ||
| EXPECT_EQ(4, *p); | ||
| TEST(Http2PlatformTest, Http2ReconstructObject) { | ||
| http2::test::Http2Random rng; | ||
| std::string s; | ||
|
|
||
| http2::test::Http2ReconstructObject(&s, &rng, "123"); | ||
| EXPECT_EQ("123", s); | ||
|
|
||
| http2::test::Http2ReconstructObject(&s, &rng, "456"); | ||
| EXPECT_EQ("456", s); | ||
|
|
||
| http2::test::Http2DefaultReconstructObject(&s, &rng); | ||
| EXPECT_EQ("", s); | ||
| } | ||
|
|
||
| TEST(Http2PlatformTest, Http2String) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #pragma once | ||
|
|
||
| // NOLINT(namespace-envoy) | ||
|
|
||
| // This file is part of the QUICHE platform implementation, and is not to be | ||
| // consumed or referenced directly by other Envoy code. It serves purely as a | ||
| // porting layer for QUICHE. | ||
|
|
||
| #include <utility> | ||
|
|
||
| namespace http2 { | ||
| namespace test { | ||
|
|
||
| class Http2Random; | ||
|
|
||
| // Reconstruct an object so that it is initialized as when it was first | ||
| // constructed. Runs the destructor to handle objects that might own resources, | ||
| // and runs the constructor with the provided arguments, if any. | ||
| template <class T, class... Args> | ||
| void Http2ReconstructObjectImpl(T* ptr, Http2Random* /*rng*/, Args&&... args) { | ||
| ptr->~T(); | ||
| ::new (ptr) T(std::forward<Args>(args)...); | ||
| } | ||
|
|
||
| // This version applies default-initialization to the object. | ||
| template <class T> void Http2DefaultReconstructObjectImpl(T* ptr, Http2Random* /*rng*/) { | ||
| ptr->~T(); | ||
| ::new (ptr) T; | ||
| } | ||
|
|
||
| } // namespace test | ||
| } // namespace http2 |
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.
This is also added in #6650
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.
Yeah, I copied it from there:) I copied it to the exact same location so it shouldn't cause merge conflicts.