|
1 | 1 | {$CLEO .s} |
2 | | -{$USE debug} |
3 | | -{$USE memory} |
4 | | -{$USE audio} |
5 | | -var 0@ : Integer |
6 | | -var 1@ : Integer |
7 | | -var 2@ : Integer |
8 | | -var 3@ : Integer |
9 | | -var 4@ : Integer |
10 | | -var 5@ : Integer |
11 | | -var 6@ : Integer |
12 | | -var 7@ : Integer |
13 | | -var 8@ : Integer |
14 | | -var 9@ : Integer |
15 | | -var 10@ : Integer |
| 2 | +{$INCLUDE_ONCE ../cleo_tester.inc} |
16 | 3 |
|
17 | | -script_name "0AB9" // get_audio_stream_state |
18 | | - |
19 | | -debug_on |
20 | | - |
21 | | -trace "0AB9 (get_audio_stream_state)" |
| 4 | +script_name '0AB9' |
| 5 | +test("0AB9 (get_audio_stream_state)", tests) |
| 6 | +terminate_this_custom_script |
22 | 7 |
|
| 8 | +const Test_File = ".\Speech.mp3" |
23 | 9 |
|
24 | | -// load the file |
25 | | -wait 0 |
26 | | -if |
27 | | - load_audio_stream ".\Ding.mp3" {store_to} 0@ |
28 | | -then |
29 | | - trace "~g~~h~~h~0AB9 (get_audio_stream_state), #0 PASSED" |
30 | | -else |
31 | | - breakpoint "~r~~h~~h~~h~0AB9 (get_audio_stream_state), #0 FAILED!~n~Failed to load file. Handle: %d" 0@ |
32 | | -end |
| 10 | +function tests |
| 11 | + int stream |
| 12 | + before_each(@setup) |
| 13 | + after_each(@cleanup) |
33 | 14 |
|
| 15 | + it("should return set state", test1) |
| 16 | + it("should return Stopped when finished", test2) |
| 17 | + return |
| 18 | + |
34 | 19 |
|
35 | | -// get state |
36 | | -wait 0 |
37 | | -0AB9: get_audio_stream_state 0@ {store_to} 1@ // tested opcode |
38 | | -if |
39 | | - 1@ == 2 // AudioStreamState.Paused |
40 | | -then |
41 | | - trace "~g~~h~~h~0AB9 (get_audio_stream_state), #1 PASSED" |
42 | | -else |
43 | | - breakpoint "~r~~h~~h~~h~0AB9 (get_audio_stream_state), #1 FAILED!~n~%d Expected~n~%d Occured" 2 1@ |
44 | | -end |
| 20 | + :setup |
| 21 | + stream = load_audio_stream Test_File |
| 22 | + assert_result_true() |
| 23 | + return |
45 | 24 |
|
46 | 25 |
|
47 | | -// set new state |
48 | | -wait 0 |
49 | | -set_audio_stream_state 0@ {state} AudioStreamAction.Play |
50 | | -trace "~g~~h~~h~0AAD (set_audio_stream_state), #2 PASSED" |
| 26 | + :cleanup |
| 27 | + remove_audio_stream stream |
| 28 | + stream = -1 |
| 29 | + return |
51 | 30 |
|
52 | 31 |
|
53 | | -// get updated state |
54 | | -wait 0 |
55 | | -0AB9: get_audio_stream_state 0@ {store_to} 1@ // tested opcode |
56 | | -if |
57 | | - 1@ == 1 // AudioStreamState.Playing |
58 | | -then |
59 | | - trace "~g~~h~~h~0AB9 (get_audio_stream_state), #3 PASSED" |
60 | | -else |
61 | | - breakpoint "~r~~h~~h~~h~0AB9 (get_audio_stream_state), #3 FAILED!~n~%d Expected~n~%d Occured" 1 1@ |
62 | | -end |
| 32 | + function test1(stream: int) |
| 33 | + int state |
| 34 | + |
| 35 | + // starts as stopped |
| 36 | + state = 0x666 |
| 37 | + state = get_audio_stream_state stream |
| 38 | + assert_eq(state, 2) // AudioStreamState.Paused |
| 39 | + |
| 40 | + // still paused |
| 41 | + wait {time} 0 |
| 42 | + state = 0x666 |
| 43 | + state = get_audio_stream_state stream |
| 44 | + assert_eq(state, 2) // AudioStreamState.Paused |
| 45 | + |
| 46 | + // play, effective right away |
| 47 | + set_audio_stream_state stream {action} AudioStreamAction.Play |
| 48 | + state = 0x666 |
| 49 | + state = get_audio_stream_state stream |
| 50 | + assert_eq(state, 1) // AudioStreamState.Playing |
| 51 | + |
| 52 | + // still playing |
| 53 | + wait {time} 0 |
| 54 | + state = 0x666 |
| 55 | + state = get_audio_stream_state stream |
| 56 | + assert_eq(state, 1) // AudioStreamState.Playing |
| 57 | + |
| 58 | + // stop, effective right away |
| 59 | + set_audio_stream_state stream {action} AudioStreamAction.Stop |
| 60 | + state = 0x666 |
| 61 | + state = get_audio_stream_state stream |
| 62 | + assert_eq(state, -1) // AudioStreamState.Stopped |
| 63 | + |
| 64 | + // still stopped |
| 65 | + wait {time} 0 |
| 66 | + state = 0x666 |
| 67 | + state = get_audio_stream_state stream |
| 68 | + assert_eq(state, -1) // AudioStreamState.Stopped |
| 69 | + |
| 70 | + // stopped can not turn into paused |
| 71 | + set_audio_stream_state stream {action} AudioStreamAction.Pause |
| 72 | + state = 0x666 |
| 73 | + state = get_audio_stream_state stream |
| 74 | + assert_eq(state, -1) // AudioStreamState.Stopped |
| 75 | + end |
63 | 76 |
|
64 | 77 |
|
65 | | -// check if state updated after playback end |
66 | | -wait 400 // Ding.mp3 is 0.25s long |
67 | | -0AB9: get_audio_stream_state 0@ {store_to} 1@ // tested opcode |
68 | | -if |
69 | | - 1@ == -1 // AudioStreamState.Stopped |
70 | | -then |
71 | | - trace "~g~~h~~h~0AB9 (get_audio_stream_state), #4 PASSED" |
72 | | -else |
73 | | - breakpoint "~r~~h~~h~~h~0AB9 (get_audio_stream_state), #4 FAILED!~n~%d Expected~n~%d Occured" -1 1@ |
| 78 | + function test2(stream: int) |
| 79 | + set_audio_stream_progress stream {progress} 0.99 |
| 80 | + set_audio_stream_state stream {action} AudioStreamAction.Play |
| 81 | + |
| 82 | + wait {time} 200 |
| 83 | + int state = 0x666 |
| 84 | + state = get_audio_stream_state stream |
| 85 | + assert_eq(state, -1) // AudioStreamState.Stopped |
| 86 | + end |
74 | 87 | end |
75 | 88 |
|
76 | 89 |
|
|
0 commit comments