Skip to content

Commit

Permalink
cleaning up tests and adding arp marshal test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonstout committed Mar 9, 2014
1 parent c69502c commit 59ac465
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
32 changes: 32 additions & 0 deletions protocol/arp/arp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package arp

import (
"encoding/hex"
"strings"
"testing"
)

func TestArpMarshalBinary(t *testing.T) {
b := " 00 01 " + // HWType
"08 00 " + // ProtoType
"06 04 " + // HWLength ProtoLength
"00 01 " + // Type_Request
"00 00 00 00 00 00 " + // HWSrc
"00 00 00 00 " + // IPSrc
"00 00 00 00 00 00 " + // HWDst
"00 00 00 00 " // IPDst
b = strings.Replace(b, " ", "", -1)

a, _ := New(Type_Request)
data, _ := a.MarshalBinary()
d := hex.EncodeToString(data)
if (len(b) != len(d)) || (b != d) {
t.Log("Exp:", b)
t.Log("Rec:", d)
t.Errorf("Received length of %d, expected %d", len(d), len(b))
}
}

func TestArpUnmarshalBinary(t *testing.T) {

}
9 changes: 3 additions & 6 deletions protocol/ofpxx/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@ import (
)

func TestHelloMarshalBinary(t *testing.T) {
s := " 01 00 00 08 00 00 00 03 " + // Header
b := " 01 00 00 08 00 00 00 03 " + // Header
"00 01 00 08 " + // Element Header
"00 00 00 09 " // Bitmap = 1001
s = strings.Replace(s, " ", "", -1)
bytes, _ := hex.DecodeString(s)
b = strings.Replace(b, " ", "", -1)

h, _ := NewHello(1)
data, _ := h.MarshalBinary()

b := hex.EncodeToString(bytes)
d := hex.EncodeToString(data)
if (len(b) != len(d)) || (b != d) {
t.Log("Exp:", b)
t.Log("Rec:", d)
t.Errorf("Received length of %d, expected %d", len(data), len(bytes))
t.Errorf("Received length of %d, expected %d", len(d), len(b))
}
}

Expand Down

0 comments on commit 59ac465

Please sign in to comment.