diff --git a/pdu/submit_test.go b/pdu/submit_test.go new file mode 100644 index 0000000..c60646b --- /dev/null +++ b/pdu/submit_test.go @@ -0,0 +1,53 @@ +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) + } +}