Skip to content

Commit 1aeeb20

Browse files
committed
ISO88595 Code page support: Fixes
1 parent 8532104 commit 1aeeb20

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

smpp/pdu/pdutext/codec_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestEncode(t *testing.T) {
1717
}{
1818
{Latin1Type, []byte("áéíóú moço"), []byte("\xe1\xe9\xed\xf3\xfa mo\xe7o")},
1919
{UCS2Type, []byte("áéíóú moço"), []byte("\x00\xe1\x00\xe9\x00\xed\x00\xf3\x00\xfa\x00 \x00m\x00o\x00\xe7\x00o")},
20+
{ISO88595Type, []byte(iso88595UTF8_Bytes), []byte(iso88595_Bytes)},
2021
}
2122
for _, tc := range test {
2223
have := Encode(tc.typ, tc.text)
@@ -35,6 +36,7 @@ func TestDecode(t *testing.T) {
3536
}{
3637
{Latin1Type, []byte("áéíóú moço"), []byte("\xe1\xe9\xed\xf3\xfa mo\xe7o")},
3738
{UCS2Type, []byte("áéíóú moço"), []byte("\x00\xe1\x00\xe9\x00\xed\x00\xf3\x00\xfa\x00 \x00m\x00o\x00\xe7\x00o")},
39+
{ISO88595Type, []byte(iso88595UTF8_Bytes), []byte(iso88595_Bytes)},
3840
}
3941
for _, tc := range test {
4042
have := Decode(tc.typ, tc.text)

smpp/pdu/pdutext/iso88595_test.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@ import (
1010
"testing"
1111
)
1212

13+
const (
14+
iso88595TypeCode = 0x06
15+
testDataDir = "testdata"
16+
)
17+
1318
var (
14-
ISO88595_Bytes []byte = readBytesFromFile("test_text/iso88595_test.txt")
15-
Utf8_Bytes []byte = readBytesFromFile("test_text/iso88595_test_utf8.txt")
19+
iso88595_Bytes []byte = readBytesFromFile(testDataDir + "/iso88595_test.txt")
20+
iso88595UTF8_Bytes []byte = readBytesFromFile(testDataDir + "/iso88595_test_utf8.txt")
1621
)
1722

1823
func TestISO88595Encoder(t *testing.T) {
19-
want := []byte(ISO88595_Bytes)
20-
text := []byte(Utf8_Bytes)
24+
want := []byte(iso88595_Bytes)
25+
text := []byte(iso88595UTF8_Bytes)
2126
s := ISO88595(text)
22-
if s.Type() != 0x06 {
23-
t.Fatalf("Unexpected data type; want 0x03, have %d", s.Type())
27+
if s.Type() != iso88595TypeCode {
28+
t.Fatalf("Unexpected data type; want %d, have %d", iso88595TypeCode, s.Type())
2429
}
2530
have := s.Encode()
2631
if !bytes.Equal(want, have) {
@@ -29,22 +34,22 @@ func TestISO88595Encoder(t *testing.T) {
2934
}
3035

3136
func TestISO88595Decoder(t *testing.T) {
32-
want := []byte(Utf8_Bytes)
33-
text := []byte(ISO88595_Bytes)
37+
want := []byte(iso88595UTF8_Bytes)
38+
text := []byte(iso88595_Bytes)
3439
s := ISO88595(text)
35-
if s.Type() != 0x06 {
36-
t.Fatalf("Unexpected data type; want 0x03, have %d", s.Type())
40+
if s.Type() != iso88595TypeCode {
41+
t.Fatalf("Unexpected data type; want %d, have %d", iso88595TypeCode, s.Type())
3742
}
3843
have := s.Decode()
3944
if !bytes.Equal(want, have) {
4045
t.Fatalf("Unexpected text; want %q, have %q", want, have)
4146
}
4247
}
4348

44-
func readBytesFromFile(aFileName string) []byte {
45-
dat, err := ioutil.ReadFile(aFileName)
49+
func readBytesFromFile(filename string) []byte {
50+
dat, err := ioutil.ReadFile(filename)
4651
if err != nil {
47-
return nil
52+
panic("Error reading testdata file; " + filename + ", err " + err.Error())
4853
} else {
4954
return dat
5055
}

0 commit comments

Comments
 (0)