a5e20a937720c0143fa3a9ac6168915326d8e78f
[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 <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
20 #include <stdlib.h>
21
22 #include <iostream>
23
24 using namespace Dali;
25
26 namespace
27 {
28 // Size of the VertexAttributeArray enables
29 // GLES specification states that there's a minimum of 8
30 const unsigned int TEST_MAX_ATTRIBUTE_CACHE_SIZE = 8;
31
32 enum TestAttribType
33 {
34   ATTRIB_UNKNOWN = -1,
35   ATTRIB_POSITION,
36   ATTRIB_NORMAL,
37   ATTRIB_TEXCOORD,
38   ATTRIB_COLOR,
39   ATTRIB_BONE_WEIGHTS,
40   ATTRIB_BONE_INDICES,
41   ATTRIB_TYPE_LAST
42 };
43
44 // Create bitmap actor
45 static Actor CreateBitmapActor()
46 {
47   Actor actor = CreateRenderableActor();
48   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
49   actor.SetProperty(Actor::Property::NAME, "Test Image Rendering Actor");
50   return actor;
51 }
52
53 } // anonymous namespace
54
55 // Positive test case for a method
56 int UtcDaliContextVertexAttribStartup(void)
57 {
58   tet_infoline("Testing vertex attrib initial state in context");
59
60   TestApplication application;
61
62   // start up
63   application.SendNotification();
64   application.Render();
65   application.Render();
66
67   // check the locations
68   for(unsigned int i = 0; i < TEST_MAX_ATTRIBUTE_CACHE_SIZE; i++)
69   {
70     DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayState(i) == false);
71   }
72
73   tet_result(TET_PASS);
74   END_TEST;
75 }
76
77 // Tests to make the attribs only get set once when continually rendering an image actor
78 int UtcDaliContextVertexAttribImageRendering(void)
79 {
80   tet_infoline("Testing vertex attrib rendering state in context with images");
81
82   TestApplication application;
83
84   // start up
85   application.SendNotification();
86   application.Render();
87   application.Render();
88
89   // the vertex attribs get modified on startup to set them to disabled
90   // clear the flag to say they've changed
91   application.GetGlAbstraction().ClearVertexAttribArrayChanged();
92
93   // create a test bitmap actor
94   Actor actor(CreateBitmapActor());
95   application.GetScene().Add(actor);
96
97   application.SendNotification();
98   application.Render();
99   application.Render();
100
101   // check to make sure the state has changed (the image renderer will enable some
102   // locations).
103   DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
104
105 #ifdef REMOVE_CACHE_TESTING_TEMPORARILY
106   // Now check to make sure the state is cached, and isn't being set each frame.
107   application.GetGlAbstraction().ClearVertexAttribArrayChanged();
108
109   application.Render();
110   application.Render();
111   application.Render();
112
113   // if it has changed then the caching has failed
114   DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged() == false);
115
116   //tet_result(TET_PASS);
117 #endif
118
119   END_TEST;
120 }