Added unit tests, Fixed syntax issues in include

This commit is contained in:
2026-10-14 20:14:15 +02:00
parent 554636ec43
commit 63ebb4281d
9 changed files with 332 additions and 134 deletions
+1
View File
@@ -17,3 +17,4 @@
Trash/
*.7z
*.zip
/spec*
-1
View File
@@ -66,7 +66,6 @@ Enumeration _MsgPack_DataTypes
#MsgPack_DataTypes_Binary
#MsgPack_DataTypes_Array
#MsgPack_DataTypes_Map
#MsgPack_DataTypes_Ext
#MsgPack_DataTypes_Extension
EndEnumeration
+38 -36
View File
@@ -71,6 +71,7 @@ Procedure.q _MsgPackGetValueDynamicSize_4After(*MsgPackData.MsgPackData)
ProcedureReturn EndianSwapL(PeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
EndProcedure
; FIXME: Rename the VariableSize to InlinedSize, the name is dogshit and doesn not convey what it represents, AT ALL !!!
Procedure _MsgPackGetValueMetaInfo(*MsgPackData.MsgPackData, ExaminedDataType.MsgPack_FormatCode, *VariableSizeQ = #Null, *ValueStartOffsetB = #Null)
CompilerIf Not #MsgPack_DisableNullChecks
If Not *MsgPackData
@@ -89,12 +90,13 @@ Procedure _MsgPackGetValueMetaInfo(*MsgPackData.MsgPackData, ExaminedDataType.Ms
PokeQ(*VariableSizeQ, _MsgPackGetValueDynamicSize_Within(*MsgPackData, %01111111))
EndIf
If *ValueStartOffsetB <> #Null
; FIXME: Is this right ?!?
PokeB(*ValueStartOffsetB, 1)
EndIf
ProcedureReturn #True
Case #MsgPack_FormatCode_FixStr:
Case #MsgPack_FormatCode_FixIntNegative:
Case #MsgPack_FormatCode_FixStr,
#MsgPack_FormatCode_FixIntNegative:
If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetValueDynamicSize_Within(*MsgPackData, %00011111))
EndIf
@@ -103,8 +105,8 @@ Procedure _MsgPackGetValueMetaInfo(*MsgPackData.MsgPackData, ExaminedDataType.Ms
EndIf
ProcedureReturn #True
Case #MsgPack_FormatCode_FixArray:
Case #MsgPack_FormatCode_FixMap:
Case #MsgPack_FormatCode_FixArray,
#MsgPack_FormatCode_FixMap:
If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetValueDynamicSize_Within(*MsgPackData, %00001111))
EndIf
@@ -113,39 +115,39 @@ Procedure _MsgPackGetValueMetaInfo(*MsgPackData.MsgPackData, ExaminedDataType.Ms
EndIf
ProcedureReturn #True
Case #MsgPack_FormatCode_Ext8:
; TODO: Check if it should it add +1 to *ValueStartOffsetB for extensions ?
Case #MsgPack_FormatCode_Str8:
Case #MsgPack_FormatCode_Bin8:
If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetValueDynamicSize_1After(*MsgPackData))
EndIf
If *ValueStartOffsetB <> #Null
PokeB(*ValueStartOffsetB, 2)
EndIf
ProcedureReturn #True
Case #MsgPack_FormatCode_Ext16:
; TODO: Check if it should it add +1 to *ValueStartOffsetB for extensions ?
Case #MsgPack_FormatCode_Str16:
Case #MsgPack_FormatCode_Bin16:
Case #MsgPack_FormatCode_Array16:
Case #MsgPack_FormatCode_Map16:
If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetValueDynamicSize_2After(*MsgPackData))
EndIf
If *ValueStartOffsetB <> #Null
PokeB(*ValueStartOffsetB, 3)
EndIf
ProcedureReturn #True
Case #MsgPack_FormatCode_Ext32:
; TODO: Check if it should it add +1 to *ValueStartOffsetB for extensions ?
Case #MsgPack_FormatCode_Str32:
Case #MsgPack_FormatCode_Bin32:
Case #MsgPack_FormatCode_Array32:
Case #MsgPack_FormatCode_Map32:
If *VariableSizeQ <> #Null
Case #MsgPack_FormatCode_Ext8,
#MsgPack_FormatCode_Str8,
#MsgPack_FormatCode_Bin8:
If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetValueDynamicSize_1After(*MsgPackData))
EndIf
If *ValueStartOffsetB <> #Null
PokeB(*ValueStartOffsetB, 2)
EndIf
ProcedureReturn #True
; TODO: Check if it should it add +1 to *ValueStartOffsetB for extensions ?
Case #MsgPack_FormatCode_Ext16,
#MsgPack_FormatCode_Str16,
#MsgPack_FormatCode_Bin16,
#MsgPack_FormatCode_Array16,
#MsgPack_FormatCode_Map16:
If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetValueDynamicSize_2After(*MsgPackData))
EndIf
If *ValueStartOffsetB <> #Null
PokeB(*ValueStartOffsetB, 3)
EndIf
ProcedureReturn #True
; TODO: Check if it should it add +1 to *ValueStartOffsetB for extensions ?
Case #MsgPack_FormatCode_Ext32,
#MsgPack_FormatCode_Str32,
#MsgPack_FormatCode_Bin32,
#MsgPack_FormatCode_Array32,
#MsgPack_FormatCode_Map32:
If *VariableSizeQ <> #Null
PokeQ(*VariableSizeQ, _MsgPackGetValueDynamicSize_4After(*MsgPackData))
EndIf
If *ValueStartOffsetB <> #Null
+66 -70
View File
@@ -34,8 +34,8 @@ XIncludeFile "./_Commons.pbi"
;-> Format Codes
Procedure.MsgPack_FormatCode MsgPackGetFormatCode(*MsgPackData.MsgPackData)
Protected DataFormatCode.MsgPack_FormatCode
Protected DataFormatCode.MsgPack_FormatCode
If Not *MsgPackData
DebuggerError("A #Null MsgPackData pointer was passed !")
ProcedureReturn #MsgPack_FormatCode_Invalid
@@ -62,9 +62,9 @@ Procedure.MsgPack_FormatCode MsgPackGetFormatCode(*MsgPackData.MsgPackData)
ProcedureReturn #MsgPack_FormatCode_FixStr
ElseIf DataFormatCode < $E0
; 0xC0 - 0xDF -> Various
; All fields types are mapped to codes present in the enumeration.
ProcedureReturn DataFormatCode
; All fields types are mapped to codes present in the enumeration.
ProcedureReturn DataFormatCode
Else
; 0xE0 - 0xFF
ProcedureReturn #MsgPack_FormatCode_FixIntNegative
@@ -75,69 +75,65 @@ EndProcedure
;-> Format Types
Procedure.MsgPack_DataType MsgPackFormatCodeToDataType(FormatCode.MsgPack_FormatCode)
Select FormatCode
Case #MsgPack_FormatCode_FixIntPositive:
Case #MsgPack_FormatCode_UInt8:
Case #MsgPack_FormatCode_UInt16:
Case #MsgPack_FormatCode_UInt32:
Case #MsgPack_FormatCode_UInt64:
Case #MsgPack_FormatCode_Int8:
Case #MsgPack_FormatCode_Int16:
Case #MsgPack_FormatCode_Int32:
Case #MsgPack_FormatCode_Int64:
Case #MsgPack_FormatCode_FixIntNegative:
ProcedureReturn #MsgPack_DataTypes_Integer
Case #MsgPack_FormatCode_Float32:
Case #MsgPack_FormatCode_Float64:
ProcedureReturn #MsgPack_DataTypes_Float
Case #MsgPack_FormatCode_FixStr:
Case #MsgPack_FormatCode_Str8:
Case #MsgPack_FormatCode_Str16:
Case #MsgPack_FormatCode_Str32:
ProcedureReturn #MsgPack_DataTypes_String
Case #MsgPack_FormatCode_Null:
ProcedureReturn #MsgPack_DataTypes_Null
Case #MsgPack_FormatCode_False:
Case #MsgPack_FormatCode_True:
ProcedureReturn #MsgPack_DataTypes_Boolean
Case #MsgPack_FormatCode_False:
Case #MsgPack_FormatCode_True:
ProcedureReturn #MsgPack_DataTypes_Boolean
Case #MsgPack_FormatCode_Bin8:
Case #MsgPack_FormatCode_Bin16:
Case #MsgPack_FormatCode_Bin32:
ProcedureReturn #MsgPack_DataTypes_Binary
Case #MsgPack_FormatCode_FixArray:
Case #MsgPack_FormatCode_Array16:
Case #MsgPack_FormatCode_Array32:
ProcedureReturn #MsgPack_DataTypes_Array
Case #MsgPack_FormatCode_FixMap:
Case #MsgPack_FormatCode_Map16:
Case #MsgPack_FormatCode_Map32:
ProcedureReturn #MsgPack_DataTypes_Map
Case #MsgPack_FormatCode_Ext8:
Case #MsgPack_FormatCode_Ext16:
Case #MsgPack_FormatCode_Ext32:
Case #MsgPack_FormatCode_FixExt1:
Case #MsgPack_FormatCode_FixExt2:
Case #MsgPack_FormatCode_FixExt4:
Case #MsgPack_FormatCode_FixExt8:
Case #MsgPack_FormatCode_FixExt16:
ProcedureReturn #MsgPack_DataTypes_Ext
Case #MsgPack_FormatCode_Invalid:
Default:
; FIXME: ADD MESSAGE HERE !!!
DebuggerWarning("")
ProcedureReturn #MsgPack_DataTypes_Unknown
EndSelect
Select FormatCode
Case #MsgPack_FormatCode_FixIntPositive,
#MsgPack_FormatCode_UInt8,
#MsgPack_FormatCode_UInt16,
#MsgPack_FormatCode_UInt32,
#MsgPack_FormatCode_UInt64,
#MsgPack_FormatCode_Int8,
#MsgPack_FormatCode_Int16,
#MsgPack_FormatCode_Int32,
#MsgPack_FormatCode_Int64,
#MsgPack_FormatCode_FixIntNegative:
ProcedureReturn #MsgPack_DataTypes_Integer
Case #MsgPack_FormatCode_Float32,
#MsgPack_FormatCode_Float64:
ProcedureReturn #MsgPack_DataTypes_Float
Case #MsgPack_FormatCode_FixStr,
#MsgPack_FormatCode_Str8,
#MsgPack_FormatCode_Str16,
#MsgPack_FormatCode_Str32:
ProcedureReturn #MsgPack_DataTypes_String
Case #MsgPack_FormatCode_Null:
ProcedureReturn #MsgPack_DataTypes_Null
Case #MsgPack_FormatCode_False,
#MsgPack_FormatCode_True:
ProcedureReturn #MsgPack_DataTypes_Boolean
Case #MsgPack_FormatCode_Bin8,
#MsgPack_FormatCode_Bin16,
#MsgPack_FormatCode_Bin32:
ProcedureReturn #MsgPack_DataTypes_Binary
Case #MsgPack_FormatCode_FixArray,
#MsgPack_FormatCode_Array16,
#MsgPack_FormatCode_Array32:
ProcedureReturn #MsgPack_DataTypes_Array
Case #MsgPack_FormatCode_FixMap,
#MsgPack_FormatCode_Map16,
#MsgPack_FormatCode_Map32:
ProcedureReturn #MsgPack_DataTypes_Map
Case #MsgPack_FormatCode_Ext8,
#MsgPack_FormatCode_Ext16,
#MsgPack_FormatCode_Ext32,
#MsgPack_FormatCode_FixExt1,
#MsgPack_FormatCode_FixExt2,
#MsgPack_FormatCode_FixExt4,
#MsgPack_FormatCode_FixExt8,
#MsgPack_FormatCode_FixExt16:
ProcedureReturn #MsgPack_DataTypes_Extension
Case #MsgPack_FormatCode_Invalid:
Default:
; FIXME: ADD MESSAGE HERE !!!
DebuggerWarning("")
ProcedureReturn #MsgPack_DataTypes_Unknown
EndSelect
EndProcedure
@@ -0,0 +1,102 @@
EnableExplicit
XIncludeFile "../_UnitTesting.pbi"
XIncludeFile "../../Includes/MessagePack.pbi"
; Note: The checks were done on the table in the spec.
; I didn't go with my own constants to avoid missing a discrepency.
Define *BufferHolder.MsgPackData = MsgPackCreate(1)
; 0x00 - 0x7F
Define iFixIntCode.a
; Positive FixInt
For iFixIntCode = $00 To $7F
PokeA(*BufferHolder\Buffer, iFixIntCode)
AssertEqualsA(MsgPackGetFormatCode(*BufferHolder), #MsgPack_FormatCode_FixIntPositive,
Str(iFixIntCode) + " resolves to #MsgPack_FormatCode_FixIntPositive")
Next
; FixMap
For iFixIntCode = $80 To $8F
PokeA(*BufferHolder\Buffer, iFixIntCode)
AssertEqualsA(MsgPackGetFormatCode(*BufferHolder), #MsgPack_FormatCode_FixMap,
Str(iFixIntCode) + " resolves to #MsgPack_FormatCode_FixMap")
Next
; FixArray
For iFixIntCode = $90 To $9F
PokeA(*BufferHolder\Buffer, iFixIntCode)
AssertEqualsA(MsgPackGetFormatCode(*BufferHolder), #MsgPack_FormatCode_FixArray,
Str(iFixIntCode) + " resolves to #MsgPack_FormatCode_FixArray")
Next
; FixStr
For iFixIntCode = $A0 To $BF
PokeA(*BufferHolder\Buffer, iFixIntCode)
AssertEqualsA(MsgPackGetFormatCode(*BufferHolder), #MsgPack_FormatCode_FixStr,
Str(iFixIntCode) + " resolves to #MsgPack_FormatCode_FixStr")
Next
; Others singles
Macro TestSingleCode(TestedFormatCode, ExpectedFormatCode, FormatCodeText)
PokeA(*BufferHolder\Buffer, TestedFormatCode)
AssertEqualsA(MsgPackGetFormatCode(*BufferHolder), ExpectedFormatCode,
Str(iFixIntCode) + " resolves to " + FormatCodeText)
EndMacro
TestSingleCode($C0, #MsgPack_FormatCode_Null, "#MsgPack_FormatCode_Null")
TestSingleCode($C1, #MsgPack_FormatCode_Invalid, "#MsgPack_FormatCode_Invalid")
TestSingleCode($C2, #MsgPack_FormatCode_False, "#MsgPack_FormatCode_False")
TestSingleCode($C3, #MsgPack_FormatCode_True, "#MsgPack_FormatCode_True")
TestSingleCode($C4, #MsgPack_FormatCode_Bin8, "#MsgPack_FormatCode_Bin8")
TestSingleCode($C5, #MsgPack_FormatCode_Bin16, "#MsgPack_FormatCode_Bin16")
TestSingleCode($C6, #MsgPack_FormatCode_Bin32, "#MsgPack_FormatCode_Bin32")
TestSingleCode($C7, #MsgPack_FormatCode_Ext8, "#MsgPack_FormatCode_Ext8")
TestSingleCode($C8, #MsgPack_FormatCode_Ext16, "#MsgPack_FormatCode_Ext16")
TestSingleCode($C9, #MsgPack_FormatCode_Ext32, "#MsgPack_FormatCode_Ext32")
TestSingleCode($CA, #MsgPack_FormatCode_Float32, "#MsgPack_FormatCode_Float32")
TestSingleCode($CB, #MsgPack_FormatCode_Float64, "#MsgPack_FormatCode_Float64")
TestSingleCode($CC, #MsgPack_FormatCode_UInt8, "#MsgPack_FormatCode_UInt8")
TestSingleCode($CD, #MsgPack_FormatCode_UInt16, "#MsgPack_FormatCode_UInt16")
TestSingleCode($CE, #MsgPack_FormatCode_UInt32, "#MsgPack_FormatCode_UInt32")
TestSingleCode($CF, #MsgPack_FormatCode_UInt64, "#MsgPack_FormatCode_UInt64")
TestSingleCode($D0, #MsgPack_FormatCode_Int8, "#MsgPack_FormatCode_Int8")
TestSingleCode($D1, #MsgPack_FormatCode_Int16, "#MsgPack_FormatCode_Int16")
TestSingleCode($D2, #MsgPack_FormatCode_Int32, "#MsgPack_FormatCode_Int32")
TestSingleCode($D3, #MsgPack_FormatCode_Int64, "#MsgPack_FormatCode_Int64")
TestSingleCode($D4, #MsgPack_FormatCode_FixExt1, "#MsgPack_FormatCode_FixExt1")
TestSingleCode($D5, #MsgPack_FormatCode_FixExt2, "#MsgPack_FormatCode_FixExt2")
TestSingleCode($D6, #MsgPack_FormatCode_FixExt4, "#MsgPack_FormatCode_FixExt4")
TestSingleCode($D7, #MsgPack_FormatCode_FixExt8, "#MsgPack_FormatCode_FixExt8")
TestSingleCode($D8, #MsgPack_FormatCode_FixExt16, "#MsgPack_FormatCode_FixExt16")
TestSingleCode($D9, #MsgPack_FormatCode_Str8, "#MsgPack_FormatCode_Str8")
TestSingleCode($DA, #MsgPack_FormatCode_Str16, "#MsgPack_FormatCode_Str16")
TestSingleCode($DB, #MsgPack_FormatCode_Str32, "#MsgPack_FormatCode_Str32")
TestSingleCode($DC, #MsgPack_FormatCode_Array16, "#MsgPack_FormatCode_Array16")
TestSingleCode($DD, #MsgPack_FormatCode_Array32, "#MsgPack_FormatCode_Array32")
TestSingleCode($DE, #MsgPack_FormatCode_Map16, "#MsgPack_FormatCode_Map16")
TestSingleCode($DF, #MsgPack_FormatCode_Map32, "#MsgPack_FormatCode_Map32")
; Negative FixInt
For iFixIntCode = $E0 To $FF
PokeA(*BufferHolder\Buffer, iFixIntCode)
AssertEqualsA(MsgPackGetFormatCode(*BufferHolder), #MsgPack_FormatCode_FixIntNegative,
Str(iFixIntCode) + " resolves to #MsgPack_FormatCode_FixIntNegative")
Next
; ...
If FailedUnitTests
End 1
EndIf
Debug "Done !"
End 0
@@ -0,0 +1,56 @@
EnableExplicit
XIncludeFile "../_UnitTesting.pbi"
XIncludeFile "../../Includes/MessagePack.pbi"
Macro TestFormatToType(TestedFormatCode, ExpectedDataType, TestMessage)
AssertEqualsA(MsgPackFormatCodeToDataType(TestedFormatCode), ExpectedDataType, TestMessage)
EndMacro
TestFormatToType(#MsgPack_FormatCode_Null, #MsgPack_DataTypes_Null, "Null -> Null")
TestFormatToType(#MsgPack_FormatCode_False, #MsgPack_DataTypes_Boolean, "False -> Boolean")
TestFormatToType(#MsgPack_FormatCode_True, #MsgPack_DataTypes_Boolean, "True -> Boolean")
TestFormatToType(#MsgPack_FormatCode_FixIntPositive, #MsgPack_DataTypes_Integer, "FixIntPositive -> Integer")
TestFormatToType(#MsgPack_FormatCode_FixIntNegative, #MsgPack_DataTypes_Integer, "FixIntNegative -> Integer")
TestFormatToType(#MsgPack_FormatCode_UInt8, #MsgPack_DataTypes_Integer, "UInt8 -> Integer")
TestFormatToType(#MsgPack_FormatCode_UInt16, #MsgPack_DataTypes_Integer, "UInt16 -> Integer")
TestFormatToType(#MsgPack_FormatCode_UInt32, #MsgPack_DataTypes_Integer, "UInt32 -> Integer")
TestFormatToType(#MsgPack_FormatCode_UInt64, #MsgPack_DataTypes_Integer, "UInt64 -> Integer")
TestFormatToType(#MsgPack_FormatCode_Int8, #MsgPack_DataTypes_Integer, "Int8 -> Integer")
TestFormatToType(#MsgPack_FormatCode_Int16, #MsgPack_DataTypes_Integer, "Int16 -> Integer")
TestFormatToType(#MsgPack_FormatCode_Int32, #MsgPack_DataTypes_Integer, "Int32 -> Integer")
TestFormatToType(#MsgPack_FormatCode_Int64, #MsgPack_DataTypes_Integer, "Int64 -> Integer")
TestFormatToType(#MsgPack_FormatCode_Float32, #MsgPack_DataTypes_Float, "Float32 -> Float")
TestFormatToType(#MsgPack_FormatCode_Float64, #MsgPack_DataTypes_Float, "Float64 -> Float")
TestFormatToType(#MsgPack_FormatCode_FixStr, #MsgPack_DataTypes_String, "FixStr -> String")
TestFormatToType(#MsgPack_FormatCode_Str8, #MsgPack_DataTypes_String, "Str8 -> String")
TestFormatToType(#MsgPack_FormatCode_Str16, #MsgPack_DataTypes_String, "Str16 -> String")
TestFormatToType(#MsgPack_FormatCode_Str32, #MsgPack_DataTypes_String, "Str32 -> String")
TestFormatToType(#MsgPack_FormatCode_Bin8, #MsgPack_DataTypes_Binary, "Bin8 -> Binary")
TestFormatToType(#MsgPack_FormatCode_Bin16, #MsgPack_DataTypes_Binary, "Bin16 -> Binary")
TestFormatToType(#MsgPack_FormatCode_Bin32, #MsgPack_DataTypes_Binary, "Bin32 -> Binary")
TestFormatToType(#MsgPack_FormatCode_FixArray, #MsgPack_DataTypes_Array, "FixArray -> Array")
TestFormatToType(#MsgPack_FormatCode_Array16, #MsgPack_DataTypes_Array, "Array16 -> Array")
TestFormatToType(#MsgPack_FormatCode_Array32, #MsgPack_DataTypes_Array, "Array32 -> Array")
TestFormatToType(#MsgPack_FormatCode_FixMap, #MsgPack_DataTypes_Map, "FixMap -> Map")
TestFormatToType(#MsgPack_FormatCode_Map16, #MsgPack_DataTypes_Map, "Map16 -> Map")
TestFormatToType(#MsgPack_FormatCode_Map32, #MsgPack_DataTypes_Map, "Map32 -> Map")
TestFormatToType(#MsgPack_FormatCode_FixExt1, #MsgPack_DataTypes_Extension, "FixExt1 -> Extension")
TestFormatToType(#MsgPack_FormatCode_FixExt2, #MsgPack_DataTypes_Extension, "FixExt2 -> Extension")
TestFormatToType(#MsgPack_FormatCode_FixExt4, #MsgPack_DataTypes_Extension, "FixExt4 -> Extension")
TestFormatToType(#MsgPack_FormatCode_FixExt8, #MsgPack_DataTypes_Extension, "FixExt8 -> Extension")
TestFormatToType(#MsgPack_FormatCode_FixExt16, #MsgPack_DataTypes_Extension, "FixExt16 -> Extension")
TestFormatToType(#MsgPack_FormatCode_Ext8, #MsgPack_DataTypes_Extension, "Ext8 -> Extension")
TestFormatToType(#MsgPack_FormatCode_Ext16, #MsgPack_DataTypes_Extension, "Ext16 -> Extension")
TestFormatToType(#MsgPack_FormatCode_Ext32, #MsgPack_DataTypes_Extension, "Ext32 -> Extension")
TestFormatToType(#MsgPack_FormatCode_Invalid, #MsgPack_DataTypes_Unknown, "Invalid -> Unknown")
If FailedUnitTests
End 1
EndIf
Debug "Done !"
End 0
@@ -0,0 +1,61 @@
EnableExplicit
XIncludeFile "../_UnitTesting.pbi"
XIncludeFile "../../Includes/MessagePack.pbi"
; Note: The checks were done on the table in the spec.
; I didn't go with my own constants to avoid missing a discrepency.
Procedure TestValueMetaInfoWithin(CodeForBuffer.a, ExpectedVariableSize.q, ExpectedDataOffset.b, TestName.s)
Protected *BufferHolder.MsgPackData = MsgPackCreate(1)
PokeA(*BufferHolder\Buffer, CodeForBuffer)
Protected ExaminedFormatCode.MsgPack_FormatCode = MsgPackGetFormatCode(*BufferHolder)
Protected ReturnedVariableSize.q
Protected ReturnedDataOffset.b
_MsgPackGetValueMetaInfo(*BufferHolder, ExaminedFormatCode, @ReturnedVariableSize, @ReturnedDataOffset)
AssertEqualsQ(ReturnedVariableSize, ExpectedVariableSize, TestName + " (Value)")
AssertEqualsB(ReturnedDataOffset, ExpectedDataOffset, TestName + " (Offset)")
MsgPackFree(*BufferHolder, #True)
EndProcedure
; Positive FixInt
TestValueMetaInfoWithin($00, 0, 1, "FixInt with positive 0") ; Value: 0 (0x00) | Offset: ???
TestValueMetaInfoWithin($7F, 127, 0, "FixInt with positive 127") ; Value: 127 (0x7F) | Offset: ???
; FixMap
TestValueMetaInfoWithin($80, 0, 1, "FixMap with 0 elements") ; Value: 0 (0x0) | Offset: 1
TestValueMetaInfoWithin($8F, 15, 1, "FixMap with 15 elements") ; Value: 15 (0xF) | Offset: 1
; FixArray
TestValueMetaInfoWithin($90, 0, 1, "FixArray with 0 elements") ; Value: 0 (0x0) | Offset: 1
TestValueMetaInfoWithin($9F, 15, 1, "FixArray with 15 elements") ; Value: 15 (0xF) | Offset: 1
; FixStr
TestValueMetaInfoWithin($A0, 0, 1, "FixStr with 0 elements") ; Value: 0 (0x00) | Offset: 1
TestValueMetaInfoWithin($AF, 15, 1, "FixStr with 15 elements") ; Value: 15 (0x0F) | Offset: 1
TestValueMetaInfoWithin($B0, 16, 1, "FixStr with 16 elements") ; Value: 16 (0x10) | Offset: 1
TestValueMetaInfoWithin($BF, 31, 1, "FixStr with 31 elements") ; Value: 31 (0x1F) | Offset: 1
; Negative FixInt
TestValueMetaInfoWithin($E0, -0, 1, "FixInt with negative 0") ; Value: 0 (0x00) | Offset: ???
TestValueMetaInfoWithin($FF, -31, 0, "FixInt with negative 31") ; Value: 31 (0x7F) | Offset: ???
If FailedUnitTests
End 1
EndIf
Debug "Done !"
End 0
@@ -1,27 +0,0 @@
EnableExplicit
XIncludeFile "../_UnitTesting.pbi"
XIncludeFile "../../Includes/MessagePack.pbi"
Define *BufferHolder.MsgPackData = MsgPackCreate(1)
; 0x00 - 0x7F
Define iFixIntCode.a
For iFixIntCode = 0 To $7F
PokeA(*BufferHolder\Buffer, iFixIntCode)
AssertEqualsA(MsgPackGetFormatCode(*BufferHolder), #MsgPack_FormatCode_FixIntPositive, Str(iFixIntCode) + " resolves to #MsgPack_FormatCode_FixIntPositive")
Next
; ...
If FailedUnitTests
End 1
EndIf
Debug "Done !"
End 0
+8
View File
@@ -50,6 +50,14 @@ Procedure AssertEqualsB(Val1.b, Val2.b, TestName.s="")
EndIf
EndProcedure
Procedure AssertEqualsQ(Val1.q, Val2.q, TestName.s="")
If Val1 = Val2
Pass(TestName)
Else
Fail(TestName, Str(Val1) + " <> " + Str(Val2))
EndIf
EndProcedure
Procedure AssertNotEquals(Val1, Val2, TestName.s="")
If Val1 <> Val2
Pass(TestName)