5b8468057338c374fb162229e757c0c0a5e176a9
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / shader-effects / utc-Dali-OverlayEffect.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include <iostream>
18
19 #include <stdlib.h>
20 #include <tet_api.h>
21
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
24
25 #include <dali-toolkit-test-suite-utils.h>
26
27 using namespace Dali;
28 using namespace Dali::Toolkit;
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 static void UtcDaliOverlayConstructor();
39 static void UtcDaliOverlayUninitializedEffect();
40
41 enum {
42   POSITIVE_TC_IDX = 0x01,
43   NEGATIVE_TC_IDX,
44 };
45
46 // Add test functionality for all APIs in the class (Positive and Negative)
47 extern "C" {
48   struct tet_testlist tet_testlist[] = {
49     { UtcDaliOverlayConstructor, POSITIVE_TC_IDX },
50     { UtcDaliOverlayUninitializedEffect, NEGATIVE_TC_IDX },
51     { NULL, 0 }
52   };
53 }
54
55 // Called only once before first test is run.
56 static void Startup()
57 {
58 }
59
60 // Called only once after last test is run
61 static void Cleanup()
62 {
63 }
64
65 // Create bitmap image
66 BitmapImage CreateBitmapImage()
67 {
68   BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
69
70   PixelBuffer* pixbuf = image.GetBuffer();
71
72   // Using a 4x4 image gives a better blend with the GL implementation
73   // than a 3x3 image
74   for(size_t i=0; i<16; i++)
75   {
76     pixbuf[i*4+0] = 0xFF;
77     pixbuf[i*4+1] = 0xFF;
78     pixbuf[i*4+2] = 0xFF;
79     pixbuf[i*4+3] = 0xFF;
80   }
81
82   return image;
83 }
84
85 static void UtcDaliOverlayConstructor()
86 {
87   ToolkitTestApplication application;
88
89   BitmapImage image = CreateBitmapImage();
90
91   Toolkit::OverlayEffect effect = Toolkit::OverlayEffect::New( image );
92   DALI_TEST_CHECK( effect );
93
94   ImageActor actor = ImageActor::New( image );
95   actor.SetSize( 100.0f, 100.0f );
96   actor.SetShaderEffect( effect );
97   Stage::GetCurrent().Add( actor );
98
99   application.SendNotification();
100   application.Render();
101
102 }
103
104 static void UtcDaliOverlayUninitializedEffect()
105 {
106   ToolkitTestApplication application;
107
108   Toolkit::OverlayEffect effect;
109
110   try
111   {
112     BitmapImage image = CreateBitmapImage();
113
114     // New() must be called to create a OverlayEffect or it wont be valid.
115     effect.SetEffectImage( image );
116     DALI_TEST_CHECK( false );
117   }
118   catch (Dali::DaliException& e)
119   {
120     // Tests that a negative test of an assertion succeeds
121     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
122     DALI_TEST_CHECK(!effect);
123   }
124 }