Conversion to Apache 2.0 license
[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 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 using namespace Dali::Toolkit;
30
31 static void Startup();
32 static void Cleanup();
33
34 extern "C" {
35   void (*tet_startup)() = Startup;
36   void (*tet_cleanup)() = Cleanup;
37 }
38
39 static void UtcDaliOverlayConstructor();
40 static void UtcDaliOverlayUninitializedEffect();
41
42 enum {
43   POSITIVE_TC_IDX = 0x01,
44   NEGATIVE_TC_IDX,
45 };
46
47 // Add test functionality for all APIs in the class (Positive and Negative)
48 extern "C" {
49   struct tet_testlist tet_testlist[] = {
50     { UtcDaliOverlayConstructor, POSITIVE_TC_IDX },
51     { UtcDaliOverlayUninitializedEffect, NEGATIVE_TC_IDX },
52     { NULL, 0 }
53   };
54 }
55
56 // Called only once before first test is run.
57 static void Startup()
58 {
59 }
60
61 // Called only once after last test is run
62 static void Cleanup()
63 {
64 }
65
66 // Create bitmap image
67 BitmapImage CreateBitmapImage()
68 {
69   BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
70
71   PixelBuffer* pixbuf = image.GetBuffer();
72
73   // Using a 4x4 image gives a better blend with the GL implementation
74   // than a 3x3 image
75   for(size_t i=0; i<16; i++)
76   {
77     pixbuf[i*4+0] = 0xFF;
78     pixbuf[i*4+1] = 0xFF;
79     pixbuf[i*4+2] = 0xFF;
80     pixbuf[i*4+3] = 0xFF;
81   }
82
83   return image;
84 }
85
86 static void UtcDaliOverlayConstructor()
87 {
88   ToolkitTestApplication application;
89
90   BitmapImage image = CreateBitmapImage();
91
92   Toolkit::OverlayEffect effect = Toolkit::OverlayEffect::New( image );
93   DALI_TEST_CHECK( effect );
94
95   ImageActor actor = ImageActor::New( image );
96   actor.SetSize( 100.0f, 100.0f );
97   actor.SetShaderEffect( effect );
98   Stage::GetCurrent().Add( actor );
99
100   application.SendNotification();
101   application.Render();
102
103 }
104
105 static void UtcDaliOverlayUninitializedEffect()
106 {
107   ToolkitTestApplication application;
108
109   Toolkit::OverlayEffect effect;
110
111   try
112   {
113     BitmapImage image = CreateBitmapImage();
114
115     // New() must be called to create a OverlayEffect or it wont be valid.
116     effect.SetEffectImage( image );
117     DALI_TEST_CHECK( false );
118   }
119   catch (Dali::DaliException& e)
120   {
121     // Tests that a negative test of an assertion succeeds
122     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
123     DALI_TEST_CHECK(!effect);
124   }
125 }