Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests
Browse files Browse the repository at this point in the history
beckdave committed Feb 10, 2024
1 parent 5645e4e commit 704a541
Showing 33 changed files with 718 additions and 624 deletions.
4 changes: 2 additions & 2 deletions csharp/src/remoteentity/RemoteEntityFormatJson.cs
Original file line number Diff line number Diff line change
@@ -38,8 +38,8 @@ public class RemoteEntityFormatJson : IRemoteEntityFormat

static readonly int JSONBLOCKSIZE = 512;
static readonly byte[] ARRAY_BEGIN = { (byte)'[' };
static readonly byte[] ARRAY_END = { (byte)']', (byte)'\t' };
static readonly byte[] ARRAY_END_NO_DATA = { (byte)',', (byte)'\t', (byte)'{', (byte)'}', (byte)']', (byte)'\t' };
static readonly byte[] ARRAY_END = { (byte)']', (byte)'\t', (byte)'\t' };
static readonly byte[] ARRAY_END_NO_DATA = { (byte)',', (byte)'\t', (byte)'{', (byte)'}', (byte)']', (byte)'\t', (byte)'\t' };
static readonly byte[] DELIMITER_HEADER_PAYLOAD = { (byte)',', (byte)'\t' };
static readonly byte[] EMPTY_PAYLOAD = { (byte)'{', (byte)'}' };

