summaryrefslogtreecommitdiff
path: root/ivi-layermanagement-api/test/ilm_control_notification_test.cpp
blob: b918e42d6e8fe6acd48500402872b55fc45b0be8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
/***************************************************************************
 *
 * Copyright 2012 BMW Car IT GmbH
 * Copyright (C) 2016 Advanced Driver Information Technology Joint Venture GmbH
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ****************************************************************************/

#include "TestBase.h"
#include <gtest/gtest.h>
#include <stdio.h>
#include <pthread.h>
#include <sys/time.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <assert.h>

extern "C" {
    #include "ilm_control.h"
}

struct screenshot_data_t {
    std::atomic<int32_t> fd;
    std::atomic<uint32_t> error;
    ilmErrorTypes result = ILM_SUCCESS;
};

void add_nsecs(struct timespec *tv, long nsec)
{
   assert(nsec < 1000000000);

   tv->tv_nsec += nsec;
   if (tv->tv_nsec >= 1000000000)
   {
      tv->tv_nsec -= 1000000000;
      tv->tv_sec++;
   }
}

/* Tests with callbacks
 * For each test first set the global variables to point to where parameters of the callbacks are supposed to be placed.
 */
static pthread_mutex_t notificationMutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t  waiterVariable = PTHREAD_COND_INITIALIZER;
static int timesCalled=0;

class NotificationTest: public TestBase, public ::testing::Test {
    class PthreadMutexLock {
    private:
        pthread_mutex_t &mutex_;

        PthreadMutexLock(const PthreadMutexLock&);
        PthreadMutexLock& operator=(const PthreadMutexLock&);

    public:
        explicit PthreadMutexLock(pthread_mutex_t &mutex): mutex_(mutex) {
            pthread_mutex_lock(&mutex_);
        }
        ~PthreadMutexLock() {
            pthread_mutex_unlock(&mutex_);
        }
    };

public:
    void SetUp()
    {
        ASSERT_EQ(ILM_SUCCESS, ilm_initWithNativedisplay((t_ilm_nativedisplay)wlDisplay));

        // set default values
        callbackLayerId = -1;
        LayerProperties = ilmLayerProperties();
        mask = static_cast<t_ilm_notification_mask>(0);
        surface = -1;
        SurfaceProperties = ilmSurfaceProperties();
        // create a layer
        layer = 345;
        ilm_layerRemove(layer);
        ilm_commitChanges();
        ilm_layerCreateWithDimension(&layer, 800, 480);
        ilm_commitChanges();
        // create a surface
        surface = 456;
        ivi_surface = (struct ivi_surface*)ivi_application_surface_create(iviApp, surface, wlSurfaces[0]);
        ilm_commitChanges();
        timesCalled=0;

        callbackLayerId = INVALID_ID;
        callbackSurfaceId = INVALID_ID;
    }

    void TearDown()
    {
       //print_lmc_get_scene();
       t_ilm_layer* layers = NULL;
       t_ilm_int numLayer=0;
       EXPECT_EQ(ILM_SUCCESS, ilm_getLayerIDs(&numLayer, &layers));
       for (t_ilm_int i=0; i<numLayer; i++)
       {
           EXPECT_EQ(ILM_SUCCESS, ilm_layerRemove(layers[i]));
       };
       free(layers);

       ivi_surface_destroy(ivi_surface);

       EXPECT_EQ(ILM_SUCCESS, ilm_commitChanges());
       EXPECT_EQ(ILM_SUCCESS, ilm_destroy());
    }

    NotificationTest(){}

    ~NotificationTest(){}

    t_ilm_uint layer;

    // Pointers where to put received values for current Test
    static t_ilm_layer callbackLayerId;
    static t_ilm_surface callbackSurfaceId;
    static struct ilmLayerProperties LayerProperties;
    static unsigned int mask;
    static t_ilm_surface surface;
    struct ivi_surface* ivi_surface;
    static ilmSurfaceProperties SurfaceProperties;

