2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file test_property.cpp
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the implementation file of test property
22 #include <dpl/test/test_runner.h>
23 #include <dpl/event/property.h>
24 #include <dpl/event/model.h>
28 const int PROPERTY_VALUE_INT = 2;
29 const std::string PROPERTY_VALUE_STRING = "aaa";
32 int ReadSomething2(DPL::Event::Model */*model*/);
33 int ReadSomething2(DPL::Event::Model */*model*/)
35 return PROPERTY_VALUE_INT;
38 std::string ReadSomething(DPL::Event::Model */*model*/);
39 std::string ReadSomething(DPL::Event::Model */*model*/)
41 return PROPERTY_VALUE_STRING;
44 void WriteSomething(const std::string & /*value*/, DPL::Event::Model */*model*/);
45 void WriteSomething(const std::string & /*value*/, DPL::Event::Model */*model*/)
49 public DPL::Event::Model
54 DPL::Event::Property<std::string>
57 DPL::Event::Property<std::string>
60 DPL::Event::Property<std::string, DPL::Event::PropertyReadOnly>
63 DPL::Event::Property<std::string, DPL::Event::PropertyReadWrite>
66 DPL::Event::Property<std::string, DPL::Event::PropertyReadWrite,
67 DPL::Event::PropertyStorageCached> Testproperty3;
69 DPL::Event::Property<std::string, DPL::Event::PropertyReadWrite,
70 DPL::Event::PropertyStorageDynamic> Testproperty4;
72 DPL::Event::Property<int, DPL::Event::PropertyReadOnly,
73 DPL::Event::PropertyStorageDynamicCached>
77 Caption(this, "Foo caption"),
78 Testproperty0(this, "", &ReadSomething),
82 Testproperty4(this, "test", &ReadSomething, &WriteSomething),
83 Testproperty5(this, &ReadSomething2)
87 std::string g_caption;
89 void OnNameChanged(const DPL::Event::PropertyEvent<std::string> &event);
90 void OnNameChanged(const DPL::Event::PropertyEvent<std::string> &event)
92 g_caption = event.value;
97 Description: tests accessing and changing models properties
98 Expected: listener should get changed value
100 RUNNER_TEST(Model_Test)
104 g_caption = "It is a bad caption";
106 model.Caption.AddListener(&OnNameChanged);
107 model.Caption.Set("Test name");
109 RUNNER_ASSERT(model.Testproperty4.Get() == PROPERTY_VALUE_STRING);
110 RUNNER_ASSERT(PROPERTY_VALUE_INT == model.Testproperty5.Get());
111 RUNNER_ASSERT(g_caption == "Test name");
112 RUNNER_ASSERT(model.Caption.Get() == "Test name");
114 model.Caption.RemoveListener(&OnNameChanged);