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
@@ -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