345 lines
12 KiB
C++
345 lines
12 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/config.h"
|
|
#include "tests/common/helpers.h"
|
|
#include "tests/fixture/memoryCheckFixture.h"
|
|
#include <ubiservices/core/errors/errorDetails.h>
|
|
#include <ubiservices/core/JSON/jsonWriter.h>
|
|
#include <ubiservices/core/tasks/asyncResultBatch.h>
|
|
#include <../private/ubiservices/core/network/URLInfo.h>
|
|
#include "ubiservices/services/http/httpUrlHelper.h"
|
|
|
|
namespace US_NS {;
|
|
US_DEFINE_TEST(TestPublicMethodsCore);
|
|
|
|
typedef LeakChecker PUBLIC_API;
|
|
|
|
TEST_F(PUBLIC_API, LOCAL_Json)
|
|
{
|
|
{
|
|
// Class Json
|
|
JsonWriter jsonWriter;
|
|
Json jsonReader(jsonWriter.renderContent());
|
|
|
|
{
|
|
// Test copy constructor
|
|
Json jsonReaderCopy(jsonReader);
|
|
}
|
|
|
|
{
|
|
// Test cloneInstance() method
|
|
Json jsonReaderClone(jsonWriter.renderContent());
|
|
jsonReaderClone = jsonReaderClone.cloneInstance();
|
|
}
|
|
|
|
String renderedContent;
|
|
renderedContent = jsonReader.renderContent();
|
|
renderedContent = jsonReader.renderContent(Json::Formatted);
|
|
|
|
const Vector<Json> jsonReaderList = jsonReader.getItems();
|
|
const int32 itemsCount = jsonReader.getItemsCount();
|
|
US_UNUSED(itemsCount);
|
|
const String nameString = jsonReader.getKey();
|
|
US_UNUSED(nameString);
|
|
const String valueString = jsonReader.getValueString();
|
|
US_UNUSED(valueString);
|
|
const double valueDouble = jsonReader.getValueDouble();
|
|
US_UNUSED(valueDouble);
|
|
const int32 valueInt32 = jsonReader.getValueInteger();
|
|
US_UNUSED(valueInt32);
|
|
const bool valueBoolean = jsonReader.getValueBoolean();
|
|
US_UNUSED(valueBoolean);
|
|
const Vector<Json> valueArray = jsonReader.getValueArray();
|
|
US_UNUSED(valueArray);
|
|
|
|
bool getValueResult;
|
|
int32 int32Value;
|
|
getValueResult = jsonReader.getValue(int32Value);
|
|
double doubleValue;
|
|
getValueResult = jsonReader.getValue(doubleValue);
|
|
bool boolValue;
|
|
getValueResult = jsonReader.getValue(boolValue);
|
|
String stringValue;
|
|
getValueResult = jsonReader.getValue(stringValue);
|
|
Vector<Json> jsonReaderListValue;
|
|
getValueResult = jsonReader.getValues(jsonReaderListValue);
|
|
US_UNUSED(getValueResult);
|
|
|
|
const bool isTypeNull = jsonReader.isTypeNull();
|
|
US_UNUSED(isTypeNull);
|
|
const bool isTypeArray = jsonReader.isTypeArray();
|
|
US_UNUSED(isTypeArray);
|
|
const bool isTypeObject = jsonReader.isTypeObject();
|
|
US_UNUSED(isTypeObject);
|
|
const bool isTypeBoolean = jsonReader.isTypeBoolean();
|
|
US_UNUSED(isTypeBoolean);
|
|
const bool isTypeNumber = jsonReader.isTypeNumber();
|
|
US_UNUSED(isTypeNumber);
|
|
const bool isTypeText = jsonReader.isTypeString();
|
|
US_UNUSED(isTypeText);
|
|
const bool isValid = jsonReader.isValid();
|
|
US_UNUSED(isValid);
|
|
|
|
const String subItemName = _T("dummySubItem");
|
|
const Json subItem = jsonReader[subItemName];
|
|
}
|
|
{
|
|
// Class JsonWriter
|
|
{
|
|
// Test constructors
|
|
const JsonWriter jsonWriterNoParameters;
|
|
const JsonWriter jsonWriterBool(JsonWriterType::Array);
|
|
}
|
|
|
|
{
|
|
// Test JsonWriter Object
|
|
JsonWriter jsonWriterObject;
|
|
jsonWriterObject.renderContent();
|
|
|
|
const String boolItemKey = _T("BoolItemKey");
|
|
jsonWriterObject[boolItemKey] = false;
|
|
|
|
const String int32ItemKey = _T("int32ItemKey");
|
|
jsonWriterObject[int32ItemKey] = static_cast<int32>(-123456);
|
|
|
|
const String uint32ItemKey = _T("uint32ItemKey");
|
|
const uint32 uint32ItemValue = 3456789012u;
|
|
jsonWriterObject[uint32ItemKey] = static_cast<int32>(uint32ItemValue);
|
|
|
|
const String doubleItemKey = _T("doubleItemKey");
|
|
jsonWriterObject[doubleItemKey] = static_cast<double>(12.3456);
|
|
|
|
const String tcharItemKey = _T("tcharItemKey");
|
|
jsonWriterObject[tcharItemKey] = _T("tcharItemValue");
|
|
|
|
const String stringItemKey = _T("stringItemKey");
|
|
jsonWriterObject[stringItemKey] = String("stringItemValue");
|
|
|
|
const String jsonWriterItemKey = _T("jsonWriterItemKey");
|
|
jsonWriterObject[jsonWriterItemKey] = JsonWriter().getJson();
|
|
|
|
const String jsonReaderItemKey = _T("jsonReaderItem");
|
|
const String jsonWriterItemString = JsonWriter().renderContent();
|
|
const Json jsonReaderItemValue(jsonWriterItemString);
|
|
jsonWriterObject[jsonReaderItemKey] = jsonReaderItemValue;
|
|
|
|
const String jsonWriterNullKey = _T("jsonReaderItem");
|
|
jsonWriterObject[jsonWriterNullKey].setToNull();
|
|
|
|
const String listStringItemKey = _T("listStringItem");
|
|
jsonWriterObject[listStringItemKey] = Vector<String>();
|
|
|
|
const String vectorInt32ItemKey = _T("vectorInt32Item");
|
|
jsonWriterObject[vectorInt32ItemKey] = Vector<int32>();
|
|
|
|
const String listInt32ItemKey = _T("listInt32Item");
|
|
jsonWriterObject[listInt32ItemKey] = Vector<int32>();
|
|
|
|
const String vectorJsonWriterItemKey = _T("vectorJsonWriterItem");
|
|
jsonWriterObject[vectorJsonWriterItemKey] = Vector<Json>();
|
|
|
|
const String jsonStringWriterItemKey = _T("jsonStringWriterItem");
|
|
const String jsonStringWriterItemValue("{\"dummyKey\":7}");
|
|
jsonWriterObject.addJsonStringToObject(jsonStringWriterItemKey, jsonStringWriterItemValue);
|
|
}
|
|
|
|
{
|
|
// Test JsonWriter array
|
|
JsonWriter jsonWriterArray(JsonWriterType::Array);
|
|
|
|
const bool boolItemValue = true;
|
|
jsonWriterArray.addItemToArray(boolItemValue);
|
|
|
|
const int32 int32ItemValue = -123456;
|
|
jsonWriterArray.addItemToArray(int32ItemValue);
|
|
|
|
const uint32 uint32ItemValue = 3456789012u;
|
|
jsonWriterArray.addItemToArray(static_cast<int32>(uint32ItemValue));
|
|
|
|
const double doubleItemValue = 12.3456;
|
|
jsonWriterArray.addItemToArray(doubleItemValue);
|
|
|
|
const tchar* tcharItemValue = _T("tcharItemValue");
|
|
jsonWriterArray.addItemToArray(tcharItemValue);
|
|
|
|
const String stringItemValue = _T("stringItemValue");
|
|
jsonWriterArray.addItemToArray(stringItemValue);
|
|
|
|
const JsonWriter jsonWriterItemValue;
|
|
jsonWriterArray.addItemToArray(jsonWriterItemValue.getJson());
|
|
|
|
const String jsonWriterItemString = jsonWriterItemValue.renderContent();
|
|
const Json jsonReaderItemValue(jsonWriterItemString);
|
|
jsonWriterArray.addItemToArray(jsonReaderItemValue);
|
|
|
|
jsonWriterArray.addNullToArray();
|
|
|
|
Vector<int32> vectorInt32ItemValue;
|
|
jsonWriterArray.addItemToArray(vectorInt32ItemValue);
|
|
|
|
//List<int32> listInt32ItemValue;
|
|
//jsonWriterArray.addItemToArray(listInt32ItemValue);
|
|
|
|
Vector<Json> vectorJsonItemValue;
|
|
jsonWriterArray.addItemToArray(vectorJsonItemValue);
|
|
|
|
const String jsonStringWriterItemValue("{\"dummyKey\":7}");
|
|
jsonWriterArray.addJsonStringToArray(jsonStringWriterItemValue);
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_F(PUBLIC_API, LOCAL_Tasks)
|
|
{
|
|
{
|
|
// Class AsyncResult
|
|
AsyncResult<int32> asyncResult;
|
|
|
|
int32 result = asyncResult.getResult();
|
|
US_UNUSED(result);
|
|
|
|
AsyncResult<int32> asyncResultDebug("DummyDebugString");
|
|
}
|
|
{
|
|
// Class AsyncResultBase
|
|
AsyncResultBase asyncResultBase;
|
|
|
|
const bool hasSucceeded = asyncResultBase.hasSucceeded();
|
|
US_UNUSED(hasSucceeded);
|
|
|
|
const bool hasFailed = asyncResultBase.hasFailed();
|
|
US_UNUSED(hasFailed);
|
|
|
|
const bool isCanceled = asyncResultBase.isCanceled();
|
|
US_UNUSED(isCanceled);
|
|
|
|
const bool isProcessing = asyncResultBase.isProcessing();
|
|
US_UNUSED(isProcessing);
|
|
|
|
const ErrorDetails error = asyncResultBase.getError();
|
|
US_UNUSED(error);
|
|
|
|
const bool isWaitOK = asyncResultBase.wait(0u);
|
|
US_UNUSED(isWaitOK);
|
|
|
|
const String description = asyncResultBase.getDescription();
|
|
US_UNUSED(description);
|
|
|
|
asyncResultBase.cancel();
|
|
|
|
const AsyncResultBase asyncResultBaseDebug("DummyDescription");
|
|
US_UNUSED(asyncResultBaseDebug);
|
|
}
|
|
{
|
|
// Class AsyncResultBatch
|
|
AsyncResultBatch<Empty, int32> asyncResultBatch;
|
|
const AsyncResult<Map<Empty, AsyncResult<int32> > > sourceAsyncResult;
|
|
|
|
Map<Empty, AsyncResult<int32> > asyncResults = asyncResultBatch.getAsyncResults();
|
|
US_UNUSED(asyncResults);
|
|
|
|
bool hasPartiallySucceeded = asyncResultBatch.hasPartiallySucceeded();
|
|
US_UNUSED(hasPartiallySucceeded);
|
|
|
|
bool hasSucceeded = asyncResultBatch.hasSucceeded();
|
|
US_UNUSED(hasSucceeded);
|
|
|
|
bool hasFailed = asyncResultBatch.hasFailed();
|
|
US_UNUSED(hasFailed);
|
|
}
|
|
}
|
|
|
|
TEST_F(PUBLIC_API, LOCAL_Types)
|
|
{
|
|
// {
|
|
// // Class DateTime
|
|
// const DateTime dateTime;
|
|
//
|
|
// {
|
|
// // Test constructors
|
|
// const DateTime copy(dateTime);
|
|
// DateTime dateTimeYmdhms(9876, Month::Dec, 23, 12, 34, 56);
|
|
// }
|
|
//
|
|
// {
|
|
// // Test operators
|
|
// DateTime newDateTime;
|
|
// const bool isEqual = (dateTime == newDateTime);
|
|
// US_UNUSED(isEqual);
|
|
// const bool isDifferent = (dateTime != newDateTime);
|
|
// US_UNUSED(isDifferent);
|
|
// const bool isLower = (dateTime < newDateTime);
|
|
// US_UNUSED(isLower);
|
|
// const bool isHigher = (dateTime > newDateTime);
|
|
// US_UNUSED(isHigher);
|
|
// const bool isLowerEqual = (dateTime <= newDateTime);
|
|
// US_UNUSED(isLowerEqual);
|
|
// const bool isHigherEqual = (dateTime >= newDateTime);
|
|
// US_UNUSED(isHigherEqual);
|
|
// }
|
|
//
|
|
// {
|
|
// // Test other methods
|
|
// const bool isValid = dateTime.isValid();
|
|
// US_UNUSED(isValid);
|
|
// }
|
|
//
|
|
// {
|
|
// // Test static methods
|
|
// const DateTime systemTime = DateTime::getSystemTime();
|
|
// US_UNUSED(systemTime);
|
|
// }
|
|
// }
|
|
{
|
|
// Class Guid
|
|
Guid guid;
|
|
|
|
const String stringGuid = _T("11111111-2222-3333-4444-555566667777");
|
|
GuidBinary guidBinary;
|
|
guidBinary.m_data1 = 0x11111111;
|
|
guidBinary.m_data2 = 0x2222;
|
|
guidBinary.m_data3 = 0x3333;
|
|
guidBinary.m_data4[0] = 0x4444;
|
|
guidBinary.m_data4[1] = 0x5555;
|
|
guidBinary.m_data4[2] = 0x6666;
|
|
guidBinary.m_data4[3] = 0x7777;
|
|
|
|
{
|
|
// Test constructors
|
|
Guid guid1(stringGuid);
|
|
Guid guid2(guidBinary);
|
|
}
|
|
|
|
const bool logAsError = false;
|
|
|
|
bool isValid = Guid::isValid(stringGuid);
|
|
isValid = Guid::isValid(stringGuid, logAsError);
|
|
isValid = guid.isValid();
|
|
US_UNUSED(isValid);
|
|
|
|
guid.set(stringGuid);
|
|
bool isSetValid = guid.isValid();
|
|
guid.set(guidBinary);
|
|
isSetValid = guid.isValid();
|
|
US_UNUSED(isSetValid);
|
|
|
|
GuidBinary retrievedGuidBinary = guid.getBinary();
|
|
US_UNUSED(retrievedGuidBinary);
|
|
|
|
// Operators
|
|
const String retrievedString = static_cast<const String&>(guid);
|
|
US_UNUSED(retrievedString);
|
|
Guid newGuid;
|
|
const bool isSet = newGuid.isSet();
|
|
US_UNUSED(isSet);
|
|
const bool isEqual = (guid == newGuid);
|
|
US_UNUSED(isEqual);
|
|
const bool isDifferent = (guid != newGuid);
|
|
US_UNUSED(isDifferent);
|
|
const bool isLower = (guid < newGuid);
|
|
US_UNUSED(isLower);
|
|
}
|
|
}
|
|
|
|
};
|