    static void assertCallbackcalled(int numberOfExpectedCalls=1){
        static struct timespec theTime;
        clock_gettime(CLOCK_REALTIME, &theTime);
        add_nsecs(&theTime, 500000000);
        PthreadMutexLock lock(notificationMutex);
        int status = 0;
        do {
            if (numberOfExpectedCalls!=timesCalled) {
                status = pthread_cond_timedwait( &waiterVariable, &notificationMutex, &theTime);
            }
        } while (status!=ETIMEDOUT && numberOfExpectedCalls!=timesCalled);

        // we cannot rely on a timeout as layer callbacks are always called synchronously on ilm_commitChanges()
        EXPECT_NE(ETIMEDOUT, status);
        timesCalled=0;
    }

    static void assertNoCallbackIsCalled(){
        struct timespec theTime;
        clock_gettime(CLOCK_REALTIME, &theTime);
        add_nsecs(&theTime, 500000000);
        PthreadMutexLock lock(notificationMutex);
        // assert that we have not been notified
        ASSERT_EQ(ETIMEDOUT, pthread_cond_timedwait( &waiterVariable, &notificationMutex, &theTime));
    }

    static void LayerCallbackFunction(t_ilm_layer layer, struct ilmLayerProperties* layerProperties, t_ilm_notification_mask m)
    {
        PthreadMutexLock lock(notificationMutex);

        if ((unsigned)m & ILM_NOTIFICATION_VISIBILITY)
        {
            LayerProperties.visibility = layerProperties->visibility;
        }

        if ((unsigned)m & ILM_NOTIFICATION_OPACITY)
        {
            LayerProperties.opacity = layerProperties->opacity;
        }

        if ((unsigned)m & ILM_NOTIFICATION_SOURCE_RECT)
        {
            LayerProperties.sourceX = layerProperties->sourceX;
            LayerProperties.sourceY = layerProperties->sourceY;
            LayerProperties.sourceWidth = layerProperties->sourceWidth;
            LayerProperties.sourceHeight = layerProperties->sourceHeight;
        }

        if ((unsigned)m & ILM_NOTIFICATION_DEST_RECT)
        {
            LayerProperties.destX = layerProperties->destX;
            LayerProperties.destY = layerProperties->destY;
            LayerProperties.destWidth = layerProperties->destWidth;
            LayerProperties.destHeight = layerProperties->destHeight;
        }

        EXPECT_TRUE(callbackLayerId == (unsigned)-1 || callbackLayerId == layer);
        callbackLayerId = layer;
        mask |= (unsigned)m;
        timesCalled++;

        pthread_cond_signal( &waiterVariable );
    }

    static void SurfaceCallbackFunction(t_ilm_surface surface, struct ilmSurfaceProperties* surfaceProperties, t_ilm_notification_mask m)
    {
        PthreadMutexLock lock(notificationMutex);

        if ((unsigned)m & ILM_NOTIFICATION_VISIBILITY)
        {
            SurfaceProperties.visibility = surfaceProperties->visibility;
        }

        if ((unsigned)m & ILM_NOTIFICATION_OPACITY)
        {
            SurfaceProperties.opacity = surfaceProperties->opacity;
        }

        if ((unsigned)m & ILM_NOTIFICATION_SOURCE_RECT)
        {
            SurfaceProperties.sourceX = surfaceProperties->sourceX;
            SurfaceProperties.sourceY = surfaceProperties->sourceY;
            SurfaceProperties.sourceWidth = surfaceProperties->sourceWidth;
            SurfaceProperties.sourceHeight = surfaceProperties->sourceHeight;
        }

        if ((unsigned)m & ILM_NOTIFICATION_DEST_RECT)
        {
            SurfaceProperties.destX = surfaceProperties->destX;
            SurfaceProperties.destY = surfaceProperties->destY;
            SurfaceProperties.destWidth = surfaceProperties->destWidth;
            SurfaceProperties.destHeight = surfaceProperties->destHeight;
        }

        EXPECT_TRUE(callbackSurfaceId == (unsigned)-1 || callbackSurfaceId == surface);
        callbackSurfaceId = surface;
        mask |= (unsigned)m;
        timesCalled++;

        pthread_cond_signal( &waiterVariable );
    }

