mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-15 01:08:31 +00:00
issue-33: Add test showing how to invoke move ctor
This commit is contained in:
parent
5804dba959
commit
043c8429d4
2 changed files with 38 additions and 0 deletions
35
tests/test_jwt_object.cc
Normal file
35
tests/test_jwt_object.cc
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "jwt/jwt.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
struct Wrapper
|
||||
{
|
||||
// The std::move here is required to resolve to the move ctor
|
||||
// rather than to the universal reference ctor.
|
||||
Wrapper(jwt::jwt_object&& obj) : object{std::move(obj)} {}
|
||||
jwt::jwt_object object;
|
||||
};
|
||||
|
||||
} // END namespace
|
||||
|
||||
TEST (ObjectTest, MoveConstructor)
|
||||
{
|
||||
using namespace jwt::params;
|
||||
|
||||
jwt::jwt_object obj{algorithm("hs256"), secret("secret")};
|
||||
|
||||
obj.add_claim("iss", "arun.muralidharan");
|
||||
|
||||
auto wrapper = Wrapper{std::move(obj)};
|
||||
|
||||
EXPECT_EQ(wrapper.object.header().algo(), jwt::algorithm::HS256);
|
||||
EXPECT_EQ(wrapper.object.secret(), "secret");
|
||||
EXPECT_TRUE(wrapper.object.payload().has_claim_with_value("iss", "arun.muralidharan"));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue