| 1 |
-- None |
| 2 |
pod = Pod.None () |
| 3 |
assert (pod:parse() == nil) |
| 4 |
assert (pod:get_type_name() == "Spa:None") |
| 5 |
|
| 6 |
-- Bool |
| 7 |
pod = Pod.Boolean (true) |
| 8 |
assert (pod:parse()) |
| 9 |
assert (pod:get_type_name() == "Spa:Bool") |
| 10 |
|
| 11 |
-- Id |
| 12 |
pod = Pod.Id (4) |
| 13 |
assert (pod:parse() == 4) |
| 14 |
assert (pod:get_type_name() == "Spa:Id") |
| 15 |
pod = Pod.Id("Spa:Enum:AudioChannel", "FL") |
| 16 |
assert (pod:parse() == 3) |
| 17 |
assert (pod:get_type_name() == "Spa:Id") |
| 18 |
|
| 19 |
-- Int |
| 20 |
pod = Pod.Int (64) |
| 21 |
assert (pod:parse() == 64) |
| 22 |
assert (pod:get_type_name() == "Spa:Int") |
| 23 |
|
| 24 |
-- Long |
| 25 |
pod = Pod.Long (1024) |
| 26 |
assert (pod:parse() == 1024) |
| 27 |
assert (pod:get_type_name() == "Spa:Long") |
| 28 |
|
| 29 |
-- Float |
| 30 |
pod = Pod.Float (1.02) |
| 31 |
val = pod:parse () |
| 32 |
assert (val > 1.01 and val < 1.03) |
| 33 |
assert (pod:get_type_name() == "Spa:Float") |
| 34 |
|
| 35 |
-- Double |
| 36 |
pod = Pod.Double (3.14159265359) |
| 37 |
val = pod:parse () |
| 38 |
assert (val > 3.14159265358 and val < 3.14159265360) |
| 39 |
assert (pod:get_type_name() == "Spa:Double") |
| 40 |
|
| 41 |
-- String |
| 42 |
pod = Pod.String ("a pod string") |
| 43 |
assert (pod:parse() == "a pod string") |
| 44 |
assert (pod:get_type_name() == "Spa:String") |
| 45 |
|
| 46 |
-- Bytes |
| 47 |
pod = Pod.Bytes ("16characterbytes") |
| 48 |
assert (pod:parse() == "16characterbytes") |
| 49 |
assert (pod:get_type_name() == "Spa:Bytes") |
| 50 |
|
| 51 |
-- Pointer |
| 52 |
pod = Pod.Pointer ("Spa:Pointer:Buffer", nil) |
| 53 |
assert (pod:parse() == nil) |
| 54 |
assert (pod:get_type_name() == "Spa:Pointer:Buffer") |
| 55 |
|
| 56 |
-- Fd |
| 57 |
pod = Pod.Fd (5) |
| 58 |
assert (pod:parse() == 5) |
| 59 |
assert (pod:get_type_name() == "Spa:Fd") |
| 60 |
|
| 61 |
-- Rectangle |
| 62 |
pod = Pod.Rectangle (1920, 1080) |
| 63 |
val = pod:parse() |
| 64 |
assert (val.pod_type == "Rectangle") |
| 65 |
assert (val.width == 1920 and val.height == 1080) |
| 66 |
assert (pod:get_type_name() == "Spa:Rectangle") |
| 67 |
|
| 68 |
-- Fraction |
| 69 |
pod = Pod.Fraction (3, 4) |
| 70 |
val = pod:parse() |
| 71 |
assert (val.pod_type == "Fraction") |
| 72 |
assert (val.num == 3 and val.denom == 4) |
| 73 |
assert (pod:get_type_name() == "Spa:Fraction") |
| 74 |
|
| 75 |
-- Struct |
| 76 |
pod = Pod.Struct { true, 1, "string" } |
| 77 |
val = pod:parse() |
| 78 |
assert (val.pod_type == "Struct") |
| 79 |
assert (val[1] and val[2] == 1 and val[3] == "string") |
| 80 |
assert (pod:get_type_name() == "Spa:Pod:Struct") |
| 81 |
|
| 82 |
-- Object |
| 83 |
pod = Pod.Object { |
| 84 |
"Spa:Pod:Object:Param:PortConfig", "PortConfig", |
| 85 |
direction = "Input", |
| 86 |
mode = "dsp", |
| 87 |
monitor = true |
| 88 |
} |
| 89 |
val = pod:parse() |
| 90 |
assert (val.pod_type == "Object") |
| 91 |
assert (val.object_id == "PortConfig") |
| 92 |
assert (val.properties.direction == "Input") |
| 93 |
assert (val.properties.mode == "dsp") |
| 94 |
assert (val.properties.monitor) |
| 95 |
assert (pod:get_type_name() == "Spa:Pod:Object:Param:PortConfig") |
| 96 |
pod = Pod.Object { |
| 97 |
"Spa:Pod:Object:Param:Props", "Props", |
| 98 |
device = "hw:Generic", |
| 99 |
deviceName = "", |
| 100 |
cardName = "", |
| 101 |
minLatency = 16, |
| 102 |
maxLatency = 8192, |
| 103 |
["id-01000000"] = Pod.Boolean (true), |
| 104 |
latencyOffsetNsec = 0 |
| 105 |
} |
| 106 |
val = pod:parse() |
| 107 |
assert (val.pod_type == "Object") |
| 108 |
assert (val.object_id == "Props") |
| 109 |
assert (val.properties.device == "hw:Generic") |
| 110 |
assert (val.properties.deviceName == "") |
| 111 |
assert (val.properties.cardName == "") |
| 112 |
assert (val.properties.minLatency == 16) |
| 113 |
assert (val.properties.maxLatency == 8192) |
| 114 |
assert (val.properties["id-01000000"] == true) |
| 115 |
assert (val.properties.latencyOffsetNsec == 0) |
| 116 |
assert (pod:get_type_name() == "Spa:Pod:Object:Param:Props") |
| 117 |
|
| 118 |
-- Sequence |
| 119 |
pod = Pod.Sequence { |
| 120 |
{offset = 10, typename = "Properties", value = 1}, |
| 121 |
{offset = 20, typename = "Properties", value = 2}, |
| 122 |
{offset = 40, typename = "Properties", value = 4}, |
| 123 |
} |
| 124 |
val = pod:parse() |
| 125 |
assert (val.pod_type == "Sequence") |
| 126 |
assert (val[1].offset == 10 and val[1].typename == "Properties" and val[1].value == 1) |
| 127 |
assert (val[2].offset == 20 and val[2].typename == "Properties" and val[2].value == 2) |
| 128 |
assert (val[3].offset == 40 and val[3].typename == "Properties" and val[3].value == 4) |
| 129 |
assert (pod:get_type_name() == "Spa:Pod:Sequence") |
| 130 |
|
| 131 |
-- Array |
| 132 |
pod = Pod.Array { "Spa:Bool", true, false, false, true } |
| 133 |
val = pod:parse() |
| 134 |
assert (val.pod_type == "Array") |
| 135 |
assert (val.value_type == "Spa:Bool") |
| 136 |
assert (val[1]) |
| 137 |
assert (not val[2]) |
| 138 |
assert (not val[3]) |
| 139 |
assert (val[4]) |
| 140 |
assert (pod:get_type_name() == "Spa:Array") |
| 141 |
pod = Pod.Array { "Spa:Enum:AudioChannel", "FL", "FR" } |
| 142 |
val = pod:parse() |
| 143 |
assert (val.pod_type == "Array") |
| 144 |
assert (val.value_type == "Spa:Id") |
| 145 |
assert (val[1] == 3) |
| 146 |
assert (val[2] == 4) |
| 147 |
|
| 148 |
-- Choice |
| 149 |
pod = Pod.Choice.None { "Spa:Bool", false } |
| 150 |
val = pod:parse() |
| 151 |
assert(val.pod_type == "Choice.None") |
| 152 |
assert(val.value_type == "Spa:Bool") |
| 153 |
assert(not val[1]) |
| 154 |
pod = Pod.Choice.Range { "Spa:Float", 1.0, 0.0, 1.0 } |
| 155 |
val = pod:parse() |
| 156 |
assert (pod:get_type_name() == "Spa:Pod:Choice") |
| 157 |
assert(val.pod_type == "Choice.Range") |
| 158 |
assert(val.value_type == "Spa:Float") |
| 159 |
assert(val[1] == 1.0) |
| 160 |
assert(val[2] == 0.0) |
| 161 |
assert(val[3] == 1.0) |
| 162 |
assert (pod:get_type_name() == "Spa:Pod:Choice") |
| 163 |
pod = Pod.Choice.Step { "Spa:Int", 5, 10 } |
| 164 |
val = pod:parse() |
| 165 |
assert(val.pod_type == "Choice.Step") |
| 166 |
assert(val.value_type == "Spa:Int") |
| 167 |
assert(val[1] == 5) |
| 168 |
assert(val[2] == 10) |
| 169 |
assert (pod:get_type_name() == "Spa:Pod:Choice") |
| 170 |
pod = Pod.Choice.Enum { "Spa:Enum:AudioChannel", "FL", "FL", "FR" } |
| 171 |
val = pod:parse() |
| 172 |
assert (val.pod_type == "Choice.Enum") |
| 173 |
assert (val.value_type == "Spa:Id") |
| 174 |
assert (val[1] == 3) |
| 175 |
assert (val[2] == 3) |
| 176 |
assert (val[3] == 4) |
| 177 |
assert (pod:get_type_name() == "Spa:Pod:Choice") |
| 178 |
pod = Pod.Choice.Flags { "Spa:Int", 1 << 0, 1 << 2, 1 << 3} |
| 179 |
val = pod:parse() |
| 180 |
assert (val.pod_type == "Choice.Flags") |
| 181 |
assert (val.value_type == "Spa:Int") |
| 182 |
assert (val[1] == 1 << 0) |
| 183 |
assert (val[2] == 1 << 2) |
| 184 |
assert (val[3] == 1 << 3) |
| 185 |
assert (pod:get_type_name() == "Spa:Pod:Choice") |
| 186 |
|
| 187 |
|
| 188 |
-- Nested Pods |
| 189 |
pod = Pod.Object { |
| 190 |
"Spa:Pod:Object:Param:PortConfig", "PortConfig", |
| 191 |
direction = "Input", |
| 192 |
mode = "dsp", |
| 193 |
monitor = true, |
| 194 |
format = Pod.Object { |
| 195 |
"Spa:Pod:Object:Param:Format", "Format", |
| 196 |
mediaType = "audio", |
| 197 |
mediaSubtype = "raw", |
| 198 |
rate = 48000, |
| 199 |
format = Pod.Choice.Enum { "Spa:Enum:AudioFormat", "S16LE", "S16LE", "F32LE" }, |
| 200 |
channels = Pod.Choice.Range { "Spa:Int", 2, 1, 32 }, |
| 201 |
position = Pod.Array { "Spa:Enum:AudioChannel", "FL", "FR" } |
| 202 |
} |
| 203 |
} |
| 204 |
val = pod:parse() |
| 205 |
assert (val.pod_type == "Object") |
| 206 |
assert (val.object_id == "PortConfig") |
| 207 |
assert (val.properties.direction == "Input") |
| 208 |
assert (val.properties.mode == "dsp") |
| 209 |
assert (val.properties.monitor) |
| 210 |
assert (val.properties.format.pod_type == "Object") |
| 211 |
assert (val.properties.format.object_id == "Format") |
| 212 |
assert (val.properties.format.properties.mediaType == "audio") |
| 213 |
assert (val.properties.format.properties.mediaSubtype == "raw") |
| 214 |
assert (val.properties.format.properties.rate == 48000) |
| 215 |
assert (val.properties.format.properties.format.pod_type == "Choice.Enum") |
| 216 |
assert (val.properties.format.properties.format.value_type == "Spa:Id") |
| 217 |
assert (val.properties.format.properties.format[1] == "S16LE") |
| 218 |
assert (val.properties.format.properties.format[2] == "S16LE") |
| 219 |
assert (val.properties.format.properties.format[3] == "F32LE") |
| 220 |
assert (val.properties.format.properties.channels.pod_type == "Choice.Range") |
| 221 |
assert (val.properties.format.properties.channels.value_type == "Spa:Int") |
| 222 |
assert (val.properties.format.properties.channels[1] == 2) |
| 223 |
assert (val.properties.format.properties.channels[2] == 1) |
| 224 |
assert (val.properties.format.properties.channels[3] == 32) |
| 225 |
assert (val.properties.format.properties.position.pod_type == "Array") |
| 226 |
assert (val.properties.format.properties.position.value_type == "Spa:Id") |
| 227 |
assert (val.properties.format.properties.position[1] == "FL") |
| 228 |
assert (val.properties.format.properties.position[2] == "FR") |
| 229 |
assert (pod:get_type_name() == "Spa:Pod:Object:Param:PortConfig") |
| 230 |
|
| 231 |
-- Nested Object Id Properties |
| 232 |
pod = Pod.Object { |
| 233 |
"Spa:Pod:Object:Param:Props", "Props", |
| 234 |
device = "my-device", |
| 235 |
["id-01000000"] = Pod.Int (4), |
| 236 |
["id-02000000"] = Pod.Object { |
| 237 |
"Spa:Pod:Object:Param:Props", "Props", |
| 238 |
device = "my-sub-device", |
| 239 |
["id-03000000"] = Pod.Boolean (true), |
| 240 |
["id-04000000"] = Pod.String ("string") |
| 241 |
} |
| 242 |
} |
| 243 |
val = pod:parse() |
| 244 |
assert (val.pod_type == "Object") |
| 245 |
assert (val.object_id == "Props") |
| 246 |
assert (val.properties.device == "my-device") |
| 247 |
assert (val.properties["id-01000000"] == 4) |
| 248 |
assert (val.properties["id-02000000"].properties.device == "my-sub-device") |
| 249 |
assert (val.properties["id-02000000"].properties["id-03000000"] == true) |
| 250 |
assert (val.properties["id-02000000"].properties["id-04000000"] == "string") |
| 251 |
assert (pod:get_type_name() == "Spa:Pod:Object:Param:Props") |