• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *
3  * Copyright 2012 BMW Car IT GmbH
4  * Copyright (C) 2016 Advanced Driver Information Technology Joint Venture GmbH
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 
21 #include "TestBase.h"
22 #include <gtest/gtest.h>
23 #include <stdio.h>
24 #include <pthread.h>
25 #include <sys/time.h>
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <signal.h>
30 #include <assert.h>
31 
32 extern "C" {
33     #include "ilm_control.h"
34 }
35 
add_nsecs(struct timespec * tv,long nsec)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:
PthreadMutexLock(pthread_mutex_t & mutex)64         explicit PthreadMutexLock(pthread_mutex_t &mutex): mutex_(mutex) {
65             pthread_mutex_lock(&mutex_);
66         }
~PthreadMutexLock()67         ~PthreadMutexLock() {
68             pthread_mutex_unlock(&mutex_);
69         }
70     };
71 
72 public:
SetUp()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         ivi_surface = (struct ivi_surface*)ivi_application_surface_create(iviApp, surface, wlSurfaces[0]);
92         ilm_commitChanges();
93         timesCalled=0;
94 
95         callbackLayerId = INVALID_ID;
96         callbackSurfaceId = INVALID_ID;
97     }
98 
TearDown()99     void TearDown()
100     {
101        //print_lmc_get_scene();
102        t_ilm_layer* layers = NULL;
103        t_ilm_int numLayer=0;
104        EXPECT_EQ(ILM_SUCCESS, ilm_getLayerIDs(&numLayer, &layers));
105        for (t_ilm_int i=0; i<numLayer; i++)
106        {
107            EXPECT_EQ(ILM_SUCCESS, ilm_layerRemove(layers[i]));
108        };
109        free(layers);
110 
111        ivi_surface_destroy(ivi_surface);
112 
113        EXPECT_EQ(ILM_SUCCESS, ilm_commitChanges());
114        EXPECT_EQ(ILM_SUCCESS, ilm_destroy());
115     }
116 
NotificationTest()117     NotificationTest(){}
118 
~NotificationTest()119     ~NotificationTest(){}
120 
121     t_ilm_uint layer;
122 
123     // Pointers where to put received values for current Test
124     static t_ilm_layer callbackLayerId;
125     static t_ilm_surface callbackSurfaceId;
126     static struct ilmLayerProperties LayerProperties;
127     static unsigned int mask;
128     static t_ilm_surface surface;
129     struct ivi_surface* ivi_surface;
130     static ilmSurfaceProperties SurfaceProperties;
131 
assertCallbackcalled(int numberOfExpectedCalls=1)132     static void assertCallbackcalled(int numberOfExpectedCalls=1){
133         static struct timespec theTime;
134         clock_gettime(CLOCK_REALTIME, &theTime);
135         add_nsecs(&theTime, 500000000);
136         PthreadMutexLock lock(notificationMutex);
137         int status = 0;
138         do {
139             if (numberOfExpectedCalls!=timesCalled) {
140                 status = pthread_cond_timedwait( &waiterVariable, &notificationMutex, &theTime);
141             }
142         } while (status!=ETIMEDOUT && numberOfExpectedCalls!=timesCalled);
143 
144         // we cannot rely on a timeout as layer callbacks are always called synchronously on ilm_commitChanges()
145         EXPECT_NE(ETIMEDOUT, status);
146         timesCalled=0;
147     }
148 
assertNoCallbackIsCalled()149     static void assertNoCallbackIsCalled(){
150         struct timespec theTime;
151         clock_gettime(CLOCK_REALTIME, &theTime);
152         add_nsecs(&theTime, 500000000);
153         PthreadMutexLock lock(notificationMutex);
154         // assert that we have not been notified
155         ASSERT_EQ(ETIMEDOUT, pthread_cond_timedwait( &waiterVariable, &notificationMutex, &theTime));
156     }
157 
LayerCallbackFunction(t_ilm_layer layer,struct ilmLayerProperties * layerProperties,t_ilm_notification_mask m)158     static void LayerCallbackFunction(t_ilm_layer layer, struct ilmLayerProperties* layerProperties, t_ilm_notification_mask m)
159     {
160         PthreadMutexLock lock(notificationMutex);
161 
162         if ((unsigned)m & ILM_NOTIFICATION_VISIBILITY)
163         {
164             LayerProperties.visibility = layerProperties->visibility;
165         }
166 
167         if ((unsigned)m & ILM_NOTIFICATION_OPACITY)
168         {
169             LayerProperties.opacity = layerProperties->opacity;
170         }
171 
172         if ((unsigned)m & ILM_NOTIFICATION_SOURCE_RECT)
173         {
174             LayerProperties.sourceX = layerProperties->sourceX;
175             LayerProperties.sourceY = layerProperties->sourceY;
176             LayerProperties.sourceWidth = layerProperties->sourceWidth;
177             LayerProperties.sourceHeight = layerProperties->sourceHeight;
178         }
179 
180         if ((unsigned)m & ILM_NOTIFICATION_DEST_RECT)
181         {
182             LayerProperties.destX = layerProperties->destX;
183             LayerProperties.destY = layerProperties->destY;
184             LayerProperties.destWidth = layerProperties->destWidth;
185             LayerProperties.destHeight = layerProperties->destHeight;
186         }
187 
188         EXPECT_TRUE(callbackLayerId == (unsigned)-1 || callbackLayerId == layer);
189         callbackLayerId = layer;
190         mask |= (unsigned)m;
191         timesCalled++;
192 
193         pthread_cond_signal( &waiterVariable );
194     }
195 
SurfaceCallbackFunction(t_ilm_surface surface,struct ilmSurfaceProperties * surfaceProperties,t_ilm_notification_mask m)196     static void SurfaceCallbackFunction(t_ilm_surface surface, struct ilmSurfaceProperties* surfaceProperties, t_ilm_notification_mask m)
197     {
198         PthreadMutexLock lock(notificationMutex);
199 
200         if ((unsigned)m & ILM_NOTIFICATION_VISIBILITY)
201         {
202             SurfaceProperties.visibility = surfaceProperties->visibility;
203         }
204 
205         if ((unsigned)m & ILM_NOTIFICATION_OPACITY)
206         {
207             SurfaceProperties.opacity = surfaceProperties->opacity;
208         }
209 
210         if ((unsigned)m & ILM_NOTIFICATION_SOURCE_RECT)
211         {
212             SurfaceProperties.sourceX = surfaceProperties->sourceX;
213             SurfaceProperties.sourceY = surfaceProperties->sourceY;
214             SurfaceProperties.sourceWidth = surfaceProperties->sourceWidth;
215             SurfaceProperties.sourceHeight = surfaceProperties->sourceHeight;
216         }
217 
218         if ((unsigned)m & ILM_NOTIFICATION_DEST_RECT)
219         {
220             SurfaceProperties.destX = surfaceProperties->destX;
221             SurfaceProperties.destY = surfaceProperties->destY;
222             SurfaceProperties.destWidth = surfaceProperties->destWidth;
223             SurfaceProperties.destHeight = surfaceProperties->destHeight;
224         }
225 
226         EXPECT_TRUE(callbackSurfaceId == (unsigned)-1 || callbackSurfaceId == surface);
227         callbackSurfaceId = surface;
228         mask |= (unsigned)m;
229         timesCalled++;
230 
231         pthread_cond_signal( &waiterVariable );
232     }
233 };
234 
235 // Pointers where to put received values for current Test
236 t_ilm_layer NotificationTest::callbackLayerId;
237 t_ilm_surface NotificationTest::callbackSurfaceId;
238 struct ilmLayerProperties NotificationTest::LayerProperties;
239 unsigned int NotificationTest::mask;
240 unsigned int NotificationTest::surface;
241 ilmSurfaceProperties NotificationTest::SurfaceProperties;
242 
TEST_F(NotificationTest,ilm_layerAddNotificationWithoutCallback)243 TEST_F(NotificationTest, ilm_layerAddNotificationWithoutCallback)
244 {
245     // create a layer
246     t_ilm_uint layer = 89;
247 
248     ASSERT_EQ(ILM_SUCCESS,ilm_layerCreateWithDimension(&layer, 800, 480));
249     ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
250     // add notification
251 
252     printf("test calling ilm_layerAddNotification\n");
253     //ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
254     ASSERT_EQ(ILM_SUCCESS, ilm_layerAddNotification(layer,NULL));
255 
256     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemove(layer));
257     ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
258 
259 }
260 
TEST_F(NotificationTest,ilm_surfaceAddNotificationWithoutCallback)261 TEST_F(NotificationTest, ilm_surfaceAddNotificationWithoutCallback)
262 {
263     // create a layer
264     t_ilm_uint surface = 67;
265     struct ivi_surface* ivi_surface = (struct ivi_surface*)
266         ivi_application_surface_create(iviApp, surface, wlSurfaces[1]);
267 
268     // add notification
269     ilmErrorTypes status = ilm_surfaceAddNotification(surface,NULL);
270     ASSERT_EQ(ILM_SUCCESS, status);
271 
272     ivi_surface_destroy(ivi_surface);
273     ilm_commitChanges();
274 }
275 
TEST_F(NotificationTest,NotifyOnLayerSetDestinationRectangle)276 TEST_F(NotificationTest, NotifyOnLayerSetDestinationRectangle)
277 {
278     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
279     // change something
280     ilm_layerSetDestinationRectangle(layer,33,567,55,99);
281     ilm_commitChanges();
282 
283     // expect callback to have been called
284     assertCallbackcalled();
285 
286     EXPECT_EQ(layer,callbackLayerId);
287     EXPECT_EQ(33u,LayerProperties.destX);
288     EXPECT_EQ(567u,LayerProperties.destY);
289     EXPECT_EQ(55u,LayerProperties.destWidth);
290     EXPECT_EQ(99u,LayerProperties.destHeight);
291     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
292 
293     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
294 }
295 
TEST_F(NotificationTest,NotifyOnLayerSetOpacity)296 TEST_F(NotificationTest, NotifyOnLayerSetOpacity)
297 {
298     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
299     // change something
300     t_ilm_float opacity = 0.789;
301     ilm_layerSetOpacity(layer,opacity);
302     ilm_commitChanges();
303 
304     // expect callback to have been called
305     assertCallbackcalled();
306 
307     EXPECT_EQ(layer,callbackLayerId);
308     EXPECT_NEAR(0.789, LayerProperties.opacity, 0.1);
309     EXPECT_EQ(ILM_NOTIFICATION_OPACITY,mask);
310 
311     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
312 }
313 
TEST_F(NotificationTest,NotifyOnLayerSetSourceRectangle)314 TEST_F(NotificationTest, NotifyOnLayerSetSourceRectangle)
315 {
316     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
317     // change something
318     ilm_layerSetSourceRectangle(layer,33,567,55,99);
319     ilm_commitChanges();
320 
321     // expect callback to have been called
322     assertCallbackcalled();
323 
324     EXPECT_EQ(layer,callbackLayerId);
325     EXPECT_EQ(33u,LayerProperties.sourceX);
326     EXPECT_EQ(567u,LayerProperties.sourceY);
327     EXPECT_EQ(55u,LayerProperties.sourceWidth);
328     EXPECT_EQ(99u,LayerProperties.sourceHeight);
329     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT,mask);
330 
331     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
332 }
333 
TEST_F(NotificationTest,NotifyOnLayerSetVisibility)334 TEST_F(NotificationTest, NotifyOnLayerSetVisibility)
335 {
336     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
337     // change something
338     t_ilm_bool value = ILM_TRUE;
339     ilm_layerSetVisibility(layer,value);
340     ilm_commitChanges();
341 
342     // expect callback to have been called
343     assertCallbackcalled();
344 
345     EXPECT_EQ(layer,callbackLayerId);
346     EXPECT_TRUE(LayerProperties.visibility);
347     EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY,mask);
348 
349     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
350 }
351 
TEST_F(NotificationTest,NotifyOnLayerMultipleValues1)352 TEST_F(NotificationTest, NotifyOnLayerMultipleValues1)
353 {
354     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
355     // change something
356     ilm_layerSetSourceRectangle(layer,33,567,55,99);
357     ilm_layerSetVisibility(layer,true);
358     ilm_commitChanges();
359 
360     // expect callback to have been called
361     assertCallbackcalled(2);
362 
363     EXPECT_EQ(layer,callbackLayerId);
364     EXPECT_EQ(33u,LayerProperties.sourceX);
365     EXPECT_EQ(567u,LayerProperties.sourceY);
366     EXPECT_EQ(55u,LayerProperties.sourceWidth);
367     EXPECT_EQ(99u,LayerProperties.sourceHeight);
368     EXPECT_TRUE(LayerProperties.visibility);
369     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_VISIBILITY,mask);
370 
371     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
372 }
373 
TEST_F(NotificationTest,NotifyOnLayerMultipleValues2)374 TEST_F(NotificationTest, NotifyOnLayerMultipleValues2)
375 {
376     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
377     // change something
378     t_ilm_float opacity = 0.789;
379     ilm_layerSetOpacity(layer,opacity);
380     ilm_layerSetVisibility(layer,true);
381     ilm_layerSetDestinationRectangle(layer,33,567,55,99);
382     ilm_commitChanges();
383 
384     // expect callback to have been called
385     assertCallbackcalled(3);
386 
387     EXPECT_EQ(layer,callbackLayerId);
388     EXPECT_TRUE(LayerProperties.visibility);
389     EXPECT_NEAR(0.789, LayerProperties.opacity, 0.1);
390     EXPECT_EQ(33u,LayerProperties.destX);
391     EXPECT_EQ(567u,LayerProperties.destY);
392     EXPECT_EQ(55u,LayerProperties.destWidth);
393     EXPECT_EQ(99u,LayerProperties.destHeight);
394     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY,mask);
395 
396     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
397 }
398 
TEST_F(NotificationTest,NotifyOnLayerAllValues)399 TEST_F(NotificationTest, NotifyOnLayerAllValues)
400 {
401     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
402     // change something
403     t_ilm_float opacity = 0.789;
404     ilm_layerSetOpacity(layer,opacity);
405     ilm_layerSetVisibility(layer,true);
406     ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
407     ilm_layerSetSourceRectangle(layer,33,567,55,99);
408     ilm_commitChanges();
409 
410     // expect callback to have been called
411     assertCallbackcalled(4);
412 
413     EXPECT_EQ(layer,callbackLayerId);
414     EXPECT_EQ(33u,LayerProperties.sourceX);
415     EXPECT_EQ(567u,LayerProperties.sourceY);
416     EXPECT_EQ(55u,LayerProperties.sourceWidth);
417     EXPECT_EQ(99u,LayerProperties.sourceHeight);
418 
419     EXPECT_TRUE(LayerProperties.visibility);
420     EXPECT_NEAR(opacity, LayerProperties.opacity, 0.1);
421     EXPECT_EQ(133u,LayerProperties.destX);
422     EXPECT_EQ(1567u,LayerProperties.destY);
423     EXPECT_EQ(155u,LayerProperties.destWidth);
424     EXPECT_EQ(199u,LayerProperties.destHeight);
425     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_SOURCE_RECT,mask);
426 
427     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
428 }
429 
TEST_F(NotificationTest,DoNotSendNotificationsAfterRemoveLayer)430 TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveLayer)
431 {
432     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
433     // get called once
434     ilm_layerSetVisibility(layer,true);
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_commitChanges();
447 
448     // assert that we have not been notified
449     assertNoCallbackIsCalled();
450 
451 }
452 
TEST_F(NotificationTest,MultipleRegistrationsLayer)453 TEST_F(NotificationTest, MultipleRegistrationsLayer)
454 {
455     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
456     // get called once
457     ilm_layerSetVisibility(layer,true);
458     ilm_commitChanges();
459     assertCallbackcalled();
460 
461     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
462 
463     // change a lot of things
464     t_ilm_float opacity = 0.789;
465     ilm_layerSetOpacity(layer,opacity);
466     ilm_layerSetVisibility(layer,true);
467     ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
468     ilm_layerSetSourceRectangle(layer,33,567,55,99);
469     ilm_commitChanges();
470 
471     // assert that we have not been notified
472     assertNoCallbackIsCalled();
473 
474     // register for notifications again
475     ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
476 
477     ilm_layerSetVisibility(layer,false);
478     ilm_commitChanges();
479     assertCallbackcalled();
480 
481     ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
482 }
483 
TEST_F(NotificationTest,DefaultIsNotToReceiveNotificationsLayer)484 TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsLayer)
485 {
486     // get called once
487     ilm_layerSetVisibility(layer,true);
488     ilm_commitChanges();
489 
490     // change a lot of things
491     t_ilm_float opacity = 0.789;
492     ilm_layerSetOpacity(layer,opacity);
493     ilm_layerSetVisibility(layer,true);
494     ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
495     ilm_layerSetSourceRectangle(layer,33,567,55,99);
496     ilm_commitChanges();
497 
498     // assert that we have not been notified
499     assertNoCallbackIsCalled();
500 }
501 
TEST_F(NotificationTest,NotifyOnSurfaceSetDestinationRectangle)502 TEST_F(NotificationTest, NotifyOnSurfaceSetDestinationRectangle)
503 {
504     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
505     // change something
506     ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
507     ilm_commitChanges();
508 
509     // expect callback to have been called
510     assertCallbackcalled(2);
511 
512     EXPECT_EQ(surface,callbackSurfaceId);
513     EXPECT_EQ(33u,SurfaceProperties.destX);
514     EXPECT_EQ(567u,SurfaceProperties.destY);
515     EXPECT_EQ(55u,SurfaceProperties.destWidth);
516     EXPECT_EQ(99u,SurfaceProperties.destHeight);
517     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);
518 
519     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
520 }
521 
TEST_F(NotificationTest,NotifyOnSurfaceSetOpacity)522 TEST_F(NotificationTest, NotifyOnSurfaceSetOpacity)
523 {
524     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
525     // change something
526     t_ilm_float opacity = 0.789;
527     ilm_surfaceSetOpacity(surface,opacity);
528     ilm_commitChanges();
529 
530     // expect callback to have been called
531     assertCallbackcalled(2);
532 
533     EXPECT_EQ(surface,callbackSurfaceId);
534     EXPECT_NEAR(0.789, SurfaceProperties.opacity, 0.1);
535     EXPECT_EQ(ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);
536 
537     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
538 }
539 
TEST_F(NotificationTest,NotifyOnSurfaceSetSourceRectangle)540 TEST_F(NotificationTest, NotifyOnSurfaceSetSourceRectangle)
541 {
542     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
543     // change something
544     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
545     ilm_commitChanges();
546 
547     // expect callback to have been called
548     assertCallbackcalled(2);
549 
550     EXPECT_EQ(surface,callbackSurfaceId);
551     EXPECT_EQ(33u,SurfaceProperties.sourceX);
552     EXPECT_EQ(567u,SurfaceProperties.sourceY);
553     EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
554     EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
555     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);
556 
557     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
558 }
559 
TEST_F(NotificationTest,NotifyOnSurfaceSetVisibility)560 TEST_F(NotificationTest, NotifyOnSurfaceSetVisibility)
561 {
562     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
563     // change something
564     t_ilm_bool value = ILM_TRUE;
565     ilm_surfaceSetVisibility(surface,value);
566     ilm_commitChanges();
567 
568     // expect callback to have been called
569     assertCallbackcalled(2);
570 
571     EXPECT_EQ(surface,callbackSurfaceId);
572     EXPECT_TRUE(SurfaceProperties.visibility);
573     EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);
574 
575     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
576 }
577 
TEST_F(NotificationTest,NotifyOnSurfaceMultipleValues1)578 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues1)
579 {
580     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
581     // change something
582     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
583     ilm_surfaceSetVisibility(surface,true);
584     ilm_commitChanges();
585 
586     // expect callback to have been called
587     assertCallbackcalled(3);
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_TRUE(SurfaceProperties.visibility);
595     EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);
596 
597     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
598 }
599 
TEST_F(NotificationTest,NotifyOnSurfaceMultipleValues2)600 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues2)
601 {
602     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
603     // change something
604     t_ilm_float opacity = 0.789;
605     ilm_surfaceSetOpacity(surface,opacity);
606     ilm_surfaceSetVisibility(surface,true);
607     ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
608     ilm_commitChanges();
609 
610     // expect callback to have been called
611     assertCallbackcalled(4);
612 
613     EXPECT_EQ(surface,callbackSurfaceId);
614     EXPECT_TRUE(SurfaceProperties.visibility);
615     EXPECT_NEAR(0.789, SurfaceProperties.opacity, 0.1);
616     EXPECT_EQ(33u,SurfaceProperties.destX);
617     EXPECT_EQ(567u,SurfaceProperties.destY);
618     EXPECT_EQ(55u,SurfaceProperties.destWidth);
619     EXPECT_EQ(99u,SurfaceProperties.destHeight);
620     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|
621               ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);
622 
623     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
624 }
625 
TEST_F(NotificationTest,NotifyOnSurfaceAllValues)626 TEST_F(NotificationTest, NotifyOnSurfaceAllValues)
627 {
628     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
629     // change something
630     t_ilm_float opacity = 0.789;
631     ilm_surfaceSetOpacity(surface,opacity);
632     ilm_surfaceSetVisibility(surface,true);
633     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
634     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
635     ilm_commitChanges();
636 
637     // expect callback to have been called
638     assertCallbackcalled(5);
639 
640     EXPECT_EQ(surface,callbackSurfaceId);
641     EXPECT_EQ(33u,SurfaceProperties.sourceX);
642     EXPECT_EQ(567u,SurfaceProperties.sourceY);
643     EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
644     EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
645 
646     EXPECT_TRUE(SurfaceProperties.visibility);
647     EXPECT_NEAR(opacity, SurfaceProperties.opacity, 0.1);
648     EXPECT_EQ(133u,SurfaceProperties.destX);
649     EXPECT_EQ(1567u,SurfaceProperties.destY);
650     EXPECT_EQ(155u,SurfaceProperties.destWidth);
651     EXPECT_EQ(199u,SurfaceProperties.destHeight);
652     EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY|
653               ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);
654 
655     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
656 }
657 
TEST_F(NotificationTest,DoNotSendNotificationsAfterRemoveSurface)658 TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveSurface)
659 {
660     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
661     // get called once
662     ilm_surfaceSetVisibility(surface,true);
663     ilm_commitChanges();
664     assertCallbackcalled(2);
665 
666     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
667 
668     // change a lot of things
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_commitChanges();
675 
676     // assert that we have not been notified
677     assertNoCallbackIsCalled();
678 
679 }
680 
TEST_F(NotificationTest,MultipleRegistrationsSurface)681 TEST_F(NotificationTest, MultipleRegistrationsSurface)
682 {
683     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
684     // get called once
685     ilm_surfaceSetVisibility(surface,true);
686     ilm_commitChanges();
687     assertCallbackcalled(2);
688 
689     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
690 
691     // change a lot of things
692     t_ilm_float opacity = 0.789;
693     ilm_surfaceSetOpacity(surface,opacity);
694     ilm_surfaceSetVisibility(surface,true);
695     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
696     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
697     ilm_commitChanges();
698 
699     // assert that we have not been notified
700     assertNoCallbackIsCalled();
701 
702     // register for notifications again
703     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
704 
705     ilm_surfaceSetVisibility(surface,false);
706     ilm_commitChanges();
707     assertCallbackcalled(2);
708 
709     ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
710 }
711 
TEST_F(NotificationTest,DefaultIsNotToReceiveNotificationsSurface)712 TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsSurface)
713 {
714     // get called once
715     ilm_surfaceSetVisibility(surface,true);
716     ilm_commitChanges();
717 
718     // change a lot of things
719     t_ilm_float opacity = 0.789;
720     ilm_surfaceSetOpacity(surface,opacity);
721     ilm_surfaceSetVisibility(surface,true);
722     ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
723     ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
724     ilm_commitChanges();
725 
726     // assert that we have not been notified
727     assertNoCallbackIsCalled();
728 }
729