    static ilmErrorTypes ScreenshotDoneCallbackFunc(void *user_data, t_ilm_int fd, t_ilm_uint width, t_ilm_uint height, t_ilm_uint stride, t_ilm_uint format, t_ilm_uint timestamp)
    {
        PthreadMutexLock lock(notificationMutex);
        screenshot_data_t *screenshotData = static_cast<screenshot_data_t*>(user_data);
        screenshotData->fd.store(fd);
        timesCalled++;
        pthread_cond_signal( &waiterVariable );
        return screenshotData->result;
    }

    static void ScreenshotErrorCallbackFunc(void *user_data, t_ilm_uint error, const char *message)
    {
        PthreadMutexLock lock(notificationMutex);
        screenshot_data_t *screenshotData = static_cast<screenshot_data_t*>(user_data);
        screenshotData->error.store(error);
        timesCalled++;
        pthread_cond_signal( &waiterVariable );
    }
};

// Pointers where to put received values for current Test
t_ilm_layer NotificationTest::callbackLayerId;
t_ilm_surface NotificationTest::callbackSurfaceId;
struct ilmLayerProperties NotificationTest::LayerProperties;
unsigned int NotificationTest::mask;
unsigned int NotificationTest::surface;
ilmSurfaceProperties NotificationTest::SurfaceProperties;

TEST_F(NotificationTest, ilm_layerAddNotificationWithoutCallback)
{
    // create a layer
    t_ilm_uint layer = 89;

    ASSERT_EQ(ILM_SUCCESS,ilm_layerCreateWithDimension(&layer, 800, 480));
    ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
    // add notification

    printf("test calling ilm_layerAddNotification\n");
    //ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());
    ASSERT_EQ(ILM_SUCCESS, ilm_layerAddNotification(layer,NULL));

    ASSERT_EQ(ILM_SUCCESS,ilm_layerRemove(layer));
    ASSERT_EQ(ILM_SUCCESS,ilm_commitChanges());

}

TEST_F(NotificationTest, ilm_surfaceAddNotificationWithoutCallback)
{
    // create a layer
    t_ilm_uint surface = 67;
    struct ivi_surface* ivi_surface = (struct ivi_surface*)
        ivi_application_surface_create(iviApp, surface, wlSurfaces[1]);

    // add notification
    ilmErrorTypes status = ilm_surfaceAddNotification(surface,NULL);
    ASSERT_EQ(ILM_SUCCESS, status);

    ivi_surface_destroy(ivi_surface);
    ilm_commitChanges();
}

TEST_F(NotificationTest, NotifyOnLayerSetDestinationRectangle)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
    // change something
    ilm_layerSetDestinationRectangle(layer,33,567,55,99);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled();

    EXPECT_EQ(layer,callbackLayerId);
    EXPECT_EQ(33u,LayerProperties.destX);
    EXPECT_EQ(567u,LayerProperties.destY);
    EXPECT_EQ(55u,LayerProperties.destWidth);
    EXPECT_EQ(99u,LayerProperties.destHeight);
    EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
}

TEST_F(NotificationTest, NotifyOnLayerSetOpacity)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
    // change something
    t_ilm_float opacity = 0.789;
    ilm_layerSetOpacity(layer,opacity);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled();

    EXPECT_EQ(layer,callbackLayerId);
    EXPECT_NEAR(0.789, LayerProperties.opacity, 0.1);
    EXPECT_EQ(ILM_NOTIFICATION_OPACITY,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
}

TEST_F(NotificationTest, NotifyOnLayerSetSourceRectangle)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
    // change something
    ilm_layerSetSourceRectangle(layer,33,567,55,99);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled();

    EXPECT_EQ(layer,callbackLayerId);
    EXPECT_EQ(33u,LayerProperties.sourceX);
    EXPECT_EQ(567u,LayerProperties.sourceY);
    EXPECT_EQ(55u,LayerProperties.sourceWidth);
    EXPECT_EQ(99u,LayerProperties.sourceHeight);
    EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
}

TEST_F(NotificationTest, NotifyOnLayerSetVisibility)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
    // change something
    t_ilm_bool value = ILM_TRUE;
    ilm_layerSetVisibility(layer,value);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled();

    EXPECT_EQ(layer,callbackLayerId);
    EXPECT_TRUE(LayerProperties.visibility);
    EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
}

