Skip to content

Commit 3f1d5e0

Browse files
committed
reflect_traits_gen_using_allocator_tests
1 parent e0062c7 commit 3f1d5e0

File tree

10 files changed

+315
-240
lines changed

10 files changed

+315
-240
lines changed

examples/src/cbor_typed_array_examples.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void decode_mult_dim_row_major()
7575

7676
void encode_decode_large_typed_array()
7777
{
78-
std::ios_base::fmtflags f( std::cout.flags() );
78+
std::ios_base::fmtflags f( std::cout.flags());
7979

8080
std::vector<float> x(15000000);
8181
for (std::size_t i = 0; i < x.size(); ++i)
@@ -131,7 +131,7 @@ void encode_mult_dim_array()
131131

132132
void encode_half_array()
133133
{
134-
std::ios_base::fmtflags f( std::cout.flags() );
134+
std::ios_base::fmtflags f( std::cout.flags());
135135

136136
std::vector<uint8_t> buffer;
137137

include/jsoncons/json_object.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ namespace jsoncons {
838838
{
839839
auto pos = std::lower_bound(members_.begin(),members_.end(), (*it).key(),
840840
Comp());
841-
if (pos == members_.end() )
841+
if (pos == members_.end())
842842
{
843843
members_.emplace_back(*it);
844844
}
@@ -874,7 +874,7 @@ namespace jsoncons {
874874
pos = std::lower_bound(members_.begin(),members_.end(), (*it).key(),
875875
Comp());
876876
}
877-
if (pos == members_.end() )
877+
if (pos == members_.end())
878878
{
879879
members_.emplace_back(*it);
880880
hint = members_.begin() + (members_.size() - 1);
@@ -904,7 +904,7 @@ namespace jsoncons {
904904
{
905905
auto pos = std::lower_bound(members_.begin(),members_.end(), (*it).key(),
906906
Comp());
907-
if (pos == members_.end() )
907+
if (pos == members_.end())
908908
{
909909
members_.emplace_back(*it);
910910
}
@@ -940,7 +940,7 @@ namespace jsoncons {
940940
pos = std::lower_bound(members_.begin(),members_.end(), (*it).key(),
941941
Comp());
942942
}
943-
if (pos == members_.end() )
943+
if (pos == members_.end())
944944
{
945945
members_.emplace_back(*it);
946946
hint = members_.begin() + (members_.size() - 1);
@@ -1452,7 +1452,7 @@ namespace jsoncons {
14521452
for (; it != end; ++it)
14531453
{
14541454
auto pos = find((*it).key());
1455-
if (pos == members_.end() )
1455+
if (pos == members_.end())
14561456
{
14571457
try_emplace((*it).key(),std::move((*it).value()));
14581458
}
@@ -1517,7 +1517,7 @@ namespace jsoncons {
15171517
for (; it != end; ++it)
15181518
{
15191519
auto pos = find((*it).key());
1520-
if (pos == members_.end() )
1520+
if (pos == members_.end())
15211521
{
15221522
insert_or_assign((*it).key(),std::move((*it).value()));
15231523
}

include/jsoncons/reflect/reflect_traits_gen.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ namespace reflect { \
733733
#define JSONCONS_CTOR_GETTER_TO_JSON(Prefix, P2, P3, Getter, Count) JSONCONS_CTOR_GETTER_TO_JSON_LAST(Prefix, P2, P3, Getter, Count)
734734
#define JSONCONS_CTOR_GETTER_TO_JSON_LAST(Prefix, P2, P3, Getter, Count) \
735735
if ((num_params-Count) < num_mandatory_params2) { \
736-
ajson.try_emplace(json_object_name_members<value_type>::Getter(char_type{}),class_instance.Getter() ); \
736+
ajson.try_emplace(json_object_name_members<value_type>::Getter(char_type{}),class_instance.Getter()); \
737737
} \
738738
else { \
739739
json_traits_helper<Json>::set_optional_json_member(json_object_name_members<value_type>::Getter(char_type{}),class_instance.Getter(), ajson); \
@@ -906,7 +906,7 @@ namespace reflect { \
906906
#define JSONCONS_CTOR_GETTER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) if ((num_params-Count) < num_mandatory_params2) JSONCONS_PP_EXPAND(JSONCONS_PP_CONCAT(JSONCONS_CTOR_GETTER_NAME_TO_JSON_,JSONCONS_NARGS Seq) Seq)
907907
#define JSONCONS_CTOR_GETTER_NAME_TO_JSON_2(Getter, Name) \
908908
{ \
909-
ajson.try_emplace(Name,class_instance.Getter() ); \
909+
ajson.try_emplace(Name,class_instance.Getter()); \
910910
} \
911911
else { \
912912
json_traits_helper<Json>::set_optional_json_member(string_view_type(Name),class_instance.Getter(), ajson); \
@@ -1459,7 +1459,7 @@ else \
14591459

14601460
#define JSONCONS_ALL_GETTER_SETTER_TO_JSON(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_ALL_GETTER_SETTER_TO_JSON_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count)
14611461
#define JSONCONS_ALL_GETTER_SETTER_TO_JSON_LAST(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_ALL_GETTER_SETTER_TO_JSON_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count)
1462-
#define JSONCONS_ALL_GETTER_SETTER_TO_JSON_(Prefix, Getter, Setter, Property, Count) ajson.try_emplace(json_object_name_members<value_type>::Property(char_type{}),class_instance.Getter() );
1462+
#define JSONCONS_ALL_GETTER_SETTER_TO_JSON_(Prefix, Getter, Setter, Property, Count) ajson.try_emplace(json_object_name_members<value_type>::Property(char_type{}),class_instance.Getter());
14631463

14641464
#define JSONCONS_N_GETTER_SETTER_COUNT(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_N_GETTER_SETTER_COUNT_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count)
14651465
#define JSONCONS_N_GETTER_SETTER_COUNT_LAST(Prefix, GetPrefix, SetPrefix, Property, Count) JSONCONS_N_GETTER_SETTER_COUNT_(Prefix, GetPrefix ## Property, SetPrefix ## Property, Property, Count)
@@ -1613,7 +1613,7 @@ namespace reflect { \
16131613
#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON(P1, P2, P3, Seq, Count) JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count)
16141614
#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_LAST(P1, P2, P3, Seq, Count) JSONCONS_PP_EXPAND(JSONCONS_PP_CONCAT(JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_,JSONCONS_NARGS Seq) Seq)
16151615
#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_3(Getter, Setter, Name) \
1616-
ajson.try_emplace(Name,class_instance.Getter() );
1616+
ajson.try_emplace(Name,class_instance.Getter());
16171617
#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_5(Getter, Setter, Name, Mode, Match) JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_7(Getter, Setter, Name, Mode, Match, , )
16181618
#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_6(Getter, Setter, Name, Mode, Match, Into) JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_7(Getter, Setter, Name, Mode, Match, Into, )
16191619
#define JSONCONS_N_GETTER_SETTER_NAME_TO_JSON_7(Getter, Setter, Name, Mode, Match, Into, From) \

include/jsoncons/source.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace jsoncons {
4141
null_buffer& operator=(const null_buffer&) = delete;
4242
null_buffer& operator=(null_buffer&&) = default;
4343

44-
int_type overflow( int_type ch = typename std::basic_streambuf<CharT>::traits_type::eof() ) override
44+
int_type overflow( int_type ch = typename std::basic_streambuf<CharT>::traits_type::eof()) override
4545
{
4646
return ch;
4747
}

include/jsoncons/utility/bigint.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
643643
{
644644
if ( this != &y )
645645
{
646-
resize( y.length() );
646+
resize( y.length());
647647
common_stor_.is_negative_ = y.is_negative();
648648
if ( y.length() > 0 )
649649
{
@@ -657,7 +657,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
657657
{
658658
const uint64_t* y_data = y.data();
659659

660-
if ( is_negative() != y.is_negative() )
660+
if ( is_negative() != y.is_negative())
661661
return *this -= -y;
662662
uint64_t d;
663663
uint64_t carry = 0;
@@ -671,7 +671,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
671671
break;
672672
d = this_data[i] + carry;
673673
carry = d < carry;
674-
if ( i < y.length() )
674+
if ( i < y.length())
675675
{
676676
this_data[i] = d + y_data[i];
677677
if ( this_data[i] < d )
@@ -688,7 +688,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
688688
{
689689
const uint64_t* y_data = y.data();
690690

691-
if ( is_negative() != y.is_negative() )
691+
if ( is_negative() != y.is_negative())
692692
return *this += -y;
693693
if ( (!is_negative() && y > *this) || (is_negative() && y < *this) )
694694
return *this = -(y - *this);
@@ -792,7 +792,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
792792
for ( jA=0; jA < x.length(); jA++ )
793793
{
794794
jB = i - jA;
795-
if ( jB >= 0 && jB < y.length() )
795+
if ( jB >= 0 && jB < y.length())
796796
{
797797
DDproduct( x_data[jA], y_data[jB], hi, lo );
798798
sumLo_old = sumLo;
@@ -858,7 +858,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
858858
basic_bigint& operator>>=(uint64_t k)
859859
{
860860
size_type q = size_type(k / basic_type_bits);
861-
if ( q >= length() )
861+
if ( q >= length())
862862
{
863863
resize( 0 );
864864
return *this;
@@ -917,9 +917,9 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
917917

918918
basic_bigint& operator|=( const basic_bigint<Allocator>& a )
919919
{
920-
if ( length() < a.length() )
920+
if ( length() < a.length())
921921
{
922-
resize( a.length() );
922+
resize( a.length());
923923
}
924924

925925
const uint64_t* qBegin = a.begin();
@@ -938,9 +938,9 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
938938

939939
basic_bigint& operator^=( const basic_bigint<Allocator>& a )
940940
{
941-
if ( length() < a.length() )
941+
if ( length() < a.length())
942942
{
943-
resize( a.length() );
943+
resize( a.length());
944944
}
945945

946946
const uint64_t* qBegin = a.begin();
@@ -961,7 +961,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
961961
{
962962
size_type old_length = length();
963963

964-
resize( (std::min)( length(), a.length() ) );
964+
resize( (std::min)( length(), a.length()) );
965965

966966
const uint64_t* pBegin = begin();
967967
uint64_t* p = end() - 1;
@@ -1129,7 +1129,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
11291129
break;
11301130
}
11311131
}
1132-
while ( v.length() );
1132+
while ( v.length());
11331133
if (is_negative())
11341134
{
11351135
data.push_back('-');
@@ -1375,7 +1375,7 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
13751375

13761376
friend basic_bigint<Allocator> abs( const basic_bigint<Allocator>& a )
13771377
{
1378-
if ( a.is_negative() )
1378+
if ( a.is_negative())
13791379
{
13801380
return -a;
13811381
}
@@ -1432,14 +1432,14 @@ class basic_bigint : protected detail::basic_bigint_base<Allocator>
14321432
{
14331433
const uint64_t* y_data = y.data();
14341434

1435-
if ( is_negative() != y.is_negative() )
1435+
if ( is_negative() != y.is_negative())
14361436
return y.is_negative() - is_negative();
14371437
int code = 0;
14381438
if ( length() == 0 && y.length() == 0 )
14391439
code = 0;
1440-
else if ( length() < y.length() )
1440+
else if ( length() < y.length())
14411441
code = -1;
1442-
else if ( length() > y.length() )
1442+
else if ( length() > y.length())
14431443
code = +1;
14441444
else
14451445
{

include/jsoncons/utility/more_type_traits.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ namespace impl {
747747
<
748748
Container, Element,
749749
typename std::enable_if<has_data<Container>::value>::type>
750-
: std::is_convertible< typename std::remove_pointer<decltype(std::declval<Container>().data() )>::type(*)[], Element(*)[]>
750+
: std::is_convertible< typename std::remove_pointer<decltype(std::declval<Container>().data())>::type(*)[], Element(*)[]>
751751
{};
752752

753753
template <typename T>

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ add_executable(unit_tests
130130
corelib/src/reflect/reflect_traits_gen_functional_tests.cpp
131131
corelib/src/reflect/reflect_traits_gen_limit_tests.cpp
132132
corelib/src/reflect/reflect_traits_gen_tests.cpp
133+
corelib/src/reflect/reflect_traits_gen_using_allocator_tests.cpp
133134
corelib/src/reflect/reflect_traits_name_gen_tests.cpp
134135
corelib/src/scoped_allocator_adaptor_tests.cpp
135136
corelib/src/short_string_tests.cpp

test/corelib/src/reflect/reflect_traits_gen_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ TEST_CASE("JSONCONS_ALL_MEMBER_TRAITS tests")
562562
REQUIRE(j.is<ns::book_all_m>() == true);
563563
REQUIRE(j.is<ns::bool_all_m_a>() == true); // isbn is optional
564564

565-
CHECK(an_author == j["author"].as<std::string>() );
565+
CHECK(an_author == j["author"].as<std::string>());
566566
CHECK(a_title == j["title"].as<std::string>() );
567567
CHECK(Approx(a_price).epsilon(0.001) == j["price"].as<double>() );
568568

@@ -654,7 +654,7 @@ TEST_CASE("JSONCONS_N_MEMBER_TRAITS with optional tests")
654654
REQUIRE(j.is<ns::book_all_m>() == true);
655655
REQUIRE(j.is<ns::bool_all_m_a>() == true); // isbn is optional
656656

657-
CHECK(an_author == j["author"].as<std::string>() );
657+
CHECK(an_author == j["author"].as<std::string>());
658658
CHECK(a_title == j["title"].as<std::string>() );
659659
CHECK(Approx(a_price).epsilon(0.001) == j["price"].as<double>() );
660660
CHECK_FALSE(j.contains("isbn"));
@@ -685,7 +685,7 @@ TEST_CASE("JSONCONS_N_MEMBER_TRAITS with optional tests")
685685
REQUIRE(j.is<ns::book_all_m>() == true);
686686
REQUIRE(j.is<ns::bool_all_m_a>() == true);
687687

688-
CHECK(an_author == j["author"].as<std::string>() );
688+
CHECK(an_author == j["author"].as<std::string>());
689689
CHECK(a_title == j["title"].as<std::string>() );
690690
CHECK(Approx(a_price).epsilon(0.001) == j["price"].as<double>() );
691691
REQUIRE(j.contains("isbn"));
@@ -781,7 +781,7 @@ TEST_CASE("JSONCONS_ALL_CTOR_GETTER_TRAITS tests")
781781

782782
json j(book);
783783

784-
CHECK(an_author == j["author"].as<std::string>() );
784+
CHECK(an_author == j["author"].as<std::string>());
785785
CHECK(a_title == j["title"].as<std::string>() );
786786
CHECK(Approx(a_price).epsilon(0.001) == j["price"].as<double>() );
787787
}
@@ -881,7 +881,7 @@ TEST_CASE("JSONCONS_N_CTOR_GETTER_TRAITS tests")
881881

882882
json j(book);
883883

884-
CHECK(an_author == j["author"].as<std::string>() );
884+
CHECK(an_author == j["author"].as<std::string>());
885885
CHECK(a_title == j["title"].as<std::string>() );
886886
CHECK(Approx(a_price).epsilon(0.001) == j["price"].as<double>() );
887887
CHECK(j["isbn"].as<std::string>() == an_isbn);
@@ -924,7 +924,7 @@ TEST_CASE("JSONCONS_N_CTOR_GETTER_TRAITS tests")
924924

925925
json j = json::parse(buffer);
926926

927-
CHECK(an_author == j["author"].as<std::string>() );
927+
CHECK(an_author == j["author"].as<std::string>());
928928
CHECK(a_title == j["title"].as<std::string>() );
929929
CHECK(Approx(a_price).epsilon(0.001) == j["price"].as<double>() );
930930
CHECK(j["isbn"].as<std::string>() == an_isbn);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2013-2025 Daniel Parker
2+
// Distributed under Boost license
3+
4+
#if defined(_MSC_VER)
5+
#include "windows.h" // test no inadvertant macro expansions
6+
#endif
7+
#include <jsoncons/json.hpp>
8+
#include <jsoncons/json_encoder.hpp>
9+
#include <jsoncons/decode_json.hpp>
10+
#include <jsoncons/encode_json.hpp>
11+
#include <catch/catch.hpp>
12+
#include <sstream>
13+
#include <vector>
14+
#include <utility>
15+
#include <ctime>
16+
#include <cstdint>
17+
18+
using namespace jsoncons;
19+
20+
namespace {
21+
namespace ns {
22+
23+
struct book_all_m
24+
{
25+
std::string author;
26+
std::string title;
27+
double price;
28+
};
29+
30+
} // namespace ns
31+
} // namespace
32+
33+
JSONCONS_ALL_MEMBER_TRAITS(ns::book_all_m,author,title,price)
34+
35+
void test_is_json_type_traits_declared(std::true_type)
36+
{
37+
}
38+
39+
TEST_CASE("JSONCONS_ALL_MEMBER_TRAITS using allocator tests")
40+
{
41+
std::string an_author = "Haruki Murakami";
42+
std::string a_title = "Kafka on the Shore";
43+
double a_price = 25.17;
44+
45+
ns::book_all_m book{an_author, a_title, a_price};
46+
47+
CHECK(is_json_type_traits_declared<ns::book_all_m>::value);
48+
test_is_json_type_traits_declared(is_json_type_traits_declared<ns::book_all_m>());
49+
50+
SECTION("success")
51+
{
52+
std::string s;
53+
54+
encode_json(book, s);
55+
56+
json j = decode_json<json>(s);
57+
58+
REQUIRE(j.is<ns::book_all_m>() == true);
59+
60+
CHECK(an_author == j["author"].as<std::string>());
61+
CHECK(a_title == j["title"].as<std::string>() );
62+
CHECK(Approx(a_price).epsilon(0.001) == j["price"].as<double>() );
63+
64+
json j2(book);
65+
66+
CHECK(j == j2);
67+
68+
ns::book_all_m val = j.as<ns::book_all_m>();
69+
70+
CHECK(val.author == book.author);
71+
CHECK(val.title == book.title);
72+
CHECK(val.price == Approx(book.price).epsilon(0.001));
73+
}
74+
}

0 commit comments

Comments
 (0)