128 lines
No EOL
4.4 KiB
C++
128 lines
No EOL
4.4 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/config.h"
|
|
#include <tests/fixture/memoryCheckFixture.h>
|
|
#include <ubiservices/services/facadeInterface.h>
|
|
#include <ubiservices/services/populations/populationInfo.h>
|
|
#include <ubiservices/services/populations/sessionManagerPopulations.h>
|
|
|
|
namespace US_NS {;
|
|
US_DEFINE_TEST(TestPopulation);
|
|
|
|
#if !defined(US_DLL)
|
|
|
|
namespace PopulationInfoPrivate
|
|
{
|
|
bool extractData(const Json& source, PopulationInfo& target);
|
|
}
|
|
|
|
typedef LeakChecker UNIT_POPULATION;
|
|
|
|
TEST_F(UNIT_POPULATION, LOCAL_PopulationInfoJsonParsing)
|
|
{
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
// {
|
|
// "name": "string",
|
|
// "obj": "object",
|
|
// "subject": "string",
|
|
// "spaceId": "guid"
|
|
// }
|
|
SAVE_ALLOC_COUNT(count2);
|
|
JsonWriter writer;
|
|
writer["name"] = "Han";
|
|
writer["subject"] = "Chewbacca";
|
|
writer["spaceId"] = "11112222-1111-2222-1111-222211112222";
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(4u, 4, count2);
|
|
|
|
{
|
|
PopulationInfo info;
|
|
EXPECT_FALSE(PopulationInfoPrivate::extractData(writer.getJson(), info));
|
|
}
|
|
|
|
JsonWriter obj;
|
|
obj["field"] = "value";
|
|
writer["obj"] = obj.getJson();
|
|
{
|
|
PopulationInfo info;
|
|
EXPECT_TRUE(PopulationInfoPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_TRUE(info.m_spaceId.isValid());
|
|
EXPECT_FALSE(info.m_name.isEmpty());
|
|
EXPECT_FALSE(info.m_subject.isEmpty());
|
|
EXPECT_TRUE(info.m_object.isValid());
|
|
}
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(91u, 91, count2);
|
|
|
|
writer["extra"] = 42;
|
|
{
|
|
PopulationInfo info;
|
|
EXPECT_TRUE(PopulationInfoPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_TRUE(info.m_spaceId.isValid());
|
|
EXPECT_FALSE(info.m_name.isEmpty());
|
|
EXPECT_FALSE(info.m_subject.isEmpty());
|
|
EXPECT_TRUE(info.m_object.isValid());
|
|
}
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(52u, 52, count2);
|
|
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(147u, 147, testCount);
|
|
|
|
// testing optional field assignmentTime
|
|
{
|
|
PopulationInfo info;
|
|
EXPECT_TRUE(PopulationInfoPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_TRUE(info.m_assignmentTime == DateTime(0, 0, 0, 0, 0, 0));
|
|
EXPECT_FALSE(info.m_assignmentTime.isValid());
|
|
}
|
|
writer["assignmentTime"] = "2014-08-01T00:00:00Z";
|
|
{
|
|
PopulationInfo info;
|
|
EXPECT_TRUE(PopulationInfoPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_TRUE(info.m_assignmentTime.isValid());
|
|
}
|
|
}
|
|
|
|
/// @test Ensures that modifying the cache has no impact on the content of the results previously returned
|
|
TEST_F(UNIT_POPULATION, LOCAL_PopulationCache)
|
|
{
|
|
Facade facade;
|
|
SessionManagerPopulations mgr(getFacadeInternal(facade));
|
|
|
|
SmartPtr<PopulationCache> noCache = mgr.getPopulationsCache();
|
|
EXPECT_FALSE(noCache.isValid());
|
|
|
|
// First cache update
|
|
Map<SpaceId, Vector<PopulationInfo>> cacheContent1;
|
|
cacheContent1[SpaceId("11111111-2222-3333-4444-555566667777")].push_back(PopulationInfo());
|
|
mgr.setPopulationsCache(cacheContent1);
|
|
// Previous result shouldn't be modified
|
|
EXPECT_FALSE(noCache.isValid());
|
|
|
|
// Retrieve current cache after first update
|
|
SmartPtr<PopulationCache> cache1 = mgr.getPopulationsCache();
|
|
// Previous result shouldn't be modified
|
|
EXPECT_FALSE(noCache.isValid());
|
|
ASSERT_TRUE(cache1.isValid());
|
|
EXPECT_EQ(1u, cache1->m_cache.size());
|
|
|
|
// Second cache update
|
|
Map<SpaceId, Vector<PopulationInfo>> cacheContent2;
|
|
cacheContent2[SpaceId("11111111-2222-3333-4444-555566667777")].push_back(PopulationInfo());
|
|
cacheContent2[SpaceId("22222222-3333-4444-5555-666677778888")].push_back(PopulationInfo());
|
|
mgr.setPopulationsCache(cacheContent2);
|
|
// Previous result shouldn't be modified
|
|
EXPECT_FALSE(noCache.isValid());
|
|
ASSERT_TRUE(cache1.isValid());
|
|
EXPECT_EQ(1u, cache1->m_cache.size());
|
|
|
|
// Retrieve current cache after first update
|
|
SmartPtr<PopulationCache> cache2 = mgr.getPopulationsCache();
|
|
// Previous result shouldn't be modified
|
|
EXPECT_FALSE(noCache.isValid());
|
|
ASSERT_TRUE(cache1.isValid());
|
|
EXPECT_EQ(1u, cache1->m_cache.size());
|
|
ASSERT_TRUE(cache2.isValid());
|
|
EXPECT_EQ(2u, cache2->m_cache.size());
|
|
}
|
|
|
|
#endif // !defined(US_DLL)
|
|
}; |