TEST_F(NotificationTest, NotifyOnLayerMultipleValues1)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
    // change something
    ilm_layerSetSourceRectangle(layer,33,567,55,99);
    ilm_layerSetVisibility(layer,true);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled(2);

    EXPECT_EQ(layer,callbackLayerId);
    EXPECT_EQ(33u,LayerProperties.sourceX);
    EXPECT_EQ(567u,LayerProperties.sourceY);
    EXPECT_EQ(55u,LayerProperties.sourceWidth);
    EXPECT_EQ(99u,LayerProperties.sourceHeight);
    EXPECT_TRUE(LayerProperties.visibility);
    EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_VISIBILITY,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
}

TEST_F(NotificationTest, NotifyOnLayerMultipleValues2)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
    // change something
    t_ilm_float opacity = 0.789;
    ilm_layerSetOpacity(layer,opacity);
    ilm_layerSetVisibility(layer,true);
    ilm_layerSetDestinationRectangle(layer,33,567,55,99);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled(3);

    EXPECT_EQ(layer,callbackLayerId);
    EXPECT_TRUE(LayerProperties.visibility);
    EXPECT_NEAR(0.789, LayerProperties.opacity, 0.1);
    EXPECT_EQ(33u,LayerProperties.destX);
    EXPECT_EQ(567u,LayerProperties.destY);
    EXPECT_EQ(55u,LayerProperties.destWidth);
    EXPECT_EQ(99u,LayerProperties.destHeight);
    EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
}

TEST_F(NotificationTest, NotifyOnLayerAllValues)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
    // change something
    t_ilm_float opacity = 0.789;
    ilm_layerSetOpacity(layer,opacity);
    ilm_layerSetVisibility(layer,true);
    ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
    ilm_layerSetSourceRectangle(layer,33,567,55,99);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled(4);

    EXPECT_EQ(layer,callbackLayerId);
    EXPECT_EQ(33u,LayerProperties.sourceX);
    EXPECT_EQ(567u,LayerProperties.sourceY);
    EXPECT_EQ(55u,LayerProperties.sourceWidth);
    EXPECT_EQ(99u,LayerProperties.sourceHeight);

    EXPECT_TRUE(LayerProperties.visibility);
    EXPECT_NEAR(opacity, LayerProperties.opacity, 0.1);
    EXPECT_EQ(133u,LayerProperties.destX);
    EXPECT_EQ(1567u,LayerProperties.destY);
    EXPECT_EQ(155u,LayerProperties.destWidth);
    EXPECT_EQ(199u,LayerProperties.destHeight);
    EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_SOURCE_RECT,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
}

TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveLayer)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
    // get called once
    ilm_layerSetVisibility(layer,true);
    ilm_commitChanges();
    assertCallbackcalled();

    ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));

    // change a lot of things
    t_ilm_float opacity = 0.789;
    ilm_layerSetOpacity(layer,opacity);
    ilm_layerSetVisibility(layer,true);
    ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
    ilm_layerSetSourceRectangle(layer,33,567,55,99);
    ilm_commitChanges();

    // assert that we have not been notified
    assertNoCallbackIsCalled();

}

TEST_F(NotificationTest, MultipleRegistrationsLayer)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));
    // get called once
    ilm_layerSetVisibility(layer,true);
    ilm_commitChanges();
    assertCallbackcalled();

    ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));

    // change a lot of things
    t_ilm_float opacity = 0.789;
    ilm_layerSetOpacity(layer,opacity);
    ilm_layerSetVisibility(layer,true);
    ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
    ilm_layerSetSourceRectangle(layer,33,567,55,99);
    ilm_commitChanges();

    // assert that we have not been notified
    assertNoCallbackIsCalled();

    // register for notifications again
    ASSERT_EQ(ILM_SUCCESS,ilm_layerAddNotification(layer,&LayerCallbackFunction));

    ilm_layerSetVisibility(layer,false);
    ilm_commitChanges();
    assertCallbackcalled();

    ASSERT_EQ(ILM_SUCCESS,ilm_layerRemoveNotification(layer));
}

TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsLayer)
{
    // get called once
    ilm_layerSetVisibility(layer,true);
    ilm_commitChanges();

    // change a lot of things
    t_ilm_float opacity = 0.789;
    ilm_layerSetOpacity(layer,opacity);
    ilm_layerSetVisibility(layer,true);
    ilm_layerSetDestinationRectangle(layer,133,1567,155,199);
    ilm_layerSetSourceRectangle(layer,33,567,55,99);
    ilm_commitChanges();

    // assert that we have not been notified
    assertNoCallbackIsCalled();
}

TEST_F(NotificationTest, NotifyOnSurfaceSetDestinationRectangle)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
    // change something
    ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled(2);

    EXPECT_EQ(surface,callbackSurfaceId);
    EXPECT_EQ(33u,SurfaceProperties.destX);
    EXPECT_EQ(567u,SurfaceProperties.destY);
    EXPECT_EQ(55u,SurfaceProperties.destWidth);
    EXPECT_EQ(99u,SurfaceProperties.destHeight);
    EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
}

TEST_F(NotificationTest, NotifyOnSurfaceSetOpacity)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
    // change something
    t_ilm_float opacity = 0.789;
    ilm_surfaceSetOpacity(surface,opacity);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled(2);

    EXPECT_EQ(surface,callbackSurfaceId);
    EXPECT_NEAR(0.789, SurfaceProperties.opacity, 0.1);
    EXPECT_EQ(ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
}

TEST_F(NotificationTest, NotifyOnSurfaceSetSourceRectangle)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
    // change something
    ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled(2);

    EXPECT_EQ(surface,callbackSurfaceId);
    EXPECT_EQ(33u,SurfaceProperties.sourceX);
    EXPECT_EQ(567u,SurfaceProperties.sourceY);
    EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
    EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
    EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
}

TEST_F(NotificationTest, NotifyOnSurfaceSetVisibility)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
    // change something
    t_ilm_bool value = ILM_TRUE;
    ilm_surfaceSetVisibility(surface,value);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled(2);

    EXPECT_EQ(surface,callbackSurfaceId);
    EXPECT_TRUE(SurfaceProperties.visibility);
    EXPECT_EQ(ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
}

TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues1)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
    // change something
    ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
    ilm_surfaceSetVisibility(surface,true);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled(3);

    EXPECT_EQ(surface,callbackSurfaceId);
    EXPECT_EQ(33u,SurfaceProperties.sourceX);
    EXPECT_EQ(567u,SurfaceProperties.sourceY);
    EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
    EXPECT_EQ(99u,SurfaceProperties.sourceHeight);
    EXPECT_TRUE(SurfaceProperties.visibility);
    EXPECT_EQ(ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
}

TEST_F(NotificationTest, NotifyOnSurfaceMultipleValues2)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
    // change something
    t_ilm_float opacity = 0.789;
    ilm_surfaceSetOpacity(surface,opacity);
    ilm_surfaceSetVisibility(surface,true);
    ilm_surfaceSetDestinationRectangle(surface,33,567,55,99);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled(4);

    EXPECT_EQ(surface,callbackSurfaceId);
    EXPECT_TRUE(SurfaceProperties.visibility);
    EXPECT_NEAR(0.789, SurfaceProperties.opacity, 0.1);
    EXPECT_EQ(33u,SurfaceProperties.destX);
    EXPECT_EQ(567u,SurfaceProperties.destY);
    EXPECT_EQ(55u,SurfaceProperties.destWidth);
    EXPECT_EQ(99u,SurfaceProperties.destHeight);
    EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|
              ILM_NOTIFICATION_OPACITY|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
}

TEST_F(NotificationTest, NotifyOnSurfaceAllValues)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
    // change something
    t_ilm_float opacity = 0.789;
    ilm_surfaceSetOpacity(surface,opacity);
    ilm_surfaceSetVisibility(surface,true);
    ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
    ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
    ilm_commitChanges();

    // expect callback to have been called
    assertCallbackcalled(5);

    EXPECT_EQ(surface,callbackSurfaceId);
    EXPECT_EQ(33u,SurfaceProperties.sourceX);
    EXPECT_EQ(567u,SurfaceProperties.sourceY);
    EXPECT_EQ(55u,SurfaceProperties.sourceWidth);
    EXPECT_EQ(99u,SurfaceProperties.sourceHeight);

    EXPECT_TRUE(SurfaceProperties.visibility);
    EXPECT_NEAR(opacity, SurfaceProperties.opacity, 0.1);
    EXPECT_EQ(133u,SurfaceProperties.destX);
    EXPECT_EQ(1567u,SurfaceProperties.destY);
    EXPECT_EQ(155u,SurfaceProperties.destWidth);
    EXPECT_EQ(199u,SurfaceProperties.destHeight);
    EXPECT_EQ(ILM_NOTIFICATION_DEST_RECT|ILM_NOTIFICATION_VISIBILITY|ILM_NOTIFICATION_OPACITY|
              ILM_NOTIFICATION_SOURCE_RECT|ILM_NOTIFICATION_CONTENT_AVAILABLE,mask);

    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
}

