56 lines
2.0 KiB
Go
56 lines
2.0 KiB
Go
package pdu
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// region size
|
|
func TestCalculateSizeTypicalInstance(t *testing.T) {
|
|
p := &SUBMIT_SM{
|
|
service_type: "test_service",
|
|
source_addr: "12345",
|
|
destination_addr: "67890",
|
|
schedule_delivery_time: "",
|
|
validity_period: "",
|
|
short_message: "Hello, World!",
|
|
}
|
|
expectedSize := uint32(16 + len(p.service_type) + 1 + 1 + len(p.source_addr) + 1 + 1 + len(p.destination_addr) + 1 + 1 + 1 + len(p.schedule_delivery_time) + len(p.validity_period) + 1 + 1 + 1 + 1 + 1 + len(p.short_message))
|
|
actualSize := p.Size()
|
|
if actualSize != expectedSize {
|
|
t.Errorf("Expected size %d, but got %d", expectedSize, actualSize)
|
|
}
|
|
}
|
|
|
|
func TestCalculateSizeMaxLengths(t *testing.T) {
|
|
maxLen := 255
|
|
p := &SUBMIT_SM{
|
|
service_type: string(make([]byte, maxLen)),
|
|
source_addr: string(make([]byte, maxLen)),
|
|
destination_addr: string(make([]byte, maxLen)),
|
|
schedule_delivery_time: string(make([]byte, maxLen)),
|
|
validity_period: string(make([]byte, maxLen)),
|
|
short_message: string(make([]byte, maxLen)),
|
|
}
|
|
expectedSize := uint32(16 + maxLen + 1 + 1 + maxLen + 1 + 1 + maxLen + 1 + 1 + 1 + maxLen + maxLen + 1 + 1 + 1 + 1 + 1 + maxLen)
|
|
actualSize := p.Size()
|
|
if actualSize != expectedSize {
|
|
t.Errorf("Expected size %d, but got %d", expectedSize, actualSize)
|
|
}
|
|
}
|
|
|
|
func TestHandlesEmptyStringsForAllStringFields(t *testing.T) {
|
|
p := &SUBMIT_SM{
|
|
service_type: "",
|
|
source_addr: "",
|
|
destination_addr: "",
|
|
schedule_delivery_time: "",
|
|
validity_period: "",
|
|
short_message: "",
|
|
}
|
|
expectedSize := uint32(16 + len(p.service_type) + 1 + 1 + len(p.source_addr) + 1 + 1 + len(p.destination_addr) + 1 + 1 + 1 + len(p.schedule_delivery_time) + len(p.validity_period) + 1 + 1 + 1 + 1 + 1 + len(p.short_message))
|
|
actualSize := p.Size()
|
|
if actualSize != expectedSize {
|
|
t.Errorf("Expected size %d, but got %d", expectedSize, actualSize)
|
|
}
|
|
}
|