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*/)
50 : public DPL::Event::Model
55 DPL::Event::Property<std::string>
58 DPL::Event::Property<std::string>
61 DPL::Event::Property<std::string, DPL::Event::PropertyReadOnly>
64 DPL::Event::Property<std::string, DPL::Event::PropertyReadWrite>
67 DPL::Event::Property<std::string, DPL::Event::PropertyReadWrite,
68 DPL::Event::PropertyStorageCached> Testproperty3;
70 DPL::Event::Property<std::string, DPL::Event::PropertyReadWrite,
71 DPL::Event::PropertyStorageDynamic> Testproperty4;
73 DPL::Event::Property<int, DPL::Event::PropertyReadOnly,
74 DPL::Event::PropertyStorageDynamicCached> Testproperty5;
77 : Caption(this, "Foo caption"),
78 Testproperty0(this, "", &ReadSomething),
82 Testproperty4(this, "test", &ReadSomething, &WriteSomething),
83 Testproperty5(this, &ReadSomething2)
88 std::string g_caption;
90 void OnNameChanged(const DPL::Event::PropertyEvent<std::string> &event);
91 void OnNameChanged(const DPL::Event::PropertyEvent<std::string> &event)
93 g_caption = event.value;
96 RUNNER_TEST(Model_Test)
100 g_caption = "It is a bad caption";
102 model.Caption.AddListener(&OnNameChanged);
103 model.Caption.Set("Test name");
105 RUNNER_ASSERT(model.Testproperty4.Get() == PROPERTY_VALUE_STRING);
106 RUNNER_ASSERT(PROPERTY_VALUE_INT == model.Testproperty5.Get());
107 RUNNER_ASSERT(g_caption == "Test name");
108 RUNNER_ASSERT(model.Caption.Get() == "Test name");
110 model.Caption.RemoveListener(&OnNameChanged);