Adapt existing tests to cover GenericRapidJsonAdapter when using a value type backed by RapidJson's CrtAllocator

This commit is contained in:
Tristan Penman 2015-12-07 22:01:06 +11:00
parent 414c46b423
commit 6546a9a945
3 changed files with 87 additions and 5 deletions

View File

@ -868,6 +868,19 @@ struct AdapterTraits<valijson::adapters::RapidJsonAdapter>
}
};
template<>
struct AdapterTraits<valijson::adapters::GenericRapidJsonAdapter<
rapidjson::GenericValue<rapidjson::UTF8<>, rapidjson::CrtAllocator> > >
{
typedef rapidjson::GenericDocument<rapidjson::UTF8<>,
rapidjson::CrtAllocator> DocumentType;
static std::string adapterName()
{
return "GenericRapidJsonAdapter (using CrtAllocator)";
}
};
} // namespace adapters
} // namespace valijson

View File

@ -125,6 +125,13 @@ TEST_F(TestAdapterComparison, JsonCppVsJsonCpp)
valijson::adapters::JsonCppAdapter>();
}
TEST_F(TestAdapterComparison, JsonCppVsPicoJson)
{
testComparison<
valijson::adapters::JsonCppAdapter,
valijson::adapters::PicoJsonAdapter>();
}
TEST_F(TestAdapterComparison, JsonCppVsPropertyTree)
{
testComparison<
@ -139,10 +146,19 @@ TEST_F(TestAdapterComparison, JsonCppVsRapidJson)
valijson::adapters::RapidJsonAdapter>();
}
TEST_F(TestAdapterComparison, JsonCppVsPicoJson)
TEST_F(TestAdapterComparison, JsonCppVsRapidJsonCrtAlloc)
{
testComparison<
valijson::adapters::JsonCppAdapter,
valijson::adapters::GenericRapidJsonAdapter<
rapidjson::GenericValue<rapidjson::UTF8<>,
rapidjson::CrtAllocator> > >();
}
TEST_F(TestAdapterComparison, PropertyTreeVsPicoJson)
{
testComparison<
valijson::adapters::PropertyTreeAdapter,
valijson::adapters::PicoJsonAdapter>();
}
@ -160,11 +176,13 @@ TEST_F(TestAdapterComparison, PropertyTreeVsRapidJson)
valijson::adapters::RapidJsonAdapter>();
}
TEST_F(TestAdapterComparison, PropertyTreeVsPicoJson)
TEST_F(TestAdapterComparison, PropertyTreeVsRapidJsonCrtAlloc)
{
testComparison<
valijson::adapters::PropertyTreeAdapter,
valijson::adapters::PicoJsonAdapter>();
valijson::adapters::GenericRapidJsonAdapter<
rapidjson::GenericValue<rapidjson::UTF8<>,
rapidjson::CrtAllocator> > >();
}
TEST_F(TestAdapterComparison, RapidJsonVsRapidJson)
@ -174,6 +192,15 @@ TEST_F(TestAdapterComparison, RapidJsonVsRapidJson)
valijson::adapters::RapidJsonAdapter>();
}
TEST_F(TestAdapterComparison, RapidJsonVsRapidJsonCrtAlloc)
{
testComparison<
valijson::adapters::RapidJsonAdapter,
valijson::adapters::GenericRapidJsonAdapter<
rapidjson::GenericValue<rapidjson::UTF8<>,
rapidjson::CrtAllocator> > >();
}
TEST_F(TestAdapterComparison, RapidJsonVsPicoJson)
{
testComparison<
@ -187,3 +214,23 @@ TEST_F(TestAdapterComparison, PicoJsonVsPicoJson)
valijson::adapters::PicoJsonAdapter,
valijson::adapters::PicoJsonAdapter>();
}
TEST_F(TestAdapterComparison, PicoJsonVsRapidJsonCrtAlloc)
{
testComparison<
valijson::adapters::PicoJsonAdapter,
valijson::adapters::GenericRapidJsonAdapter<
rapidjson::GenericValue<rapidjson::UTF8<>,
rapidjson::CrtAllocator> > >();
}
TEST_F(TestAdapterComparison, RapidJsonCrtAllocVsRapidJsonCrtAlloc)
{
testComparison<
valijson::adapters::GenericRapidJsonAdapter<
rapidjson::GenericValue<rapidjson::UTF8<>,
rapidjson::CrtAllocator> >,
valijson::adapters::GenericRapidJsonAdapter<
rapidjson::GenericValue<rapidjson::UTF8<>,
rapidjson::CrtAllocator> > >();
}

View File

@ -10,7 +10,8 @@ class TestRapidJsonAdapter : public testing::Test
};
TEST_F(TestRapidJsonAdapter, BasicArrayIteration)
template<class ValueType>
void testBasicArrayIteration()
{
const unsigned int numElements = 10;
@ -47,7 +48,8 @@ TEST_F(TestRapidJsonAdapter, BasicArrayIteration)
EXPECT_EQ(numElements, expectedValue);
}
TEST_F(TestRapidJsonAdapter, BasicObjectIteration)
template<typename ValueType>
void testBasicObjectIteration()
{
const unsigned int numElements = 10;
@ -85,4 +87,24 @@ TEST_F(TestRapidJsonAdapter, BasicObjectIteration)
// Ensure that the correct number of elements were iterated over
EXPECT_EQ( numElements, expectedValue );
}
TEST_F(TestRapidJsonAdapter, BasicArrayIteration)
{
// Test using default RapidJson value type, which uses MemoryPoolAllocator
testBasicArrayIteration<rapidjson::Value>();
// Test using value type based on CrtAllocator
testBasicArrayIteration<rapidjson::GenericValue<rapidjson::UTF8<>,
rapidjson::CrtAllocator> >();
}
TEST_F(TestRapidJsonAdapter, BasicObjectIteration)
{
// Test using default RapidJson value type, which uses MemoryPoolAllocator
testBasicObjectIteration<rapidjson::Value>();
// Test using value type based on CrtAllocator
testBasicObjectIteration<rapidjson::GenericValue<rapidjson::UTF8<>,
rapidjson::CrtAllocator> >();
}