[Tizen] Add screen and client rotation itself function
[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 a minimum of 8
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 actor
46 static Actor CreateBitmapActor()
47 {
48   BufferImage image = BufferImage::New(4,4,Pixel::RGBA8888);
49   Actor actor = CreateRenderableActor( image );
50   actor.SetSize( 100.0f, 100.0f );
51   actor.SetName("Test Image Rendering Actor");
52   return actor;
53 }
54
55 } // anonymous namespace
56
57
58 // Positive test case for a method
59 int UtcDaliContextVertexAttribStartup(void)
60 {
61   tet_infoline("Testing vertex attrib initial state in context");
62
63   TestApplication application;
64
65   // start up
66   application.SendNotification();
67   application.Render();
68   application.Render();
69
70   // check the locations
71   for (unsigned int i = 0; i < TEST_MAX_ATTRIBUTE_CACHE_SIZE; i++)
72   {
73     DALI_TEST_CHECK( application.GetGlAbstraction().GetVertexAttribArrayState(i) == false);
74   }
75
76   tet_result(TET_PASS);
77   END_TEST;
78 }
79
80 // Tests to make the attribs only get set once when continually rendering an image actor
81 int UtcDaliContextVertexAttribImageRendering(void)
82 {
83   tet_infoline("Testing vertex attrib rendering state in context with images");
84
85   TestApplication application;
86
87   // start up
88   application.SendNotification();
89   application.Render();
90   application.Render();
91
92   // the vertex attribs get modified on startup to set them to disabled
93   // clear the flag to say they've changed
94   application.GetGlAbstraction().ClearVertexAttribArrayChanged();
95
96
97   // create a test bitmap actor
98   Actor actor(CreateBitmapActor());
99   Stage::GetCurrent().Add(actor);
100
101
102   application.SendNotification();
103   application.Render();
104   application.Render();
105
106   // check to make sure the state has changed (the image renderer will enable some
107   // locations).
108   DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged());
109
110   // Now check to make sure the state is cached, and isn't being set each frame.
111   application.GetGlAbstraction().ClearVertexAttribArrayChanged();
112
113   application.Render();
114   application.Render();
115   application.Render();
116
117   // if it has changed then the caching has failed
118   DALI_TEST_CHECK(application.GetGlAbstraction().GetVertexAttribArrayChanged() == false);
119
120
121   tet_result(TET_PASS);
122   END_TEST;
123 }