test-client-godot/gdnative/test/bitstreamqueue.gd

84 lines
1.9 KiB
GDScript3

#extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func test_init():
#var bitstream = preload("res://bitstream.gdns").new()
var bitstreamqueue = BitStreamQueue.new()
var res = bitstreamqueue.length()
assert(res == 0)
bitstreamqueue.clear()
res = bitstreamqueue.get_received_number(0)
assert(res == 0)
func test_msg_1():
var bitstreamqueue = BitStreamQueue.new()
var pos
var res
var tmp = PoolByteArray()
tmp.append(0)
tmp.append(0)
tmp.append(0)
tmp.append(3)
tmp.append(2)
res = bitstreamqueue.length()
assert(res == 0)
pos = bitstreamqueue.put_msgbytes(tmp)
res = bitstreamqueue.get_received_number(pos)
assert(res == 3)
res = bitstreamqueue.get_msg(pos)
#print(res.show())
assert(res.show() == "0000000000000000000000000000001100000010")
res = bitstreamqueue.get_received_number(pos)
assert(res == 3)
res = bitstreamqueue.length()
assert(res == 1)
bitstreamqueue.erase(pos)
res = bitstreamqueue.length()
assert(res == 0)
func test_msg_2():
var bitstreamqueue = BitStreamQueue.new()
var pos
var res
var tmp = PoolByteArray()
tmp.append(0)
tmp.append(0)
tmp.append(0)
tmp.append(2)
tmp.append(7)
pos = bitstreamqueue.put_msgbytes(tmp)
res = bitstreamqueue.get_received_number(pos)
assert(res == 2)
res = bitstreamqueue.get_msg(pos)
#print(res.show())
assert(res.show() == "0000000000000000000000000000001000000111")
res = bitstreamqueue.get_received_number(pos)
assert(res == 2)
func test():
print("[bitstreamqueue] Start check -> start")
test_init()
test_msg_1()
test_msg_2()
print("[bitstreamqueue] Start check -> end")