71 changes: 29 additions & 42 deletions csharp/src/serializevariant/VariantToVarValue.cs
Original file line number Diff line number Diff line change
@@ -29,42 +29,13 @@ public void EnterLeaf(Variant var, int type, int index, int level, int size, str
Variant variant = var;

Debug.Assert(m_structVarValue != null);
if (m_fieldStruct == null)
{
m_fieldStruct = m_structVarValue.GetFieldByName("valstruct");
}
MetaField? fieldStruct = m_fieldStruct;
Debug.Assert(fieldStruct != null);

if (m_fieldStructWithoutArray == null)
{
m_fieldStructWithoutArray = fieldStruct.FieldWithoutArray;
}
MetaField? fieldStructWithoutArray = m_fieldStructWithoutArray;
Debug.Assert(fieldStructWithoutArray != null);

if (m_fieldList == null)
{
m_fieldList = m_structVarValue.GetFieldByName("vallist");
}
MetaField? fieldList = m_fieldList;
Debug.Assert(fieldList != null);

if (m_fieldListWithoutArray == null)
{
m_fieldListWithoutArray = fieldList.FieldWithoutArray;
}
MetaField? fieldListWithoutArray = m_fieldListWithoutArray;
Debug.Assert(fieldListWithoutArray != null);

MetaField? field = (type == VariantValueStruct.VARTYPE_STRUCT) ? fieldStruct : fieldList;
Debug.Assert(field != null);
MetaField? fieldWithoutArray = field.FieldWithoutArray;
Debug.Assert(fieldWithoutArray != null);

if (level > 0)
{
m_visitor.EnterStruct(fieldWithoutArray);
if (m_fieldStack.Count() != 0) // empty would be an error
{
m_visitor.EnterStruct(m_fieldStack.Last());
}
}

if (name.Length != 0)
@@ -416,15 +387,18 @@ public void EnterLeaf(Variant var, int type, int index, int level, int size, str

if (level > 0)
{
m_visitor.ExitStruct(fieldWithoutArray);
if (m_fieldStack.Count() != 0) // empty would be an error
{
m_visitor.ExitStruct(m_fieldStack.Last());
}
}
}
public void EnterStruct(Variant variant, int type, int index, int level, int size, string name)
{
if (m_fieldStruct == null)
{
Debug.Assert(m_structVarValue != null);
m_fieldList = m_structVarValue.GetFieldByName("valstruct");
m_fieldStruct = m_structVarValue.GetFieldByName("valstruct");
}
MetaField? fieldStruct = m_fieldStruct;
Debug.Assert(fieldStruct != null);
@@ -458,7 +432,10 @@ public void EnterStruct(Variant variant, int type, int index, int level, int siz

if (level > 0)
{
m_visitor.EnterStruct(fieldWithoutArray);
if (m_fieldStack.Count() != 0) // empty would be an error
{
m_visitor.EnterStruct(m_fieldStack.Last());
}
}

Debug.Assert(m_structVarValue != null);
@@ -485,13 +462,14 @@ public void EnterStruct(Variant variant, int type, int index, int level, int siz
m_visitor.EnterInt32(fieldIndex, (int)VarValueType2Index.VARVALUETYPE_VARIANTLIST);
}
m_visitor.EnterArrayStruct(field);
m_fieldStack.Add(fieldWithoutArray);
}
public void ExitStruct(Variant variant, int type, int index, int level, int size, string name)
{
if (m_fieldStruct == null)
{
Debug.Assert(m_structVarValue != null);
m_fieldList = m_structVarValue.GetFieldByName("valstruct");
m_fieldStruct = m_structVarValue.GetFieldByName("valstruct");
}
MetaField? fieldStruct = m_fieldStruct;
Debug.Assert(fieldStruct != null);
@@ -520,12 +498,20 @@ public void ExitStruct(Variant variant, int type, int index, int level, int size

MetaField? field = (type == VariantValueStruct.VARTYPE_STRUCT) ? fieldStruct : fieldList;
Debug.Assert(field != null);
MetaField? fieldWithoutArray = field.FieldWithoutArray;
Debug.Assert(fieldWithoutArray != null);

if (m_fieldStack.Count() != 0)
{
m_fieldStack.RemoveAt(m_fieldStack.Count() - 1);
}

m_visitor.ExitArrayStruct(field);

if (level > 0)
{
m_visitor.ExitStruct(fieldWithoutArray);
if (m_fieldStack.Count() != 0) // empty would be an error
{
m_visitor.ExitStruct(m_fieldStack.Last());
}
}
}
public void EnterList(Variant variant, int type, int index, int level, int size, string name)
@@ -539,12 +525,13 @@ public void ExitList(Variant variant, int type, int index, int level, int size,

Variant m_variant;
IParserVisitor m_visitor;
readonly IList<MetaField> m_fieldStack = new List<MetaField>();
static MetaStruct? m_structVarValue = null;

static MetaField? m_fieldStruct = null;
static MetaField? m_fieldStructWithoutArray = null;
static MetaField? m_fieldName = null;
static MetaField? m_fieldType = null;
// static MetaField? m_fieldIndex = null;
static MetaField? m_fieldBool = null;
static MetaField? m_fieldInt8 = null;
static MetaField? m_fieldUInt8 = null;
@@ -560,7 +547,7 @@ public void ExitList(Variant variant, int type, int index, int level, int size,
static MetaField? m_fieldBytes = null;
static MetaField? m_fieldArrayBool = null;
static MetaField? m_fieldArrayInt8 = null;
static MetaField? m_fieldArrayUInt8 = null;
// static MetaField? m_fieldArrayUInt8 = null;
static MetaField? m_fieldArrayInt16 = null;
static MetaField? m_fieldArrayUInt16 = null;
static MetaField? m_fieldArrayInt32 = null;
4 changes: 2 additions & 2 deletions csharp/src/variant/VariantValueStruct.cs
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ public int Length

public void Accept(IVariantVisitor visitor, Variant variant, int index, int level, int size, string name)
{
visitor.EnterList(variant, VARTYPE_STRUCT, index, level, size, name);
visitor.EnterStruct(variant, VARTYPE_STRUCT, index, level, size, name);
++level;
int i = 0;
int subsize = m_value.Count;
@@ -185,7 +185,7 @@ public void Accept(IVariantVisitor visitor, Variant variant, int index, int leve
i++;
}
--level;
visitor.ExitList(variant, VARTYPE_STRUCT, index, level, size, name);
visitor.ExitStruct(variant, VARTYPE_STRUCT, index, level, size, name);
}

public int VarType { get { return VARTYPE_STRUCT; } }
72 changes: 39 additions & 33 deletions csharp/test/testfinalmq/TestParserStruct.cs
Original file line number Diff line number Diff line change
@@ -25,9 +25,11 @@ public class TestParserStruct : IDisposable
MetaField? m_fieldValue2 = null;
MetaField? m_fieldValueInt32 = null;
MetaField? m_fieldName = null;
MetaField? m_fieldType = null;
MetaField? m_fieldIndex = null;
MetaField? m_fieldInt32 = null;
MetaField? m_fieldString = null;
MetaField? m_fieldStruct = null;
MetaField? m_fieldStructWithoutArray = null;
MetaField? m_fieldList = null;
MetaField? m_fieldListWithoutArray = null;

@@ -48,16 +50,20 @@ public TestParserStruct()
Debug.Assert(structVarVariant != null);

m_fieldName = structVarVariant.GetFieldByName("name");
m_fieldType = structVarVariant.GetFieldByName("type");
m_fieldIndex = structVarVariant.GetFieldByName("index");
m_fieldInt32 = structVarVariant.GetFieldByName("valint32");
m_fieldString = structVarVariant.GetFieldByName("valstring");
m_fieldStruct = structVarVariant.GetFieldByName("valstruct");
m_fieldStructWithoutArray = MetaDataGlobal.Instance.GetArrayField(m_fieldStruct!);
m_fieldList = structVarVariant.GetFieldByName("vallist");
m_fieldListWithoutArray = MetaDataGlobal.Instance.GetArrayField(m_fieldList!);

Debug.Assert(m_fieldName != null);
Debug.Assert(m_fieldType != null);
Debug.Assert(m_fieldIndex != null);
Debug.Assert(m_fieldInt32 != null);
Debug.Assert(m_fieldString != null);
Debug.Assert(m_fieldStruct != null);
Debug.Assert(m_fieldStructWithoutArray != null);
Debug.Assert(m_fieldList != null);
Debug.Assert(m_fieldListWithoutArray != null);
}
@@ -624,7 +630,7 @@ public void TestVariantEmpty()

mockVisitor.Verify(x => x.StartStruct(It.IsAny<MetaStruct>()), Times.Once);
mockVisitor.Verify(x => x.EnterStruct(m_fieldValue!), Times.Once);
mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_NONE), Times.Exactly(2));
mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_NONE), Times.Exactly(2));
mockVisitor.Verify(x => x.ExitStruct(m_fieldValue!), Times.Once);

