test-client-godot/gdnative/test/bitstreamqueue.gd
2020-03-03 22:45:30 +01:00

230 lines
5.6 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.length()
assert(res == 0)
func test_msg_1():
var bitstreamqueue = BitStreamQueue.new()
var index
var res
var tmp = PoolByteArray()
tmp.append(0)
tmp.append(0)
tmp.append(0)
tmp.append(3)
tmp.append(2)
var data = BitStream.new()
assert(bitstreamqueue.length() == 0)
data.put_data(tmp)
var id = data.get_uint32()
assert(id == 3)
var bitstreamfield = BitStreamField.new()
bitstreamfield.put_id(id)
bitstreamfield.put_msgin(data)
index = bitstreamqueue.put_bitstreamfield(bitstreamfield)
assert(index == 0)
assert(bitstreamqueue.length() == 1)
#res = bitstreamqueue.get_received_number(pos)
#assert(res == 3)
res = bitstreamqueue.get_msg(index)
#print(res.show())
assert(res.get_msgin().show() == "0000000000000000000000000000001100000010")
#res = bitstreamqueue.get_msg_withid(id)
#assert(res == 3)
res = bitstreamqueue.length()
assert(res == 1)
bitstreamqueue.erase_index(index)
res = bitstreamqueue.length()
assert(res == 0)
func test_msg_2():
var bitstreamqueue = BitStreamQueue.new()
var index
var res
var tmp = PoolByteArray()
tmp.append(0)
tmp.append(0)
tmp.append(0)
tmp.append(2)
tmp.append(7)
var data = BitStream.new()
assert(bitstreamqueue.length() == 0)
data.put_data(tmp)
var id = data.get_uint32()
assert(id == 2)
var bitstreamfield = BitStreamField.new()
bitstreamfield.put_id(id)
bitstreamfield.put_msgin(data)
index = bitstreamqueue.put_bitstreamfield(bitstreamfield)
assert(index == 0)
assert(bitstreamqueue.length() == 1)
res = bitstreamqueue.get_msg(index)
#print(res.show())
assert(res.get_msgin().show() == "0000000000000000000000000000001000000111")
assert(res.get_id() == 2)
func test_msg_3():
var bitstreamqueue = BitStreamQueue.new()
var index
var res
var tmp = PoolByteArray()
tmp.append(0)
tmp.append(0)
tmp.append(0)
tmp.append(2)
tmp.append(7)
var data = BitStream.new()
assert(bitstreamqueue.length() == 0)
data.put_data(tmp)
var id = data.get_uint32()
assert(id == 2)
var bitstreamfield = BitStreamField.new()
bitstreamfield.put_id(id)
bitstreamfield.put_msgin(data)
index = bitstreamqueue.put_bitstreamfield(bitstreamfield)
assert(index == 0)
assert(bitstreamqueue.length() == 1)
res = bitstreamqueue.get_msg(index)
#print(res.show())
assert(res.get_msgin().show() == "0000000000000000000000000000001000000111")
assert(res.get_id() == 2)
tmp = PoolByteArray()
tmp.append(0)
tmp.append(0)
tmp.append(0)
tmp.append(3)
tmp.append(2)
data = BitStream.new()
assert(bitstreamqueue.length() == 1)
data.put_data(tmp)
id = data.get_uint32()
assert(id == 3)
bitstreamfield = BitStreamField.new()
bitstreamfield.put_id(id)
bitstreamfield.put_msgin(data)
index = bitstreamqueue.put_bitstreamfield(bitstreamfield)
assert(index == 1)
assert(bitstreamqueue.length() == 2)
res = bitstreamqueue.get_msg(index)
#print(res.show())
assert(res.get_msgin().show() == "0000000000000000000000000000001100000010")
assert(res.get_id() == 3)
tmp = PoolByteArray()
tmp.append(0)
tmp.append(0)
tmp.append(0)
tmp.append(1)
tmp.append(2)
data = BitStream.new()
assert(bitstreamqueue.length() == 2)
data.put_data(tmp)
id = data.get_uint32()
assert(id == 1)
bitstreamfield = BitStreamField.new()
bitstreamfield.put_id(id)
bitstreamfield.put_msgin(data)
index = bitstreamqueue.put_bitstreamfield(bitstreamfield)
assert(index == 2)
assert(bitstreamqueue.length() == 3)
res = bitstreamqueue.get_msg(index)
#print(res.show())
assert(res.get_msgin().show() == "0000000000000000000000000000000100000010")
assert(res.get_id() == 1)
assert(bitstreamqueue.length() == 3)
bitstreamqueue.erase_id(1)
assert(bitstreamqueue.length() == 2)
func step(id, data, bitstreamqueue):
var tmp = PoolByteArray()
tmp.append(0)
tmp.append(0)
tmp.append(0)
tmp.append(id)
tmp.append(data)
data = BitStream.new()
data.put_data(tmp)
var lid = data.get_uint32()
assert(lid == id)
var bitstreamfield = BitStreamField.new()
bitstreamfield.put_id(id)
bitstreamfield.put_msgin(data)
return bitstreamqueue.put_bitstreamfield(bitstreamfield)
func test_msg_4():
var bitstreamqueue = BitStreamQueue.new()
var index1
var index2
var index3
var index4
assert(bitstreamqueue.length() == 0)
index1 = step(1,1,bitstreamqueue)
assert(bitstreamqueue.length() == 1)
index2 = step(2,2,bitstreamqueue)
assert(bitstreamqueue.length() == 2)
index3 = step(3,3,bitstreamqueue)
assert(bitstreamqueue.length() == 3)
bitstreamqueue.erase_id(2)
assert(bitstreamqueue.length() == 2)
index4 = step(4,4,bitstreamqueue)
assert(bitstreamqueue.length() == 3)
index3 = step(5,5,bitstreamqueue)
assert(bitstreamqueue.length() == 4)
func test():
print("[bitstreamqueue] Start check -> start")
test_init()
test_msg_1()
test_msg_2()
test_msg_3()
test_msg_4()
print("[bitstreamqueue] Start check -> end")