2018-07-15 19:15:52 +03:00
|
|
|
/*
|
|
|
|
NAME
|
|
|
|
rtmp_test.go
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
See Readme.md
|
|
|
|
|
|
|
|
AUTHOR
|
|
|
|
Saxon Nelson-Milton <saxon@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
rtmp_test.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
|
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package rtmp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2018-07-16 17:37:34 +03:00
|
|
|
arrStart = 0
|
|
|
|
arrEnd = 5
|
|
|
|
arrSize = 6
|
|
|
|
inc = 3
|
|
|
|
dec = 3
|
2018-07-15 19:15:52 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2018-07-16 17:37:34 +03:00
|
|
|
byteArr = [arrSize]byte{0x01,0x02,0x03,0x04,0x05,0x06}
|
|
|
|
int32Arr = [arrSize]int32{1,2,3,4,5,6}
|
|
|
|
int64Arr = [arrSize]int64{1,2,3,4,5,6}
|
|
|
|
errMsg = "Obtained: %v, but wanted: %v"
|
2018-07-15 19:15:52 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIncPtr(t *testing.T){
|
|
|
|
// Test how it deals with bytes
|
2018-07-16 17:37:34 +03:00
|
|
|
bytePtr := unsafe.Pointer(&byteArr[arrStart])
|
2018-07-15 19:15:52 +03:00
|
|
|
valueByte := *(*byte)(incPtr(bytePtr,inc,byteSize))
|
|
|
|
if valueByte != byteArr[inc] {
|
|
|
|
t.Errorf(errMsg,valueByte,byteArr[inc])
|
|
|
|
}
|
|
|
|
|
2018-07-16 17:37:34 +03:00
|
|
|
// Test how it deals with int32s
|
|
|
|
int32Ptr := unsafe.Pointer(&int32Arr[arrStart])
|
|
|
|
valueInt32 := *(*int32)(incPtr(int32Ptr,inc,int32Size))
|
2018-07-15 19:15:52 +03:00
|
|
|
if valueInt32 != int32Arr[inc] {
|
|
|
|
t.Errorf(errMsg,valueInt32,int32Arr[inc])
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test how it deals with int64
|
2018-07-16 17:37:34 +03:00
|
|
|
int64Ptr := unsafe.Pointer(&int64Arr[arrStart])
|
2018-07-15 19:15:52 +03:00
|
|
|
valueInt64 := *(*int64)(incPtr(int64Ptr,inc,int64Size))
|
|
|
|
if valueInt64 != int64Arr[inc] {
|
|
|
|
t.Errorf(errMsg,valueInt64,int64Arr[inc])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDecPtr(t *testing.T){
|
2018-07-16 17:37:34 +03:00
|
|
|
// Test how it deals with bytes
|
|
|
|
bytePtr := unsafe.Pointer(&byteArr[arrEnd ])
|
|
|
|
valueByte := *(*byte)(decPtr(bytePtr,dec,byteSize))
|
|
|
|
if valueByte != byteArr[arrEnd-dec] {
|
|
|
|
t.Errorf(errMsg,valueByte,byteArr[inc])
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test how it deals with ints
|
|
|
|
int32Ptr := unsafe.Pointer(&int32Arr[arrEnd])
|
|
|
|
valueInt32 := *(*int32)(decPtr(int32Ptr,dec,int32Size))
|
|
|
|
if valueInt32 != int32Arr[arrEnd-inc] {
|
|
|
|
t.Errorf(errMsg,valueInt32,int32Arr[inc])
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test how it deals with int64
|
|
|
|
int64Ptr := unsafe.Pointer(&int64Arr[arrEnd])
|
|
|
|
valueInt64 := *(*int64)(decPtr(int64Ptr,dec,int64Size))
|
|
|
|
if valueInt64 != int64Arr[arrEnd-dec] {
|
|
|
|
t.Errorf(errMsg,valueInt64,int64Arr[inc])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIndxBytePtr(t *testing.T) {
|
|
|
|
// Test how it deals with bytes
|
|
|
|
bytePtr := unsafe.Pointer(&byteArr[arrStart])
|
|
|
|
valueByte := indxBytePtr(bytePtr,inc)
|
|
|
|
if valueByte != byteArr[inc] {
|
|
|
|
t.Errorf(errMsg,valueByte,byteArr[inc])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIndxInt32Ptr(t *testing.T) {
|
|
|
|
// Test how it deals with int32s
|
|
|
|
int32Ptr := unsafe.Pointer(&int32Arr[arrStart])
|
|
|
|
valueInt32 := indxInt32Ptr(int32Ptr,inc)
|
|
|
|
if valueInt32 != int32Arr[inc] {
|
|
|
|
t.Errorf(errMsg,valueInt32,int32Arr[inc])
|
|
|
|
}
|
2018-07-15 19:15:52 +03:00
|
|
|
}
|
|
|
|
|
2018-07-16 17:37:34 +03:00
|
|
|
func TestIndxInt64Ptr(t *testing.T) {
|
|
|
|
// Test how it deals with int64
|
|
|
|
int64Ptr := unsafe.Pointer(&int64Arr[arrStart])
|
|
|
|
valueInt64 := indxInt64Ptr(int64Ptr,inc)
|
|
|
|
if valueInt64 != int64Arr[inc] {
|
|
|
|
t.Errorf(errMsg,valueInt64,int64Arr[inc])
|
|
|
|
}
|
|
|
|
}
|
2018-07-15 19:15:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
func TestPtrToSlice(t *testing.T){
|
|
|
|
}
|
|
|
|
*/
|