mockVisitor.Verify(x => x.EnterInt32(m_fieldValueInt32!, 0), Times.Once);
@@ -650,14 +656,14 @@ public void TestVariantString()

mockVisitor.Verify(x => x.StartStruct(It.IsAny<MetaStruct>()), Times.Once);
mockVisitor.Verify(x => x.EnterStruct(m_fieldValue!), Times.Once);
mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_STRING), Times.Exactly(1));
mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_STRING), Times.Exactly(1));
mockVisitor.Verify(x => x.EnterString(m_fieldString!, VALUE_STRING), Times.Exactly(1));
mockVisitor.Verify(x => x.ExitStruct(m_fieldValue!), Times.Once);

mockVisitor.Verify(x => x.EnterInt32(m_fieldValueInt32!, 0), Times.Once);

mockVisitor.Verify(x => x.EnterStruct(m_fieldValue2!), Times.Once);
mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_NONE), Times.Once);
mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_NONE), Times.Once);
mockVisitor.Verify(x => x.ExitStruct(m_fieldValue2!), Times.Once);

mockVisitor.Verify(x => x.Finished(), Times.Once);
@@ -680,61 +686,61 @@ public void TestVariantStruct()
mockVisitor.Verify(x => x.StartStruct(It.IsAny<MetaStruct>()), Times.Exactly(1));
// VariantStruct{ {"value", VariantStruct{
mockVisitor.Verify(x => x.EnterStruct(m_fieldValue!), Times.Once);
mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_VARIANTSTRUCT), Times.Exactly(2));
mockVisitor.Verify(x => x.EnterArrayStruct(m_fieldList!), Times.Exactly(3));
mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_VARIANTSTRUCT), Times.Exactly(2));
mockVisitor.Verify(x => x.EnterArrayStruct(m_fieldStruct!), Times.Exactly(2));
// {"key1", VariantList{
mockVisitor.Verify(x => x.EnterStruct(m_fieldListWithoutArray!), Times.Exactly(7));
mockVisitor.Verify(x => x.EnterStruct(m_fieldStructWithoutArray!), Times.Exactly(5));
mockVisitor.Verify(x => x.EnterString(m_fieldName!, "key1"), Times.Exactly(1));
mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_VARIANTLIST), Times.Exactly(1));
// mockVisitor.Verify(x => x.EnterArrayStruct(m_fieldList!), Times.Once);
mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_VARIANTLIST), Times.Exactly(1));
mockVisitor.Verify(x => x.EnterArrayStruct(m_fieldList!), Times.Once);
// 2
// mockVisitor.Verify(x => x.EnterStruct(m_fieldListWithoutArray!), Times.Once);
mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_INT32), Times.Exactly(2));
mockVisitor.Verify(x => x.EnterStruct(m_fieldListWithoutArray!), Times.Exactly(2));
mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_INT32), Times.Exactly(2));
mockVisitor.Verify(x => x.EnterInt32(m_fieldInt32!, 2), Times.Exactly(1));
mockVisitor.Verify(x => x.ExitStruct(m_fieldListWithoutArray!), Times.Exactly(7));
mockVisitor.Verify(x => x.ExitStruct(m_fieldListWithoutArray!), Times.Exactly(2));
// , std::string("Hello")
// mockVisitor.Verify(x => x.EnterStruct(m_fieldListWithoutArray!), Times.Once);
mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_STRING), Times.Exactly(2));
mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_STRING), Times.Exactly(2));
mockVisitor.Verify(x => x.EnterString(m_fieldString!, "Hello"), Times.Exactly(1));
// mockVisitor.Verify(x => x.ExitStruct(m_fieldListWithoutArray!), Times.Once);
// }
mockVisitor.Verify(x => x.ExitArrayStruct(m_fieldList!), Times.Exactly(3));
// mockVisitor.Verify(x => x.ExitStruct(m_fieldListWithoutArray!), Times.Once);
mockVisitor.Verify(x => x.ExitArrayStruct(m_fieldList!), Times.Exactly(1));
mockVisitor.Verify(x => x.ExitStruct(m_fieldStructWithoutArray!), Times.Exactly(5));

