ilmControl: cancel read even on thread cancellation
[profile/ivi/wayland-ivi-extension.git] / ivi-layermanagement-api / test / ilm_control_notification_test.cpp
1 /***************************************************************************
2  *
3  * Copyright 2012 BMW Car IT GmbH
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  ****************************************************************************/
19
20 #include "TestBase.h"
21 #include <gtest/gtest.h>
22 #include <stdio.h>
23 #include <pthread.h>
24 #include <sys/time.h>
25 #include <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <signal.h>
29 #include <assert.h>
30
31 extern "C" {
32     #include "ilm_client.h"
33     #include "ilm_control.h"
34 }
35
36 void add_nsecs(struct timespec *tv, long nsec)
37 {
38    assert(nsec < 1000000000);
39
40    tv->tv_nsec += nsec;
41    if (tv->tv_nsec >= 1000000000)
42    {
43       tv->tv_nsec -= 1000000000;
44       tv->tv_sec++;
45    }
46 }
47
48 /* Tests with callbacks
49  * For each test first set the global variables to point to where parameters of the callbacks are supposed to be placed.
50  */
51 static pthread_mutex_t notificationMutex = PTHREAD_MUTEX_INITIALIZER;
52 static pthread_cond_t  waiterVariable = PTHREAD_COND_INITIALIZER;
53 static int timesCalled=0;
54
55 class NotificationTest: public TestBase, public ::testing::Test {
56     class PthreadMutexLock {
57     private:
58         pthread_mutex_t &mutex_;
59
60         PthreadMutexLock(const PthreadMutexLock&);
61         PthreadMutexLock& operator=(const PthreadMutexLock&);
62
63     public:
64         explicit PthreadMutexLock(pthread_mutex_t &mutex): mutex_(mutex) {
65             pthread_mutex_lock(&mutex_);
66         }
67         ~PthreadMutexLock() {
68             pthread_mutex_unlock(&mutex_);
69         }
70     };
71
72 public:
73     void SetUp()
74     {
75         ASSERT_EQ(ILM_SUCCESS, ilm_initWithNativedisplay((t_ilm_nativedisplay)wlDisplay));
76
77         // set default values
78         callbackLayerId = -1;
79         LayerProperties = ilmLayerProperties();
80         mask = static_cast<t_ilm_notification_mask>(0);
81         surface = -1;
82         SurfaceProperties = ilmSurfaceProperties();
83         // create a layer
84         layer = 345;
85         ilm_layerRemove(layer);
86         ilm_commitChanges();
87         ilm_layerCreateWithDimension(&layer, 800, 480);
88         ilm_commitChanges();
89         // create a surface
90         surface = 456;
91         ilm_surfaceRemove(surface);
92         ilm_commitChanges();
93         ilm_surfaceCreate((t_ilm_nativehandle)wlSurfaces[0],10,10,ILM_PIXELFORMAT_RGBA_8888,&surface);
94         ilm_commitChanges();
95         timesCalled=0;
96
97         callbackLayerId = INVALID_ID;
98         callbackSurfaceId = INVALID_ID;
99     }
100
101     void TearDown()
102     {
103        //print_lmc_get_scene();
104        t_ilm_layer* layers = NULL;
105        t_ilm_int numLayer=0;
106        EXPECT_EQ(ILM_SUCCESS, ilm_getLayerIDs(&numLayer, &layers));
107        for (t_ilm_int i=0; i<numLayer; i++)
108        {
109            EXPECT_EQ(ILM_SUCCESS, ilm_layerRemove(layers[i]));
110        };
111        free(layers);
112
113        t_ilm_surface* surfaces = NULL;
114        t_ilm_int numSurfaces=0;
115        EXPECT_EQ(ILM_SUCCESS, ilm_getSurfaceIDs(&numSurfaces, &surfaces));
116        for (t_ilm_int i=0; i<numSurfaces; i++)
117        {
118            EXPECT_EQ(ILM_SUCCESS, ilm_surfaceRemove(surfaces[i]));
119        };
120        free(surfaces);
121
122        EXPECT_EQ(ILM_SUCCESS, ilm_commitChanges());
123        EXPECT_EQ(ILM_SUCCESS, ilm_destroy());
124     }
125
126     NotificationTest(){}
127
128     ~NotificationTest(){}
129
130     t_ilm_uint layer;
131
132     // Pointers where to put received values for current Test
133     static t_ilm_layer callbackLayerId;
134     static t_ilm_surface callbackSurfaceId;
135     static struct ilmLayerProperties LayerProperties;
136     static unsigned int mask;
137     static t_ilm_surface surface;
138     static ilmSurfaceProperties SurfaceProperties;
139
140     static void assertCallbackcalled(int numberOfExpectedCalls=1){
141         static struct timespec theTime;
142         clock_gettime(CLOCK_REALTIME, &theTime);
143         add_nsecs(&theTime, 500000000);
144         PthreadMutexLock lock(notificationMutex);
145         int status = 0;
146         do {
147             if (numberOfExpectedCalls!=timesCalled) {
148                 status = pthread_cond_timedwait( &waiterVariable, &notificationMutex, &theTime);
149             }
150         } while (status!=ETIMEDOUT && numberOfExpectedCalls!=timesCalled);
151
152         // we cannot rely on a timeout as layer callbacks are always called synchronously on ilm_commitChanges()
153         EXPECT_NE(ETIMEDOUT, status);
154         timesCalled=0;
155     }
156
157     static void assertNoCallbackIsCalled(){
158         struct timespec theTime;
159         clock_gettime(CLOCK_REALTIME, &theTime);
160         add_nsecs(&theTime, 500000000);
161         PthreadMutexLock lock(notificationMutex);
162         // assert that we have not been notified
163         ASSERT_EQ(ETIMEDOUT, pthread_cond_timedwait( &waiterVariable, &notificationMutex, &theTime));
164     }
165
166     static void LayerCallbackFunction(t_ilm_layer layer, struct ilmLayerProperties* layerProperties, t_ilm_notification_mask m)
167     {
168         PthreadMutexLock lock(notificationMutex);
169
170         if ((unsigned)m & ILM_NOTIFICATION_VISIBILITY)
171         {
172             LayerProperties.visibility = layerProperties->visibility;
173         }
174
175         if ((unsigned)m & ILM_NOTIFICATION_OPACITY)
176         {
177             LayerProperties.opacity = layerProperties->opacity;
178         }
179
180         if ((unsigned)m & ILM_NOTIFICATION_ORIENTATION)
181         {
182             LayerProperties.orientation = layerProperties->orientation;
183         }
184
185         if ((unsigned)m & ILM_NOTIFICATION_SOURCE_RECT)
186         {
187             LayerProperties.sourceX = layerProperties->sourceX;
188             LayerProperties.sourceY = layerProperties->sourceY;
189             LayerProperties.sourceWidth = layerProperties->sourceWidth;
190             LayerProperties.sourceHeight = layerProperties->sourceHeight;
191         }
192
193         if ((unsigned)m & ILM_NOTIFICATION_DEST_RECT)
194         {
195             LayerProperties.destX = layerProperties->destX;
196             LayerProperties.destY = layerProperties->destY;
197             LayerProperties.destWidth = layerProperties->destWidth;
198             LayerProperties.destHeight = layerProperties->destHeight;
199         }
200
201         EXPECT_TRUE(callbackLayerId == (unsigned)-1 || callbackLayerId == layer);
202         callbackLayerId = layer;
203         mask |= (unsigned)m;
204         timesCalled++;
205
206         pthread_cond_signal( &waiterVariable );
207     }
208
209     static void SurfaceCallbackFunction(t_ilm_surface surface, struct ilmSurfaceProperties* surfaceProperties, t_ilm_notification_mask m)
210     {
211         PthreadMutexLock lock(notificationMutex);
212
213         if ((unsigned)m & ILM_NOTIFICATION_VISIBILITY)
214         {
215             SurfaceProperties.visibility = surfaceProperties->visibility;
216         }
217
218         if ((unsigned)m & ILM_NOTIFICATION_OPACITY)
219         {
220             SurfaceProperties.opacity = surfaceProperties->opacity;
221         }
222
223         if ((unsigned)m & ILM_NOTIFICATION_ORIENTATION)
224         {
225             SurfaceProperties.orientation = surfaceProperties->orientation;
226         }
227
228         if ((unsigned)m & ILM_NOTIFICATION_SOURCE_RECT)
229         {
230             SurfaceProperties.sourceX = surfaceProperties->sourceX;
231             SurfaceProperties.sourceY = surfaceProperties->sourceY;
232             SurfaceProperties.sourceWidth = surfaceProperties->sourceWidth;
233             SurfaceProperties.sourceHeight = surfaceProperties->sourceHeight;
234         }
235
236         if ((unsigned)m & ILM_NOTIFICATION_DEST_RECT)
237         {
238             SurfaceProperties.destX = surfaceProperties->destX;
239             SurfaceProperties.destY = surfaceProperties->destY;
240             SurfaceProperties.destWidth = surfaceProperties->destWidth;
241             SurfaceProperties.destHeight = surfaceProperties->destHeight;
242         }
243
244         EXPECT_TRUE(callbackSurfaceId == (unsigned)-1 || callbackSurfaceId == surface);
245         callbackSurfaceId = surface;
246         mask |= (unsigned)m;
247         timesCalled++;
248
249         pthread_cond_signal( &waiterVariable );
250     }
251 };
252
253 // Pointers where to put received values for current Test
254 t_ilm_layer NotificationTest::callbackLayerId;
255 t_ilm_surface NotificationTest::callbackSurfaceId;
256 struct ilmLayerProperties NotificationTest::LayerProperties;
257 unsigned int NotificationTest::mask;
258 t_ilm_surface NotificationTest::surface;
259 ilmSurfaceProperties NotificationTest::SurfaceProperties;
260
261
262
263
264 TEST_F(NotificationTest, ilm_layerAddNotificationWithoutCallback)
265 {
266     // create a layer
267     t_ilm_uint layer = 89;
268
269     ASSERT_EQ(ILM_SUCCESS,ilm_layerCreateWithDimension(&layer, 800, 480));
270     ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
271     // add notification
272
273     printf("test calling ilm_layerAddNotification\n");
274     //ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
275     ASSERT_EQ(ILM_SUCCESS, ilm_layerAddNotification(layer,NULL));
276
277     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemove(layer));
278     ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
279
280 }
281
282 TEST_F(NotificationTest, ilm_surfaceAddNotificationWithoutCallback)
283 {
284     // create a layer
285     t_ilm_uint surface = 67;
286
287     ilm_surfaceCreate((t_ilm_nativehandle)wlSurfaces[1],10,10,ILM_PIXELFORMAT_RGBA_8888,&surface);
288     ilm_commitChanges();
289
290     // add notification
291     ilmErrorTypes status = ilm_surfaceAddNotification(surface,NULL);
292     ASSERT_EQ(ILM_SUCCESS, status);
293
294     ilm_surfaceRemove(surface);
295     ilm_commitChanges();
296 }
297
298 // ######### LAYERS
299 TEST_F(NotificationTest, NotifyOnLayerSetPosition)
300 {
301     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
302     // change something
303     t_ilm_uint* pos = new t_ilm_uint[2];
304     pos[0] = 7;
305     pos[1] = 2;
306     ilm_layerSetPosition(layer,pos);
307     ilm_commitChanges();
308
309     // expect callback to have been called
310     assertCallbackcalled();
311
312     EXPECT_EQ(layer,callbackLayerId);
313     EXPECT_EQ(7u,LayerProperties.destX);
314     EXPECT_EQ(2u,LayerProperties.destY);
315     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
316
317     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
318 }
319
320 TEST_F(NotificationTest, NotifyOnLayerSetDimension)
321 {
322     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
323     // change something
324     t_ilm_uint* pos = new t_ilm_uint[2];
325     pos[0] = 70;
326     pos[1] = 22;
327     ilm_layerSetDimension(layer,pos);
328     ilm_commitChanges();
329
330     // expect callback to have been called
331     assertCallbackcalled();
332
333     EXPECT_EQ(layer,callbackLayerId);
334     EXPECT_EQ(70u,LayerProperties.destWidth);
335     EXPECT_EQ(22u,LayerProperties.destHeight);
336     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
337
338     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
339 }
340
341 TEST_F(NotificationTest, NotifyOnLayerSetDestinationRectangle)
342 {
343     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
344     // change something
345     ilm_layerSetDestinationRectangle(layer,33,567,55,99);
346     ilm_commitChanges();
347
348     // expect callback to have been called
349     assertCallbackcalled();
350
351     EXPECT_EQ(layer,callbackLayerId);
352     EXPECT_EQ(33u,LayerProperties.destX);
353     EXPECT_EQ(567u,LayerProperties.destY);
354     EXPECT_EQ(55u,LayerProperties.destWidth);
355     EXPECT_EQ(99u,LayerProperties.destHeight);
356     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
357
358     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
359 }
360
361 TEST_F(NotificationTest, NotifyOnLayerSetOpacity)
362 {
363     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
364     // change something
365     t_ilm_float opacity = 0.789;
366     ilm_layerSetOpacity(layer,opacity);
367     ilm_commitChanges();
368
369     // expect callback to have been called
370     assertCallbackcalled();
371
372     EXPECT_EQ(layer,callbackLayerId);
373     EXPECT_NEAR(0.789, LayerProperties.opacity, 0.1);
374     EXPECT_EQ(ILM_NOTIFICATION_OPACITY,mask);
375
376     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
377 }
378
379 TEST_F(NotificationTest, NotifyOnLayerSetOrientation)
380 {
381     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
382     // change something
383     e_ilmOrientation orientation = ILM_ONEHUNDREDEIGHTY;
384     ilm_layerSetOrientation(layer,orientation);
385     ilm_commitChanges();
386
387     // expect callback to have been called
388     assertCallbackcalled();
389
390     EXPECT_EQ(layer,callbackLayerId);
391     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,LayerProperties.orientation);
392     EXPECT_EQ(ILM_NOTIFICATION_ORIENTATION,mask);
393
394     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
395 }
396
397 TEST_F(NotificationTest, NotifyOnLayerSetSourceRectangle)
398 {
399     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
400     // change something
401     ilm_layerSetSourceRectangle(layer,33,567,55,99);
402     ilm_commitChanges();
403
404     // expect callback to have been called
405     assertCallbackcalled();
406
407     EXPECT_EQ(layer,callbackLayerId);
408     EXPECT_EQ(33u,LayerProperties.sourceX);
409     EXPECT_EQ(567u,LayerProperties.sourceY);
410     EXPECT_EQ(55u,LayerProperties.sourceWidth);
411     EXPECT_EQ(99u,LayerProperties.sourceHeight);
412     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT,mask);
413
414     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
415 }
416
417 TEST_F(NotificationTest, NotifyOnLayerSetVisibility)
418 {
419     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
420     // change something
421     t_ilm_bool value = ILM_TRUE;
422     ilm_layerSetVisibility(layer,value);
423     ilm_commitChanges();
424
425     // expect callback to have been called
426     assertCallbackcalled();
427
428     EXPECT_EQ(layer,callbackLayerId);
429     EXPECT_TRUE(LayerProperties.visibility);
430     EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY,mask);
431
432     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
433 }
434
435 TEST_F(NotificationTest, NotifyOnLayerMultipleValues1)
436 {
437     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
438     // change something
439     ilm_layerSetSourceRectangle(layer,33,567,55,99);
440     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
441     ilm_commitChanges();
442
443     // expect callback to have been called
444     assertCallbackcalled(2);
445
446     EXPECT_EQ(layer,callbackLayerId);
447     EXPECT_EQ(33u,LayerProperties.sourceX);
448     EXPECT_EQ(567u,LayerProperties.sourceY);
449     EXPECT_EQ(55u,LayerProperties.sourceWidth);
450     EXPECT_EQ(99u,LayerProperties.sourceHeight);
451     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,LayerProperties.orientation);
452     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
453
454     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
455 }
456
457 TEST_F(NotificationTest, NotifyOnLayerMultipleValues2)
458 {
459     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
460     // change something
461     t_ilm_float opacity = 0.789;
462     ilm_layerSetOpacity(layer,opacity);
463     ilm_layerSetVisibility(layer,true);
464     ilm_layerSetDestinationRectangle(layer,33,567,55,99);
465     ilm_commitChanges();
466
467     // expect callback to have been called
468     assertCallbackcalled(3);
469
470     EXPECT_EQ(layer,callbackLayerId);
471     EXPECT_TRUE(LayerProperties.visibility);
472     EXPECT_NEAR(0.789, LayerProperties.opacity, 0.1);
473     EXPECT_EQ(33u,LayerProperties.destX);
474     EXPECT_EQ(567u,LayerProperties.destY);
475     EXPECT_EQ(55u,LayerProperties.destWidth);
476     EXPECT_EQ(99u,LayerProperties.destHeight);
477     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY,mask);
478
479     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
480 }
481
482 TEST_F(NotificationTest, NotifyOnLayerAllValues)
483 {
484     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
485     // change something
486     t_ilm_float opacity = 0.789;
487     ilm_layerSetOpacity(layer,opacity);
488     ilm_layerSetVisibility(layer,true);
489     ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
490     ilm_layerSetSourceRectangle(layer,33,567,55,99);
491     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
492     ilm_commitChanges();
493
494     // expect callback to have been called
495     assertCallbackcalled(5);
496
497     EXPECT_EQ(layer,callbackLayerId);
498     EXPECT_EQ(33u,LayerProperties.sourceX);
499     EXPECT_EQ(567u,LayerProperties.sourceY);
500     EXPECT_EQ(55u,LayerProperties.sourceWidth);
501     EXPECT_EQ(99u,LayerProperties.sourceHeight);
502     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,LayerProperties.orientation);
503
504     EXPECT_TRUE(LayerProperties.visibility);
505     EXPECT_NEAR(opacity, LayerProperties.opacity, 0.1);
506     EXPECT_EQ(133u,LayerProperties.destX);
507     EXPECT_EQ(1567u,LayerProperties.destY);
508     EXPECT_EQ(155u,LayerProperties.destWidth);
509     EXPECT_EQ(199u,LayerProperties.destHeight);
510     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
511
512     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
513 }
514
515 TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveLayer)
516 {
517     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
518     // get called once
519     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
520     ilm_commitChanges();
521     assertCallbackcalled();
522
523     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
524
525     // change a lot of things
526     t_ilm_float opacity = 0.789;
527     ilm_layerSetOpacity(layer,opacity);
528     ilm_layerSetVisibility(layer,true);
529     ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
530     ilm_layerSetSourceRectangle(layer,33,567,55,99);
531     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
532     ilm_commitChanges();
533
534     // assert that we have not been notified
535     assertNoCallbackIsCalled();
536
537 }
538
539 TEST_F(NotificationTest, MultipleRegistrationsLayer)
540 {
541     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
542     // get called once
543     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
544     ilm_commitChanges();
545     assertCallbackcalled();
546
547     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
548
549     // change a lot of things
550     t_ilm_float opacity = 0.789;
551     ilm_layerSetOpacity(layer,opacity);
552     ilm_layerSetVisibility(layer,true);
553     ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
554     ilm_layerSetSourceRectangle(layer,33,567,55,99);
555     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
556     ilm_commitChanges();
557
558     // assert that we have not been notified
559     assertNoCallbackIsCalled();
560
561     // register for notifications again
562     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
563
564     ilm_layerSetOrientation(layer,ILM_ZERO);
565     ilm_commitChanges();
566     assertCallbackcalled();
567
568     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
569 }
570
571 TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsLayer)
572 {
573     // get called once
574     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
575     ilm_commitChanges();
576
577     // change a lot of things
578     t_ilm_float opacity = 0.789;
579     ilm_layerSetOpacity(layer,opacity);
580     ilm_layerSetVisibility(layer,true);
581     ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
582     ilm_layerSetSourceRectangle(layer,33,567,55,99);
583     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
584     ilm_commitChanges();
585
586     // assert that we have not been notified
587     assertNoCallbackIsCalled();
588 }
589
590 // ######## SURFACES
591 TEST_F(NotificationTest, NotifyOnSurfaceSetPosition)
592 {
593     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
594     // change something
595     t_ilm_uint pos[] = { 7, 2 };
596     ilm_surfaceSetPosition(surface,pos);
597     ilm_commitChanges();
598
599     // expect callback to have been called
600     assertCallbackcalled();
601
602     EXPECT_EQ(surface,callbackSurfaceId);
603     EXPECT_EQ(7u,SurfaceProperties.destX);
604     EXPECT_EQ(2u,SurfaceProperties.destY);
605     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
606
607     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
608 }
609
610 TEST_F(NotificationTest, NotifyOnSurfaceSetDimension)
611 {
612     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
613     // change something
614     t_ilm_uint pos[] = { 70, 22 };
615     ilm_surfaceSetDimension(surface,pos);
616     ilm_commitChanges();
617
618     // expect callback to have been called
619     assertCallbackcalled();
620
621     EXPECT_EQ(surface,callbackSurfaceId);
622     EXPECT_EQ(70u,SurfaceProperties.destWidth);
623     EXPECT_EQ(22u,SurfaceProperties.destHeight);
624     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
625
626     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
627 }
628
629 TEST_F(NotificationTest, NotifyOnSurfaceSetDestinationRectangle)
630 {
631     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
632     // change something
633     ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
634     ilm_commitChanges();
635
636     // expect callback to have been called
637     assertCallbackcalled();
638
639     EXPECT_EQ(surface,callbackSurfaceId);
640     EXPECT_EQ(33u,SurfaceProperties.destX);
641     EXPECT_EQ(567u,SurfaceProperties.destY);
642     EXPECT_EQ(55u,SurfaceProperties.destWidth);
643     EXPECT_EQ(99u,SurfaceProperties.destHeight);
644     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
645
646     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
647 }
648
649 TEST_F(NotificationTest, NotifyOnSurfaceSetOpacity)
650 {
651     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
652     // change something
653     t_ilm_float opacity = 0.789;
654     ilm_surfaceSetOpacity(surface,opacity);
655     ilm_commitChanges();
656
657     // expect callback to have been called
658     assertCallbackcalled();
659
660     EXPECT_EQ(surface,callbackSurfaceId);
661     EXPECT_NEAR(0.789, SurfaceProperties.opacity, 0.1);
662     EXPECT_EQ(ILM_NOTIFICATION_OPACITY,mask);
663
664     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
665 }
666
667 TEST_F(NotificationTest, NotifyOnSurfaceSetOrientation)
668 {
669     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
670     // change something
671     e_ilmOrientation orientation = ILM_ONEHUNDREDEIGHTY;
672     ilm_surfaceSetOrientation(surface,orientation);
673     ilm_commitChanges();
674
675     // expect callback to have been called
676     assertCallbackcalled();
677
678     EXPECT_EQ(surface,callbackSurfaceId);
679     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
680     EXPECT_EQ(ILM_NOTIFICATION_ORIENTATION,mask);
681
682     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
683 }
684
685 TEST_F(NotificationTest, NotifyOnSurfaceSetSourceRectangle)
686 {
687     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
688     // change something
689     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
690     ilm_commitChanges();
691
692     // expect callback to have been called
693     assertCallbackcalled();
694
695     EXPECT_EQ(surface,callbackSurfaceId);
696     EXPECT_EQ(33u,SurfaceProperties.sourceX);
697     EXPECT_EQ(567u,SurfaceProperties.sourceY);
698     EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
699     EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
700     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT,mask);
701
702     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
703 }
704
705 TEST_F(NotificationTest, NotifyOnSurfaceSetVisibility)
706 {
707     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
708     // change something
709     t_ilm_bool value = ILM_TRUE;
710     ilm_surfaceSetVisibility(surface,value);
711     ilm_commitChanges();
712
713     // expect callback to have been called
714     assertCallbackcalled();
715
716     EXPECT_EQ(surface,callbackSurfaceId);
717     EXPECT_TRUE(SurfaceProperties.visibility);
718     EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY,mask);
719
720     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
721 }
722
723 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues1)
724 {
725     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
726     // change something
727     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
728     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
729     ilm_commitChanges();
730
731     // expect callback to have been called
732     assertCallbackcalled(2);
733
734     EXPECT_EQ(surface,callbackSurfaceId);
735     EXPECT_EQ(33u,SurfaceProperties.sourceX);
736     EXPECT_EQ(567u,SurfaceProperties.sourceY);
737     EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
738     EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
739     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
740     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
741
742     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
743 }
744
745 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues2)
746 {
747     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
748     // change something
749     t_ilm_float opacity = 0.789;
750     ilm_surfaceSetOpacity(surface,opacity);
751     ilm_surfaceSetVisibility(surface,true);
752     ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
753     ilm_commitChanges();
754
755     // expect callback to have been called
756     assertCallbackcalled(3);
757
758     EXPECT_EQ(surface,callbackSurfaceId);
759     EXPECT_TRUE(SurfaceProperties.visibility);
760     EXPECT_NEAR(0.789, SurfaceProperties.opacity, 0.1);
761     EXPECT_EQ(33u,SurfaceProperties.destX);
762     EXPECT_EQ(567u,SurfaceProperties.destY);
763     EXPECT_EQ(55u,SurfaceProperties.destWidth);
764     EXPECT_EQ(99u,SurfaceProperties.destHeight);
765     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY,mask);
766
767     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
768 }
769
770 TEST_F(NotificationTest, NotifyOnSurfaceAllValues)
771 {
772     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
773     // change something
774     t_ilm_float opacity = 0.789;
775     ilm_surfaceSetOpacity(surface,opacity);
776     ilm_surfaceSetVisibility(surface,true);
777     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
778     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
779     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
780     ilm_commitChanges();
781
782     // expect callback to have been called
783     assertCallbackcalled(5);
784
785     EXPECT_EQ(surface,callbackSurfaceId);
786     EXPECT_EQ(33u,SurfaceProperties.sourceX);
787     EXPECT_EQ(567u,SurfaceProperties.sourceY);
788     EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
789     EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
790     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
791
792     EXPECT_TRUE(SurfaceProperties.visibility);
793     EXPECT_NEAR(opacity, SurfaceProperties.opacity, 0.1);
794     EXPECT_EQ(133u,SurfaceProperties.destX);
795     EXPECT_EQ(1567u,SurfaceProperties.destY);
796     EXPECT_EQ(155u,SurfaceProperties.destWidth);
797     EXPECT_EQ(199u,SurfaceProperties.destHeight);
798     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
799
800     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
801 }
802
803 TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveSurface)
804 {
805     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
806     // get called once
807     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
808     ilm_commitChanges();
809     assertCallbackcalled();
810
811     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
812
813     // change a lot of things
814     t_ilm_float opacity = 0.789;
815     ilm_surfaceSetOpacity(surface,opacity);
816     ilm_surfaceSetVisibility(surface,true);
817     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
818     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
819     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
820     ilm_commitChanges();
821
822     // assert that we have not been notified
823     assertNoCallbackIsCalled();
824
825 }
826
827 TEST_F(NotificationTest, MultipleRegistrationsSurface)
828 {
829     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
830     // get called once
831     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
832     ilm_commitChanges();
833     assertCallbackcalled();
834
835     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
836
837     // change a lot of things
838     t_ilm_float opacity = 0.789;
839     ilm_surfaceSetOpacity(surface,opacity);
840     ilm_surfaceSetVisibility(surface,true);
841     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
842     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
843     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
844     ilm_commitChanges();
845
846     // assert that we have not been notified
847     assertNoCallbackIsCalled();
848
849     // register for notifications again
850     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
851
852     ilm_surfaceSetOrientation(surface,ILM_ZERO);
853     ilm_commitChanges();
854     assertCallbackcalled();
855
856     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
857 }
858
859 TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsSurface)
860 {
861     // get called once
862     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
863     ilm_commitChanges();
864
865     // change a lot of things
866     t_ilm_float opacity = 0.789;
867     ilm_surfaceSetOpacity(surface,opacity);
868     ilm_surfaceSetVisibility(surface,true);
869     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
870     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
871     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
872     ilm_commitChanges();
873
874     // assert that we have not been notified
875     assertNoCallbackIsCalled();
876 }