4ad00c3cb4f49daf347fd4e609d5cc89391ea4f0
[framework/web/wrt-commons.git] / tests / core / test_task.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file        test_task.cpp
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the implementation file of task tests
21  */
22 #include <dpl/test/test_runner.h>
23 #include <dpl/task.h>
24 #include <dpl/log/log.h>
25
26 RUNNER_TEST_GROUP_INIT(DPL)
27
28 class MySingleTask
29     : public DPL::TaskDecl<MySingleTask>
30 {
31 protected:
32     void StepOne()
33     {
34     }
35
36 public:
37     MySingleTask()
38         : DPL::TaskDecl<MySingleTask>(this)
39     {
40         AddStep(&MySingleTask::StepOne);
41     }
42 };
43
44 class MyMultiTask
45     : public DPL::MultiTaskDecl<MyMultiTask>
46 {
47 protected:
48     typedef DPL::MultiTaskDecl<MyMultiTask> BaseType;
49
50     void StepOne()
51     {
52         LogInfo("Step one");
53     }
54
55     void StepTwo()
56     {
57         LogInfo("Step two");
58     }
59
60     void StepThree()
61     {
62         LogInfo("Step three");
63     }
64
65 public:
66     MyMultiTask()
67         : BaseType(this, 2)
68     {
69         BaseType::StepList depListStepThree;
70         depListStepThree.push_back(&MyMultiTask::StepOne);
71         depListStepThree.push_back(&MyMultiTask::StepTwo);
72         AddStep(&MyMultiTask::StepThree, depListStepThree);
73
74         BaseType::StepList depListStepTwo;
75         depListStepTwo.push_back(&MyMultiTask::StepOne);
76         AddStep(&MyMultiTask::StepTwo, depListStepTwo);
77
78         BaseType::StepList depListStepOne;
79         AddStep(&MyMultiTask::StepOne, depListStepOne);
80     }
81 };
82
83 RUNNER_TEST(Task_SingleTask)
84 {
85     MySingleTask task;
86     while (task.NextStep());
87 }
88
89 RUNNER_TEST(Task_MultiTask)
90 {
91     MyMultiTask task;
92     while (task.NextStep());
93 }