|
| 1 | + # -- |
| 2 | + # This file is part of Sonic Pi: http://sonic-pi.net |
| 3 | + # Full project source: https://github.com/sonic-pi-net/sonic-pi |
| 4 | + # License: https://github.com/sonic-pi-net/sonic-pi/blob/main/LICENSE.md |
| 5 | + |
| 6 | + # Copyright 2021 by Sam Aaron (http://sam.aaron.name/) |
| 7 | + # All rights reserved. |
| 8 | + |
| 9 | + # Permission is granted for use, copying, modification, and |
| 10 | + # distribution of modified versions of this work as long as this |
| 11 | + # notice is included. |
| 12 | + # ++ |
| 13 | + |
| 14 | + defmodule ErlangTauOSCTest do |
| 15 | + use ExUnit.Case |
| 16 | + |
| 17 | + test "basic osc encode/decode" do |
| 18 | + a = :osc.encode(['/test', 1, 3.5, 'bar']) |
| 19 | + {:cmd, ['/test', 1, 3.5, 'bar']} = :osc.decode(a) |
| 20 | + end |
| 21 | + |
| 22 | + test "osc encode/decode int64" do |
| 23 | + a = :osc.encode(['/testi64', {:int64, 347873045749854}]) |
| 24 | + {:cmd, ['/testi64', 347873045749854]} = :osc.decode(a) |
| 25 | + end |
| 26 | + |
| 27 | + test "decode osc binary" do |
| 28 | + bin = (<<35,98,117,110,100,108,101,0, |
| 29 | + 218,114,254,188,137,88,216,0,0,0,0,16, |
| 30 | + 47,102,111,111,0,0,0,0,44,115,0,0,98,97,114,0>>) |
| 31 | + |
| 32 | + {:bundle, _, [{_n, internal_osc}]} = :osc.decode(bin) |
| 33 | + {:cmd, ['/foo', 'bar']} = :osc.decode(internal_osc) |
| 34 | + |
| 35 | + end |
| 36 | + |
| 37 | + test "making a bundle with a timestamp" do |
| 38 | + t = :osc.now() |
| 39 | + bin = :osc.pack_ts(t, ['/forward', 'localhost', 6000, '/sendmidi', 12, 34, 56]) |
| 40 | + {:bundle, new_t, [{_n, internal_osc}]} = :osc.decode(bin) |
| 41 | + # take into account encoding/decoding rounding differences |
| 42 | + assert(abs(t - new_t) < 0.0001) |
| 43 | + {:cmd, ['/forward', 'localhost', 6000, '/sendmidi', 12, 34, 56]} = :osc.decode(internal_osc) |
| 44 | + end |
| 45 | +end |
0 commit comments