ilmNotifyTests: another set of fixes for notify callbacks
[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();
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();
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();
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 = new t_ilm_uint[2];
596     pos[0] = 7;
597     pos[1] = 2;
598     ilm_surfaceSetPosition(surface,pos);
599     ilm_commitChanges();
600
601     // expect callback to have been called
602     assertCallbackcalled();
603
604     EXPECT_EQ(surface,callbackSurfaceId);
605     EXPECT_EQ(7u,SurfaceProperties.destX);
606     EXPECT_EQ(2u,SurfaceProperties.destY);
607     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
608
609     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
610 }
611
612 TEST_F(NotificationTest, NotifyOnSurfaceSetDimension)
613 {
614     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
615     // change something
616     t_ilm_uint* pos = new t_ilm_uint[2];
617     pos[0] = 70;
618     pos[1] = 22;
619     ilm_surfaceSetDimension(surface,pos);
620     ilm_commitChanges();
621
622     // expect callback to have been called
623     assertCallbackcalled();
624
625     EXPECT_EQ(surface,callbackSurfaceId);
626     EXPECT_EQ(70u,SurfaceProperties.destWidth);
627     EXPECT_EQ(22u,SurfaceProperties.destHeight);
628     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
629
630     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
631 }
632
633 TEST_F(NotificationTest, NotifyOnSurfaceSetDestinationRectangle)
634 {
635     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
636     // change something
637     ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
638     ilm_commitChanges();
639
640     // expect callback to have been called
641     assertCallbackcalled();
642
643     EXPECT_EQ(surface,callbackSurfaceId);
644     EXPECT_EQ(33u,SurfaceProperties.destX);
645     EXPECT_EQ(567u,SurfaceProperties.destY);
646     EXPECT_EQ(55u,SurfaceProperties.destWidth);
647     EXPECT_EQ(99u,SurfaceProperties.destHeight);
648     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
649
650     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
651 }
652
653 TEST_F(NotificationTest, NotifyOnSurfaceSetOpacity)
654 {
655     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
656     // change something
657     t_ilm_float opacity = 0.789;
658     ilm_surfaceSetOpacity(surface,opacity);
659     ilm_commitChanges();
660
661     // expect callback to have been called
662     assertCallbackcalled();
663
664     EXPECT_EQ(surface,callbackSurfaceId);
665     EXPECT_NEAR(0.789, SurfaceProperties.opacity, 0.1);
666     EXPECT_EQ(ILM_NOTIFICATION_OPACITY,mask);
667
668     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
669 }
670
671 TEST_F(NotificationTest, NotifyOnSurfaceSetOrientation)
672 {
673     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
674     // change something
675     e_ilmOrientation orientation = ILM_ONEHUNDREDEIGHTY;
676     ilm_surfaceSetOrientation(surface,orientation);
677     ilm_commitChanges();
678
679     // expect callback to have been called
680     assertCallbackcalled();
681
682     EXPECT_EQ(surface,callbackSurfaceId);
683     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
684     EXPECT_EQ(ILM_NOTIFICATION_ORIENTATION,mask);
685
686     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
687 }
688
689 TEST_F(NotificationTest, NotifyOnSurfaceSetSourceRectangle)
690 {
691     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
692     // change something
693     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
694     ilm_commitChanges();
695
696     // expect callback to have been called
697     assertCallbackcalled();
698
699     EXPECT_EQ(surface,callbackSurfaceId);
700     EXPECT_EQ(33u,SurfaceProperties.sourceX);
701     EXPECT_EQ(567u,SurfaceProperties.sourceY);
702     EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
703     EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
704     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT,mask);
705
706     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
707 }
708
709 TEST_F(NotificationTest, NotifyOnSurfaceSetVisibility)
710 {
711     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
712     // change something
713     t_ilm_bool value = ILM_TRUE;
714     ilm_surfaceSetVisibility(surface,value);
715     ilm_commitChanges();
716
717     // expect callback to have been called
718     assertCallbackcalled();
719
720     EXPECT_EQ(surface,callbackSurfaceId);
721     EXPECT_TRUE(SurfaceProperties.visibility);
722     EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY,mask);
723
724     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
725 }
726
727 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues1)
728 {
729     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
730     // change something
731     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
732     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
733     ilm_commitChanges();
734
735     // expect callback to have been called
736     assertCallbackcalled();
737
738     EXPECT_EQ(surface,callbackSurfaceId);
739     EXPECT_EQ(33u,SurfaceProperties.sourceX);
740     EXPECT_EQ(567u,SurfaceProperties.sourceY);
741     EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
742     EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
743     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
744     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
745
746     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
747 }
748
749 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues2)
750 {
751     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
752     // change something
753     t_ilm_float opacity = 0.789;
754     ilm_surfaceSetOpacity(surface,opacity);
755     ilm_surfaceSetVisibility(surface,true);
756     ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
757     ilm_commitChanges();
758
759     // expect callback to have been called
760     assertCallbackcalled();
761
762     EXPECT_EQ(surface,callbackSurfaceId);
763     EXPECT_TRUE(SurfaceProperties.visibility);
764     EXPECT_NEAR(0.789, SurfaceProperties.opacity, 0.1);
765     EXPECT_EQ(33u,SurfaceProperties.destX);
766     EXPECT_EQ(567u,SurfaceProperties.destY);
767     EXPECT_EQ(55u,SurfaceProperties.destWidth);
768     EXPECT_EQ(99u,SurfaceProperties.destHeight);
769     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY,mask);
770
771     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
772 }
773
774 TEST_F(NotificationTest, NotifyOnSurfaceAllValues)
775 {
776     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
777     // change something
778     t_ilm_float opacity = 0.789;
779     ilm_surfaceSetOpacity(surface,opacity);
780     ilm_surfaceSetVisibility(surface,true);
781     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
782     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
783     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
784     ilm_commitChanges();
785
786     // expect callback to have been called
787     assertCallbackcalled();
788
789     EXPECT_EQ(surface,callbackSurfaceId);
790     EXPECT_EQ(33u,SurfaceProperties.sourceX);
791     EXPECT_EQ(567u,SurfaceProperties.sourceY);
792     EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
793     EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
794     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
795
796     EXPECT_TRUE(SurfaceProperties.visibility);
797     EXPECT_NEAR(opacity, SurfaceProperties.opacity, 0.1);
798     EXPECT_EQ(133u,SurfaceProperties.destX);
799     EXPECT_EQ(1567u,SurfaceProperties.destY);
800     EXPECT_EQ(155u,SurfaceProperties.destWidth);
801     EXPECT_EQ(199u,SurfaceProperties.destHeight);
802     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
803
804     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
805 }
806
807 TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveSurface)
808 {
809     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
810     // get called once
811     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
812     ilm_commitChanges();
813     assertCallbackcalled();
814
815     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
816
817     // change a lot of things
818     t_ilm_float opacity = 0.789;
819     ilm_surfaceSetOpacity(surface,opacity);
820     ilm_surfaceSetVisibility(surface,true);
821     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
822     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
823     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
824     ilm_commitChanges();
825
826     // assert that we have not been notified
827     assertNoCallbackIsCalled();
828
829 }
830
831 TEST_F(NotificationTest, MultipleRegistrationsSurface)
832 {
833     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
834     // get called once
835     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
836     ilm_commitChanges();
837     assertCallbackcalled();
838
839     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
840
841     // change a lot of things
842     t_ilm_float opacity = 0.789;
843     ilm_surfaceSetOpacity(surface,opacity);
844     ilm_surfaceSetVisibility(surface,true);
845     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
846     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
847     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
848     ilm_commitChanges();
849
850     // assert that we have not been notified
851     assertNoCallbackIsCalled();
852
853     // register for notifications again
854     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
855
856     ilm_surfaceSetOrientation(surface,ILM_ZERO);
857     ilm_commitChanges();
858     assertCallbackcalled();
859
860     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
861 }
862
863 TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsSurface)
864 {
865     // get called once
866     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
867     ilm_commitChanges();
868
869     // change a lot of things
870     t_ilm_float opacity = 0.789;
871     ilm_surfaceSetOpacity(surface,opacity);
872     ilm_surfaceSetVisibility(surface,true);
873     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
874     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
875     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
876     ilm_commitChanges();
877
878     // assert that we have not been notified
879     assertNoCallbackIsCalled();
880 }