Merge branch 'new_text' into tizen
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Builder.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 #include <stdlib.h>
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/public-api/builder/builder.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23
24 using namespace Dali;
25 using namespace Toolkit;
26
27 namespace
28 {
29
30 std::string ReplaceQuotes(const std::string &in_s)
31 {
32   std::string s(in_s);
33   // wrong as no embedded quote but had regex link problems
34   std::replace(s.begin(), s.end(), '\'', '"');
35   return s;
36 }
37
38 struct BuilderFunctor
39 {
40   BuilderFunctor( bool& called ) : mCalled( called )
41   {
42     mCalled = false;
43   }
44
45   void operator()()
46   {
47     mCalled = true;
48   }
49
50   bool& mCalled;
51 };
52
53 } // namespace
54
55
56
57 void builder_startup(void)
58 {
59   test_return_value = TET_UNDEF;
60 }
61
62 void builder_cleanup(void)
63 {
64   test_return_value = TET_PASS;
65 }
66
67 int UtcDaliBuilderQuitSignal(void)
68 {
69   ToolkitTestApplication application;
70
71   // JSON with a quit event when the actor is touched
72   std::string json(
73       "{"
74          "\"stage\":"
75          "[{"
76            "\"type\": \"Actor\","
77            "\"size\": [100,100,1],"
78            "\"parent-origin\": \"TOP_LEFT\","
79            "\"anchor-point\": \"TOP_LEFT\","
80            "\"signals\": [{"
81              "\"name\": \"touched\","
82              "\"action\": \"quit\""
83            "}]"
84          "}]"
85       "}"
86   );
87   Builder builder = Builder::New();
88   builder.LoadFromString( json );
89   builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
90
91   // Connect to builder's quit signal
92   bool functorCalled( false );
93   builder.QuitSignal().Connect( &application, BuilderFunctor( functorCalled ) );
94
95   // Render and notify
96   application.SendNotification();
97   application.Render();
98
99   // Emit touch event and check that our quit method is called
100   Integration::TouchEvent touchEvent;
101   touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
102   application.ProcessEvent( touchEvent );
103   DALI_TEST_CHECK( functorCalled );
104
105   END_TEST;
106 }