From 0f560f7e4e6c06338790fb52a3e77cd26baf895c Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Mon, 24 Apr 2017 11:58:05 +0100 Subject: [PATCH 1/1] Test for C# Animation Tests animation, color visual, text visual and signal callback Change-Id: Ibde03e86116e047353f360ee6bb2fa8c852e866d --- plugins/dali-sharp/.gitignore | 1 + plugins/dali-sharp/build/Makefile.am | 17 +++- plugins/dali-sharp/test/test.cs | 174 +++++++++++++++++++++++++++++++++++ 3 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 plugins/dali-sharp/test/test.cs diff --git a/plugins/dali-sharp/.gitignore b/plugins/dali-sharp/.gitignore index 704f959..9f87a93 100644 --- a/plugins/dali-sharp/.gitignore +++ b/plugins/dali-sharp/.gitignore @@ -7,3 +7,4 @@ build/autom4te.cache/ examples/*.exe NDali.dll ../examples/NDali.dll +test/*.exe diff --git a/plugins/dali-sharp/build/Makefile.am b/plugins/dali-sharp/build/Makefile.am index 796c15c..f1e10e7 100644 --- a/plugins/dali-sharp/build/Makefile.am +++ b/plugins/dali-sharp/build/Makefile.am @@ -13,7 +13,7 @@ # limitations under the License. CLEANFILES = ./dali-bindings/*.o *.so *.dll \ - ../examples/*.so ../examples/*.dll examples/*.exe + ../examples/*.so ../examples/*.dll examples/*.exe test/*.exe BUILT_SOURCES = ../dali-bindings/dali_wrap.cpp ../dali-bindings/dali_wrap.h @@ -48,14 +48,25 @@ $(DALI_BINDINGS_DIR): NDali.dll: $(BUILT_SOURCES) $(MCS) -nologo -target:library -out:NDali.dll ../sharp/internal/*.cs ../sharp/public/*.cs -check-local: examples/hello-world.exe \ +check-local: test/test.exe \ + examples/hello-world.exe \ examples/scroll-view.exe \ examples/control-dashboard.exe \ examples/user-alphafunction.exe \ examples/image-view.exe \ examples/visuals-example.exe \ examples/visuals-using-custom-view.exe \ - examples/libNDalic.so examples/NDali.dll + examples/libNDalic.so examples/NDali.dll \ + test/libNDalic.so test/NDali.dll + +test/test.exe: ../test/test.cs + $(MCS) -nologo -target:exe -out:../$@ -reference:NDali.dll $< + +test/libNDalic.so: + cd ../test && ln -sf ../build/libNDalic.so + +test/NDali.dll: + cd ../test && ln -sf ../build/NDali.dll examples/hello-world.exe: ../examples/hello-world.cs $(MCS) -nologo -target:exe -out:../$@ -reference:NDali.dll $< diff --git a/plugins/dali-sharp/test/test.cs b/plugins/dali-sharp/test/test.cs new file mode 100644 index 0000000..fbbccbc --- /dev/null +++ b/plugins/dali-sharp/test/test.cs @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 /* + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * 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 Dali; +using Dali.Constants; +using System; +using System.Timers; + +namespace Test +{ + class AnimationTest + { + private View _colorView; + private View _textView; + + private bool _textAnimationComplete; + + private Dali.Application _currentApplication; + + private AnimationTest(Dali.Application application) + { + _currentApplication = application; + _textAnimationComplete = false; + _currentApplication.Initialized += Initialize; + } + + private void Initialize(object source, NUIApplicationInitEventArgs e) + { + AnimationTest01(); + StartTimer(4000); + } + + private void AnimationFinished(object sender, EventArgs e) + { + Console.WriteLine("Visual AnimationFinished"); + + Property.Map colorVisual = new Property.Map(); + colorVisual.Add( Visual.Property.Type, new Property.Value( (int)Visual.Type.Color )) + .Add( ColorVisualProperty.MixColor, new Property.Value( Color.Blue )); + _colorView.Background = colorVisual; + } + + private void TextAnimationFinished(object sender, EventArgs e) + { + Console.WriteLine("Text AnimationFinished"); + _textAnimationComplete = true; + } + + /** + * Test animates a text visual automatically and logs result to console once animation finished signal emitted. + * + * Manually pressing the button starts animating a visual and changes it color at end of animation. + * + * Tests Animation signal logic. + */ + + private void AnimationTest01() + { + Console.WriteLine("AnimationTest"); + + _textAnimationComplete = false; + + Window window = Window.Instance; + window.BackgroundColor = Color.White; + Size2D windowSize = window.Size; + + // Create Color Visual + _colorView = new View(); + _colorView.Size = new Vector3(120.0f, 120.0f, 0.0f); + _colorView.WidthResizePolicy = "FIXED"; + _colorView.HeightResizePolicy = "FIXED"; + Property.Map colorVisual = new Property.Map(); + colorVisual.Add( Visual.Property.Type, new Property.Value( (int)Visual.Type.Color )) + .Add( ColorVisualProperty.MixColor, new Property.Value( Color.Green )); + _colorView.Background = colorVisual; + + Window.Instance.Add(_colorView); + + Animation _animation = new Animation(1000); // 1000 milli-second of duration + _animation.StartTime = 500; + _animation.EndTime = 1000; + _animation.TargetProperty = "Position"; + _animation.Destination = new Vector3(150.0f, 150.0f, 0.0f); + _animation.AnimateTo(_colorView); + _animation.Finished += AnimationFinished; + + PushButton buttonWithSimpleTooltip = new PushButton(); + buttonWithSimpleTooltip.LabelText = "Press to Animate"; + buttonWithSimpleTooltip.UnselectedColor = new Vector4(0.6f, 0.92f, 1.0f, 1.0f); + buttonWithSimpleTooltip.SelectedColor = new Vector4(0.6f, 0.7f, 1.0f, 1.0f); + buttonWithSimpleTooltip.WidthResizePolicy = "USE_NATURAL_SIZE"; + buttonWithSimpleTooltip.Position = new Position(windowSize.Width /2 , 0, 0); + + Window.Instance.Add(buttonWithSimpleTooltip); + buttonWithSimpleTooltip.SetKeyboardFocusable(true); + buttonWithSimpleTooltip.TooltipText = "RePosition Square and change color to Blue"; + buttonWithSimpleTooltip.Clicked += (obj, ee) => + { + _animation.Play(); + return true; + }; + + _textView = new View(); + _textView.WidthResizePolicy = "USE_NATURAL_SIZE"; + Property.Map textVisual = new Property.Map(); + textVisual.Add(Dali.Constants.Visual.Property.Type, new Property.Value((int)Dali.Constants.Visual.Type.Text)) + .Add(Dali.Constants.TextVisualProperty.Text, new Property.Value("Moved Text")) + .Add(Dali.Constants.TextVisualProperty.PointSize, new Property.Value(24)); + + _textView.Background = textVisual; + _textView.Position = new Position(0, 200, 0); + Window.Instance.Add(_textView); + + Animation textAnimation = new Animation(3000); // 3000 milli-second of duration + + textAnimation.TargetProperty = "Position"; + textAnimation.Destination = new Vector3(windowSize.Width/2, 200.0f, 0.0f); + textAnimation.AnimateTo(_textView); + textAnimation.Finished += TextAnimationFinished; + + textAnimation.Play(); + } + + private void StartTimer(int duration) + { + System.Timers.Timer timer = new System.Timers.Timer(duration); + timer.Elapsed += OnTimerElasped; + timer.AutoReset = false; + timer.Start(); + } + + private void OnTimerElasped(System.Object source, ElapsedEventArgs e) + { + if (_textAnimationComplete == true) + { + Console.WriteLine("PASSED."); + } + else + { + Console.WriteLine("FAILED"); + } + } + + static void Main(string[] args) + { + Application application = Application.NewApplication(); + AnimationTest test = new AnimationTest(application); + application.MainLoop(); + } + } +} \ No newline at end of file -- 2.7.4