Fixed that EcoreMainLoop timer does not repeat
authordarkleem <cdark.lim@samsung.com>
Wed, 31 May 2017 11:13:34 +0000 (20:13 +0900)
committerdarkleem <cdark.lim@samsung.com>
Thu, 1 Jun 2017 04:30:00 +0000 (13:30 +0900)
  - TASK=TCAPI-2448

Change-Id: Ibec2316057c37f3090c3afa842b0b08a6d2a60e6
Signed-off-by: darkleem <cdark.lim@samsung.com>
src/ElmSharp/ElmSharp/EcoreMainloop.cs
test/ElmSharp.Test/ElmSharp.Test.csproj
test/ElmSharp.Test/TC/EcoreTimerTest1.cs [new file with mode: 0644]

index 0e880c0..505e2c0 100755 (executable)
@@ -126,14 +126,19 @@ namespace ElmSharp
         {
             int task_id = (int)user_data;
             Func<bool> userAction = null;
-            _taskMap.TryGetValue(task_id, out userAction);
-            if (userAction != null)
+            if (_taskMap.TryGetValue(task_id, out userAction))
             {
-                _taskMap.Remove(task_id);
-                return userAction();
+                bool result = false;
+
+                if (userAction != null)
+                    result = userAction();
+
+                if (result == false)
+                    _taskMap.Remove(task_id);
+
+                return result;
             }
             return false;
         }
-
     }
 }
index 8457572..9e0b6cf 100755 (executable)
@@ -45,6 +45,7 @@
     <Compile Include="TC\BackgroundTest1.cs" />
     <Compile Include="TC\BackgroundTest2.cs" />
     <Compile Include="TC\BackgroundTest3.cs" />
+    <Compile Include="TC\EcoreTimerTest1.cs" />
     <Compile Include="TC\GenListTest10.cs" />
     <Compile Include="TC\LabelTest4.cs" />
     <Compile Include="TC\Log.cs" />
diff --git a/test/ElmSharp.Test/TC/EcoreTimerTest1.cs b/test/ElmSharp.Test/TC/EcoreTimerTest1.cs
new file mode 100644 (file)
index 0000000..325f6a4
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace ElmSharp.Test
+{
+    class EcoreTimerTest1 : TestCaseBase
+    {
+        public override string TestName => "EcoreTimerTest1";
+        public override string TestDescription => "To timer operation of EcoreMainLoop";
+
+        public override void Run(Window window)
+        {
+            Background bg = new Background(window)
+            {
+                AlignmentX = -1,
+                AlignmentY = -1,
+                WeightX = 1,
+                WeightY = 1,
+                Color = Color.White
+            };
+            bg.Show();
+            window.AddResizeObject(bg);
+
+            Conformant conformant = new Conformant(window);
+            conformant.Show();
+
+
+            int number = 0;
+            bool bReturn = true;
+            Label label1 = new Label(window);
+            label1.Move(150, 150);
+            label1.Resize(300, 100);
+
+            Button btnTimerSwitch = new Button(window);
+            btnTimerSwitch.Text = "Timer : On";
+            btnTimerSwitch.Move(0, 300);
+            btnTimerSwitch.Resize(300, 100);
+
+            Func<bool> handler = () =>
+            {
+                label1.Text = (++number).ToString();
+                label1.EdjeObject["elm.text"].TextStyle = "DEFAULT='color=#000000 font_size=64 align=left valign=bottom wrap=word'";
+                return bReturn;
+            };
+            IntPtr prevId = EcoreMainloop.AddTimer(1.0, handler);
+            btnTimerSwitch.Clicked += (s, e) =>
+             {
+                 if(bReturn)
+                 {
+                     bReturn = false;
+                     btnTimerSwitch.Text = "Timer : Off";
+                 }
+                 else
+                 {
+                     bReturn = true;
+                     btnTimerSwitch.Text = "Timer : On";
+                     EcoreMainloop.RemoveTimer(prevId);
+                     prevId = EcoreMainloop.AddTimer(1.0, handler);
+                 }
+             };
+
+            window.BackButtonPressed += (s, e) =>
+            {
+                EcoreMainloop.RemoveTimer(prevId);
+            };
+
+            label1.Show();
+            btnTimerSwitch.Show();
+        }
+    }
+}