~mandel/ubuntu-download-manager/remove-shared-process-factory

« back to all changes in this revision

Viewing changes to ubuntu-download-manager-tests/downloads/state_machines/test_final_state.h

  • Committer: Tarmac
  • Author(s): Manuel de la Pena
  • Date: 2013-11-21 12:06:12 UTC
  • mfrom: (148.13.24 keep-track-of-states)
  • Revision ID: tarmac-20131121120612-s3xcba5yvun01q6u
Keep track of the state in the state machine so that tests are easier to perform.

Approved by PS Jenkins bot, Mike McCracken.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of version 3 of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public
 
14
 * License along with this library; if not, write to the
 
15
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
16
 * Boston, MA 02110-1301, USA.
 
17
 */
 
18
 
 
19
#ifndef TEST_FINAL_STATE_H
 
20
#define TEST_FINAL_STATE_H
 
21
 
 
22
#include <QObject>
 
23
#include <QState>
 
24
#include <QStateMachine>
 
25
#include <QSignalTransition>
 
26
#include <downloads/state_machines/final_state.h>
 
27
#include "base_testcase.h"
 
28
#include "test_runner.h"
 
29
 
 
30
 
 
31
using namespace Ubuntu::DownloadManager::StateMachines;
 
32
 
 
33
class TestFinalStateHelperObject : public QObject {
 
34
    Q_OBJECT
 
35
    Q_PROPERTY(QString name READ name WRITE setName)
 
36
    Q_PROPERTY(QString surname READ surname WRITE setSurname)
 
37
 
 
38
 public:
 
39
    explicit TestFinalStateHelperObject(QObject* parent=0)
 
40
        : QObject(parent),
 
41
          _name(""),
 
42
          _surname("") {
 
43
    }
 
44
 
 
45
    TestFinalStateHelperObject(QString name,
 
46
                               QString surname,
 
47
                               QObject* parent=0)
 
48
        : QObject(parent),
 
49
          _name(name),
 
50
          _surname(surname) {
 
51
    }
 
52
 
 
53
    QString name() {
 
54
        return _name;
 
55
    }
 
56
 
 
57
    void setName(QString name) {
 
58
        _name = name;
 
59
    }
 
60
 
 
61
    QString surname() {
 
62
        return _surname;
 
63
    }
 
64
 
 
65
    void setSurname(QString surname) {
 
66
        _surname = surname;
 
67
    }
 
68
 
 
69
    void emitMoveStates() {
 
70
        emit moveStates();
 
71
    }
 
72
 
 
73
 signals:
 
74
    void moveStates();
 
75
 
 
76
 private:
 
77
    QString _name = "";
 
78
    QString _surname = "";
 
79
};
 
80
 
 
81
class TestFinalState : public BaseTestCase {
 
82
    Q_OBJECT
 
83
public:
 
84
    explicit TestFinalState(QObject *parent = 0);
 
85
    
 
86
 private slots:  // NOLINT(whitespace/indent)
 
87
 
 
88
    void init() override;
 
89
    void cleanup() override;
 
90
    void testSetNotProperties();
 
91
    void testSetSingleProperty();
 
92
    void testMultipleProperties();
 
93
 
 
94
 private:
 
95
    QString _originalName;
 
96
    QString _originalSurname;
 
97
    TestFinalStateHelperObject* _obj;
 
98
    QStateMachine _stateMachine;
 
99
    QState* _s1;
 
100
    FinalState* _s2;
 
101
    QSignalTransition* _transition;
 
102
};
 
103
 
 
104
DECLARE_TEST(TestFinalState)
 
105
 
 
106
#endif // TEST_FINAL_STATE_H