Added sampler properties, test cases.
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Context.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 <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23
24 using namespace Dali;
25
26
27 namespace
28 {
29 // Size of the VertexAttributeArray enables
30 // GLES specification states that there's minimum of
31 const unsigned int TEST_MAX_ATTRIBUTE_CACHE_SIZE = 8;
32
33 enum TestAttribType
34 {
35   ATTRIB_UNKNOWN = -1,
36   ATTRIB_POSITION,
37   ATTRIB_NORMAL,
38   ATTRIB_TEXCOORD,
39   ATTRIB_COLOR,
40   ATTRIB_BONE_WEIGHTS,
41   ATTRIB_BONE_INDICES,
42   ATTRIB_TYPE_LAST
43 };
44
45 // Create bitmap image
46 static BufferImage CreateBufferImage()
47 {
48   BufferImage image = BufferImage::New(4,4,Pixel::RGBA8888);
49
50   return image;
51 }
52
53 static ImageActor CreateImageActor()
54 {
55   BufferImage image = CreateBufferImage();
56   ImageActor actor = ImageActor::New( image );
57   actor.SetSize( 100.0f, 100.0f );
58   actor.SetName("Test ImageActor");
59   return actor;
60 }
61
62 } // anonymous namespace
63
64
65 // Positive test case for a method
66 int UtcDaliContextVertexAttribStartup(void)
67 {
68   tet_infoline("Testing vertex attrib initial state in context");
69
70   TestApplication application;
71
72   // start up
73   application.SendNotification();
74   application.Render();
75   application.Render();
76
77   // context class should initially set the vertex attrib locations to disable
78   // Make sure it has been modified
79   DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
80
81   // check the locations
82   for (unsigned int i = 0; i < TEST_MAX_ATTRIBUTE_CACHE_SIZE; i++)
83   {
84     DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(i) == false);
85   }
86
87   tet_result(TET_PASS);
88   END_TEST;
89 }
90
91 // Tests to make the attribs only get set once when continually rendering an image actor
92 int UtcDaliContextVertexAttribImageRendering(void)
93 {
94   tet_infoline("Testing vertex attrib rendering state in context with images");
95
96   TestApplication application;
97
98   // start up
99   application.SendNotification();
100   application.Render();
101   application.Render();
102
103   // the vertex attribs get modified on startup to set them to disabled
104   // clear the flag to say they've changed
105   application.GetGlAbstraction().ClearVertexAttribArrayChanged();
106
107
108   // create a test image actor
109   ImageActor imageActor(CreateImageActor());
110   Stage::GetCurrent().Add(imageActor);
111
112
113   application.SendNotification();
114   application.Render();
115   application.Render();
116
117   // check to make sure the state has changed (the image renderer will enable some
118   // locations).
119   DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
120
121   // Now check to make sure the state is cached, and isn't being set each frame.
122   application.GetGlAbstraction().ClearVertexAttribArrayChanged();
123
124   application.Render();
125   application.Render();
126   application.Render();
127
128   // if it has changed then the caching has failed
129   DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged() == false);
130
131
132   tet_result(TET_PASS);
133   END_TEST;
134 }