aboutsummaryrefslogtreecommitdiffstats
path: root/binapigen/gen_helpers_test.go
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2020-10-23 11:40:18 +0200
committerOndrej Fabry <ofabry@cisco.com>2020-10-30 10:00:00 +0000
commit0f46871b4cc45f2c3bd5bdb0aa0f7615795a2c6d (patch)
tree3d3de8febc3e2becfbbbd648538fc5dd1748374f /binapigen/gen_helpers_test.go
parentcb540dc166c12180adba024d5b8fd463d2582928 (diff)
Fix encoding for float64 and generate conversion for Timestamp
- fixes encoding/decoding of float64 - uses little endian (contrary to all other types) - generates helper methods for vpe_types.Timestamp type - adds usage code to simple-client and binapi-types examples Change-Id: I2e83eee0629eb67964049406c50c7ee0a692ccaf Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'binapigen/gen_helpers_test.go')
-rw-r--r--binapigen/gen_helpers_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/binapigen/gen_helpers_test.go b/binapigen/gen_helpers_test.go
index 371fd6c..075dd8e 100644
--- a/binapigen/gen_helpers_test.go
+++ b/binapigen/gen_helpers_test.go
@@ -17,11 +17,13 @@ package binapigen
import (
"strings"
"testing"
+ "time"
. "github.com/onsi/gomega"
"git.fd.io/govpp.git/binapi/ethernet_types"
"git.fd.io/govpp.git/binapi/ip_types"
+ "git.fd.io/govpp.git/binapi/vpe_types"
)
func TestGeneratedParseAddress(t *testing.T) {
@@ -154,3 +156,28 @@ func TestGeneratedParseMACError(t *testing.T) {
_, err := ethernet_types.ParseMacAddress("malformed_mac")
Expect(err).Should(HaveOccurred())
}
+
+func TestGeneratedParseTimestamp(t *testing.T) {
+ RegisterTestingT(t)
+
+ var data = []struct {
+ input time.Time
+ result vpe_types.Timestamp
+ }{
+ {time.Unix(0, 0), vpe_types.Timestamp(0)},
+ {time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC),
+ vpe_types.Timestamp(9.466848e+08)},
+ }
+
+ for _, entry := range data {
+ t.Run(entry.input.String(), func(t *testing.T) {
+ ts := vpe_types.NewTimestamp(entry.input)
+ Expect(ts).To(Equal(entry.result))
+
+ Expect(entry.input.Equal(ts.ToTime())).To(BeTrue())
+
+ originTime := ts.String()
+ Expect(originTime).To(Equal(entry.input.Local().String()))
+ })
+ }
+}