//////////////////////////////////////////////////////////////////////////////// // (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour // //////////////////////////////////////////////////////////////////////////////// #include "tests/config.h" #if defined(US_SDK_LIGHT_MOBILE) #error This file shall not be part of the solution #endif #include "tests/fixture/loginMockFixture.h" #include "tests/fixture/memoryCheckFixture.h" #include "testsIntegration/entityTestHelper.h" #include #include #include #include #include #include namespace US_NS {; US_DEFINE_TEST(TestEntity); #if !defined(US_DLL) typedef LeakCheckerNoScheduler UNIT_ENTITY_NOSCHEDULER; TEST_F(UNIT_ENTITY_NOSCHEDULER, LOCAL_CtorEmpty) { SAVE_ALLOC_COUNT(count1); const EntityProfile entity; EXPECT_ALLOC_COUNT_PC_EQ(7u, count1); EXPECT_EQ(EntityId(), entity.getEntityId()); EXPECT_TRUE(entity.getName().isEmpty()); EXPECT_TRUE(entity.getType().isEmpty()); EXPECT_EQ(0u, entity.getTags().size()); EXPECT_TRUE(entity.getJsonData().isEmpty()); EXPECT_EQ(ProfileId(), entity.getProfileId()); EXPECT_EQ(SpaceId(), entity.getSpaceId()); EXPECT_EQ(1u, entity.getRevision()); EXPECT_FALSE(entity.isEditable()); EXPECT_ALLOC_COUNT_PC_EQ(3u, count1); } TEST_F(UNIT_ENTITY_NOSCHEDULER, LOCAL_CtorParams) { SAVE_ALLOC_COUNT(count1); EXPECT_ALLOC_COUNT_PC_EQ(5u, count1); const EntityCreation entityCreation("settings", "name", "{\"settings\":{\"automatchTimeout\": 30, \"favorProximity\": true}}", { "tag1", "tag2" }, SpaceId("11111111-2222-3333-4444-555555666666")); EXPECT_ALLOC_COUNT_PC_EQ(14u, count1); EXPECT_STREQ("settings", entityCreation.m_type.getUtf8()); EXPECT_EQ(2u, entityCreation.m_tags.size()); EXPECT_STREQ("{\"settings\":{\"automatchTimeout\": 30, \"favorProximity\": true}}", entityCreation.m_jsonData.getUtf8()); EXPECT_ALLOC_COUNT_PC_EQ(0u, count1); } TEST_F(UNIT_ENTITY_NOSCHEDULER, LOCAL_SetFunctions) { SAVE_ALLOC_COUNT(count1); EntityProfile entity; EXPECT_ALLOC_COUNT_PC_EQ(7u, count1); // JsonData const String jsonData = "{\"data\":\"jsonData\"}"; entity.setJsonData(jsonData); EXPECT_EQ(jsonData, entity.getJsonData()); // Name const String name("EntityName"); entity.setName(name); EXPECT_EQ(name, entity.getName()); // Tags const Vector tags = Vector({ "tag1", "tag2" }); entity.setTags(tags); EXPECT_EQ(tags.size(), entity.getTags().size()); EXPECT_ALLOC_COUNT_PC_EQ(11u, count1); for(Vector::const_iterator itExpect = tags.begin(), itActual = entity.getTags().begin(); itExpect != tags.end() && itActual != entity.getTags().end(); ++itExpect, ++itActual) { EXPECT_EQ(*itExpect, *itActual); } // Type const String type(_T("myType")); entity.setType(type); EXPECT_EQ(type, entity.getType()); EXPECT_FALSE(entity.isEditable()); EXPECT_ALLOC_COUNT_PC_EQ(1u, count1); } TEST_F(UNIT_ENTITY_NOSCHEDULER, LOCAL_JsonParsing) { SAVE_ALLOC_COUNT(count1); const EntityId entityId("689a42b7-89a9-32ss-a184-be96d4302345"); const ProfileId profileId("4d9061de-7c20-4cc9-9f55-b8d6228da6ae"); const SpaceId spaceId("11111111-2222-3333-4444-555555666666"); const String type = "settings"; const String name = "Multiplayer Settings"; JsonWriter storage; JsonWriter settings; { settings["automatchTimeout"] = 30; settings["favorProximity"] = true; } storage["settings"] = settings.getJson(); JsonWriter entityJson; { entityJson["entityId"] = entityId; entityJson["profileId"] = profileId; entityJson["spaceId"] = spaceId; entityJson["type"] = type; entityJson["name"] = name; entityJson["tags"] = Vector({ "tag1", "tag2" }); entityJson["revision"] = 10; entityJson["obj"] = storage.getJson(); entityJson["lastModified"] = DateTimeHelper::formatDateISO8601(DateTime(2014,10,17,10,01,25)); entityJson["editable"] = true; } EXPECT_ALLOC_COUNT_PC_EQ(101u, count1); { EntityProfile entity; EXPECT_TRUE(EntityTestHelper::parseJson(entity, entityJson.getJson())); EXPECT_EQ(profileId, entity.getProfileId()); EXPECT_EQ(entityId, entity.getEntityId()); EXPECT_EQ(spaceId, entity.getSpaceId()); EXPECT_STREQ(name.getUtf8(), entity.getName().getUtf8()); EXPECT_STREQ(type.getUtf8(), entity.getType().getUtf8()); EXPECT_EQ(2u, entity.getTags().size()); EXPECT_STREQ(storage.renderContent().getUtf8(), entity.getJsonData().getUtf8()); EXPECT_EQ(10u, entity.getRevision()); EXPECT_EQ(ExtendedStorageProvider::None, entity.getExtendedStorageProvider()); EXPECT_TRUE(entity.isEditable()); } const String extendedProvider = "s3"; const StringUrl extendedLocationUrl = "https://aws.amazon.com/s3/dummyLocation"; JsonWriter extendStorage; { extendStorage["provider"] = extendedProvider; extendStorage["headUrl"] = extendedLocationUrl; extendStorage["getUrl"] = extendedLocationUrl; extendStorage["putUrl"] = extendedLocationUrl; extendStorage["deleteUrl"] = extendedLocationUrl; } { ExtendedStorageInfo storage2; EXPECT_ALLOC_COUNT_PC_EQ(210u, count1); const bool result = storage2.parseJson(extendStorage.getJson()); EXPECT_ALLOC_COUNT_PC_EQ(154, count1); EXPECT_TRUE(result); EXPECT_EQ(storage2.m_provider, ExtendedStorageProvider::S3); EXPECT_STREQ(extendedLocationUrl.getUtf8(), storage2.m_getUrl.getUtf8()); EXPECT_STREQ(extendedLocationUrl.getUtf8(), storage2.m_headUrl.getUtf8()); EXPECT_STREQ(extendedLocationUrl.getUtf8(), storage2.m_deleteUrl.getUtf8()); EXPECT_STREQ(extendedLocationUrl.getUtf8(), storage2.m_putUrl.getUtf8()); } { EntityProfile entity; EXPECT_ALLOC_COUNT_PC_EQ(35u, count1) entityJson["extendedStorage"] = extendStorage.getJson(); EXPECT_ALLOC_COUNT_PC_EQ(18u, count1); EXPECT_TRUE(EntityTestHelper::parseJson(entity, entityJson.getJson())); EXPECT_EQ(ExtendedStorageProvider::S3, entity.getExtendedStorageProvider()); } } TEST_F(UNIT_ENTITY_NOSCHEDULER, LOCAL_JsonParsingExtendedStorage) { SAVE_ALLOC_COUNT(count1); JsonWriter writer; EXPECT_ALLOC_COUNT_PC_EQ(3u, count1); { writer["getUrl"] = "http://urlGet.com"; writer["putUrl"] = "http://urlPut.com"; writer["headUrl"] = "http://urlHead.com"; writer["deleteUrl"] = "http://urlDelete.com"; } EXPECT_ALLOC_COUNT_PC_EQ(16u, count1); { // Missing field ExtendedStorageInfo storage; EXPECT_ALLOC_COUNT_PC_EQ(132u, count1); const Json data = writer.getJson(); EXPECT_ALLOC_COUNT_PC_EQ(0, count1); EXPECT_FALSE(storage.parseJson(data)); EXPECT_ALLOC_COUNT_PC_EQ(130, count1); // (extraction occurs as much as possible with ExtractContent) } { // All fields writer["provider"] = "s3"; ExtendedStorageInfo storage; EXPECT_ALLOC_COUNT_PC_EQ(136, count1); EXPECT_TRUE(storage.parseJson(writer.getJson())); EXPECT_ALLOC_COUNT_PC_EQ(130, count1); } { // Extra field writer["field"] = 45; ExtendedStorageInfo storage; EXPECT_ALLOC_COUNT_PC_EQ(135, count1); EXPECT_TRUE(storage.parseJson(writer.getJson())); EXPECT_ALLOC_COUNT_PC_EQ(130, count1); } } #endif // DLL };