TEST_F(NotificationTest, DoNotSendNotificationsAfterRemoveSurface)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
    // get called once
    ilm_surfaceSetVisibility(surface,true);
    ilm_commitChanges();
    assertCallbackcalled(2);

    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));

    // change a lot of things
    t_ilm_float opacity = 0.789;
    ilm_surfaceSetOpacity(surface,opacity);
    ilm_surfaceSetVisibility(surface,true);
    ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
    ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
    ilm_commitChanges();

    // assert that we have not been notified
    assertNoCallbackIsCalled();

}

TEST_F(NotificationTest, MultipleRegistrationsSurface)
{
    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));
    // get called once
    ilm_surfaceSetVisibility(surface,true);
    ilm_commitChanges();
    assertCallbackcalled(2);

    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));

    // change a lot of things
    t_ilm_float opacity = 0.789;
    ilm_surfaceSetOpacity(surface,opacity);
    ilm_surfaceSetVisibility(surface,true);
    ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
    ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
    ilm_commitChanges();

    // assert that we have not been notified
    assertNoCallbackIsCalled();

    // register for notifications again
    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceAddNotification(surface,&SurfaceCallbackFunction));

    ilm_surfaceSetVisibility(surface,false);
    ilm_commitChanges();
    assertCallbackcalled(2);

    ASSERT_EQ(ILM_SUCCESS,ilm_surfaceRemoveNotification(surface));
}

TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsSurface)
{
    // get called once
    ilm_surfaceSetVisibility(surface,true);
    ilm_commitChanges();

    // change a lot of things
    t_ilm_float opacity = 0.789;
    ilm_surfaceSetOpacity(surface,opacity);
    ilm_surfaceSetVisibility(surface,true);
    ilm_surfaceSetDestinationRectangle(surface,133,1567,155,199);
    ilm_surfaceSetSourceRectangle(surface,33,567,55,99);
    ilm_commitChanges();

    // assert that we have not been notified
    assertNoCallbackIsCalled();
}

TEST_F(NotificationTest, getNotificationWhenScreenshotDone)
{
    /* Call ilm_takeAsyncScreenshot with right screen id
     * The ilm_takeAsyncScreenshot should return ILM_SUCCESS
     * Screenshot done callback should trigged
     */ 
    screenshot_data_t screenshotData;
    screenshotData.fd.store(-1);
    ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncScreenshot(0, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData));
    assertCallbackcalled();
    ASSERT_NE(screenshotData.fd.load(), -1);

    /* Call ilm_takeAsyncSurfaceScreenshot with right surface id
     * The ilm_takeAsyncSurfaceScreenshot should return ILM_SUCCESS
     * Screenshot done callback should trigged
     */ 
    screenshotData.fd.store(-1);
    ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncSurfaceScreenshot(surface, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData));
    assertCallbackcalled();
    ASSERT_NE(screenshotData.fd.load(), -1);
}

TEST_F(NotificationTest, getNotificationWhenScreenshotError)
{
    /* Call ilm_takeAsyncSurfaceScreenshot with wrong surface id
     * The ilm_takeAsyncSurfaceScreenshot should return ILM_SUCCESS
     * Screenshot error callback should trigged
     */
    screenshot_data_t screenshotData;
    screenshotData.error.store(0);
    ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncSurfaceScreenshot(surface + 1, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData));
    assertCallbackcalled();
    ASSERT_EQ(screenshotData.error.load(), 3); //IVI_SCREENSHOT_ERROR_NO_SURFACE is 3
}