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(2);
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(3);
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(5);
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[] = { 7, 2 };
596 ilm_surfaceSetPosition(surface,pos);
599 // expect callback to have been called
600 assertCallbackcalled();
602 EXPECT_EQ(surface,callbackSurfaceId);
603 EXPECT_EQ(7u,SurfaceProperties.destX);
604 EXPECT_EQ(2u,SurfaceProperties.destY);
605 EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
607 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
610 TEST_F(NotificationTest, NotifyOnSurfaceSetDimension)
612 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
614 t_ilm_uint pos[] = { 70, 22 };
615 ilm_surfaceSetDimension(surface,pos);
618 // expect callback to have been called
619 assertCallbackcalled();
621 EXPECT_EQ(surface,callbackSurfaceId);
622 EXPECT_EQ(70u,SurfaceProperties.destWidth);
623 EXPECT_EQ(22u,SurfaceProperties.destHeight);
624 EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
626 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
629 TEST_F(NotificationTest, NotifyOnSurfaceSetDestinationRectangle)
631 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
633 ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
636 // expect callback to have been called
637 assertCallbackcalled();
639 EXPECT_EQ(surface,callbackSurfaceId);
640 EXPECT_EQ(33u,SurfaceProperties.destX);
641 EXPECT_EQ(567u,SurfaceProperties.destY);
642 EXPECT_EQ(55u,SurfaceProperties.destWidth);
643 EXPECT_EQ(99u,SurfaceProperties.destHeight);
644 EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);
646 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
649 TEST_F(NotificationTest, NotifyOnSurfaceSetOpacity)
651 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
653 t_ilm_float opacity = 0.789;
654 ilm_surfaceSetOpacity(surface,opacity);
657 // expect callback to have been called
658 assertCallbackcalled();
660 EXPECT_EQ(surface,callbackSurfaceId);
661 EXPECT_NEAR(0.789, SurfaceProperties.opacity, 0.1);
662 EXPECT_EQ(ILM_NOTIFICATION_OPACITY,mask);
664 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
667 TEST_F(NotificationTest, NotifyOnSurfaceSetOrientation)
669 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
671 e_ilmOrientation orientation = ILM_ONEHUNDREDEIGHTY;
672 ilm_surfaceSetOrientation(surface,orientation);
675 // expect callback to have been called
676 assertCallbackcalled();
678 EXPECT_EQ(surface,callbackSurfaceId);
679 EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
680 EXPECT_EQ(ILM_NOTIFICATION_ORIENTATION,mask);
682 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
685 TEST_F(NotificationTest, NotifyOnSurfaceSetSourceRectangle)
687 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
689 ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
692 // expect callback to have been called
693 assertCallbackcalled();
695 EXPECT_EQ(surface,callbackSurfaceId);
696 EXPECT_EQ(33u,SurfaceProperties.sourceX);
697 EXPECT_EQ(567u,SurfaceProperties.sourceY);
698 EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
699 EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
700 EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT,mask);
702 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
705 TEST_F(NotificationTest, NotifyOnSurfaceSetVisibility)
707 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
709 t_ilm_bool value = ILM_TRUE;
710 ilm_surfaceSetVisibility(surface,value);
713 // expect callback to have been called
714 assertCallbackcalled();
716 EXPECT_EQ(surface,callbackSurfaceId);
717 EXPECT_TRUE(SurfaceProperties.visibility);
718 EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY,mask);
720 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
723 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues1)
725 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
727 ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
728 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
731 // expect callback to have been called
732 assertCallbackcalled(2);
734 EXPECT_EQ(surface,callbackSurfaceId);
735 EXPECT_EQ(33u,SurfaceProperties.sourceX);
736 EXPECT_EQ(567u,SurfaceProperties.sourceY);
737 EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
738 EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
739 EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
740 EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
742 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
745 TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues2)
747 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
749 t_ilm_float opacity = 0.789;
750 ilm_surfaceSetOpacity(surface,opacity);
751 ilm_surfaceSetVisibility(surface,true);
752 ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
755 // expect callback to have been called
756 assertCallbackcalled(3);
758 EXPECT_EQ(surface,callbackSurfaceId);
759 EXPECT_TRUE(SurfaceProperties.visibility);
760 EXPECT_NEAR(0.789, SurfaceProperties.opacity, 0.1);
761 EXPECT_EQ(33u,SurfaceProperties.destX);
762 EXPECT_EQ(567u,SurfaceProperties.destY);
763 EXPECT_EQ(55u,SurfaceProperties.destWidth);
764 EXPECT_EQ(99u,SurfaceProperties.destHeight);
765 EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY,mask);
767 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
770 TEST_F(NotificationTest, NotifyOnSurfaceAllValues)
772 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
774 t_ilm_float opacity = 0.789;
775 ilm_surfaceSetOpacity(surface,opacity);
776 ilm_surfaceSetVisibility(surface,true);
777 ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
778 ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
779 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
782 // expect callback to have been called
783 assertCallbackcalled(5);
785 EXPECT_EQ(surface,callbackSurfaceId);
786 EXPECT_EQ(33u,SurfaceProperties.sourceX);
787 EXPECT_EQ(567u,SurfaceProperties.sourceY);
788 EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
789 EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
790 EXPECT_EQ(ILM_ONEHUNDREDEIGHTY,SurfaceProperties.orientation);
792 EXPECT_TRUE(SurfaceProperties.visibility);
793 EXPECT_NEAR(opacity, SurfaceProperties.opacity, 0.1);
794 EXPECT_EQ(133u,SurfaceProperties.destX);
795 EXPECT_EQ(1567u,SurfaceProperties.destY);
796 EXPECT_EQ(155u,SurfaceProperties.destWidth);
797 EXPECT_EQ(199u,SurfaceProperties.destHeight);
798 EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_ORIENTATION,mask);
800 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
803 TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveSurface)
805 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
807 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
809 assertCallbackcalled();
811 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
813 // change a lot of things
814 t_ilm_float opacity = 0.789;
815 ilm_surfaceSetOpacity(surface,opacity);
816 ilm_surfaceSetVisibility(surface,true);
817 ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
818 ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
819 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
822 // assert that we have not been notified
823 assertNoCallbackIsCalled();
827 TEST_F(NotificationTest, MultipleRegistrationsSurface)
829 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
831 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
833 assertCallbackcalled();
835 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
837 // change a lot of things
838 t_ilm_float opacity = 0.789;
839 ilm_surfaceSetOpacity(surface,opacity);
840 ilm_surfaceSetVisibility(surface,true);
841 ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
842 ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
843 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
846 // assert that we have not been notified
847 assertNoCallbackIsCalled();
849 // register for notifications again
850 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
852 ilm_surfaceSetOrientation(surface,ILM_ZERO);
854 assertCallbackcalled();
856 ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
859 TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsSurface)
862 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
865 // change a lot of things
866 t_ilm_float opacity = 0.789;
867 ilm_surfaceSetOpacity(surface,opacity);
868 ilm_surfaceSetVisibility(surface,true);
869 ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
870 ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
871 ilm_surfaceSetOrientation(surface,ILM_ONEHUNDREDEIGHTY);
874 // assert that we have not been notified
875 assertNoCallbackIsCalled();