Skip to content

Commit 234a7c3

Browse files
Modified test codes
1 parent 4d71e71 commit 234a7c3

File tree

5 files changed

+187
-171
lines changed

5 files changed

+187
-171
lines changed

packet/tags/tag10_test.go

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55

66
"github.com/spiegel-im-spiegel/gpgpdump/options"
77
"github.com/spiegel-im-spiegel/gpgpdump/packet/context"
8+
"github.com/spiegel-im-spiegel/gpgpdump/packet/reader"
9+
"github.com/spiegel-im-spiegel/gpgpdump/packet/values"
810

911
openpgp "golang.org/x/crypto/openpgp/packet"
1012
)
@@ -22,26 +24,41 @@ const (
2224
)
2325

2426
func TestTag10(t *testing.T) {
25-
op := &openpgp.OpaquePacket{Tag: 10, Contents: tag10Body}
26-
cxt := context.NewContext(options.New(
27-
options.Set(options.DebugOpt, true),
28-
options.Set(options.IntegerOpt, true),
29-
options.Set(options.MarkerOpt, true),
30-
options.Set(options.LiteralOpt, true),
31-
options.Set(options.PrivateOpt, true),
32-
options.Set(options.UTCOpt, true),
33-
))
34-
i, err := NewTag(op, cxt).Parse()
35-
if err != nil {
36-
t.Errorf("NewTag() = %v, want nil error.", err)
37-
return
27+
testCases := []struct {
28+
tag uint8
29+
content []byte
30+
ktm []byte
31+
cxt context.SymAlgMode
32+
res string
33+
}{
34+
{tag: 10, content: tag10Body, ktm: nil, cxt: context.ModeNotSpecified, res: tag10Result},
3835
}
39-
if cxt.AlgMode() != context.ModeNotSpecified {
40-
t.Errorf("Options.Mode = %v, want \"%v\".", cxt.AlgMode(), context.ModeNotSpecified)
41-
}
42-
str := i.String()
43-
if str != tag10Result {
44-
t.Errorf("Tag.String = \"%s\", want \"%s\".", str, tag10Result)
36+
for _, tc := range testCases {
37+
op := &openpgp.OpaquePacket{Tag: tc.tag, Contents: tc.content}
38+
cxt := context.NewContext(options.New(
39+
options.Set(options.DebugOpt, true),
40+
options.Set(options.IntegerOpt, true),
41+
options.Set(options.MarkerOpt, true),
42+
options.Set(options.LiteralOpt, true),
43+
options.Set(options.PrivateOpt, true),
44+
options.Set(options.UTCOpt, true),
45+
))
46+
if tc.ktm != nil {
47+
tm, _ := values.NewDateTime(reader.New(tc.ktm), cxt.UTC())
48+
cxt.KeyCreationTime = tm
49+
}
50+
i, err := NewTag(op, cxt).Parse()
51+
if err != nil {
52+
t.Errorf("NewTag() = %v, want nil error.", err)
53+
return
54+
}
55+
if cxt.AlgMode() != tc.cxt {
56+
t.Errorf("Options.Mode = %v, want \"%v\".", cxt.AlgMode(), tc.cxt)
57+
}
58+
res := i.String()
59+
if res != tc.res {
60+
t.Errorf("Tag.String = \"%s\", want \"%s\".", res, tc.res)
61+
}
4562
}
4663
}
4764

packet/tags/tag11_test.go

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55

66
"github.com/spiegel-im-spiegel/gpgpdump/options"
77
"github.com/spiegel-im-spiegel/gpgpdump/packet/context"
8+
"github.com/spiegel-im-spiegel/gpgpdump/packet/reader"
9+
"github.com/spiegel-im-spiegel/gpgpdump/packet/values"
810

911
openpgp "golang.org/x/crypto/openpgp/packet"
1012
)
@@ -36,51 +38,43 @@ const (
3638
`
3739
)
3840

39-
func TestTag11a(t *testing.T) {
40-
op := &openpgp.OpaquePacket{Tag: 11, Contents: tag11Body1}
41-
cxt := context.NewContext(options.New(
42-
options.Set(options.DebugOpt, true),
43-
options.Set(options.IntegerOpt, true),
44-
options.Set(options.MarkerOpt, true),
45-
options.Set(options.LiteralOpt, true),
46-
options.Set(options.PrivateOpt, true),
47-
options.Set(options.UTCOpt, true),
48-
))
49-
i, err := NewTag(op, cxt).Parse()
50-
if err != nil {
51-
t.Errorf("NewTag() = %v, want nil error.", err)
52-
return
41+
func TestTag11(t *testing.T) {
42+
testCases := []struct {
43+
tag uint8
44+
content []byte
45+
ktm []byte
46+
cxt context.SymAlgMode
47+
res string
48+
}{
49+
{tag: 11, content: tag11Body1, ktm: nil, cxt: context.ModeNotSpecified, res: tag11Result1},
50+
{tag: 11, content: tag11Body2, ktm: nil, cxt: context.ModeNotSpecified, res: tag11Result2},
5351
}
54-
if cxt.AlgMode() != context.ModeNotSpecified {
55-
t.Errorf("Options.Mode = %v, want \"%v\".", cxt.AlgMode(), context.ModeNotSpecified)
56-
}
57-
str := i.String()
58-
if str != tag11Result1 {
59-
t.Errorf("Tag.String = \"%s\", want \"%s\".", str, tag11Result1)
60-
}
61-
}
62-
63-
func TestTag11b(t *testing.T) {
64-
op := &openpgp.OpaquePacket{Tag: 11, Contents: tag11Body2}
65-
cxt := context.NewContext(options.New(
66-
options.Set(options.DebugOpt, true),
67-
options.Set(options.IntegerOpt, true),
68-
options.Set(options.MarkerOpt, true),
69-
options.Set(options.LiteralOpt, true),
70-
options.Set(options.PrivateOpt, true),
71-
options.Set(options.UTCOpt, true),
72-
))
73-
i, err := NewTag(op, cxt).Parse()
74-
if err != nil {
75-
t.Errorf("NewTag() = %v, want nil error.", err)
76-
return
77-
}
78-
if cxt.AlgMode() != context.ModeNotSpecified {
79-
t.Errorf("Options.Mode = %v, want \"%v\".", cxt.AlgMode(), context.ModeNotSpecified)
80-
}
81-
str := i.String()
82-
if str != tag11Result2 {
83-
t.Errorf("Tag.String = \"%s\", want \"%s\".", str, tag11Result2)
52+
for _, tc := range testCases {
53+
op := &openpgp.OpaquePacket{Tag: tc.tag, Contents: tc.content}
54+
cxt := context.NewContext(options.New(
55+
options.Set(options.DebugOpt, true),
56+
options.Set(options.IntegerOpt, true),
57+
options.Set(options.MarkerOpt, true),
58+
options.Set(options.LiteralOpt, true),
59+
options.Set(options.PrivateOpt, true),
60+
options.Set(options.UTCOpt, true),
61+
))
62+
if tc.ktm != nil {
63+
tm, _ := values.NewDateTime(reader.New(tc.ktm), cxt.UTC())
64+
cxt.KeyCreationTime = tm
65+
}
66+
i, err := NewTag(op, cxt).Parse()
67+
if err != nil {
68+
t.Errorf("NewTag() = %v, want nil error.", err)
69+
return
70+
}
71+
if cxt.AlgMode() != tc.cxt {
72+
t.Errorf("Options.Mode = %v, want \"%v\".", cxt.AlgMode(), tc.cxt)
73+
}
74+
res := i.String()
75+
if res != tc.res {
76+
t.Errorf("Tag.String = \"%s\", want \"%s\".", res, tc.res)
77+
}
8478
}
8579
}
8680

packet/tags/tag13_test.go

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55

66
"github.com/spiegel-im-spiegel/gpgpdump/options"
77
"github.com/spiegel-im-spiegel/gpgpdump/packet/context"
8+
"github.com/spiegel-im-spiegel/gpgpdump/packet/reader"
9+
"github.com/spiegel-im-spiegel/gpgpdump/packet/values"
810

911
openpgp "golang.org/x/crypto/openpgp/packet"
1012
)
@@ -22,26 +24,41 @@ const (
2224
)
2325

2426
func TestTag13(t *testing.T) {
25-
op := &openpgp.OpaquePacket{Tag: 13, Contents: tag13Body1}
26-
cxt := context.NewContext(options.New(
27-
options.Set(options.DebugOpt, true),
28-
options.Set(options.IntegerOpt, true),
29-
options.Set(options.MarkerOpt, true),
30-
options.Set(options.LiteralOpt, true),
31-
options.Set(options.PrivateOpt, true),
32-
options.Set(options.UTCOpt, true),
33-
))
34-
i, err := NewTag(op, cxt).Parse()
35-
if err != nil {
36-
t.Errorf("NewTag() = %v, want nil error.", err)
37-
return
27+
testCases := []struct {
28+
tag uint8
29+
content []byte
30+
ktm []byte
31+
cxt context.SymAlgMode
32+
res string
33+
}{
34+
{tag: 13, content: tag13Body1, ktm: nil, cxt: context.ModeNotSpecified, res: tag13Result1},
3835
}
39-
if cxt.AlgMode() != context.ModeNotSpecified {
40-
t.Errorf("Options.Mode = %v, want \"%v\".", cxt.AlgMode(), context.ModeNotSpecified)
41-
}
42-
str := i.String()
43-
if str != tag13Result1 {
44-
t.Errorf("Tag.String = \"%s\", want \"%s\".", str, tag13Result1)
36+
for _, tc := range testCases {
37+
op := &openpgp.OpaquePacket{Tag: tc.tag, Contents: tc.content}
38+
cxt := context.NewContext(options.New(
39+
options.Set(options.DebugOpt, true),
40+
options.Set(options.IntegerOpt, true),
41+
options.Set(options.MarkerOpt, true),
42+
options.Set(options.LiteralOpt, true),
43+
options.Set(options.PrivateOpt, true),
44+
options.Set(options.UTCOpt, true),
45+
))
46+
if tc.ktm != nil {
47+
tm, _ := values.NewDateTime(reader.New(tc.ktm), cxt.UTC())
48+
cxt.KeyCreationTime = tm
49+
}
50+
i, err := NewTag(op, cxt).Parse()
51+
if err != nil {
52+
t.Errorf("NewTag() = %v, want nil error.", err)
53+
return
54+
}
55+
if cxt.AlgMode() != tc.cxt {
56+
t.Errorf("Options.Mode = %v, want \"%v\".", cxt.AlgMode(), tc.cxt)
57+
}
58+
res := i.String()
59+
if res != tc.res {
60+
t.Errorf("Tag.String = \"%s\", want \"%s\".", res, tc.res)
61+
}
4562
}
4663
}
4764

packet/tags/tag14_test.go

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55

66
"github.com/spiegel-im-spiegel/gpgpdump/options"
77
"github.com/spiegel-im-spiegel/gpgpdump/packet/context"
8+
"github.com/spiegel-im-spiegel/gpgpdump/packet/reader"
9+
"github.com/spiegel-im-spiegel/gpgpdump/packet/values"
810

911
openpgp "golang.org/x/crypto/openpgp/packet"
1012
)
@@ -32,26 +34,42 @@ const (
3234
)
3335

3436
func TestTag14(t *testing.T) {
35-
op := &openpgp.OpaquePacket{Tag: 14, Contents: tag14Body1}
36-
cxt := context.NewContext(options.New(
37-
options.Set(options.DebugOpt, true),
38-
options.Set(options.IntegerOpt, true),
39-
options.Set(options.MarkerOpt, true),
40-
options.Set(options.LiteralOpt, true),
41-
options.Set(options.PrivateOpt, true),
42-
options.Set(options.UTCOpt, true),
43-
))
44-
i, err := NewTag(op, cxt).Parse()
45-
if err != nil {
46-
t.Errorf("NewTag() = %v, want nil error.", err)
47-
return
37+
testCases := []struct {
38+
tag uint8
39+
content []byte
40+
ktm []byte
41+
cxt context.SymAlgMode
42+
res string
43+
}{
44+
{tag: 14, content: tag14Body1, ktm: nil, cxt: context.ModeNotSpecified, res: tag14Result1},
4845
}
49-
if cxt.AlgMode() != context.ModeNotSpecified {
50-
t.Errorf("Options.Mode = %v, want \"%v\".", cxt.AlgMode(), context.ModeNotSpecified)
51-
}
52-
str := i.String()
53-
if str != tag14Result1 {
54-
t.Errorf("Tag.String = \"%s\", want \"%s\".", str, tag14Result1)
46+
47+
for _, tc := range testCases {
48+
op := &openpgp.OpaquePacket{Tag: tc.tag, Contents: tc.content}
49+
cxt := context.NewContext(options.New(
50+
options.Set(options.DebugOpt, true),
51+
options.Set(options.IntegerOpt, true),
52+
options.Set(options.MarkerOpt, true),
53+
options.Set(options.LiteralOpt, true),
54+
options.Set(options.PrivateOpt, true),
55+
options.Set(options.UTCOpt, true),
56+
))
57+
if tc.ktm != nil {
58+
tm, _ := values.NewDateTime(reader.New(tc.ktm), cxt.UTC())
59+
cxt.KeyCreationTime = tm
60+
}
61+
i, err := NewTag(op, cxt).Parse()
62+
if err != nil {
63+
t.Errorf("NewTag() = %v, want nil error.", err)
64+
return
65+
}
66+
if cxt.AlgMode() != tc.cxt {
67+
t.Errorf("Options.Mode = %v, want \"%v\".", cxt.AlgMode(), tc.cxt)
68+
}
69+
res := i.String()
70+
if res != tc.res {
71+
t.Errorf("Tag.String = \"%s\", want \"%s\".", res, tc.res)
72+
}
5573
}
5674
}
5775

0 commit comments

Comments
 (0)