tests: screen resolution
[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
30 extern "C" {
31     #include "ilm_client.h"
32     #include "ilm_control.h"
33 }
34
35
36
37 /* Tests with callbacks
38  * For each test first set the global variables to point to where parameters of the callbacks are supposed to be placed.
39  */
40 static pthread_mutex_t notificationMutex = PTHREAD_MUTEX_INITIALIZER;
41 static pthread_cond_t  waiterVariable = PTHREAD_COND_INITIALIZER;
42 static int timesCalled=0;
43
44 class NotificationTest: public TestBase, public ::testing::Test {
45 public:
46
47     static void SetUpTestCase() {
48         ilm_init();
49      }
50     static void TearDownTestCase() {
51         ilm_destroy();
52     }
53
54     NotificationTest()
55     {
56         // set default values
57         callbackLayerId = -1;
58         LayerProperties = ilmLayerProperties();
59         mask = ILM_NOTIFICATION_ALL;
60         surface = -1;
61         SurfaceProperties = ilmSurfaceProperties();
62         // create a layer
63         layer = 345;
64         ilm_layerRemove(layer);
65         ilm_commitChanges();
66         ilm_layerCreateWithDimension(&layer, 800, 480);
67         ilm_commitChanges();
68         // create a surface
69         surface = 456;
70         ilm_surfaceRemove(surface);
71         ilm_commitChanges();
72         ilm_surfaceCreate((t_ilm_nativehandle)wlSurface,10,10,ILM_PIXELFORMAT_RGBA_8888,&surface);
73         ilm_commitChanges();
74         timesCalled=0;
75     }
76
77     ~NotificationTest(){}
78
79
80
81     t_ilm_uint layer;
82
83     // Pointers where to put received values for current Test
84     static t_ilm_layer callbackLayerId;
85     static t_ilm_layer callbackSurfaceId;
86     static struct ilmLayerProperties LayerProperties;
87     static t_ilm_notification_mask mask;
88     static t_ilm_surface surface;
89     static ilmSurfaceProperties SurfaceProperties;
90
91
92     static void assertCallbackcalled(int numberOfExpectedCalls=1){
93         static struct timespec theTime;
94         clock_gettime(CLOCK_REALTIME, &theTime);
95         theTime.tv_sec += 2;
96         pthread_mutex_lock( &notificationMutex );
97         int status = 0;
98         do {
99             if (numberOfExpectedCalls!=timesCalled){
100                 status = pthread_cond_timedwait( &waiterVariable, &notificationMutex, &theTime);
101             }
102         } while (status!=ETIMEDOUT && numberOfExpectedCalls!=timesCalled);
103         ASSERT_NE(ETIMEDOUT, status);
104         pthread_mutex_unlock( &notificationMutex );
105         timesCalled=0;
106     }
107
108     static void assertNoCallbackIsCalled(){
109         struct timespec theTime;
110         clock_gettime(CLOCK_REALTIME, &theTime);
111         theTime.tv_sec += 1;
112         pthread_mutex_lock( &notificationMutex );
113         // assert that we have not been notified
114         ASSERT_EQ(ETIMEDOUT, pthread_cond_timedwait( &waiterVariable, &notificationMutex, &theTime));
115         pthread_mutex_unlock( &notificationMutex );
116     }
117
118
119     static void LayerCallbackFunction(t_ilm_layer layer, struct ilmLayerProperties* LayerProperties, t_ilm_notification_mask mask)
120     {
121         pthread_mutex_lock( &notificationMutex );
122
123         NotificationTest::callbackLayerId = layer;
124         NotificationTest::LayerProperties = *LayerProperties;
125         NotificationTest::mask = mask;
126         timesCalled++;
127         pthread_cond_signal( &waiterVariable );
128         pthread_mutex_unlock( &notificationMutex );
129     }
130
131     static void SurfaceCallbackFunction(t_ilm_surface surface, struct ilmSurfaceProperties* surfaceProperties, t_ilm_notification_mask mask)
132     {
133         pthread_mutex_lock( &notificationMutex );
134
135         NotificationTest::callbackSurfaceId = surface;
136         NotificationTest::SurfaceProperties = *surfaceProperties;
137         NotificationTest::mask = mask;
138         timesCalled++;
139         pthread_cond_signal( &waiterVariable );
140         pthread_mutex_unlock( &notificationMutex );
141     }
142 };
143
144 // Pointers where to put received values for current Test
145 t_ilm_layer NotificationTest::callbackLayerId;
146 t_ilm_layer NotificationTest::callbackSurfaceId;
147 struct ilmLayerProperties NotificationTest::LayerProperties;
148 t_ilm_notification_mask NotificationTest::mask;
149 t_ilm_surface NotificationTest::surface;
150 ilmSurfaceProperties NotificationTest::SurfaceProperties;
151
152
153
154
155 TEST_F(NotificationTest, ilm_layerAddNotificationWithoutCallback)
156 {
157     // create a layer
158     t_ilm_uint layer = 89;
159
160     ASSERT_EQ(ILM_SUCCESS,ilm_layerCreateWithDimension(&layer, 800, 480));
161     ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
162     // add notification
163
164     printf("test calling ilm_layerAddNotification\n");
165     //ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
166     ASSERT_EQ(ILM_SUCCESS, ilm_layerAddNotification(layer,NULL));
167
168     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemove(layer));
169     ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
170
171 }
172
173 TEST_F(NotificationTest, ilm_surfaceAddNotificationWithoutCallback)
174 {
175     // create a layer
176     t_ilm_uint surface = 67;
177
178     ilm_surfaceCreate((t_ilm_nativehandle)wlSurface,10,10,ILM_PIXELFORMAT_RGBA_8888,&surface);
179     ilm_commitChanges();
180
181     // add notification
182     ilmErrorTypes status = ilm_surfaceAddNotification(surface,NULL);
183     ASSERT_EQ(ILM_SUCCESS, status);
184
185     ilm_surfaceRemove(surface);
186     ilm_commitChanges();
187 }
188
189 // ######### LAYERS
190 TEST_F(NotificationTest, NotifyOnLayerSetPosition)
191 {
192     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
193     // change something
194     t_ilm_uint* pos = new t_ilm_uint[2];
195     pos[0] = 7;
196     pos[1] = 2;
197     ilm_layerSetPosition(layer,pos);
198     ilm_commitChanges();
199
200     // expect callback to have been called
201     assertCallbackcalled();
202
203     EXPECT_EQ(layer,callbackLayerId);
204     EXPECT_EQ(7u,LayerProperties.destX);
205     EXPECT_EQ(2u,LayerProperties.destY);
206     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
207
208     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
209 }
210
211 TEST_F(NotificationTest, NotifyOnLayerSetDimension)
212 {
213     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
214     // change something
215     t_ilm_uint* pos = new t_ilm_uint[2];
216     pos[0] = 70;
217     pos[1] = 22;
218     ilm_layerSetDimension(layer,pos);
219     ilm_commitChanges();
220
221     // expect callback to have been called
222     assertCallbackcalled();
223
224     EXPECT_EQ(layer,callbackLayerId);
225     EXPECT_EQ(70u,LayerProperties.destWidth);
226     EXPECT_EQ(22u,LayerProperties.destHeight);
227     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
228
229     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
230 }
231
232 TEST_F(NotificationTest, NotifyOnLayerSetDestinationRectangle)
233 {
234     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
235     // change something
236     ilm_layerSetDestinationRectangle(layer,33,567,55,99);
237     ilm_commitChanges();
238
239     // expect callback to have been called
240     assertCallbackcalled();
241
242     EXPECT_EQ(layer,callbackLayerId);
243     EXPECT_EQ(33u,LayerProperties.destX);
244     EXPECT_EQ(567u,LayerProperties.destY);
245     EXPECT_EQ(55u,LayerProperties.destWidth);
246     EXPECT_EQ(99u,LayerProperties.destHeight);
247     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
248
249     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
250 }
251
252 TEST_F(NotificationTest, NotifyOnLayerSetOpacity)
253 {
254     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
255     // change something
256     t_ilm_float opacity = 0.789;
257     ilm_layerSetOpacity(layer,opacity);
258     ilm_commitChanges();
259
260     // expect callback to have been called
261     assertCallbackcalled();
262
263     EXPECT_EQ(layer,callbackLayerId);
264     EXPECT_FLOAT_EQ(0.789,LayerProperties.opacity);
265     EXPECT_EQ(ILM_NOTIFICATION_OPACITY,mask);
266
267     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
268 }
269
270 TEST_F(NotificationTest, NotifyOnLayerSetOrientation)
271 {
272     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
273     // change something
274     e_ilmOrientation orientation = ILM_ONEHUNDREDEIGHTY;
275     ilm_layerSetOrientation(layer,orientation);
276     ilm_commitChanges();
277
278     // expect callback to have been called
279     assertCallbackcalled();
280
281     EXPECT_EQ(layer,callbackLayerId);
282     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,LayerProperties.orientation);
283     EXPECT_EQ(ILM_NOTIFICATION_ORIENTATION,mask);
284
285     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
286 }
287
288 TEST_F(NotificationTest, NotifyOnLayerSetSourceRectangle)
289 {
290     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
291     // change something
292     ilm_layerSetSourceRectangle(layer,33,567,55,99);
293     ilm_commitChanges();
294
295     // expect callback to have been called
296     assertCallbackcalled();
297
298     EXPECT_EQ(layer,callbackLayerId);
299     EXPECT_EQ(33u,LayerProperties.sourceX);
300     EXPECT_EQ(567u,LayerProperties.sourceY);
301     EXPECT_EQ(55u,LayerProperties.sourceWidth);
302     EXPECT_EQ(99u,LayerProperties.sourceHeight);
303     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT,mask);
304
305     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
306 }
307
308 TEST_F(NotificationTest, NotifyOnLayerSetVisibility)
309 {
310     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
311     // change something
312     t_ilm_bool value = ILM_TRUE;
313     ilm_layerSetVisibility(layer,value);
314     ilm_commitChanges();
315
316     // expect callback to have been called
317     assertCallbackcalled();
318
319     EXPECT_EQ(layer,callbackLayerId);
320     EXPECT_TRUE(LayerProperties.visibility);
321     EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY,mask);
322
323     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
324 }
325
326 TEST_F(NotificationTest, NotifyOnLayerMultipleValues1)
327 {
328     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
329     // change something
330     ilm_layerSetSourceRectangle(layer,33,567,55,99);
331     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
332     ilm_commitChanges();
333
334     // expect callback to have been called
335     assertCallbackcalled();
336
337     EXPECT_EQ(layer,callbackLayerId);
338     EXPECT_EQ(33u,LayerProperties.sourceX);
339     EXPECT_EQ(567u,LayerProperties.sourceY);
340     EXPECT_EQ(55u,LayerProperties.sourceWidth);
341     EXPECT_EQ(99u,LayerProperties.sourceHeight);
342     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,LayerProperties.orientation);
343     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
344
345     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
346 }
347
348 TEST_F(NotificationTest, NotifyOnLayerMultipleValues2)
349 {
350     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
351     // change something
352     t_ilm_float opacity = 0.789;
353     ilm_layerSetOpacity(layer,opacity);
354     ilm_layerSetVisibility(layer,true);
355     ilm_layerSetDestinationRectangle(layer,33,567,55,99);
356     ilm_commitChanges();
357
358     // expect callback to have been called
359     assertCallbackcalled();
360
361     EXPECT_EQ(layer,callbackLayerId);
362     EXPECT_TRUE(LayerProperties.visibility);
363     EXPECT_FLOAT_EQ(0.789,LayerProperties.opacity);
364     EXPECT_EQ(33u,LayerProperties.destX);
365     EXPECT_EQ(567u,LayerProperties.destY);
366     EXPECT_EQ(55u,LayerProperties.destWidth);
367     EXPECT_EQ(99u,LayerProperties.destHeight);
368     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY,mask);
369
370     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
371 }
372
373 TEST_F(NotificationTest, NotifyOnLayerAllValues)
374 {
375     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
376     // change something
377     t_ilm_float opacity = 0.789;
378     ilm_layerSetOpacity(layer,opacity);
379     ilm_layerSetVisibility(layer,true);
380     ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
381     ilm_layerSetSourceRectangle(layer,33,567,55,99);
382     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
383     ilm_commitChanges();
384
385     // expect callback to have been called
386     assertCallbackcalled();
387
388     EXPECT_EQ(layer,callbackLayerId);
389     EXPECT_EQ(33u,LayerProperties.sourceX);
390     EXPECT_EQ(567u,LayerProperties.sourceY);
391     EXPECT_EQ(55u,LayerProperties.sourceWidth);
392     EXPECT_EQ(99u,LayerProperties.sourceHeight);
393     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,LayerProperties.orientation);
394
395     EXPECT_TRUE(LayerProperties.visibility);
396     EXPECT_FLOAT_EQ(opacity,LayerProperties.opacity);
397     EXPECT_EQ(133u,LayerProperties.destX);
398     EXPECT_EQ(1567u,LayerProperties.destY);
399     EXPECT_EQ(155u,LayerProperties.destWidth);
400     EXPECT_EQ(199u,LayerProperties.destHeight);
401     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
402
403     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
404 }
405
406 TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveLayer)
407 {
408     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
409     // get called once
410     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
411     ilm_commitChanges();
412     assertCallbackcalled();
413
414     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
415
416     // change a lot of things
417     t_ilm_float opacity = 0.789;
418     ilm_layerSetOpacity(layer,opacity);
419     ilm_layerSetVisibility(layer,true);
420     ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
421     ilm_layerSetSourceRectangle(layer,33,567,55,99);
422     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
423     ilm_commitChanges();
424
425     // assert that we have not been notified
426     assertNoCallbackIsCalled();
427
428 }
429
430 TEST_F(NotificationTest, MultipleRegistrationsLayer)
431 {
432     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
433     // get called once
434     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
435     ilm_commitChanges();
436     assertCallbackcalled();
437
438     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
439
440     // change a lot of things
441     t_ilm_float opacity = 0.789;
442     ilm_layerSetOpacity(layer,opacity);
443     ilm_layerSetVisibility(layer,true);
444     ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
445     ilm_layerSetSourceRectangle(layer,33,567,55,99);
446     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
447     ilm_commitChanges();
448
449     // assert that we have not been notified
450     assertNoCallbackIsCalled();
451
452     // register for notifications again
453     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
454
455     ilm_layerSetOrientation(layer,ILM_ZERO);
456     ilm_commitChanges();
457     assertCallbackcalled();
458
459     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
460 }
461
462 TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsLayer)
463 {
464     // get called once
465     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
466     ilm_commitChanges();
467
468     // change a lot of things
469     t_ilm_float opacity = 0.789;
470     ilm_layerSetOpacity(layer,opacity);
471     ilm_layerSetVisibility(layer,true);
472     ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
473     ilm_layerSetSourceRectangle(layer,33,567,55,99);
474     ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
475     ilm_commitChanges();
476
477     // assert that we have not been notified
478     assertNoCallbackIsCalled();
479 }
480
481 // ######## SURFACES
482 TEST_F(NotificationTest, NotifyOnSurfaceSetPosition)
483 {
484     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
485     // change something
486     t_ilm_uint* pos = new t_ilm_uint[2];
487     pos[0] = 7;
488     pos[1] = 2;
489     ilm_surfaceSetPosition(surface,pos);
490     ilm_commitChanges();
491
492     // expect callback to have been called
493     assertCallbackcalled();
494
495     EXPECT_EQ(surface,callbackSurfaceId);
496     EXPECT_EQ(7u,SurfaceProperties.destX);
497     EXPECT_EQ(2u,SurfaceProperties.destY);
498     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
499
500     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
501 }
502
503 TEST_F(NotificationTest, NotifyOnSurfaceSetDimension)
504 {
505     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
506     // change something
507     t_ilm_uint* pos = new t_ilm_uint[2];
508     pos[0] = 70;
509     pos[1] = 22;
510     ilm_surfaceSetDimension(surface,pos);
511     ilm_commitChanges();
512
513     // expect callback to have been called
514     assertCallbackcalled();
515
516     EXPECT_EQ(surface,callbackSurfaceId);
517     EXPECT_EQ(70u,SurfaceProperties.destWidth);
518     EXPECT_EQ(22u,SurfaceProperties.destHeight);
519     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
520
521     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
522 }
523
524 TEST_F(NotificationTest, NotifyOnSurfaceSetDestinationRectangle)
525 {
526     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
527     // change something
528     ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
529     ilm_commitChanges();
530
531     // expect callback to have been called
532     assertCallbackcalled();
533
534     EXPECT_EQ(surface,callbackSurfaceId);
535     EXPECT_EQ(33u,SurfaceProperties.destX);
536     EXPECT_EQ(567u,SurfaceProperties.destY);
537     EXPECT_EQ(55u,SurfaceProperties.destWidth);
538     EXPECT_EQ(99u,SurfaceProperties.destHeight);
539     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
540
541     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
542 }
543
544 TEST_F(NotificationTest, NotifyOnSurfaceSetOpacity)
545 {
546     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
547     // change something
548     t_ilm_float opacity = 0.789;
549     ilm_surfaceSetOpacity(surface,opacity);
550     ilm_commitChanges();
551
552     // expect callback to have been called
553     assertCallbackcalled();
554
555     EXPECT_EQ(surface,callbackSurfaceId);
556     EXPECT_FLOAT_EQ(0.789,SurfaceProperties.opacity);
557     EXPECT_EQ(ILM_NOTIFICATION_OPACITY,mask);
558
559     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
560 }
561
562 TEST_F(NotificationTest, NotifyOnSurfaceSetOrientation)
563 {
564     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
565     // change something
566     e_ilmOrientation orientation = ILM_ONEHUNDREDEIGHTY;
567     ilm_surfaceSetOrientation(surface,orientation);
568     ilm_commitChanges();
569
570     // expect callback to have been called
571     assertCallbackcalled();
572
573     EXPECT_EQ(surface,callbackSurfaceId);
574     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
575     EXPECT_EQ(ILM_NOTIFICATION_ORIENTATION,mask);
576
577     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
578 }
579
580 TEST_F(NotificationTest, NotifyOnSurfaceSetSourceRectangle)
581 {
582     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
583     // change something
584     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
585     ilm_commitChanges();
586
587     // expect callback to have been called
588     assertCallbackcalled();
589
590     EXPECT_EQ(surface,callbackSurfaceId);
591     EXPECT_EQ(33u,SurfaceProperties.sourceX);
592     EXPECT_EQ(567u,SurfaceProperties.sourceY);
593     EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
594     EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
595     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT,mask);
596
597     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
598 }
599
600 TEST_F(NotificationTest, NotifyOnSurfaceSetVisibility)
601 {
602     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
603     // change something
604     t_ilm_bool value = ILM_TRUE;
605     ilm_surfaceSetVisibility(surface,value);
606     ilm_commitChanges();
607
608     // expect callback to have been called
609     assertCallbackcalled();
610
611     EXPECT_EQ(surface,callbackSurfaceId);
612     EXPECT_TRUE(SurfaceProperties.visibility);
613     EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY,mask);
614
615     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
616 }
617
618 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues1)
619 {
620     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
621     // change something
622     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
623     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
624     ilm_commitChanges();
625
626     // expect callback to have been called
627     assertCallbackcalled();
628
629     EXPECT_EQ(surface,callbackSurfaceId);
630     EXPECT_EQ(33u,SurfaceProperties.sourceX);
631     EXPECT_EQ(567u,SurfaceProperties.sourceY);
632     EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
633     EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
634     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
635     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
636
637     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
638 }
639
640 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues2)
641 {
642     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
643     // change something
644     t_ilm_float opacity = 0.789;
645     ilm_surfaceSetOpacity(surface,opacity);
646     ilm_surfaceSetVisibility(surface,true);
647     ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
648     ilm_commitChanges();
649
650     // expect callback to have been called
651     assertCallbackcalled();
652
653     EXPECT_EQ(surface,callbackSurfaceId);
654     EXPECT_TRUE(SurfaceProperties.visibility);
655     EXPECT_FLOAT_EQ(0.789,SurfaceProperties.opacity);
656     EXPECT_EQ(33u,SurfaceProperties.destX);
657     EXPECT_EQ(567u,SurfaceProperties.destY);
658     EXPECT_EQ(55u,SurfaceProperties.destWidth);
659     EXPECT_EQ(99u,SurfaceProperties.destHeight);
660     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY,mask);
661
662     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
663 }
664
665 TEST_F(NotificationTest, NotifyOnSurfaceAllValues)
666 {
667     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
668     // change something
669     t_ilm_float opacity = 0.789;
670     ilm_surfaceSetOpacity(surface,opacity);
671     ilm_surfaceSetVisibility(surface,true);
672     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
673     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
674     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
675     ilm_commitChanges();
676
677     // expect callback to have been called
678     assertCallbackcalled();
679
680     EXPECT_EQ(surface,callbackSurfaceId);
681     EXPECT_EQ(33u,SurfaceProperties.sourceX);
682     EXPECT_EQ(567u,SurfaceProperties.sourceY);
683     EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
684     EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
685     EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
686
687     EXPECT_TRUE(SurfaceProperties.visibility);
688     EXPECT_FLOAT_EQ(opacity,SurfaceProperties.opacity);
689     EXPECT_EQ(133u,SurfaceProperties.destX);
690     EXPECT_EQ(1567u,SurfaceProperties.destY);
691     EXPECT_EQ(155u,SurfaceProperties.destWidth);
692     EXPECT_EQ(199u,SurfaceProperties.destHeight);
693     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
694
695     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
696 }
697
698 TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveSurface)
699 {
700     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
701     // get called once
702     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
703     ilm_commitChanges();
704     assertCallbackcalled();
705
706     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
707
708     // change a lot of things
709     t_ilm_float opacity = 0.789;
710     ilm_surfaceSetOpacity(surface,opacity);
711     ilm_surfaceSetVisibility(surface,true);
712     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
713     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
714     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
715     ilm_commitChanges();
716
717     // assert that we have not been notified
718     assertNoCallbackIsCalled();
719
720 }
721
722 TEST_F(NotificationTest, MultipleRegistrationsSurface)
723 {
724     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
725     // get called once
726     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
727     ilm_commitChanges();
728     assertCallbackcalled();
729
730     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
731
732     // change a lot of things
733     t_ilm_float opacity = 0.789;
734     ilm_surfaceSetOpacity(surface,opacity);
735     ilm_surfaceSetVisibility(surface,true);
736     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
737     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
738     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
739     ilm_commitChanges();
740
741     // assert that we have not been notified
742     assertNoCallbackIsCalled();
743
744     // register for notifications again
745     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
746
747     ilm_surfaceSetOrientation(surface,ILM_ZERO);
748     ilm_commitChanges();
749     assertCallbackcalled();
750
751     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
752 }
753
754 TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsSurface)
755 {
756     // get called once
757     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
758     ilm_commitChanges();
759
760     // change a lot of things
761     t_ilm_float opacity = 0.789;
762     ilm_surfaceSetOpacity(surface,opacity);
763     ilm_surfaceSetVisibility(surface,true);
764     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
765     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
766     ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
767     ilm_commitChanges();
768
769     // assert that we have not been notified
770     assertNoCallbackIsCalled();
771 }