-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed extraneous ASCII from dumped messages
- Loading branch information
Showing
4 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package messages | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestDump(t *testing.T) { | ||
message := []byte{ | ||
0x17, 0x20, 0x00, 0x00, 0x2d, 0x55, 0x39, 0x19, 0x39, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x01, | ||
0xaa, 0xe8, 0x5d, 0x00, 0x20, 0x19, 0x04, 0x19, 0x17, 0x00, 0x09, 0x06, 0x01, 0x00, 0x01, 0x01, | ||
0x00, 0x00, 0x01, 0x01, 0x09, 0x14, 0x37, 0x02, 0x11, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, | ||
0x2b, 0x04, 0x01, 0x19, 0x04, 0x20, 0x00, 0x00, 0x93, 0x26, 0x04, 0x88, 0x08, 0x92, 0x00, 0x00, | ||
} | ||
|
||
expected := | ||
`00000000 17 20 00 00 2d 55 39 19 39 00 00 00 01 00 03 01 | ||
00000010 aa e8 5d 00 20 19 04 19 17 00 09 06 01 00 01 01 | ||
00000020 00 00 01 01 09 14 37 02 11 00 00 00 21 00 00 00 | ||
00000030 2b 04 01 19 04 20 00 00 93 26 04 88 08 92 00 00 | ||
` | ||
|
||
s := dump(message, "") | ||
|
||
if s != expected { | ||
t.Errorf("incorrectly 'dumped' message\n expected:\n%v\n got:\n%v", expected, s) | ||
} | ||
} | ||
|
||
func TestDumpWithPrefix(t *testing.T) { | ||
message := []byte{ | ||
0x17, 0x20, 0x00, 0x00, 0x2d, 0x55, 0x39, 0x19, 0x39, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x01, | ||
0xaa, 0xe8, 0x5d, 0x00, 0x20, 0x19, 0x04, 0x19, 0x17, 0x00, 0x09, 0x06, 0x01, 0x00, 0x01, 0x01, | ||
0x00, 0x00, 0x01, 0x01, 0x09, 0x14, 0x37, 0x02, 0x11, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, | ||
0x2b, 0x04, 0x01, 0x19, 0x04, 0x20, 0x00, 0x00, 0x93, 0x26, 0x04, 0x88, 0x08, 0x92, 0x00, 0x00, | ||
} | ||
|
||
expected := | ||
` 00000000 17 20 00 00 2d 55 39 19 39 00 00 00 01 00 03 01 | ||
00000010 aa e8 5d 00 20 19 04 19 17 00 09 06 01 00 01 01 | ||
00000020 00 00 01 01 09 14 37 02 11 00 00 00 21 00 00 00 | ||
00000030 2b 04 01 19 04 20 00 00 93 26 04 88 08 92 00 00 | ||
` | ||
|
||
s := dump(message, " ") | ||
|
||
if s != expected { | ||
t.Errorf("incorrectly 'dumped' message\n expected:\n%v\n got:\n%v", expected, s) | ||
} | ||
} | ||
|
||
func BenchmarkDump(b *testing.B) { | ||
m := make([]byte, 64) | ||
r := rand.New(rand.NewSource(time.Now().UnixNano())) | ||
|
||
r.Read(m) | ||
|
||
for n := 0; n < b.N; n++ { | ||
dump(m, "") | ||
} | ||
} | ||
|