2299f9524453326024b8e145f3c47c414689fad2
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / shader-effects / utc-Dali-PageTurnEffect.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <tet_api.h>
22
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
25
26 #include <dali-toolkit-test-suite-utils.h>
27
28 using namespace Dali;
29
30 static void Startup();
31 static void Cleanup();
32
33 extern "C" {
34   void (*tet_startup)() = Startup;
35   void (*tet_cleanup)() = Cleanup;
36 }
37
38
39 enum {
40   POSITIVE_TC_IDX = 0x01,
41   NEGATIVE_TC_IDX,
42 };
43
44
45 #define MAX_NUMBER_OF_TESTS 10000
46 extern "C" {
47   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
48 }
49
50 // Add test functionality for all APIs in the class (Positive and Negative)
51 TEST_FUNCTION( UtcDaliPageTurnEffectApply, POSITIVE_TC_IDX );
52 TEST_FUNCTION( UtcDaliPageTurnEffectConstruct, POSITIVE_TC_IDX );
53
54 // Called only once before first test is run.
55 static void Startup()
56 {
57 }
58
59 // Called only once after last test is run
60 static void Cleanup()
61 {
62 }
63
64 // Create bitmap image
65 static BitmapImage CreateBitmapImage()
66 {
67   BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
68
69   PixelBuffer* pixbuf = image.GetBuffer();
70
71   // Using a 4x4 image gives a better blend with the GL implementation
72   // than a 3x3 image
73   for(size_t i=0; i<16; i++)
74   {
75     pixbuf[i*4+0] = 0xFF;
76     pixbuf[i*4+1] = 0xFF;
77     pixbuf[i*4+2] = 0xFF;
78     pixbuf[i*4+3] = 0xFF;
79   }
80
81   return image;
82 }
83
84 static void UtcDaliPageTurnEffectApply()
85 {
86   ToolkitTestApplication application;
87
88   BitmapImage image = CreateBitmapImage();
89
90   Toolkit::PageTurnEffect pageTurnEffect = Toolkit::PageTurnEffect::New();
91   Toolkit::PageTurnEffect pageTurnEffect2 = Toolkit::PageTurnEffect::New(false);
92
93   ImageActor pageActor = ImageActor::New( image );
94   ImageActor backPageActor = ImageActor::New( image );
95   pageActor.Add( backPageActor );
96
97   pageTurnEffect.SetIsTurningBack( true );
98   pageTurnEffect.SetShadowWidth( 0.0f );
99   pageTurnEffect.SetSpineShadowParameter( Vector2( 0.0f, 0.0f ) );
100
101   pageActor.SetShaderEffect( pageTurnEffect );
102   Stage::GetCurrent().Add( pageActor );
103
104   application.SendNotification();
105   application.Render();
106
107   const Vector2 pageSize( 0.0f, 0.0f );
108   pageTurnEffect.SetPageSize( pageSize );
109
110   const Vector2 originalCenter( 0.0f, 0.0f );
111   pageTurnEffect.SetOriginalCenter( originalCenter );
112
113   const Vector2 currentCenter( 0.0f, 0.0f );
114   pageTurnEffect.SetCurrentCenter( currentCenter );
115
116   application.SendNotification();
117   application.Render();
118
119   TestGlAbstraction& gl = application.GetGlAbstraction();
120   DALI_TEST_CHECK( gl.CheckUniformValue( pageTurnEffect.GetPageSizePropertyName().c_str(), pageSize ) );
121   DALI_TEST_CHECK( gl.CheckUniformValue( pageTurnEffect.GetOriginalCenterPropertyName().c_str(), originalCenter ) );
122   DALI_TEST_CHECK( gl.CheckUniformValue( pageTurnEffect.GetCurrentCenterPropertyName().c_str(), currentCenter ) );
123 }
124
125 static void UtcDaliPageTurnEffectConstruct()
126 {
127   ToolkitTestApplication application;
128
129   Toolkit::PageTurnEffect* effect = new Toolkit::PageTurnEffect();
130   delete effect;
131
132   DALI_TEST_CHECK( true );
133 }