Browse Source

Refactor `Get...ByPointer()` into two methods

Now Acedia collections provide functionality of `Get...ByPointer()`
method (that allows to fetch values nested into several collection by
JSON pointers) for both `JSONPointer` and `Text` classes.

Previously, each use of `Get...ByPointer()` method caused convertion of
a `Text` into `JSONPointer`, even if used `Text` value did not change.
This patch allows to create `JSONPointer` once and them use that as a
parameter, which should be much faster.
pull/8/head
Anton Tarasenko 3 years ago
parent
commit
7fc8328752
  1. 4
      sources/Commands/BuiltInCommands/ACommandDosh.uc
  2. 325
      sources/Data/Collections/Collection.uc
  3. 62
      sources/Data/Collections/Tests/TEST_CollectionsMixed.uc
  4. 46
      sources/Data/Database/Tests/TEST_LocalDatabase.uc

4
sources/Commands/BuiltInCommands/ACommandDosh.uc

@ -53,8 +53,8 @@ protected function ExecutedFor(APlayer player, CommandCall result)
local AssociativeArray commandOptions;
// Find min and max value boundaries
commandOptions = result.GetOptions();
minValue = commandOptions.GetIntByPointer(P("/min/minValue"), 0);
maxValue = commandOptions.GetIntByPointer(P("/max/maxValue"), MaxInt);
minValue = commandOptions.GetIntBy(P("/min/minValue"), 0);
maxValue = commandOptions.GetIntBy(P("/max/maxValue"), MaxInt);
if (minValue > maxValue) {
maxValue = minValue;
}

325
sources/Data/Collections/Collection.uc

