mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-21 14:28:59 +00:00
error tests for arg values when encoding
This commit is contained in:
@@ -166,6 +166,62 @@ func TestBadOSCMessageEncoding(t *testing.T) {
|
|||||||
},
|
},
|
||||||
errorString: "unsupported OSC argument type: x",
|
errorString: "unsupported OSC argument type: x",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "string arg that is not a string",
|
||||||
|
message: &OSCMessage{
|
||||||
|
Address: "/hello",
|
||||||
|
Args: []OSCArg{{Type: "s", Value: 123}},
|
||||||
|
},
|
||||||
|
errorString: "OSC arg had string type but non-string value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "int32 arg that is not a number",
|
||||||
|
message: &OSCMessage{
|
||||||
|
Address: "/hello",
|
||||||
|
Args: []OSCArg{{Type: "i", Value: "not an int"}},
|
||||||
|
},
|
||||||
|
errorString: "OSC arg had int32 type but non-number value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float32 arg that is not a number",
|
||||||
|
message: &OSCMessage{
|
||||||
|
Address: "/hello",
|
||||||
|
Args: []OSCArg{{Type: "f", Value: "not a float"}},
|
||||||
|
},
|
||||||
|
errorString: "OSC arg had float32 type but non-number value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "int64 arg that is not a number",
|
||||||
|
message: &OSCMessage{
|
||||||
|
Address: "/hello",
|
||||||
|
Args: []OSCArg{{Type: "h", Value: "not an int"}},
|
||||||
|
},
|
||||||
|
errorString: "OSC arg had int64 type but non-number value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "float64 arg that is not a number",
|
||||||
|
message: &OSCMessage{
|
||||||
|
Address: "/hello",
|
||||||
|
Args: []OSCArg{{Type: "d", Value: "not a float"}},
|
||||||
|
},
|
||||||
|
errorString: "OSC arg had float64 type but non-number value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "blob arg that is not a byte array",
|
||||||
|
message: &OSCMessage{
|
||||||
|
Address: "/hello",
|
||||||
|
Args: []OSCArg{{Type: "b", Value: "not a blob"}},
|
||||||
|
},
|
||||||
|
errorString: "OSC arg had blob type but non-blob value",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "color arg that is not an OSCColor",
|
||||||
|
message: &OSCMessage{
|
||||||
|
Address: "/hello",
|
||||||
|
Args: []OSCArg{{Type: "r", Value: "not a color"}},
|
||||||
|
},
|
||||||
|
errorString: "OSC arg had color type but non-color value",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ func argsToBuffer(args []OSCArg) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
argBuffers = append(argBuffers, valueBytes...)
|
argBuffers = append(argBuffers, valueBytes...)
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("OSC arg had integer type but non-integer value")
|
return nil, errors.New("OSC arg had int32 type but non-number value")
|
||||||
}
|
}
|
||||||
case "f":
|
case "f":
|
||||||
if value, ok := arg.Value.(float32); ok {
|
if value, ok := arg.Value.(float32); ok {
|
||||||
@@ -157,7 +157,7 @@ func argsToBuffer(args []OSCArg) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
argBuffers = append(argBuffers, valueBytes...)
|
argBuffers = append(argBuffers, valueBytes...)
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("OSC arg had float type but non-float value.")
|
return nil, errors.New("OSC arg had float32 type but non-number value")
|
||||||
}
|
}
|
||||||
case "b":
|
case "b":
|
||||||
if value, ok := arg.Value.([]byte); ok {
|
if value, ok := arg.Value.([]byte); ok {
|
||||||
@@ -167,7 +167,7 @@ func argsToBuffer(args []OSCArg) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
argBuffers = append(argBuffers, valueBytes...)
|
argBuffers = append(argBuffers, valueBytes...)
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("OSC arg had blob type but non-blob value.")
|
return nil, errors.New("OSC arg had blob type but non-blob value")
|
||||||
}
|
}
|
||||||
case "T":
|
case "T":
|
||||||
argBuffers = append(argBuffers, make([]byte, 0)...)
|
argBuffers = append(argBuffers, make([]byte, 0)...)
|
||||||
@@ -179,6 +179,9 @@ func argsToBuffer(args []OSCArg) ([]byte, error) {
|
|||||||
argBuffers = append(argBuffers, make([]byte, 0)...)
|
argBuffers = append(argBuffers, make([]byte, 0)...)
|
||||||
case "r":
|
case "r":
|
||||||
color, ok := arg.Value.(OSCColor)
|
color, ok := arg.Value.(OSCColor)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("OSC arg had color type but non-color value")
|
||||||
|
}
|
||||||
if ok {
|
if ok {
|
||||||
colorBytes := []byte{color.r, color.g, color.b, color.a}
|
colorBytes := []byte{color.r, color.g, color.b, color.a}
|
||||||
argBuffers = append(argBuffers, colorBytes...)
|
argBuffers = append(argBuffers, colorBytes...)
|
||||||
@@ -203,7 +206,7 @@ func argsToBuffer(args []OSCArg) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
argBuffers = append(argBuffers, valueBytes...)
|
argBuffers = append(argBuffers, valueBytes...)
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("OSC arg had integer type but non-integer value.")
|
return nil, errors.New("OSC arg had int64 type but non-number value")
|
||||||
}
|
}
|
||||||
case "d":
|
case "d":
|
||||||
if value, ok := arg.Value.(float32); ok {
|
if value, ok := arg.Value.(float32); ok {
|
||||||
@@ -237,7 +240,7 @@ func argsToBuffer(args []OSCArg) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
argBuffers = append(argBuffers, valueBytes...)
|
argBuffers = append(argBuffers, valueBytes...)
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New("OSC arg had float type but non-float value.")
|
return nil, errors.New("OSC arg had float64 type but non-number value")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported OSC argument type: %s", oscType)
|
return nil, fmt.Errorf("unsupported OSC argument type: %s", oscType)
|
||||||
|
|||||||
Reference in New Issue
Block a user