1 /***************************************************************************
3 * Copyright 2012 BMW Car IT GmbH
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 ****************************************************************************/
21 #include <gtest/gtest.h>
32 #include "ilm_client.h"
33 #include "ilm_control.h"
36 void add_nsecs(struct timespec *tv, long nsec)
38 assert(nsec < 1000000000);
41 if (tv->tv_nsec >= 1000000000)
43 tv->tv_nsec -= 1000000000;
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.
51 static pthread_mutex_t notificationMutex = PTHREAD_MUTEX_INITIALIZER;
52 static pthread_cond_t waiterVariable = PTHREAD_COND_INITIALIZER;
53 static int timesCalled=0;
55 class NotificationTest: public TestBase, public ::testing::Test {
56 class PthreadMutexLock {
58 pthread_mutex_t &mutex_;
60 PthreadMutexLock(const PthreadMutexLock&);
61 PthreadMutexLock& operator=(const PthreadMutexLock&);
64 explicit PthreadMutexLock(pthread_mutex_t &mutex): mutex_(mutex) {
65 pthread_mutex_lock(&mutex_);
68 pthread_mutex_unlock(&mutex_);
75 ASSERT_EQ(ILM_SUCCESS, ilm_initWithNativedisplay((t_ilm_nativedisplay)wlDisplay));
79 LayerProperties = ilmLayerProperties();
80 mask = static_cast<t_ilm_notification_mask>(0);
82 SurfaceProperties = ilmSurfaceProperties();
85 ilm_layerRemove(layer);
87 ilm_layerCreateWithDimension(&layer, 800, 480);
91 ilm_surfaceRemove(surface);
93 ilm_surfaceCreate((t_ilm_nativehandle)wlSurfaces[0],10,10,ILM_PIXELFORMAT_RGBA_8888,&surface);
97 callbackLayerId = INVALID_ID;
98 callbackSurfaceId = INVALID_ID;
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++)
109 EXPECT_EQ(ILM_SUCCESS, ilm_layerRemove(layers[i]));
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++)
118 EXPECT_EQ(ILM_SUCCESS, ilm_surfaceRemove(surfaces[i]));
122 EXPECT_EQ(ILM_SUCCESS, ilm_commitChanges());
123 EXPECT_EQ(ILM_SUCCESS, ilm_destroy());
128 ~NotificationTest(){}
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;
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);
147 if (numberOfExpectedCalls!=timesCalled) {
148 status = pthread_cond_timedwait( &waiterVariable, ¬ificationMutex, &theTime);
150 } while (status!=ETIMEDOUT && numberOfExpectedCalls!=timesCalled);
152 // we cannot rely on a timeout as layer callbacks are always called synchronously on ilm_commitChanges()
153 EXPECT_NE(ETIMEDOUT, status);
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, ¬ificationMutex, &theTime));
166 static void LayerCallbackFunction(t_ilm_layer layer, struct ilmLayerProperties* layerProperties, t_ilm_notification_mask m)
168 PthreadMutexLock lock(notificationMutex);
170 if ((unsigned)m & ILM_NOTIFICATION_VISIBILITY)
172 LayerProperties.visibility = layerProperties->visibility;
175 if ((unsigned)m & ILM_NOTIFICATION_OPACITY)
177 LayerProperties.opacity = layerProperties->opacity;
180 if ((unsigned)m & ILM_NOTIFICATION_ORIENTATION)
182 LayerProperties.orientation = layerProperties->orientation;
185 if ((unsigned)m & ILM_NOTIFICATION_SOURCE_RECT)
187 LayerProperties.sourceX = layerProperties->sourceX;
188 LayerProperties.sourceY = layerProperties->sourceY;
189 LayerProperties.sourceWidth = layerProperties->sourceWidth;
190 LayerProperties.sourceHeight = layerProperties->sourceHeight;
193 if ((unsigned)m & ILM_NOTIFICATION_DEST_RECT)
195 LayerProperties.destX = layerProperties->destX;
196 LayerProperties.destY = layerProperties->destY;
197 LayerProperties.destWidth = layerProperties->destWidth;
198 LayerProperties.destHeight = layerProperties->destHeight;
201 EXPECT_TRUE(callbackLayerId == (unsigned)-1 || callbackLayerId == layer);
202 callbackLayerId = layer;
206 pthread_cond_signal( &waiterVariable );
209 static void SurfaceCallbackFunction(t_ilm_surface surface, struct ilmSurfaceProperties* surfaceProperties, t_ilm_notification_mask m)
211 PthreadMutexLock lock(notificationMutex);
213 if ((unsigned)m & ILM_NOTIFICATION_VISIBILITY)
215 SurfaceProperties.visibility = surfaceProperties->visibility;
218 if ((unsigned)m & ILM_NOTIFICATION_OPACITY)
220 SurfaceProperties.opacity = surfaceProperties->opacity;
223 if ((unsigned)m & ILM_NOTIFICATION_ORIENTATION)
225 SurfaceProperties.orientation = surfaceProperties->orientation;
228 if ((unsigned)m & ILM_NOTIFICATION_SOURCE_RECT)
230 SurfaceProperties.sourceX = surfaceProperties->sourceX;
231 SurfaceProperties.sourceY = surfaceProperties->sourceY;
232 SurfaceProperties.sourceWidth = surfaceProperties->sourceWidth;
233 SurfaceProperties.sourceHeight = surfaceProperties->sourceHeight;
236 if ((unsigned)m & ILM_NOTIFICATION_DEST_RECT)
238 SurfaceProperties.destX = surfaceProperties->destX;
239 SurfaceProperties.destY = surfaceProperties->destY;
240 SurfaceProperties.destWidth = surfaceProperties->destWidth;
241 SurfaceProperties.destHeight = surfaceProperties->destHeight;
244 EXPECT_TRUE(callbackSurfaceId == (unsigned)-1 || callbackSurfaceId == surface);
245 callbackSurfaceId = surface;
249 pthread_cond_signal( &waiterVariable );
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;
264 TEST_F(NotificationTest, ilm_layerAddNotificationWithoutCallback)
267 t_ilm_uint layer = 89;
269 ASSERT_EQ(ILM_SUCCESS,ilm_layerCreateWithDimension(&layer, 800, 480));
270 ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
273 printf("test calling ilm_layerAddNotification\n");
274 //ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
275 ASSERT_EQ(ILM_SUCCESS, ilm_layerAddNotification(layer,NULL));
277 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemove(layer));
278 ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
282 TEST_F(NotificationTest, ilm_surfaceAddNotificationWithoutCallback)
285 t_ilm_uint surface = 67;
287 ilm_surfaceCreate((t_ilm_nativehandle)wlSurfaces[1],10,10,ILM_PIXELFORMAT_RGBA_8888,&surface);
291 ilmErrorTypes status = ilm_surfaceAddNotification(surface,NULL);
292 ASSERT_EQ(ILM_SUCCESS, status);
294 ilm_surfaceRemove(surface);
299 TEST_F(NotificationTest, NotifyOnLayerSetPosition)
301 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
303 t_ilm_uint* pos = new t_ilm_uint[2];
306 ilm_layerSetPosition(layer,pos);
309 // expect callback to have been called
310 assertCallbackcalled();
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);
317 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
320 TEST_F(NotificationTest, NotifyOnLayerSetDimension)
322 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
324 t_ilm_uint* pos = new t_ilm_uint[2];
327 ilm_layerSetDimension(layer,pos);
330 // expect callback to have been called
331 assertCallbackcalled();
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);
338 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
341 TEST_F(NotificationTest, NotifyOnLayerSetDestinationRectangle)
343 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
345 ilm_layerSetDestinationRectangle(layer,33,567,55,99);
348 // expect callback to have been called
349 assertCallbackcalled();
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);
358 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
361 TEST_F(NotificationTest, NotifyOnLayerSetOpacity)
363 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
365 t_ilm_float opacity = 0.789;
366 ilm_layerSetOpacity(layer,opacity);
369 // expect callback to have been called
370 assertCallbackcalled();
372 EXPECT_EQ(layer,callbackLayerId);
373 EXPECT_NEAR(0.789, LayerProperties.opacity, 0.1);
374 EXPECT_EQ(ILM_NOTIFICATION_OPACITY,mask);
376 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
379 TEST_F(NotificationTest, NotifyOnLayerSetOrientation)
381 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
383 e_ilmOrientation orientation = ILM_ONEHUNDREDEIGHTY;
384 ilm_layerSetOrientation(layer,orientation);
387 // expect callback to have been called
388 assertCallbackcalled();
390 EXPECT_EQ(layer,callbackLayerId);
391 EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,LayerProperties.orientation);
392 EXPECT_EQ(ILM_NOTIFICATION_ORIENTATION,mask);
394 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
397 TEST_F(NotificationTest, NotifyOnLayerSetSourceRectangle)
399 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
401 ilm_layerSetSourceRectangle(layer,33,567,55,99);
404 // expect callback to have been called
405 assertCallbackcalled();
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);
414 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
417 TEST_F(NotificationTest, NotifyOnLayerSetVisibility)
419 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
421 t_ilm_bool value = ILM_TRUE;
422 ilm_layerSetVisibility(layer,value);
425 // expect callback to have been called
426 assertCallbackcalled();
428 EXPECT_EQ(layer,callbackLayerId);
429 EXPECT_TRUE(LayerProperties.visibility);
430 EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY,mask);
432 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
435 TEST_F(NotificationTest, NotifyOnLayerMultipleValues1)
437 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
439 ilm_layerSetSourceRectangle(layer,33,567,55,99);
440 ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
443 // expect callback to have been called
444 assertCallbackcalled();
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);
454 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
457 TEST_F(NotificationTest, NotifyOnLayerMultipleValues2)
459 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
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);
467 // expect callback to have been called
468 assertCallbackcalled();
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);
479 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
482 TEST_F(NotificationTest, NotifyOnLayerAllValues)
484 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
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);
494 // expect callback to have been called
495 assertCallbackcalled();
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);
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);
512 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
515 TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveLayer)
517 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
519 ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
521 assertCallbackcalled();
523 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
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);
534 // assert that we have not been notified
535 assertNoCallbackIsCalled();
539 TEST_F(NotificationTest, MultipleRegistrationsLayer)
541 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
543 ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
545 assertCallbackcalled();
547 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
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);
558 // assert that we have not been notified
559 assertNoCallbackIsCalled();
561 // register for notifications again
562 ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
564 ilm_layerSetOrientation(layer,ILM_ZERO);
566 assertCallbackcalled();
568 ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
571 TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsLayer)
574 ilm_layerSetOrientation(layer,ILM_ONEHUNDREDEIGHTY);
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);
586 // assert that we have not been notified
587 assertNoCallbackIsCalled();
591 TEST_F(NotificationTest, NotifyOnSurfaceSetPosition)
593 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
595 t_ilm_uint* pos = new t_ilm_uint[2];
598 ilm_surfaceSetPosition(surface,pos);
601 // expect callback to have been called
602 assertCallbackcalled();
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);
609 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
612 TEST_F(NotificationTest, NotifyOnSurfaceSetDimension)
614 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
616 t_ilm_uint* pos = new t_ilm_uint[2];
619 ilm_surfaceSetDimension(surface,pos);
622 // expect callback to have been called
623 assertCallbackcalled();
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);
630 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
633 TEST_F(NotificationTest, NotifyOnSurfaceSetDestinationRectangle)
635 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
637 ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
640 // expect callback to have been called
641 assertCallbackcalled();
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);
650 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
653 TEST_F(NotificationTest, NotifyOnSurfaceSetOpacity)
655 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
657 t_ilm_float opacity = 0.789;
658 ilm_surfaceSetOpacity(surface,opacity);
661 // expect callback to have been called
662 assertCallbackcalled();
664 EXPECT_EQ(surface,callbackSurfaceId);
665 EXPECT_NEAR(0.789, SurfaceProperties.opacity, 0.1);
666 EXPECT_EQ(ILM_NOTIFICATION_OPACITY,mask);
668 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
671 TEST_F(NotificationTest, NotifyOnSurfaceSetOrientation)
673 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
675 e_ilmOrientation orientation = ILM_ONEHUNDREDEIGHTY;
676 ilm_surfaceSetOrientation(surface,orientation);
679 // expect callback to have been called
680 assertCallbackcalled();
682 EXPECT_EQ(surface,callbackSurfaceId);
683 EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
684 EXPECT_EQ(ILM_NOTIFICATION_ORIENTATION,mask);
686 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
689 TEST_F(NotificationTest, NotifyOnSurfaceSetSourceRectangle)
691 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
693 ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
696 // expect callback to have been called
697 assertCallbackcalled();
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);
706 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
709 TEST_F(NotificationTest, NotifyOnSurfaceSetVisibility)
711 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
713 t_ilm_bool value = ILM_TRUE;
714 ilm_surfaceSetVisibility(surface,value);
717 // expect callback to have been called
718 assertCallbackcalled();
720 EXPECT_EQ(surface,callbackSurfaceId);
721 EXPECT_TRUE(SurfaceProperties.visibility);
722 EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY,mask);
724 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
727 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues1)
729 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
731 ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
732 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
735 // expect callback to have been called
736 assertCallbackcalled();
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);
746 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
749 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues2)
751 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
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);
759 // expect callback to have been called
760 assertCallbackcalled();
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);
771 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
774 TEST_F(NotificationTest, NotifyOnSurfaceAllValues)
776 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
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);
786 // expect callback to have been called
787 assertCallbackcalled();
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);
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);
804 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
807 TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveSurface)
809 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
811 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
813 assertCallbackcalled();
815 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
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);
826 // assert that we have not been notified
827 assertNoCallbackIsCalled();
831 TEST_F(NotificationTest, MultipleRegistrationsSurface)
833 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
835 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
837 assertCallbackcalled();
839 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
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);
850 // assert that we have not been notified
851 assertNoCallbackIsCalled();
853 // register for notifications again
854 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
856 ilm_surfaceSetOrientation(surface,ILM_ZERO);
858 assertCallbackcalled();
860 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
863 TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsSurface)
866 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
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);
878 // assert that we have not been notified
879 assertNoCallbackIsCalled();