Anklang-0.3.0.dev956+gd75ac925 anklang-0.3.0.dev956+gd75ac925
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
prjtests.cc
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#include <ase/project.hh>
3#include <ase/clip.hh>
4#include <ase/track.hh>
5#include <ase/testing.hh>
6
7namespace { // Anon
8using namespace Ase;
9
10static void
11project_creation()
12{
13 ProjectImplP project = ProjectImpl::create ("TestProject");
14 TASSERT (project);
15 TASSERT (project->name() == "TestProject");
16
17 const double initial_bpm = project->bpm();
18 TASSERT (initial_bpm >= 10.0 && initial_bpm <= 999.0);
19 uint64_t bpm_notifications = 0;
20 auto bpm_connection = project->on_event ("notify:bpm", [&bpm_notifications] (const Event &event) { bpm_notifications++; });
21
22 uint64_t name_notifications = 0;
23 auto name_connection = project->on_event ("notify:name", [&name_notifications] (const Event &event) { name_notifications++; });
24
25 uint64_t volume_notifications = 0;
26 auto volume_connection = project->on_event ("notify:master_volume", [&volume_notifications] (const Event &event) { volume_notifications++; });
27
28 const double initial_vol = project->master_volume();
29 TASSERT (initial_vol >= -100.0 && initial_vol <= 20.0);
30
31 // Test BPM notify/undo/redo
32 project->bpm (130.0);
33 TASSERT (std::abs (project->bpm() - 130.0) < 0.001);
34 uint64_t last_bpm_notifications = bpm_notifications;
35 project->bpm (123.0);
36 TASSERT (std::abs (project->bpm() - 123.0) < 0.001);
37 TASSERT (bpm_notifications > last_bpm_notifications);
38
39 // Test undo
40 TASSERT (project->can_undo());
41 TASSERT (!project->can_redo());
42 last_bpm_notifications = bpm_notifications;
43 project->undo();
44 TASSERT (!project->can_undo());
45 TASSERT (project->can_redo());
46 TASSERT (std::abs (project->bpm() - initial_bpm) < 0.001);
47 TASSERT (bpm_notifications > last_bpm_notifications);
48 // Test redo
49 last_bpm_notifications = bpm_notifications;
50 project->redo();
51 TASSERT (project->can_undo());
52 TASSERT (!project->can_redo());
53 TASSERT (std::abs (project->bpm() - 123.0) < 0.001);
54 TASSERT (bpm_notifications > last_bpm_notifications);
55
56 project->undo();
57 TASSERT (!project->can_undo());
58 TASSERT (project->can_redo());
59 TASSERT (std::abs (project->bpm() - initial_bpm) < 0.001);
60
61 // Test name notify/undo/redo
62 const String initial_name = project->name();
63 TASSERT (initial_name == "TestProject");
64 uint64_t last_name_notifications = name_notifications;
65 project->name ("NewName");
66 TASSERT (project->name() == "NewName");
67 TASSERT (name_notifications > last_name_notifications);
68
69 TASSERT (project->can_undo());
70 last_name_notifications = name_notifications;
71 project->undo();
72 TASSERT (project->name() == initial_name);
73 TASSERT (project->can_redo());
74 TASSERT (name_notifications > last_name_notifications);
75
76 last_name_notifications = name_notifications;
77 project->redo();
78 TASSERT (project->name() == "NewName");
79 TASSERT (name_notifications > last_name_notifications);
80
81 // Test master_volume notify/undo/redo
82 uint64_t last_volume_notifications = volume_notifications;
83 project->master_volume (-6.0);
84 TASSERT (std::abs (project->master_volume() - (-6.0)) < 0.01);
85 TASSERT (volume_notifications > last_volume_notifications);
86
87 TASSERT (project->can_undo());
88 last_volume_notifications = volume_notifications;
89 project->undo();
90 TASSERT (std::abs (project->master_volume() - initial_vol) < 0.01);
91 TASSERT (project->can_redo());
92 TASSERT (volume_notifications > last_volume_notifications);
93
94 last_volume_notifications = volume_notifications;
95 project->redo();
96 TASSERT (std::abs (project->master_volume() - (-6.0)) < 0.01);
97 TASSERT (volume_notifications > last_volume_notifications);
98
99 project->discard();
100
101 // Test create second project
102 ProjectImplP project2 = ProjectImpl::create ("TestProject2");
103 project2->name ("foo");
104 TASSERT (project2->name() == "foo");
105 project2->name ("bar");
106 TASSERT (project2->name() == "bar");
107 project2->discard();
108}
109TEST_ADD (project_creation);
110
111static void
112project_length()
113{
114 ProjectImplP project = ProjectImpl::create ("LengthTest");
115 TASSERT (project);
116
117 double len = project->length();
118 TASSERT (len >= 0.0);
119
120 project->discard();
121}
122TEST_ADD (project_length);
123
124static void
125project_track_management()
126{
127 ProjectImplP project = ProjectImpl::create ("TrackTest");
128 TASSERT (project);
129
130 TrackS tracks = project->all_tracks();
131 const size_t initial_count = tracks.size();
132 TASSERT (initial_count >= 1);
133
134 TrackP new_track = project->create_track();
135 TASSERT (new_track);
136
137 tracks = project->all_tracks();
138 TASSERT (tracks.size() == initial_count + 1);
139
140 project->discard();
141}
142TEST_ADD (project_track_management);
143
144static void
145project_playback_state()
146{
147 ProjectImplP project = ProjectImpl::create ("PlaybackTest");
148 TASSERT (project);
149
150 // Initially not playing
151 TASSERT (!project->is_playing());
152
153 project->discard();
154}
155TEST_ADD (project_playback_state);
156
157static void
158track_mute_solo()
159{
160 ProjectImplP project = ProjectImpl::create ("TrackMuteSoloTest");
161 TASSERT (project);
162
163 TrackP track = project->create_track();
164 TASSERT (track);
165
166 // Test initial mute/solo state
167 TASSERT (!track->is_muted());
168 TASSERT (!track->is_solo());
169
170 // Test mute notifications
171 uint64_t muted_notifications = 0;
172 auto muted_connection = track->on_event ("notify:muted", [&muted_notifications] (const Event &event) { muted_notifications++; });
173
174 uint64_t solo_notifications = 0;
175 auto solo_connection = track->on_event ("notify:solo", [&solo_notifications] (const Event &event) { solo_notifications++; });
176
177 // Test mute with notification
178 uint64_t last_muted_notifications = muted_notifications;
179 track->set_muted (true);
180 TASSERT (track->is_muted());
181 TASSERT (muted_notifications > last_muted_notifications);
182
183 // Reset mute
184 last_muted_notifications = muted_notifications;
185 track->set_muted (false);
186 TASSERT (!track->is_muted());
187 TASSERT (muted_notifications > last_muted_notifications);
188
189 // Test solo with notification
190 uint64_t last_solo_notifications = solo_notifications;
191 track->set_solo (true);
192 TASSERT (track->is_solo());
193 TASSERT (solo_notifications > last_solo_notifications);
194
195 // Reset solo
196 last_solo_notifications = solo_notifications;
197 track->set_solo (false);
198 TASSERT (!track->is_solo());
199 TASSERT (solo_notifications > last_solo_notifications);
200
201 project->discard();
202}
203TEST_ADD (track_mute_solo);
204
205static void
206track_hidden()
207{
208 ProjectImplP project = ProjectImpl::create ("TrackHiddenTest");
209 TASSERT (project);
210
211 TrackP track = project->create_track();
212 TASSERT (track);
213
214 // Test initial hidden state
215 TASSERT (!track->is_hidden());
216
217 // Test hidden notifications
218 uint64_t hidden_notifications = 0;
219 auto hidden_connection = track->on_event ("notify:hidden", [&hidden_notifications] (const Event &event) { hidden_notifications++; });
220
221 // Test hide with notification
222 uint64_t last_hidden_notifications = hidden_notifications;
223 track->set_hidden (true);
224 TASSERT (track->is_hidden());
225 TASSERT (hidden_notifications > last_hidden_notifications);
226
227 // Reset hidden
228 last_hidden_notifications = hidden_notifications;
229 track->set_hidden (false);
230 TASSERT (!track->is_hidden());
231 TASSERT (hidden_notifications > last_hidden_notifications);
232
233 project->discard();
234}
235TEST_ADD (track_hidden);
236
237static void
238track_undo_redo()
239{
240 ProjectImplP project = ProjectImpl::create ("TrackUndoRedoTest");
241 TASSERT (project);
242
243 TrackP track = project->create_track();
244 TASSERT (track);
245
246 // Test track volume/pan notifications
247 uint64_t volume_notifications = 0;
248 auto volume_connection = track->on_event ("notify:volume", [&volume_notifications] (const Event &event) { volume_notifications++; });
249
250 uint64_t pan_notifications = 0;
251 auto pan_connection = track->on_event ("notify:pan", [&pan_notifications] (const Event &event) { pan_notifications++; });
252
253 // Change volume
254 uint64_t last_volume_notifications = volume_notifications;
255 track->volume (-6.0);
256 TASSERT (std::abs (track->volume() - (-6.0)) < 0.01);
257 TASSERT (volume_notifications > last_volume_notifications);
258
259 // Change volume back
260 last_volume_notifications = volume_notifications;
261 track->volume (0.0);
262 TASSERT (std::abs (track->volume()) < 0.01);
263 TASSERT (volume_notifications > last_volume_notifications);
264
265 // Change pan
266 uint64_t last_pan_notifications = pan_notifications;
267 track->pan (0.5);
268 TASSERT (std::abs (track->pan() - 0.5) < 0.01);
269 TASSERT (pan_notifications > last_pan_notifications);
270
271 // Change pan back
272 last_pan_notifications = pan_notifications;
273 track->pan (-0.5);
274 TASSERT (std::abs (track->pan() - (-0.5)) < 0.01);
275 TASSERT (pan_notifications > last_pan_notifications);
276
277 project->discard();
278}
279TEST_ADD (track_undo_redo);
280
281static void
282track_volume_pan()
283{
284 ProjectImplP project = ProjectImpl::create ("TrackVolumePanTest");
285 TASSERT (project);
286
287 TrackP track = project->create_track();
288 TASSERT (track);
289
290 // Test initial volume
291 double initial_vol = track->volume();
292 TASSERT (initial_vol >= -100.0 && initial_vol <= 20.0);
293
294 // Test volume notifications
295 uint64_t volume_notifications = 0;
296 auto volume_connection = track->on_event ("notify:volume", [&volume_notifications] (const Event &event) { volume_notifications++; });
297
298 uint64_t pan_notifications = 0;
299 auto pan_connection = track->on_event ("notify:pan", [&pan_notifications] (const Event &event) { pan_notifications++; });
300
301 // Test setting volume with notification
302 uint64_t last_volume_notifications = volume_notifications;
303 track->volume (-6.0);
304 TASSERT (std::abs (track->volume() - (-6.0)) < 0.01);
305 TASSERT (volume_notifications > last_volume_notifications);
306
307 // Reset volume
308 last_volume_notifications = volume_notifications;
309 track->volume (0.0);
310 TASSERT (std::abs (track->volume()) < 0.01);
311 TASSERT (volume_notifications > last_volume_notifications);
312
313 // Test pan
314 double initial_pan = track->pan();
315 TASSERT (initial_pan >= -1.0 && initial_pan <= 1.0);
316
317 // Test setting pan with notification
318 uint64_t last_pan_notifications = pan_notifications;
319 track->pan (0.5);
320 TASSERT (std::abs (track->pan() - 0.5) < 0.01);
321 TASSERT (pan_notifications > last_pan_notifications);
322
323 // Reset pan
324 last_pan_notifications = pan_notifications;
325 track->pan (-0.5);
326 TASSERT (std::abs (track->pan() - (-0.5)) < 0.01);
327 TASSERT (pan_notifications > last_pan_notifications);
328
329 project->discard();
330}
331TEST_ADD (track_volume_pan);
332
333static void
334track_name()
335{
336 ProjectImplP project = ProjectImpl::create ("TrackNameTest");
337 TASSERT (project);
338
339 TrackP track = project->create_track();
340 TASSERT (track);
341
342 // Set and get track name
343 track->name ("MyTrack");
344 TASSERT (track->name() == "MyTrack");
345
346 track->name ("AnotherName");
347 TASSERT (track->name() == "AnotherName");
348
349 project->discard();
350}
351TEST_ADD (track_name);
352
353static void
354clip_creation()
355{
356 ProjectImplP project = ProjectImpl::create ("ClipTest");
357 TASSERT (project);
358
359 TrackP track = project->create_track();
360 TASSERT (track);
361
362 TrackImplP trackimpl = std::dynamic_pointer_cast<TrackImpl> (track);
363 TASSERT (trackimpl);
364
365 ClipP clip = trackimpl->create_midi_clip ("TestClip", 0.0, 4.0);
366 TASSERT (clip);
367
368 project->discard();
369}
370TEST_ADD (clip_creation);
371
372static void
373clip_notes()
374{
375 ProjectImplP project = ProjectImpl::create ("ClipNotesTest");
376 TASSERT (project);
377
378 TrackP track = project->create_track();
379 TASSERT (track);
380
381 TrackImplP trackimpl = std::dynamic_pointer_cast<TrackImpl> (track);
382 TASSERT (trackimpl);
383
384 ClipP clip = trackimpl->create_midi_clip ("NotesClip", 0.0, 4.0);
385 TASSERT (clip);
386
387 ClipNoteS notes = clip->list_all_notes();
388 TASSERT (notes.empty());
389
390 ClipNote note;
391 note.id = -1;
392 note.key = 60;
393 note.channel = 0;
394 note.tick = 0;
395 note.duration = 960;
396 note.velocity = 0.8f;
397
398 ClipNoteS batch;
399 batch.push_back (note);
400 clip->change_batch (batch, "Add Note");
401
402 notes = clip->list_all_notes();
403 TASSERT (notes.size() == 1);
404 TASSERT (notes[0].key == 60);
405
406 project->discard();
407}
408TEST_ADD (clip_notes);
409
410static void
411clip_range()
412{
413 ProjectImplP project = ProjectImpl::create ("ClipRangeTest");
414 TASSERT (project);
415
416 TrackP track = project->create_track();
417 TASSERT (track);
418
419 TrackImplP trackimpl = std::dynamic_pointer_cast<TrackImpl> (track);
420 TASSERT (trackimpl);
421
422 ClipP clip = trackimpl->create_midi_clip ("RangeClip", 0.0, 4.0);
423 TASSERT (clip);
424
425 int64 start = clip->start_tick();
426 int64 stop = clip->stop_tick();
427 TASSERT (start >= 0);
428 TASSERT (stop > start);
429
430 clip->assign_range (start + 960, stop + 960);
431 TASSERT (clip->start_tick() == start + 960);
432
433 project->discard();
434}
435TEST_ADD (clip_range);
436
437static void
438clip_mute_volume_pan()
439{
440 ProjectImplP project = ProjectImpl::create ("ClipMuteVolPanTest");
441 TASSERT (project);
442
443 TrackP track = project->create_track();
444 TASSERT (track);
445
446 TrackImplP trackimpl = std::dynamic_pointer_cast<TrackImpl> (track);
447 TASSERT (trackimpl);
448
449 // Test MIDI clip
450 ClipP mclip = trackimpl->create_midi_clip ("MidiClip", 0.0, 4.0);
451 TASSERT (mclip);
452
453 // Test initial state
454 TASSERT (!mclip->is_muted());
455
456 // Test mute notifications
457 uint64_t muted_notifications = 0;
458 auto muted_connection = mclip->on_event ("notify:muted", [&muted_notifications] (const Event &event) { muted_notifications++; });
459
460 // Test mute with notification
461 uint64_t last_muted_notifications = muted_notifications;
462 mclip->set_muted (true);
463 TASSERT (mclip->is_muted());
464 TASSERT (muted_notifications > last_muted_notifications);
465
466 // Reset mute
467 last_muted_notifications = muted_notifications;
468 mclip->set_muted (false);
469 TASSERT (!mclip->is_muted());
470 TASSERT (muted_notifications > last_muted_notifications);
471
472 // Test volume notifications
473 uint64_t volume_notifications = 0;
474 auto volume_connection = mclip->on_event ("notify:volume", [&volume_notifications] (const Event &event) { volume_notifications++; });
475
476 // Test setting volume with notification
477 uint64_t last_volume_notifications = volume_notifications;
478 mclip->volume (-6.0);
479 TASSERT (std::abs (mclip->volume() - (-6.0)) < 0.01);
480 TASSERT (volume_notifications > last_volume_notifications);
481
482 // Reset volume
483 last_volume_notifications = volume_notifications;
484 mclip->volume (0.0);
485 TASSERT (std::abs (mclip->volume()) < 0.01);
486 TASSERT (volume_notifications > last_volume_notifications);
487
488 // Test audio clip (pan is only available on audio clips)
489 ClipP aclip = trackimpl->create_audio_clip ("AudioClip", 0.0, 4.0);
490 TASSERT (aclip);
491
492 // Test pan notifications for audio clip
493 uint64_t pan_notifications = 0;
494 auto pan_connection = aclip->on_event ("notify:pan", [&pan_notifications] (const Event &event) { pan_notifications++; });
495
496 // Initial pan should be 0
497 TASSERT (std::abs (aclip->pan()) < 0.01);
498
499 // Test setting pan with notification
500 uint64_t last_pan_notifications = pan_notifications;
501 aclip->pan (0.5);
502 TASSERT (std::abs (aclip->pan() - 0.5) < 0.01);
503 TASSERT (pan_notifications > last_pan_notifications);
504
505 // Reset pan
506 last_pan_notifications = pan_notifications;
507 aclip->pan (-0.5);
508 TASSERT (std::abs (aclip->pan() - (-0.5)) < 0.01);
509 TASSERT (pan_notifications > last_pan_notifications);
510
511 // Test audio clip volume
512 uint64_t audio_volume_notifications = 0;
513 auto audio_volume_connection = aclip->on_event ("notify:volume", [&audio_volume_notifications] (const Event &event) { audio_volume_notifications++; });
514
515 last_volume_notifications = audio_volume_notifications;
516 aclip->volume (-3.0);
517 TASSERT (std::abs (aclip->volume() - (-3.0)) < 0.01);
518 TASSERT (audio_volume_notifications > last_volume_notifications);
519
520 project->discard();
521}
522TEST_ADD (clip_mute_volume_pan);
523
524static void
525clip_undo_redo()
526{
527 ProjectImplP project = ProjectImpl::create ("ClipUndoRedoTest");
528 TASSERT (project);
529
530 TrackP track = project->create_track();
531 TASSERT (track);
532
533 TrackImplP trackimpl = std::dynamic_pointer_cast<TrackImpl> (track);
534 TASSERT (trackimpl);
535
536 // Test MIDI clip mute undo/redo
537 ClipP mclip = trackimpl->create_midi_clip ("UndoMidiClip", 0.0, 4.0);
538 TASSERT (mclip);
539
540 uint64_t muted_notifications = 0;
541 auto muted_connection = mclip->on_event ("notify:muted", [&muted_notifications] (const Event &event) { muted_notifications++; });
542
543 // Set muted
544 uint64_t last_muted_notifications = muted_notifications;
545 mclip->set_muted (true);
546 TASSERT (mclip->is_muted());
547 TASSERT (muted_notifications > last_muted_notifications);
548
549 // Undo mute
550 TASSERT (project->can_undo());
551 project->undo();
552 TASSERT (!mclip->is_muted());
553
554 // Redo mute
555 TASSERT (project->can_redo());
556 project->redo();
557 TASSERT (mclip->is_muted());
558
559 // Test MIDI clip volume undo/redo
560 uint64_t volume_notifications = 0;
561 auto volume_connection = mclip->on_event ("notify:volume", [&volume_notifications] (const Event &event) { volume_notifications++; });
562
563 // Set volume
564 double initial_vol = mclip->volume();
565 uint64_t last_volume_notifications = volume_notifications;
566 mclip->volume (-12.0);
567 TASSERT (std::abs (mclip->volume() - (-12.0)) < 0.01);
568 TASSERT (volume_notifications > last_volume_notifications);
569
570 // Undo volume
571 TASSERT (project->can_undo());
572 project->undo();
573 TASSERT (std::abs (mclip->volume() - initial_vol) < 0.01);
574
575 // Redo volume
576 TASSERT (project->can_redo());
577 project->redo();
578 TASSERT (std::abs (mclip->volume() - (-12.0)) < 0.01);
579
580 // Test audio clip pan undo/redo
581 ClipP aclip = trackimpl->create_audio_clip ("UndoAudioClip", 0.0, 4.0);
582 TASSERT (aclip);
583
584 uint64_t pan_notifications = 0;
585 auto pan_connection = aclip->on_event ("notify:pan", [&pan_notifications] (const Event &event) { pan_notifications++; });
586
587 // Set pan
588 double initial_pan = aclip->pan();
589 uint64_t last_pan_notifications = pan_notifications;
590 aclip->pan (0.8);
591 TASSERT (std::abs (aclip->pan() - 0.8) < 0.01);
592 TASSERT (pan_notifications > last_pan_notifications);
593
594 // Undo pan
595 TASSERT (project->can_undo());
596 project->undo();
597 TASSERT (std::abs (aclip->pan() - initial_pan) < 0.01);
598
599 // Redo pan
600 TASSERT (project->can_redo());
601 project->redo();
602 TASSERT (std::abs (aclip->pan() - 0.8) < 0.01);
603
604 // Test MIDI clip notes undo/redo
605 ClipNoteS batch;
606 ClipNote note;
607 note.id = -1;
608 note.key = 60;
609 note.channel = 0;
610 note.tick = 0;
611 note.duration = 960;
612 note.velocity = 0.8f;
613 batch.push_back (note);
614
615 uint64_t notes_notifications = 0;
616 auto notes_connection = mclip->on_event ("notify:notes", [&notes_notifications] (const Event &event) { notes_notifications++; });
617
618 // Add notes
619 uint64_t last_notes_notifications = notes_notifications;
620 mclip->change_batch (batch, "Add Note");
621 TASSERT (mclip->list_all_notes().size() == 1);
622 TASSERT (notes_notifications > last_notes_notifications);
623
624 // Undo notes
625 TASSERT (project->can_undo());
626 project->undo();
627 TASSERT (mclip->list_all_notes().empty());
628
629 // Redo notes
630 TASSERT (project->can_redo());
631 project->redo();
632 TASSERT (mclip->list_all_notes().size() == 1);
633
634 // Test MIDI clip range undo/redo
635 int64 initial_start = mclip->start_tick();
636 int64 initial_stop = mclip->stop_tick();
637
638 // Assign new range
639 uint64_t range_notifications = 0;
640 auto range_connection = mclip->on_event ("notify:start_tick", [&range_notifications] (const Event &event) { range_notifications++; });
641
642 uint64_t last_range_notifications = range_notifications;
643 mclip->assign_range (initial_start + 960, initial_stop + 960);
644 TASSERT (mclip->start_tick() == initial_start + 960);
645 TASSERT (range_notifications > last_range_notifications);
646
647 // Undo range
648 TASSERT (project->can_undo());
649 project->undo();
650 TASSERT (mclip->start_tick() == initial_start);
651 TASSERT (mclip->stop_tick() == initial_stop);
652
653 // Redo range
654 TASSERT (project->can_redo());
655 project->redo();
656 TASSERT (mclip->start_tick() == initial_start + 960);
657 TASSERT (mclip->stop_tick() == initial_stop + 960);
658
659 project->discard();
660}
661TEST_ADD (clip_undo_redo);
662
663static void
664plugin_creation()
665{
666 ProjectImplP project = ProjectImpl::create ("PluginTest");
667 TASSERT (project);
668
669 TrackP track = project->create_track();
670 TASSERT (track);
671
672 TrackImplP trackimpl = std::dynamic_pointer_cast<TrackImpl> (track);
673 TASSERT (trackimpl);
674
675 // Check initial plugins list (tracks have default plugins like volume/pan)
676 PluginS plugins = trackimpl->list_plugins();
677 TASSERT (plugins.size() >= 0);
678
679 // Test with existing plugins (tracks have default plugins)
680 if (plugins.size() > 0) {
681 PluginP plugin = plugins[0];
682 TASSERT (plugin != nullptr);
683
684 // Check plugin properties
685 TASSERT (!plugin->name().empty());
686 TASSERT (!plugin->plugin_type().empty());
687
688 // Setup notification counters
689 uint64_t enabled_notifications = 0;
690 auto enabled_connection = plugin->on_event ("notify:enabled", [&enabled_notifications] (const Event &event) { enabled_notifications++; });
691
692 uint64_t frozen_notifications = 0;
693 auto frozen_connection = plugin->on_event ("notify:frozen", [&frozen_notifications] (const Event &event) { frozen_notifications++; });
694
695 // Check enabled state (should be either true or false)
696 bool enabled = plugin->is_enabled();
697 TASSERT (enabled == true || enabled == false);
698
699 // Toggle enabled - should emit notification
700 uint64_t last_enabled_notifications = enabled_notifications;
701 plugin->set_enabled (!enabled);
702 TASSERT (plugin->is_enabled() != enabled);
703 TASSERT (enabled_notifications > last_enabled_notifications);
704
705 // Check frozen state
706 bool frozen = plugin->is_frozen();
707 TASSERT (frozen == true || frozen == false);
708
709 // Toggle frozen - should emit notification
710 uint64_t last_frozen_notifications = frozen_notifications;
711 plugin->set_frozen (!frozen);
712 TASSERT (plugin->is_frozen() != frozen);
713 TASSERT (frozen_notifications > last_frozen_notifications);
714
715 // Test plugin removal via remove_self
716 uint64_t removed_count = 0;
717 auto removed_connection = plugin->on_event ("object:removed", [&removed_count] (const Event &event) { removed_count++; });
718 plugin->remove_self();
719 TASSERT (removed_count > 0);
720 }
721
722 project->discard();
723}
724TEST_ADD (plugin_creation);
725
726} // Anon
The Anklang C++ API namespace.
Definition api.hh:8
int64_t int64
A 64-bit unsigned integer, use PRI*64 in format strings.
Definition cxxaux.hh:28
typedef uint64_t
Part specific note event representation.
Definition api.hh:227
int64 tick
UI selection flag.
Definition api.hh:232
float velocity
Duration in number of ticks.
Definition api.hh:234
int64 duration
Position in ticks.
Definition api.hh:233
int8 channel
ID, > 0.
Definition api.hh:229
int8 key
MIDI Channel.
Definition api.hh:230
Structure for callback based notifications.
Definition value.hh:112
#define TASSERT(cond)
Unconditional test assertion, enters breakpoint if not fullfilled.
Definition testing.hh:23
#define TEST_ADD(fun)
Register a function to run as part of the unit test suite.
Definition testing.hh:30