aboutsummaryrefslogtreecommitdiffstats
path: root/formats/objfile/common_test.go
diff options
context:
space:
mode:
authorJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-27 14:07:22 -0800
committerJoshua Sjoding <joshua.sjoding@scjalliance.com>2016-02-27 14:07:22 -0800
commit31f920a06aa5d7e7cf363645dac02f6e798fffb1 (patch)
treeddd60f794c193e1a407e78b5ca94d0a83466fd78 /formats/objfile/common_test.go
parente6855829c4df2861e779adcccbb422e7c0830afd (diff)
downloadgo-git-31f920a06aa5d7e7cf363645dac02f6e798fffb1.tar.gz
Improved objfile error handling and test coverage
Diffstat (limited to 'formats/objfile/common_test.go')
-rw-r--r--formats/objfile/common_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/formats/objfile/common_test.go b/formats/objfile/common_test.go
index 4727685..0c5a4cd 100644
--- a/formats/objfile/common_test.go
+++ b/formats/objfile/common_test.go
@@ -1,6 +1,7 @@
package objfile
import (
+ "bytes"
"encoding/base64"
"testing"
@@ -67,3 +68,33 @@ var objfileFixtures = []objfileFixture{
}
func Test(t *testing.T) { TestingT(t) }
+
+type SuiteCommon struct{}
+
+var _ = Suite(&SuiteCommon{})
+
+func (s *SuiteCommon) TestHeaderReadEmpty(c *C) {
+ var h header
+ c.Assert(h.Read(new(bytes.Buffer)), Equals, ErrHeader)
+}
+
+func (s *SuiteCommon) TestHeaderReadGarbage(c *C) {
+ var h header
+ c.Assert(h.Read(bytes.NewBuffer([]byte{1, 2, 3, 4, 5})), Equals, ErrHeader)
+ c.Assert(h.Read(bytes.NewBuffer([]byte{1, 2, 3, 4, 5, '0'})), Equals, ErrHeader)
+}
+
+func (s *SuiteCommon) TestHeaderReadInvalidType(c *C) {
+ var h header
+ c.Assert(h.Read(bytes.NewBuffer([]byte{1, 2, ' ', 4, 5, 0})), Equals, core.ErrInvalidType)
+}
+
+func (s *SuiteCommon) TestHeaderReadInvalidSize(c *C) {
+ var h header
+ c.Assert(h.Read(bytes.NewBuffer([]byte{'b', 'l', 'o', 'b', ' ', 'a', 0})), Equals, ErrHeader)
+}
+
+func (s *SuiteCommon) TestHeaderReadNegativeSize(c *C) {
+ var h header
+ c.Assert(h.Read(bytes.NewBuffer([]byte{'b', 'l', 'o', 'b', ' ', '-', '1', 0})), Equals, ErrNegativeSize)
+}