152a38012Sejakowatz #include <TimedEventQueue.h>
252a38012Sejakowatz #include <stdio.h>
352a38012Sejakowatz
452a38012Sejakowatz #define DEBUG 1
552a38012Sejakowatz #include <Debug.h>
652a38012Sejakowatz
7*07d1d1ffSbeveloper BTimedEventQueue::queue_action DoForEachHook(media_timed_event *event, void *context);
8*07d1d1ffSbeveloper void DumpEvent(const media_timed_event & e);
9*07d1d1ffSbeveloper void DumpEvent(const media_timed_event * e);
10*07d1d1ffSbeveloper void InsertRemoveTest();
11*07d1d1ffSbeveloper void DoForEachTest();
12*07d1d1ffSbeveloper void MatchTest();
13*07d1d1ffSbeveloper void FlushTest();
14*07d1d1ffSbeveloper
DumpEvent(const media_timed_event & e)15*07d1d1ffSbeveloper void DumpEvent(const media_timed_event & e)
16*07d1d1ffSbeveloper {
17*07d1d1ffSbeveloper DumpEvent(&e);
18*07d1d1ffSbeveloper }
19*07d1d1ffSbeveloper
DumpEvent(const media_timed_event * e)2052a38012Sejakowatz void DumpEvent(const media_timed_event * e)
2152a38012Sejakowatz {
2252a38012Sejakowatz if (!e) {
2352a38012Sejakowatz printf("NULL\n");
2452a38012Sejakowatz return;
2552a38012Sejakowatz }
2652a38012Sejakowatz printf("time = 0x%x, type = ",int(e->event_time));
2752a38012Sejakowatz switch (e->type) {
2852a38012Sejakowatz case BTimedEventQueue::B_NO_EVENT: printf("B_NO_EVENT\n"); break;
2952a38012Sejakowatz case BTimedEventQueue::B_ANY_EVENT: printf("B_ANY_EVENT\n"); break;
3052a38012Sejakowatz case BTimedEventQueue::B_START: printf("B_START\n"); break;
3152a38012Sejakowatz case BTimedEventQueue::B_STOP: printf("B_STOP\n"); break;
3252a38012Sejakowatz case BTimedEventQueue::B_SEEK: printf("B_SEEK\n"); break;
3352a38012Sejakowatz case BTimedEventQueue::B_WARP: printf("B_WARP\n"); break;
3452a38012Sejakowatz case BTimedEventQueue::B_TIMER: printf("B_TIMER\n"); break;
3552a38012Sejakowatz case BTimedEventQueue::B_HANDLE_BUFFER: printf("B_HANDLE_BUFFER\n"); break;
3652a38012Sejakowatz case BTimedEventQueue::B_DATA_STATUS: printf("B_DATA_STATUS\n"); break;
3752a38012Sejakowatz case BTimedEventQueue::B_HARDWARE: printf("B_HARDWARE\n"); break;
3852a38012Sejakowatz case BTimedEventQueue::B_PARAMETER: printf("B_PARAMETER\n"); break;
3952a38012Sejakowatz default: printf("0x%x\n",int(e->type));
4052a38012Sejakowatz }
4152a38012Sejakowatz }
4252a38012Sejakowatz
InsertRemoveTest()4352a38012Sejakowatz void InsertRemoveTest()
4452a38012Sejakowatz {
4552a38012Sejakowatz BTimedEventQueue *q =new BTimedEventQueue;
4652a38012Sejakowatz q->AddEvent(media_timed_event(0x1007,BTimedEventQueue::B_START));//
4752a38012Sejakowatz q->AddEvent(media_timed_event(0x1005,BTimedEventQueue::B_START));//
4852a38012Sejakowatz q->AddEvent(media_timed_event(0x9999,BTimedEventQueue::B_STOP));//
4952a38012Sejakowatz q->AddEvent(media_timed_event(0x1006,BTimedEventQueue::B_START));//
5052a38012Sejakowatz q->AddEvent(media_timed_event(0x1002,BTimedEventQueue::B_START));//
5152a38012Sejakowatz q->AddEvent(media_timed_event(0x1011,BTimedEventQueue::B_START));//
5252a38012Sejakowatz q->AddEvent(media_timed_event(0x1000,BTimedEventQueue::B_START));//
5352a38012Sejakowatz q->AddEvent(media_timed_event(0x0777,BTimedEventQueue::B_START));//
5452a38012Sejakowatz q->AddEvent(media_timed_event(0x1001,BTimedEventQueue::B_START));//
5552a38012Sejakowatz q->AddEvent(media_timed_event(0x1000,BTimedEventQueue::B_STOP));//
5652a38012Sejakowatz q->AddEvent(media_timed_event(0x1003,BTimedEventQueue::B_START));//
5752a38012Sejakowatz q->AddEvent(media_timed_event(0x1000,BTimedEventQueue::B_SEEK));//
5852a38012Sejakowatz ASSERT(q->EventCount() == 12);
5952a38012Sejakowatz ASSERT(q->HasEvents() == true);
6052a38012Sejakowatz
61*07d1d1ffSbeveloper media_timed_event e1(0x1003,BTimedEventQueue::B_START);
62*07d1d1ffSbeveloper q->RemoveEvent(&e1);
6352a38012Sejakowatz ASSERT(q->EventCount() == 11);
6452a38012Sejakowatz ASSERT(q->HasEvents() == true);
6552a38012Sejakowatz
66*07d1d1ffSbeveloper media_timed_event e2(0x1007,BTimedEventQueue::B_START);
67*07d1d1ffSbeveloper q->RemoveEvent(&e2);
6852a38012Sejakowatz ASSERT(q->EventCount() == 10);
6952a38012Sejakowatz ASSERT(q->HasEvents() == true);
7052a38012Sejakowatz
71*07d1d1ffSbeveloper media_timed_event e3(0x1000,BTimedEventQueue::B_STOP);
72*07d1d1ffSbeveloper q->RemoveEvent(&e3);
7352a38012Sejakowatz ASSERT(q->EventCount() == 9);
7452a38012Sejakowatz ASSERT(q->HasEvents() == true);
7552a38012Sejakowatz
76*07d1d1ffSbeveloper media_timed_event e4(0x1000,BTimedEventQueue::B_SEEK);
77*07d1d1ffSbeveloper q->RemoveEvent(&e4);
7852a38012Sejakowatz ASSERT(q->EventCount() == 8);
7952a38012Sejakowatz ASSERT(q->HasEvents() == true);
8052a38012Sejakowatz
8152a38012Sejakowatz //remove non existing element (time)
82*07d1d1ffSbeveloper media_timed_event e5(0x1111,BTimedEventQueue::B_STOP);
83*07d1d1ffSbeveloper q->RemoveEvent(&e5);
8452a38012Sejakowatz ASSERT(q->EventCount() == 8);
8552a38012Sejakowatz ASSERT(q->HasEvents() == true);
8652a38012Sejakowatz
8752a38012Sejakowatz //remove non existing element (type)
88*07d1d1ffSbeveloper media_timed_event e6(0x1011,BTimedEventQueue::B_STOP);
89*07d1d1ffSbeveloper q->RemoveEvent(&e6);
9052a38012Sejakowatz ASSERT(q->EventCount() == 8);
9152a38012Sejakowatz ASSERT(q->HasEvents() == true);
9252a38012Sejakowatz
93*07d1d1ffSbeveloper media_timed_event e7(0x1000,BTimedEventQueue::B_START);
94*07d1d1ffSbeveloper q->RemoveEvent(&e7);
9552a38012Sejakowatz ASSERT(q->EventCount() == 7);
9652a38012Sejakowatz ASSERT(q->HasEvents() == true);
9752a38012Sejakowatz
98*07d1d1ffSbeveloper media_timed_event e8(0x1011,BTimedEventQueue::B_START);
99*07d1d1ffSbeveloper q->RemoveEvent(&e8);
10052a38012Sejakowatz ASSERT(q->EventCount() == 6);
10152a38012Sejakowatz ASSERT(q->HasEvents() == true);
10252a38012Sejakowatz
103*07d1d1ffSbeveloper media_timed_event e9(0x1002,BTimedEventQueue::B_START);
104*07d1d1ffSbeveloper q->RemoveEvent(&e9);
10552a38012Sejakowatz ASSERT(q->EventCount() == 5);
10652a38012Sejakowatz ASSERT(q->HasEvents() == true);
10752a38012Sejakowatz
108*07d1d1ffSbeveloper media_timed_event e10(0x0777,BTimedEventQueue::B_START);
109*07d1d1ffSbeveloper q->RemoveEvent(&e10);
11052a38012Sejakowatz ASSERT(q->EventCount() == 4);
11152a38012Sejakowatz ASSERT(q->HasEvents() == true);
11252a38012Sejakowatz
113*07d1d1ffSbeveloper media_timed_event e11(0x9999,BTimedEventQueue::B_STOP);
114*07d1d1ffSbeveloper q->RemoveEvent(&e11);
11552a38012Sejakowatz ASSERT(q->EventCount() == 3);
11652a38012Sejakowatz ASSERT(q->HasEvents() == true);
11752a38012Sejakowatz
118*07d1d1ffSbeveloper media_timed_event e12(0x1006,BTimedEventQueue::B_START);
119*07d1d1ffSbeveloper q->RemoveEvent(&e12);
12052a38012Sejakowatz ASSERT(q->EventCount() == 2);
12152a38012Sejakowatz ASSERT(q->HasEvents() == true);
12252a38012Sejakowatz
123*07d1d1ffSbeveloper media_timed_event e13(0x1001,BTimedEventQueue::B_START);
124*07d1d1ffSbeveloper q->RemoveEvent(&e13);
12552a38012Sejakowatz ASSERT(q->EventCount() == 1);
12652a38012Sejakowatz ASSERT(q->HasEvents() == true);
12752a38012Sejakowatz
128*07d1d1ffSbeveloper media_timed_event e14(0x1005,BTimedEventQueue::B_START);
129*07d1d1ffSbeveloper q->RemoveEvent(&e14);
13052a38012Sejakowatz ASSERT(q->EventCount() == 0);
13152a38012Sejakowatz ASSERT(q->HasEvents() == false);
13252a38012Sejakowatz
13352a38012Sejakowatz delete q;
13452a38012Sejakowatz }
13552a38012Sejakowatz
13652a38012Sejakowatz media_timed_event DoForEachEvent;
13752a38012Sejakowatz int DoForEachCount;
13852a38012Sejakowatz
13952a38012Sejakowatz BTimedEventQueue::queue_action
DoForEachHook(media_timed_event * event,void * context)14052a38012Sejakowatz DoForEachHook(media_timed_event *event, void *context)
14152a38012Sejakowatz {
14252a38012Sejakowatz DoForEachEvent = *event;
14352a38012Sejakowatz DoForEachCount++;
14452a38012Sejakowatz printf("Callback, event_time = %x\n",int(event->event_time));
14552a38012Sejakowatz return BTimedEventQueue::B_NO_ACTION;
14652a38012Sejakowatz }
14752a38012Sejakowatz
DoForEachTest()14852a38012Sejakowatz void DoForEachTest()
14952a38012Sejakowatz {
15052a38012Sejakowatz BTimedEventQueue *q =new BTimedEventQueue;
15152a38012Sejakowatz ASSERT(q->EventCount() == 0);
15252a38012Sejakowatz ASSERT(q->HasEvents() == false);
15352a38012Sejakowatz
15452a38012Sejakowatz q->AddEvent(media_timed_event(0x1000,BTimedEventQueue::B_SEEK));
15552a38012Sejakowatz q->AddEvent(media_timed_event(0x1001,BTimedEventQueue::B_START));
15652a38012Sejakowatz q->AddEvent(media_timed_event(0x1002,BTimedEventQueue::B_START));
15752a38012Sejakowatz q->AddEvent(media_timed_event(0x1003,BTimedEventQueue::B_START));
15852a38012Sejakowatz q->AddEvent(media_timed_event(0x1010,BTimedEventQueue::B_START));
15952a38012Sejakowatz q->AddEvent(media_timed_event(0x1011,BTimedEventQueue::B_START));
16052a38012Sejakowatz q->AddEvent(media_timed_event(0x1012,BTimedEventQueue::B_START));
16152a38012Sejakowatz q->AddEvent(media_timed_event(0x1004,BTimedEventQueue::B_START));
16252a38012Sejakowatz q->AddEvent(media_timed_event(0x1005,BTimedEventQueue::B_START));
16352a38012Sejakowatz q->AddEvent(media_timed_event(0x1006,BTimedEventQueue::B_STOP));
16452a38012Sejakowatz q->AddEvent(media_timed_event(0x1007,BTimedEventQueue::B_START));
16552a38012Sejakowatz q->AddEvent(media_timed_event(0x1008,BTimedEventQueue::B_START));
16652a38012Sejakowatz q->AddEvent(media_timed_event(0x1009,BTimedEventQueue::B_START));
16752a38012Sejakowatz q->AddEvent(media_timed_event(0x1013,BTimedEventQueue::B_START));
16852a38012Sejakowatz q->AddEvent(media_timed_event(0x1013,BTimedEventQueue::B_START));
16952a38012Sejakowatz q->AddEvent(media_timed_event(0x1013,BTimedEventQueue::B_SEEK));
17052a38012Sejakowatz ASSERT(q->EventCount() == 16);
17152a38012Sejakowatz ASSERT(q->HasEvents() == true);
17252a38012Sejakowatz
17352a38012Sejakowatz
17452a38012Sejakowatz printf("\n expected: 0x1000\n");
17552a38012Sejakowatz DoForEachCount = 0;
17652a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x1000,BTimedEventQueue::B_AT_TIME);
17752a38012Sejakowatz ASSERT(DoForEachEvent == media_timed_event(0x1000,BTimedEventQueue::B_SEEK));
17852a38012Sejakowatz ASSERT(DoForEachCount == 1);
17952a38012Sejakowatz
18052a38012Sejakowatz
18152a38012Sejakowatz printf("\n expected: 0x1006\n");
18252a38012Sejakowatz DoForEachCount = 0;
18352a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x1006,BTimedEventQueue::B_AT_TIME);
18452a38012Sejakowatz ASSERT(DoForEachEvent == media_timed_event(0x1006,BTimedEventQueue::B_STOP));
18552a38012Sejakowatz ASSERT(DoForEachCount == 1);
18652a38012Sejakowatz
18752a38012Sejakowatz printf("\n expected: 0x1013, 0x1013, 0x1013\n");
18852a38012Sejakowatz DoForEachCount = 0;
18952a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x1013,BTimedEventQueue::B_AT_TIME);
19052a38012Sejakowatz ASSERT(DoForEachCount == 3);
19152a38012Sejakowatz
19252a38012Sejakowatz printf("\n expected: 0x1000, 0x1001, 0x1002\n");
19352a38012Sejakowatz DoForEachCount = 0;
19452a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x1003,BTimedEventQueue::B_BEFORE_TIME,false);
19552a38012Sejakowatz ASSERT(DoForEachCount == 3);
19652a38012Sejakowatz
19752a38012Sejakowatz printf("\n expected: 0x1000, 0x1001, 0x1002, 0x1003\n");
19852a38012Sejakowatz DoForEachCount = 0;
19952a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x1003,BTimedEventQueue::B_BEFORE_TIME,true);
20052a38012Sejakowatz ASSERT(DoForEachCount == 4);
20152a38012Sejakowatz
20252a38012Sejakowatz printf("\n expected: 0x1013, 0x1013, 0x1013\n");
20352a38012Sejakowatz DoForEachCount = 0;
20452a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x1012,BTimedEventQueue::B_AFTER_TIME,false);
20552a38012Sejakowatz ASSERT(DoForEachCount == 3);
20652a38012Sejakowatz
20752a38012Sejakowatz printf("\n expected: 0x1012, 0x1013, 0x1013, 0x1013\n");
20852a38012Sejakowatz DoForEachCount = 0;
20952a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x1012,BTimedEventQueue::B_AFTER_TIME,true);
21052a38012Sejakowatz ASSERT(DoForEachCount == 4);
21152a38012Sejakowatz
21252a38012Sejakowatz printf("\n expected: none\n");
21352a38012Sejakowatz DoForEachCount = 0;
21452a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x1013,BTimedEventQueue::B_AFTER_TIME,false);
21552a38012Sejakowatz ASSERT(DoForEachCount == 0);
21652a38012Sejakowatz
21752a38012Sejakowatz printf("\n expected: 0x1013, 0x1013, 0x1013\n");
21852a38012Sejakowatz DoForEachCount = 0;
21952a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x1013,BTimedEventQueue::B_AFTER_TIME,true);
22052a38012Sejakowatz ASSERT(DoForEachCount == 3);
22152a38012Sejakowatz
22252a38012Sejakowatz printf("\n expected: all 16\n");
22352a38012Sejakowatz DoForEachCount = 0;
22452a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x0,BTimedEventQueue::B_ALWAYS);
22552a38012Sejakowatz ASSERT(DoForEachCount == 16);
22652a38012Sejakowatz
22752a38012Sejakowatz printf("\n expected: none\n");
22852a38012Sejakowatz DoForEachCount = 0;
22952a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x0,BTimedEventQueue::B_ALWAYS,false,BTimedEventQueue::B_WARP);
23052a38012Sejakowatz ASSERT(DoForEachCount == 0);
23152a38012Sejakowatz
23252a38012Sejakowatz printf("\n expected: 0x1000, 0x1013\n");
23352a38012Sejakowatz DoForEachCount = 0;
23452a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x0,BTimedEventQueue::B_ALWAYS,false,BTimedEventQueue::B_SEEK);
23552a38012Sejakowatz ASSERT(DoForEachCount == 2);
23652a38012Sejakowatz
23752a38012Sejakowatz printf("\n expected: 0x1000, 0x1013\n");
23852a38012Sejakowatz DoForEachCount = 0;
23952a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x0999,BTimedEventQueue::B_AFTER_TIME,false,BTimedEventQueue::B_SEEK);
24052a38012Sejakowatz ASSERT(DoForEachCount == 2);
24152a38012Sejakowatz
24252a38012Sejakowatz printf("\n expected: 0x1000, 0x1013\n");
24352a38012Sejakowatz DoForEachCount = 0;
24452a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x1014,BTimedEventQueue::B_BEFORE_TIME,false,BTimedEventQueue::B_SEEK);
24552a38012Sejakowatz ASSERT(DoForEachCount == 2);
24652a38012Sejakowatz
24752a38012Sejakowatz printf("\n expected: none\n");
24852a38012Sejakowatz DoForEachCount = 0;
24952a38012Sejakowatz q->DoForEach(DoForEachHook,(void*)1234,0x0004,BTimedEventQueue::B_BEFORE_TIME,true);
25052a38012Sejakowatz ASSERT(DoForEachCount == 0);
25152a38012Sejakowatz
25252a38012Sejakowatz delete q;
25352a38012Sejakowatz }
25452a38012Sejakowatz
MatchTest()25552a38012Sejakowatz void MatchTest()
25652a38012Sejakowatz {
25752a38012Sejakowatz BTimedEventQueue *q = new BTimedEventQueue;
25852a38012Sejakowatz ASSERT(q->EventCount() == 0);
25952a38012Sejakowatz ASSERT(q->HasEvents() == false);
26052a38012Sejakowatz
26152a38012Sejakowatz q->AddEvent(media_timed_event(0x1000,BTimedEventQueue::B_SEEK));
26252a38012Sejakowatz q->AddEvent(media_timed_event(0x1001,BTimedEventQueue::B_START));
26352a38012Sejakowatz q->AddEvent(media_timed_event(0x1002,BTimedEventQueue::B_START));
26452a38012Sejakowatz q->AddEvent(media_timed_event(0x1003,BTimedEventQueue::B_START));
26552a38012Sejakowatz q->AddEvent(media_timed_event(0x1010,BTimedEventQueue::B_START));
26652a38012Sejakowatz q->AddEvent(media_timed_event(0x1011,BTimedEventQueue::B_START));
26752a38012Sejakowatz q->AddEvent(media_timed_event(0x1012,BTimedEventQueue::B_START));
26852a38012Sejakowatz q->AddEvent(media_timed_event(0x1004,BTimedEventQueue::B_START));
26952a38012Sejakowatz q->AddEvent(media_timed_event(0x1005,BTimedEventQueue::B_START));
27052a38012Sejakowatz q->AddEvent(media_timed_event(0x1006,BTimedEventQueue::B_STOP));
27152a38012Sejakowatz q->AddEvent(media_timed_event(0x1007,BTimedEventQueue::B_START));
27252a38012Sejakowatz q->AddEvent(media_timed_event(0x1008,BTimedEventQueue::B_START));
27352a38012Sejakowatz q->AddEvent(media_timed_event(0x1009,BTimedEventQueue::B_START));
27452a38012Sejakowatz q->AddEvent(media_timed_event(0x1013,BTimedEventQueue::B_START));
27552a38012Sejakowatz q->AddEvent(media_timed_event(0x1013,BTimedEventQueue::B_START));
27652a38012Sejakowatz q->AddEvent(media_timed_event(0x1013,BTimedEventQueue::B_SEEK));
27752a38012Sejakowatz ASSERT(q->EventCount() == 16);
27852a38012Sejakowatz ASSERT(q->HasEvents() == true);
27952a38012Sejakowatz
280*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1006,BTimedEventQueue::B_STOP));
28152a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1001,BTimedEventQueue::B_AFTER_TIME,true,BTimedEventQueue::B_STOP));
28252a38012Sejakowatz
283*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1006,BTimedEventQueue::B_STOP));
28452a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1006,BTimedEventQueue::B_AT_TIME,true));
28552a38012Sejakowatz
286*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1006,BTimedEventQueue::B_STOP));
28752a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1007,BTimedEventQueue::B_BEFORE_TIME,true,BTimedEventQueue::B_STOP));
28852a38012Sejakowatz
289*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1000,BTimedEventQueue::B_SEEK));
29052a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1006,BTimedEventQueue::B_BEFORE_TIME,true));
29152a38012Sejakowatz
292*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1006,BTimedEventQueue::B_STOP));
29352a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1006,BTimedEventQueue::B_AFTER_TIME,true));
29452a38012Sejakowatz
29552a38012Sejakowatz printf("\nexpected: "); DumpEvent(0);
29652a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1006,BTimedEventQueue::B_BEFORE_TIME,false,BTimedEventQueue::B_STOP));
29752a38012Sejakowatz
29852a38012Sejakowatz printf("\nexpected: "); DumpEvent(0);
29952a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1006,BTimedEventQueue::B_AFTER_TIME,false,BTimedEventQueue::B_STOP));
30052a38012Sejakowatz
30152a38012Sejakowatz printf("\nexpected: "); DumpEvent(0);
30252a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1006,BTimedEventQueue::B_AT_TIME,false,BTimedEventQueue::B_SEEK));
30352a38012Sejakowatz
304*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1000,BTimedEventQueue::B_SEEK));
30552a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1000,BTimedEventQueue::B_AFTER_TIME,true));
30652a38012Sejakowatz
307*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1000,BTimedEventQueue::B_SEEK));
30852a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1010,BTimedEventQueue::B_BEFORE_TIME,true));
30952a38012Sejakowatz
310*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1000,BTimedEventQueue::B_SEEK));
31152a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1007,BTimedEventQueue::B_BEFORE_TIME,false));
31252a38012Sejakowatz
313*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1013,BTimedEventQueue::B_SEEK));
31452a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1001,BTimedEventQueue::B_AFTER_TIME,false,BTimedEventQueue::B_SEEK));
31552a38012Sejakowatz
316*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1010,BTimedEventQueue::B_START));
31752a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1009,BTimedEventQueue::B_AFTER_TIME,false));
31852a38012Sejakowatz
319*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1010,BTimedEventQueue::B_START));
32052a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1010,BTimedEventQueue::B_AFTER_TIME,true));
32152a38012Sejakowatz
322*07d1d1ffSbeveloper printf("\nexpected: "); DumpEvent(media_timed_event(0x1010,BTimedEventQueue::B_START));
32352a38012Sejakowatz printf("found: "); DumpEvent(q->FindFirstMatch(0x1010,BTimedEventQueue::B_AT_TIME,true));
32452a38012Sejakowatz
32552a38012Sejakowatz delete q;
32652a38012Sejakowatz }
32752a38012Sejakowatz
FlushTest()32852a38012Sejakowatz void FlushTest()
32952a38012Sejakowatz {
33052a38012Sejakowatz BTimedEventQueue *q = new BTimedEventQueue;
33152a38012Sejakowatz ASSERT(q->EventCount() == 0);
33252a38012Sejakowatz ASSERT(q->HasEvents() == false);
33352a38012Sejakowatz
33452a38012Sejakowatz q->AddEvent(media_timed_event(0x1000,BTimedEventQueue::B_SEEK));
33552a38012Sejakowatz q->AddEvent(media_timed_event(0x1001,BTimedEventQueue::B_START));
33652a38012Sejakowatz q->AddEvent(media_timed_event(0x1002,BTimedEventQueue::B_START));
33752a38012Sejakowatz q->AddEvent(media_timed_event(0x1003,BTimedEventQueue::B_START));
33852a38012Sejakowatz q->AddEvent(media_timed_event(0x1004,BTimedEventQueue::B_START));
33952a38012Sejakowatz q->AddEvent(media_timed_event(0x1005,BTimedEventQueue::B_START));
34052a38012Sejakowatz q->AddEvent(media_timed_event(0x1006,BTimedEventQueue::B_STOP));
34152a38012Sejakowatz q->AddEvent(media_timed_event(0x1007,BTimedEventQueue::B_START));
34252a38012Sejakowatz q->AddEvent(media_timed_event(0x1008,BTimedEventQueue::B_START));
34352a38012Sejakowatz q->AddEvent(media_timed_event(0x1009,BTimedEventQueue::B_START));
34452a38012Sejakowatz q->AddEvent(media_timed_event(0x1010,BTimedEventQueue::B_START));
34552a38012Sejakowatz q->AddEvent(media_timed_event(0x1011,BTimedEventQueue::B_START));
34652a38012Sejakowatz q->AddEvent(media_timed_event(0x1012,BTimedEventQueue::B_START));
34752a38012Sejakowatz q->AddEvent(media_timed_event(0x1013,BTimedEventQueue::B_START));
34852a38012Sejakowatz q->AddEvent(media_timed_event(0x1013,BTimedEventQueue::B_START));
34952a38012Sejakowatz q->AddEvent(media_timed_event(0x1013,BTimedEventQueue::B_SEEK));
35052a38012Sejakowatz ASSERT(q->EventCount() == 16);
35152a38012Sejakowatz ASSERT(q->HasEvents() == true);
35252a38012Sejakowatz
35352a38012Sejakowatz printf("### removing 0x1007\n");
35452a38012Sejakowatz q->FlushEvents(0x1007, BTimedEventQueue::B_AT_TIME);
35552a38012Sejakowatz ASSERT(q->EventCount() == 15);
35652a38012Sejakowatz
35752a38012Sejakowatz printf("### removing 0x1013\n");
35852a38012Sejakowatz q->FlushEvents(0x1012, BTimedEventQueue::B_AFTER_TIME,false);
35952a38012Sejakowatz ASSERT(q->EventCount() == 12);
36052a38012Sejakowatz
36152a38012Sejakowatz printf("### removing none\n");
36252a38012Sejakowatz q->FlushEvents(0x1fff, BTimedEventQueue::B_AFTER_TIME,false);
36352a38012Sejakowatz ASSERT(q->EventCount() == 12);
36452a38012Sejakowatz
36552a38012Sejakowatz printf("### removing none\n");
36652a38012Sejakowatz q->FlushEvents(0x1fff, BTimedEventQueue::B_AFTER_TIME,true);
36752a38012Sejakowatz ASSERT(q->EventCount() == 12);
36852a38012Sejakowatz
36952a38012Sejakowatz printf("### removing 0x1010, 0x1011, 0x1012\n");
37052a38012Sejakowatz q->FlushEvents(0x1010, BTimedEventQueue::B_AFTER_TIME,true);
37152a38012Sejakowatz ASSERT(q->EventCount() == 9);
37252a38012Sejakowatz
37352a38012Sejakowatz printf("### removing 0x1000 to 0x1005\n");
37452a38012Sejakowatz q->FlushEvents(0x1006, BTimedEventQueue::B_BEFORE_TIME,false);
37552a38012Sejakowatz ASSERT(q->EventCount() == 3);
37652a38012Sejakowatz
37752a38012Sejakowatz printf("### removing 0x1006\n");
37852a38012Sejakowatz q->FlushEvents(0x1006, BTimedEventQueue::B_AT_TIME);
37952a38012Sejakowatz ASSERT(q->EventCount() == 2);
38052a38012Sejakowatz
38152a38012Sejakowatz printf("### removing 0x1008 0x1009\n");
38252a38012Sejakowatz q->FlushEvents(0xffffff, BTimedEventQueue::B_BEFORE_TIME);
38352a38012Sejakowatz ASSERT(q->EventCount() == 0);
38452a38012Sejakowatz
38552a38012Sejakowatz delete q;
38652a38012Sejakowatz }
38752a38012Sejakowatz
38852a38012Sejakowatz
main()38952a38012Sejakowatz int main()
39052a38012Sejakowatz {
39152a38012Sejakowatz InsertRemoveTest();
39252a38012Sejakowatz DoForEachTest();
39352a38012Sejakowatz MatchTest();
39452a38012Sejakowatz FlushTest();
39552a38012Sejakowatz return 0;
39652a38012Sejakowatz }
397