MCPcopy Create free account
hub / github.com/cisco/senml / TestEncode

Function TestEncode

senml_test.go:63–98  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestEncode(t *testing.T) {
64 value := 22.1
65 sum := 0.0
66 vb := true
67 s := senml.SenML{
68 Records: []senml.SenMLRecord{
69 senml.SenMLRecord{BaseName: "dev123",
70 BaseTime: -45.67,
71 BaseUnit: "degC",
72 BaseVersion: 5,
73 Value: &value, Unit: "degC", Name: "temp", Time: -1.0, UpdateTime: 10.0, Sum: &sum},
74 senml.SenMLRecord{StringValue: "kitchen", Name: "room", Time: -1.0},
75 senml.SenMLRecord{DataValue: "abc", Name: "data"},
76 senml.SenMLRecord{BoolValue: &vb, Name: "ok"},
77 },
78 }
79 options := senml.OutputOptions{Topic: "fluffySenml", PrettyPrint: false}
80 for i, vector := range testVectors {
81
82 dataOut, err := senml.Encode(s, vector.format, options)
83 if err != nil {
84 t.Fail()
85 }
86 if vector.binary {
87 fmt.Print("Test Encode " + strconv.Itoa(i) + " got: ")
88 fmt.Println(dataOut)
89 } else {
90 fmt.Println("Test Encode " + strconv.Itoa(i) + " got: " + string(dataOut))
91 }
92
93 if base64.StdEncoding.EncodeToString(dataOut) != vector.value {
94 t.Error("Failed Encode for format " + strconv.Itoa(i) + " got: " + base64.StdEncoding.EncodeToString(dataOut))
95 }
96 }
97
98}
99
100func TestDecode(t *testing.T) {
101 for i, vector := range testVectors {

Callers

nothing calls this directly

Calls 1

EncodeFunction · 0.92

Tested by

no test coverage detected