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