Browse Source

codec: test: move features broken in other libs out of values_test.go into values_flex_test.go

To test features, we either expose them in values_test.go or values_flex_test.go

Some libs (e.g. bson, xdr, sereal, etc) do not handle these well
- encoding/decoding of arrays or pointers to arrays
- unexported anonymous fields
- large integers (greater than math.MaxInt64 ... up to math.MaxUint64)

To accomodate, we move these features to be in values_flex_test.go
or only use large integers when running codec tests (not in benchmarks).
Ugorji Nwoke 8 years ago
parent
commit
dade91789f
3 changed files with 25 additions and 17 deletions
  1. 2 0
      codec/gen.generated.go
  2. 9 2
      codec/values_flex_test.go
  3. 14 15
      codec/values_test.go

+ 2 - 0
codec/gen.generated.go

@@ -1,3 +1,5 @@
+// +build codecgen.exec
+
 // Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
 // Use of this source code is governed by a MIT license found in the LICENSE file.
 

+ 9 - 2
codec/values_flex_test.go

@@ -67,7 +67,7 @@ func init() {
 
 type TestStrucFlex struct {
 	_struct struct{} `codec:",omitempty"` //set omitempty for every field
-	testStrucCommon
+	TestStrucCommon
 
 	Mis     map[int]string
 	Mbu64   map[bool]struct{}
@@ -81,6 +81,9 @@ type TestStrucFlex struct {
 	Swrapbytes []wrapBytes
 	Swrapuint8 []wrapUint8
 
+	Ui64array      [4]uint64
+	Ui64slicearray []*[4]uint64
+
 	//M map[interface{}]interface{}  `json:"-",bson:"-"`
 	Mtsptr     map[string]*TestStrucFlex
 	Mts        map[string]TestStrucFlex
@@ -132,8 +135,12 @@ func newTestStrucFlex(depth, n int, bench, useInterface, useStringKeyOnly bool)
 		Swrapuint8: []wrapUint8{
 			'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
 		},
+		Ui64array: [4]uint64{4, 16, 64, 256},
 	}
-	populateTestStrucCommon(&ts.testStrucCommon, n, bench, useInterface, useStringKeyOnly)
+
+	ts.Ui64slicearray = []*[4]uint64{&ts.Ui64array, &ts.Ui64array}
+
+	populateTestStrucCommon(&ts.TestStrucCommon, n, bench, useInterface, useStringKeyOnly)
 	if depth > 0 {
 		depth--
 		if ts.Mtsptr == nil {

+ 14 - 15
codec/values_test.go

@@ -100,15 +100,13 @@ type testSimpleFields struct {
 	// TODO: test these separately, specifically for reflection and codecgen.
 	// Unfortunately, ffjson doesn't support these. Its compilation even fails.
 
-	Ui64array       [4]uint64
-	Ui64slicearray  []*[4]uint64
 	WrapSliceInt64  wrapSliceUint64
 	WrapSliceString wrapSliceString
 
 	Msi64 map[string]int64
 }
 
-type testStrucCommon struct {
+type TestStrucCommon struct {
 	S string
 
 	I64 int64
@@ -145,8 +143,6 @@ type testStrucCommon struct {
 	// TODO: test these separately, specifically for reflection and codecgen.
 	// Unfortunately, ffjson doesn't support these. Its compilation even fails.
 
-	Ui64array       [4]uint64
-	Ui64slicearray  []*[4]uint64
 	WrapSliceInt64  wrapSliceUint64
 	WrapSliceString wrapSliceString
 
@@ -174,7 +170,7 @@ type testStrucCommon struct {
 type TestStruc struct {
 	// _struct struct{} `json:",omitempty"` //set omitempty for every field
 
-	testStrucCommon
+	TestStrucCommon
 
 	Mtsptr     map[string]*TestStruc
 	Mts        map[string]TestStruc
@@ -184,9 +180,11 @@ type TestStruc struct {
 
 var testStrucTime = time.Date(2012, 2, 2, 2, 2, 2, 2000, time.UTC).UTC()
 
-func populateTestStrucCommon(ts *testStrucCommon, n int, bench, useInterface, useStringKeyOnly bool) {
+func populateTestStrucCommon(ts *TestStrucCommon, n int, bench, useInterface, useStringKeyOnly bool) {
 	var i64a, i64b, i64c, i64d int64 = 64, 6464, 646464, 64646464
 
+	// if bench, do not use uint64 values > math.MaxInt64, as bson, etc cannot decode them
+
 	var a = AnonInTestStruc{
 		// There's more leeway in altering this.
 		AS:    strRpt(n, "A-String"),
@@ -223,7 +221,6 @@ func populateTestStrucCommon(ts *testStrucCommon, n int, bench, useInterface, us
 			math.MaxUint8, math.MaxUint8 + 4, math.MaxUint8 - 4,
 			math.MaxUint16, math.MaxUint16 + 4, math.MaxUint16 - 4,
 			math.MaxUint32, math.MaxUint32 + 4, math.MaxUint32 - 4,
-			math.MaxUint64, math.MaxUint64 - 4,
 		},
 		AMSU16: map[string]uint16{strRpt(n, "1"): 1, strRpt(n, "22"): 2, strRpt(n, "333"): 3, strRpt(n, "4444"): 4},
 
@@ -268,7 +265,10 @@ func populateTestStrucCommon(ts *testStrucCommon, n int, bench, useInterface, us
 		AMSU16E:     map[string]uint16{},
 	}
 
-	*ts = testStrucCommon{
+	if !bench {
+		a.AUi64slice = append(a.AUi64slice, math.MaxUint64, math.MaxUint64-4)
+	}
+	*ts = TestStrucCommon{
 		S: strRpt(n, `some really really cool names that are nigerian and american like "ugorji melody nwoke" - get it? `),
 
 		// set the numbers close to the limits
@@ -306,8 +306,6 @@ func populateTestStrucCommon(ts *testStrucCommon, n int, bench, useInterface, us
 			strRpt(n, "\"three\""): 3,
 		},
 
-		Ui64array: [4]uint64{4, 16, 64, 256},
-
 		WrapSliceInt64:  []uint64{4, 16, 64, 256},
 		WrapSliceString: []string{strRpt(n, "4"), strRpt(n, "16"), strRpt(n, "64"), strRpt(n, "256")},
 
@@ -362,8 +360,6 @@ func populateTestStrucCommon(ts *testStrucCommon, n int, bench, useInterface, us
 				strRpt(n, "\"three\""): 3,
 			},
 
-			Ui64array: [4]uint64{4, 16, 64, 256},
-
 			WrapSliceInt64:  []uint64{4, 16, 64, 256},
 			WrapSliceString: []string{strRpt(n, "4"), strRpt(n, "16"), strRpt(n, "64"), strRpt(n, "256")},
 		},
@@ -372,7 +368,10 @@ func populateTestStrucCommon(ts *testStrucCommon, n int, bench, useInterface, us
 		NotAnon:         a,
 	}
 
-	ts.Ui64slicearray = []*[4]uint64{&ts.Ui64array, &ts.Ui64array}
+	if bench {
+		ts.Ui64 = math.MaxInt64 * 2 / 3
+		ts.Simplef.Ui64 = ts.Ui64
+	}
 
 	if useInterface {
 		ts.AnonInTestStrucIntf = &AnonInTestStrucIntf{
@@ -403,7 +402,7 @@ func populateTestStrucCommon(ts *testStrucCommon, n int, bench, useInterface, us
 
 func newTestStruc(depth, n int, bench, useInterface, useStringKeyOnly bool) (ts *TestStruc) {
 	ts = &TestStruc{}
-	populateTestStrucCommon(&ts.testStrucCommon, n, bench, useInterface, useStringKeyOnly)
+	populateTestStrucCommon(&ts.TestStrucCommon, n, bench, useInterface, useStringKeyOnly)
 	if depth > 0 {
 		depth--
 		if ts.Mtsptr == nil {