@ -62,15 +62,7 @@ public final function Iter Iterate()
/**
* Returns stored `AcediaObject` from the caller storage
* (or from it's sub-storages) via given `Text` path.
*
* Path is treated like a [JSON pointer](https://tools.ietf.org/html/rfc6901).
* If given path does not start with "/" character (like it is expected from
* a json pointer) - it will be added automatically.
* This means that "foo/bar" is treated like "/foo/bar" and
* "path" like "/path". However, empty `Text` is treated like itself (""),
* since it constitutes a valid JSON pointer (it will point at a caller
* collection itself).
* (or from it's sub-storages) via given `JSONPointer` path.
*
* Acedia provides two collections:
* 1. `DynamicArray` is treated as a JSON array in the context of
@ -85,34 +77,27 @@ public final function Iter Iterate()
* integrated with this method by making it a sub-class of `Collection` and
* appropriately defining `GetByText()` protected method.
*
* Making only getter available (without setters or `Take...()` methods that
* also remove returned element) is a deliberate choice made to reduce amount
* of possible errors when working with collections.
*
* There is no requirement that all stored values must be reachable by
* this method (i.e. `AssociativeArray` only lets you access values with
* `Text` keys).
*
* @param jsonPointerAsText Path, given by a JSON pointer.
* @param jsonPointer Path, given by a JSON pointer.
* @return An item `jsonPointerAsText` is referring to (according to the above
* stated rules). `none` if such item does not exist.
*/
public final function AcediaObject GetItemByPointer(Text jsonPointerAsText)
public final function AcediaObject GetItemByJSON(JSONPointer jsonPointer)
{
local int segmentIndex;
local Text nextSegment;
local AcediaObject result;
local JSONPointer pointer;
local Collection nextCollection;
if (jsonPointerAsText == none) return none;
if (jsonPointerAsText.IsEmpty()) return self;
pointer = _.json.Pointer(jsonPointerAsText);
if (jsonPointerAsText.GetLength() < 1) return self;
if (jsonPointer == none) return none;
if (jsonPointer.GetLength() < 1) return self;
nextCollection = self;
while (segmentIndex < pointer.GetLength() - 1)
while (segmentIndex < jsonPointer.GetLength() - 1)
{
nextSegment = pointer.GetComponent(segmentIndex);
nextSegment = jsonPointer.GetComponent(segmentIndex);
nextCollection = Collection(nextCollection.GetByText(nextSegment));
_.memory.Free(nextSegment);
if (nextCollection == none) {
@ -122,11 +107,59 @@ public final function AcediaObject GetItemByPointer(Text jsonPointerAsText)
}
if (nextCollection != none)
{
nextSegment = pointer.GetComponent(segmentIndex);
nextSegment = jsonPointer.GetComponent(segmentIndex);
result = nextCollection.GetByText(nextSegment);
_.memory.Free(nextSegment);
}
_.memory.Free(pointer);
_.memory.Free(jsonPointer);
return result;
}
/**
* Returns stored `AcediaObject` from the caller storage
* (or from it's sub-storages) via given `Text` path.
*
* Path is treated like a
* [JSON pointer](https://tools.ietf.org/html/rfc6901)
* with an additional fix applied:
* If given path does not start with "/" character (like it is expected
* from a json pointer) - it will be added automatically.
* This means that "foo/bar" is treated like "/foo/bar" and
* "path" like "/path". However, empty `Text` is treated like itself (""),
* since it constitutes a valid JSON pointer (it will point at a caller
* collection itself).
*
* Acedia provides two collections:
* 1. `DynamicArray` is treated as a JSON array in the context of
* JSON pointers and passed variable names are treated as a `Text`
* representation of it's integer indices;
* 2. `AssociativeArray` is treated as a JSON object in the context of
* JSON pointers and passed variable names are treated as it's
* `Text` keys (to refer to an element with an empty key, use "/",
* since "" is treated as a JSON pointer and refers to
* the array itself).
* It is also possible to define your own collection type that will also be
* integrated with this method by making it a sub-class of `Collection` and
* appropriately defining `GetByText()` protected method.
*
* There is no requirement that all stored values must be reachable by
* this method (i.e. `AssociativeArray` only lets you access values with
* `Text` keys).
*
* @param jsonPointer Path, given by a JSON pointer.
* @return An item `jsonPointerAsText` is referring to (according to the above
* stated rules). `none` if such item does not exist.
*/
public final function AcediaObject GetItemBy(Text jsonPointerAsText)
{
local AcediaObject result;
local JSONPointer jsonPointer;
if (jsonPointerAsText == none) return none;
if (jsonPointerAsText.IsEmpty()) return self;
jsonPointer = _.json.Pointer(jsonPointerAsText);
result = GetItemByJSON(jsonPointer);
_.memory.Free(jsonPointer);
return result;
}
@ -134,7 +167,7 @@ public final function AcediaObject GetItemByPointer(Text jsonPointerAsText)
* Returns a `bool` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer()` for more information.
* See `GetItemBy()` for more information.
*
* Referred value must be stored as `BoolBox` or `BoolRef`
* (or one of their sub-classes) for this method to work.
@ -146,14 +179,14 @@ public final function AcediaObject GetItemByPointer(Text jsonPointerAsText)
* @return `bool` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function bool GetBoolByPointer(
public final function bool GetBoolBy(
Text jsonPointerAsText,
optional bool defaultValue)
{
local AcediaObject result;
local BoolBox asBox;
local BoolRef asRef;
result = GetItemByPointer(jsonPointerAsText);
result = GetItemBy(jsonPointerAsText);
if (result == none) {
return defaultValue;
}
@ -172,7 +205,7 @@ public final function bool GetBoolByPointer(
* Returns a `byte` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer()` for more information.
* See `GetItemBy()` for more information.
*
* Referred value must be stored as `ByteBox` or `ByteRef`
* (or one of their sub-classes) for this method to work.
@ -184,14 +217,14 @@ public final function bool GetBoolByPointer(
* @return `byte` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function byte GetByteByPointer(
public final function byte GetByteBy(
Text jsonPointerAsText,
optional byte defaultValue)
{
local AcediaObject result;
local ByteBox asBox;
local ByteRef asRef;
result = GetItemByPointer(jsonPointerAsText);
result = GetItemBy(jsonPointerAsText);
if (result == none) {
return defaultValue;
}
@ -210,7 +243,7 @@ public final function byte GetByteByPointer(
* Returns a `int` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer()` for more information.
* See `GetItemBy()` for more information.
*
* Referred value must be stored as `IntBox` or `IntRef`
* (or one of their sub-classes) for this method to work.
@ -222,14 +255,14 @@ public final function byte GetByteByPointer(
* @return `int` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function int GetIntByPointer(
public final function int GetIntBy(
Text jsonPointerAsText,
optional int defaultValue)
{
local AcediaObject result;
local IntBox asBox;
local IntRef asRef;
result = GetItemByPointer(jsonPointerAsText);
result = GetItemBy(jsonPointerAsText);
if (result == none) {
return defaultValue;
}
@ -248,7 +281,7 @@ public final function int GetIntByPointer(
* Returns a `float` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer()` for more information.
* See `GetItemBy()` for more information.
*
* Referred value must be stored as `FloatBox` or `FloatRef`
* (or one of their sub-classes) for this method to work.
@ -260,14 +293,14 @@ public final function int GetIntByPointer(
* @return `float` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function float GetFloatByPointer(
public final function float GetFloatBy(
Text jsonPointerAsText,
optional float defaultValue)
{
local AcediaObject result;
local FloatBox asBox;
local FloatRef asRef;
result = GetItemByPointer(jsonPointerAsText);
result = GetItemBy(jsonPointerAsText);
if (result == none) {
return defaultValue;
}
@ -286,7 +319,7 @@ public final function float GetFloatByPointer(
* Returns a `Text` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer()` for more information.
* See `GetItemBy()` for more information.
*
* Referred value must be stored as `Text` (or one of it's sub-classes,
* such as `MutableText`) for this method to work.
@ -295,16 +328,16 @@ public final function float GetFloatByPointer(
* @return `Text` value, stored at `jsonPointerAsText` or `none` if it
* is missing or has a different type.
*/
public final function Text GetTextByPointer(Text jsonPointerAsText)
public final function Text GetTextBy(Text jsonPointerAsText)
{
return Text(GetItemByPointer(jsonPointerAsText));
return Text(GetItemBy(jsonPointerAsText));
}
/**
* Returns an `AssociativeArray` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer()` for more information.
* See `GetItemBy()` for more information.
*
* Referred value must be stored as `AssociativeArray`
* (or one of it's sub-classes) for this method to work.
@ -314,17 +347,17 @@ public final function Text GetTextByPointer(Text jsonPointerAsText)
* @return `AssociativeArray` value, stored at `jsonPointerAsText` or
* `none` if it is missing or has a different type.
*/
public final function AssociativeArray GetAssociativeArrayByPointer(
public final function AssociativeArray GetAssociativeArrayBy(
Text jsonPointerAsText)
{
return AssociativeArray(GetItemByPointer(jsonPointerAsText));
return AssociativeArray(GetItemBy(jsonPointerAsText));
}
/**
* Returns an `DynamicArray` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by
* [JSON pointer](https://tools.ietf.org/html/rfc6901).
* See `GetItemByPointer()` for more information.
* See `GetItemBy()` for more information.
*
* Referred value must be stored as `DynamicArray`
* (or one of it's sub-classes) for this method to work.
@ -334,10 +367,210 @@ public final function AssociativeArray GetAssociativeArrayByPointer(
* @return `DynamicArray` value, stored at `jsonPointerAsText` or
* `none` if it is missing or has a different type.
*/
public final function DynamicArray GetDynamicArrayByPointer(
Text jsonPointerAsText)
public final function DynamicArray GetDynamicArrayBy(Text jsonPointerAsText)
{
return DynamicArray(GetItemBy(jsonPointerAsText));
}
/**
* Returns a `bool` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `BoolBox` or `BoolRef`
* (or one of their sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `bool` value.
* @param defaultValue Value to return in case `jsonPointer`
* does not point at any existing value or if that value does not have
* appropriate type.
* @return `bool` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function bool GetBoolByJSON(
JSONPointer jsonPointer,
optional bool defaultValue)
{
local AcediaObject result;
local BoolBox asBox;
local BoolRef asRef;
result = GetItemByJSON(jsonPointer);
if (result == none) {
return defaultValue;
}
asBox = BoolBox(result);
if (asBox != none) {
return asBox.Get();
}
asRef = BoolRef(result);
if (asRef != none) {
return asRef.Get();
}
return defaultValue;
}
/**
* Returns a `byte` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `ByteBox` or `ByteRef`
* (or one of their sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `byte` value.
* @param defaultValue Value to return in case `jsonPointer`
* does not point at any existing value or if that value does not have
* appropriate type.
* @return `byte` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function byte GetByteByJSON(
JSONPointer jsonPointer,
optional byte defaultValue)
{
local AcediaObject result;
local ByteBox asBox;
local ByteRef asRef;
result = GetItemByJSON(jsonPointer);
if (result == none) {
return defaultValue;
}
asBox = ByteBox(result);
if (asBox != none) {
return asBox.Get();
}
asRef = ByteRef(result);
if (asRef != none) {
return asRef.Get();
}
return defaultValue;
}
/**
* Returns a `int` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `IntBox` or `IntRef`
* (or one of their sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `int` value.
* @param defaultValue Value to return in case `jsonPointer`
* does not point at any existing value or if that value does not have
* appropriate type.
* @return `int` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function int GetIntByJSON(
JSONPointer jsonPointer,
optional int defaultValue)
{
local AcediaObject result;
local IntBox asBox;
local IntRef asRef;
result = GetItemByJSON(jsonPointer);
if (result == none) {
return defaultValue;
}
asBox = IntBox(result);
if (asBox != none) {
return asBox.Get();
}
asRef = IntRef(result);
if (asRef != none) {
return asRef.Get();
}
return defaultValue;
}
/**
* Returns a `float` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `FloatBox` or `FloatRef`
* (or one of their sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `float` value.
* @param defaultValue Value to return in case `jsonPointer`
* does not point at any existing value or if that value does not have
* appropriate type.
* @return `float` value, stored at `jsonPointerAsText` or `defaultValue` if it
* is missing or has a different type.
*/
public final function float GetFloatByJSON(
JSONPointer jsonPointer,
optional float defaultValue)
{
local AcediaObject result;
local FloatBox asBox;
local FloatRef asRef;
result = GetItemByJSON(jsonPointer);
if (result == none) {
return defaultValue;
}
asBox = FloatBox(result);
if (asBox != none) {
return asBox.Get();
}
asRef = FloatRef(result);
if (asRef != none) {
return asRef.Get();
}
return defaultValue;
}
/**
* Returns a `Text` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `Text` (or one of it's sub-classes,
* such as `MutableText`) for this method to work.
*
* @param jsonPointer JSON path to the `Text` value.
* @return `Text` value, stored at `jsonPointerAsText` or `none` if it
* is missing or has a different type.
*/
public final function Text GetTextByJSON(JSONPointer jsonPointer)
{
return Text(GetItemByJSON(jsonPointer));
}
/**
* Returns an `AssociativeArray` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `AssociativeArray`
* (or one of it's sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `AssociativeArray` value.
* @return `AssociativeArray` value, stored at `jsonPointerAsText` or
* `none` if it is missing or has a different type.
*/
public final function AssociativeArray GetAssociativeArrayByJSON(
JSONPointer jsonPointer)
{
return AssociativeArray(GetItemByJSON(jsonPointer));
}
/**
* Returns an `DynamicArray` value stored (in the caller `Collection` or
* one of it's sub-collections) pointed by JSON pointer.
* See `GetItemByJSON()` for more information.
*
* Referred value must be stored as `DynamicArray`
* (or one of it's sub-classes) for this method to work.
*
* @param jsonPointer JSON path to the `DynamicArray` value.
* @return `DynamicArray` value, stored at `jsonPointerAsText` or
* `none` if it is missing or has a different type.
*/
public final function DynamicArray GetDynamicArrayByJSON(
JSONPointer jsonPointer)
{
return DynamicArray(GetItemByPointer(jsonPointerAsText));
return DynamicArray(GetItemByJSON(jsonPointer));
}
defaultproperties

62
sources/Data/Collections/Tests/TEST_CollectionsMixed.uc

@ -25,75 +25,75 @@ var protected const string complexJSONObject;
protected static function TESTS()
{
Context("Testing accessing collections by JSON pointers.");
Test_GetByPointer();
Test_GetTypeByPointer();
Test_GetBy();
Test_GetTypeBy();
}
protected static function Test_GetByPointer()
protected static function Test_GetBy()
{
local AcediaObject result;
local AssociativeArray obj;
Issue("`GetItemByPointer()` does not return correct objects.");
Issue("`GetItemBy()` does not return correct objects.");
obj = __().json.ParseObjectWith(
__().text.ParseString(default.complexJSONObject));
TEST_ExpectTrue(obj.GetItemByPointer(P("")) == obj);
result = obj.GetItemByPointer(P("/innerObject/array/1"));
TEST_ExpectTrue(obj.GetItemBy(P("")) == obj);
result = obj.GetItemBy(P("/innerObject/array/1"));
TEST_ExpectNotNone(BoolBox(result));
TEST_ExpectTrue(BoolBox(result).Get() == false);
result = obj.GetItemByPointer(P("/innerObject/array/3/maybe"));
result = obj.GetItemBy(P("/innerObject/array/3/maybe"));
TEST_ExpectNotNone(FloatBox(result));
TEST_ExpectTrue(FloatBox(result).Get() == 0.003);
Issue("`GetItemByPointer()` does not return correct objects when using"
Issue("`GetItemBy()` does not return correct objects when using"
@ "'~'-escaped sequences.");
result = obj.GetItemByPointer(P("/another~01var"));
result = obj.GetItemBy(P("/another~01var"));
TEST_ExpectNotNone(Text(result));
TEST_ExpectTrue(Text(result).ToPlainString() == "aye!");
result = obj.GetItemByPointer(P("/innerObject/one more/no~1pe"));
result = obj.GetItemBy(P("/innerObject/one more/no~1pe"));
TEST_ExpectNotNone(IntBox(result));
TEST_ExpectTrue(IntBox(result).Get() == 324532);
TEST_ExpectNotNone(
DynamicArray(obj.GetItemByPointer(P("/innerObject/array"))));
DynamicArray(obj.GetItemBy(P("/innerObject/array"))));
Issue("`GetItemByPointer()` does not return `none` for incorrect pointers");
TEST_ExpectNone(obj.GetItemByPointer(P("//")));
TEST_ExpectNone(obj.GetItemByPointer(P("/innerObject/array/5")));
TEST_ExpectNone(obj.GetItemByPointer(P("/innerObject/array/-1")));
TEST_ExpectNone(obj.GetItemByPointer(P("/innerObject/array/")));
Issue("`GetItemBy()` does not return `none` for incorrect pointers");
TEST_ExpectNone(obj.GetItemBy(P("//")));
TEST_ExpectNone(obj.GetItemBy(P("/innerObject/array/5")));
TEST_ExpectNone(obj.GetItemBy(P("/innerObject/array/-1")));
TEST_ExpectNone(obj.GetItemBy(P("/innerObject/array/")));
}
protected static function Test_GetTypeByPointer()
protected static function Test_GetTypeBy()
{
local AssociativeArray obj;
obj = __().json.ParseObjectWith(
__().text.ParseString(default.complexJSONObject));
obj.SetItem(P("byte"), __().ref.byte(56));
Issue("`Get<Type>ByPointer()` methods do not return correct"
Issue("`Get<Type>By()` methods do not return correct"
@ "existing values.");
TEST_ExpectTrue(obj.GetAssociativeArrayByPointer(P("")) == obj);
TEST_ExpectNotNone(obj.GetDynamicArrayByPointer(P("/innerObject/array")));
TEST_ExpectTrue(obj.GetAssociativeArrayBy(P("")) == obj);
TEST_ExpectNotNone(obj.GetDynamicArrayBy(P("/innerObject/array")));
TEST_ExpectTrue(
obj.GetBoolByPointer(P("/innerObject/array/1"), true)
obj.GetBoolBy(P("/innerObject/array/1"), true)
== false);
TEST_ExpectTrue(obj.GetByteByPointer(P("/byte"), 128) == 56);
TEST_ExpectTrue(obj.GetIntByPointer(P("/innerObject/my_int")) == -9823452);
TEST_ExpectTrue(obj.GetByteBy(P("/byte"), 128) == 56);
TEST_ExpectTrue(obj.GetIntBy(P("/innerObject/my_int")) == -9823452);
TEST_ExpectTrue(obj
.GetFloatByPointer(P("/innerObject/array/4"), 2.34)
.GetFloatBy(P("/innerObject/array/4"), 2.34)
== 56.6);
TEST_ExpectTrue(obj
.GetTextByPointer(P("/innerObject/one more/o rly?")).ToPlainString()
.GetTextBy(P("/innerObject/one more/o rly?")).ToPlainString()
== "ya rly");
Issue("`Get<Type>ByPointer()` methods do not return default value for"
Issue("`Get<Type>By()` methods do not return default value for"
@ "incorrect pointers.");
TEST_ExpectTrue(
obj.GetBoolByPointer(P("/innerObject/array/20"), true)
obj.GetBoolBy(P("/innerObject/array/20"), true)
== true);
TEST_ExpectTrue(obj.GetByteByPointer(P("/byte/"), 128) == 128);
TEST_ExpectTrue(obj.GetIntByPointer(P("/innerObject/my int")) == 0);
TEST_ExpectTrue(obj.GetByteBy(P("/byte/"), 128) == 128);
TEST_ExpectTrue(obj.GetIntBy(P("/innerObject/my int")) == 0);
TEST_ExpectTrue(obj
.GetFloatByPointer(P("/innerObject/array"), 2.34)
.GetFloatBy(P("/innerObject/array"), 2.34)
== 2.34);
TEST_ExpectNone(obj.GetTextByPointer(P("")));
TEST_ExpectNone(obj.GetTextBy(P("")));
}
defaultproperties

46
sources/Data/Database/Tests/TEST_LocalDatabase.uc

@ -242,19 +242,19 @@ protected static function SubTest_LoadingPreparedSuccessRoot(
TEST_ExpectTrue(default.resultType == DBR_Success);
TEST_ExpectTrue(default.resultData.GetLength() == 1);
TEST_ExpectTrue(default.resultData
.GetAssociativeArrayByPointer(P("/web-app")).GetLength() == 3);
.GetAssociativeArrayBy(P("/web-app")).GetLength() == 3);
TEST_ExpectTrue(default.resultData
.GetDynamicArrayByPointer(P("/web-app/servlet")).GetLength() == 5);
.GetDynamicArrayBy(P("/web-app/servlet")).GetLength() == 5);
TEST_ExpectTrue(default.resultData
.GetAssociativeArrayByPointer(P("/web-app/servlet/0/init-param"))
.GetAssociativeArrayBy(P("/web-app/servlet/0/init-param"))
.GetLength() == 42);
TEST_ExpectTrue(default.resultData
.GetTextByPointer(P("/web-app/servlet/2/servlet-class"))
.GetTextBy(P("/web-app/servlet/2/servlet-class"))
.ToPlainString() == "org.cofax.cds.AdminServlet");
TEST_ExpectFalse(default.resultData
.GetBoolByPointer(P("/web-app/servlet/0/init-param/useJSP")));
.GetBoolBy(P("/web-app/servlet/0/init-param/useJSP")));
TEST_ExpectTrue(default.resultData
.GetIntByPointer(P("/web-app/servlet/0/init-param/dataStoreMaxConns"))
.GetIntBy(P("/web-app/servlet/0/init-param/dataStoreMaxConns"))
== 100);
}
@ -599,14 +599,14 @@ protected static function SubTest_WritingDataCheck(LocalDatabaseInstance db)
TEST_ExpectTrue(default.resultType == DBR_Success);
TEST_ExpectTrue(default.resultData.GetLength() == 2);
TEST_ExpectTrue(
default.resultData.GetTextByPointer(P("/B/A/1//2")).ToPlainString()
default.resultData.GetTextBy(P("/B/A/1//2")).ToPlainString()
== "huh");
TEST_ExpectTrue(
default.resultData.GetTextByPointer(P("/A")).ToPlainString()
default.resultData.GetTextBy(P("/A")).ToPlainString()
== "simpleValue");
TEST_ExpectTrue(default.resultData.GetFloatByPointer(P("/B/B")) == 11.12);
TEST_ExpectTrue(default.resultData.GetBoolByPointer(P("/B/A/0"), false));
TEST_ExpectNone(default.resultData.GetItemByPointer(P("/B/A/1//1")));
TEST_ExpectTrue(default.resultData.GetFloatBy(P("/B/B")) == 11.12);
TEST_ExpectTrue(default.resultData.GetBoolBy(P("/B/A/0"), false));
TEST_ExpectNone(default.resultData.GetItemBy(P("/B/A/1//1")));
}
protected static function SubTest_WritingDataCheck_Immutable(
@ -617,16 +617,16 @@ protected static function SubTest_WritingDataCheck_Immutable(
// Full db read
ReadFromDB(db, "");
TEST_ExpectTrue(
default.resultData.GetItemByPointer(P("/B/A/1//2")).class
default.resultData.GetItemBy(P("/B/A/1//2")).class
== class'Text');
TEST_ExpectTrue(
default.resultData.GetItemByPointer(P("/A")).class
default.resultData.GetItemBy(P("/A")).class
== class'Text');
TEST_ExpectTrue(
default.resultData.GetItemByPointer(P("/B/B")).class
default.resultData.GetItemBy(P("/B/B")).class
== class'FloatBox');
TEST_ExpectTrue(
default.resultData.GetItemByPointer(P("/B/A/0")).class
default.resultData.GetItemBy(P("/B/A/0")).class
== class'BoolBox');
}
@ -640,16 +640,16 @@ protected static function SubTest_WritingDataCheck_Mutable(
task.connect = DBReadingHandler;
task.TryCompleting();
TEST_ExpectTrue(
default.resultData.GetItemByPointer(P("/B/A/1//2")).class
default.resultData.GetItemBy(P("/B/A/1//2")).class
== class'MutableText');
TEST_ExpectTrue(
default.resultData.GetItemByPointer(P("/A")).class
default.resultData.GetItemBy(P("/A")).class
== class'MutableText');
TEST_ExpectTrue(
default.resultData.GetItemByPointer(P("/B/B")).class
default.resultData.GetItemBy(P("/B/B")).class
== class'FloatRef');
TEST_ExpectTrue(
default.resultData.GetItemByPointer(P("/B/A/0")).class
default.resultData.GetItemBy(P("/B/A/0")).class
== class'BoolRef');
}
@ -1086,12 +1086,12 @@ protected static function SubTest_IncrementArray(LocalDatabaseInstance db)
protected static function CheckValuesAfterIncrement(AssociativeArray root)
{
local DynamicArray jsonArray;
TEST_ExpectTrue(root.GetBoolByPointer(P("/D")));
TEST_ExpectTrue(root.GetFloatByPointer(P("/B/B")) == 10.12);
TEST_ExpectTrue(root.GetBoolBy(P("/D")));
TEST_ExpectTrue(root.GetFloatBy(P("/B/B")) == 10.12);
TEST_ExpectTrue(
root.GetTextByPointer(P("/A")).ToPlainString()
root.GetTextBy(P("/A")).ToPlainString()
== "simpleValue!?");
jsonArray = root.GetDynamicArrayByPointer(P("/B/A"));
jsonArray = root.GetDynamicArrayBy(P("/B/A"));
TEST_ExpectTrue(jsonArray.GetBool(0));
TEST_ExpectNotNone(jsonArray.GetAssociativeArray(1));
TEST_ExpectTrue(jsonArray.GetText(2).ToPlainString() == "huh");

Loading…
Cancel
Save