// {"key2", VariantStruct{
// mockVisitor.Verify(x => x.EnterStruct(m_fieldListWithoutArray!), Times.Once);
// mockVisitor.Verify(x => x.EnterStruct(m_fieldStructWithoutArray!), Times.Once);
mockVisitor.Verify(x => x.EnterString(m_fieldName!, "key2"), Times.Exactly(1));
// mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_STRUCT), Times.Exactly(1));
// mockVisitor.Verify(x => x.EnterArrayStruct(m_fieldList!), Times.Exactly(1));
// mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_STRUCT), Times.Exactly(1));
// mockVisitor.Verify(x => x.EnterArrayStruct(m_fieldStruct!), Times.Exactly(1));
// {"a", 3},
// mockVisitor.Verify(x => x.EnterStruct(m_fieldListWithoutArray!), Times.Once);
// mockVisitor.Verify(x => x.EnterStruct(m_fieldStructWithoutArray!), Times.Once);
mockVisitor.Verify(x => x.EnterString(m_fieldName!, "a"), Times.Exactly(1));
// mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_INT32), Times.Exactly(1));
// mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_INT32), Times.Exactly(1));
mockVisitor.Verify(x => x.EnterInt32(m_fieldInt32!, 3), Times.Exactly(1));
// mockVisitor.Verify(x => x.ExitStruct(m_fieldListWithoutArray!), Times.Once);
// mockVisitor.Verify(x => x.ExitStruct(m_fieldStructWithoutArray!), Times.Once);
// {"b", std::string("Hi")}
// mockVisitor.Verify(x => x.EnterStruct(m_fieldListWithoutArray!), Times.Once);
// mockVisitor.Verify(x => x.EnterStruct(m_fieldStructWithoutArray!), Times.Once);
mockVisitor.Verify(x => x.EnterString(m_fieldName!, "b"), Times.Exactly(1));
// mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_STRING), Times.Exactly(1));
// mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_STRING), Times.Exactly(1));
mockVisitor.Verify(x => x.EnterString(m_fieldString!, "Hi"), Times.Exactly(1));
// mockVisitor.Verify(x => x.ExitStruct(m_fieldListWithoutArray!), Times.Once);
// mockVisitor.Verify(x => x.ExitStruct(m_fieldStructWithoutArray!), Times.Once);
// }
// mockVisitor.Verify(x => x.ExitArrayStruct(m_fieldList!), Times.Once);
// mockVisitor.Verify(x => x.ExitStruct(m_fieldListWithoutArray!), Times.Once);
mockVisitor.Verify(x => x.ExitArrayStruct(m_fieldStruct!), Times.Exactly(2));
// mockVisitor.Verify(x => x.ExitStruct(m_fieldStructWithoutArray!), Times.Once);

// {
// mockVisitor.Verify(x => x.EnterStruct(m_fieldListWithoutArray!), Times.Once);
// mockVisitor.Verify(x => x.EnterStruct(m_fieldStructWithoutArray!), Times.Once);
mockVisitor.Verify(x => x.EnterString(m_fieldName!, "key3"), Times.Exactly(1));
mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_NONE), Times.Exactly(2));
// mockVisitor.Verify(x => x.ExitStruct(m_fieldListWithoutArray!), Times.Once);
mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_NONE), Times.Exactly(2));
// mockVisitor.Verify(x => x.ExitStruct(m_fieldStructWithoutArray!), Times.Once);
// }}
// mockVisitor.Verify(x => x.ExitArrayStruct(m_fieldList!), Times.Once);
// mockVisitor.Verify(x => x.ExitArrayStruct(m_fieldStruct!), Times.Once);
mockVisitor.Verify(x => x.ExitStruct(m_fieldValue!), Times.Once);

mockVisitor.Verify(x => x.EnterInt32(m_fieldValueInt32!, 0), Times.Exactly(1));

mockVisitor.Verify(x => x.EnterStruct(m_fieldValue2!), Times.Once);
// mockVisitor.Verify(x => x.EnterEnum(m_fieldType!, (int)VarValueType2Index.VARVALUETYPE_NONE), Times.Exactly(1));
// mockVisitor.Verify(x => x.EnterInt32(m_fieldIndex!, (int)VarValueType2Index.VARVALUETYPE_NONE), Times.Exactly(1));
mockVisitor.Verify(x => x.ExitStruct(m_fieldValue2!), Times.Once);

mockVisitor.Verify(x => x.Finished(), Times.Exactly(1));
Loading

0 comments on commit 704a541

Please sign in to comment.