~ubuntu-branches/ubuntu/vivid/zentyal-core/vivid-proposed

« back to all changes in this revision

Viewing changes to src/EBox/Types/t/Int.t

  • Committer: Package Import Robot
  • Author(s): Jorge Salamero Sanz
  • Date: 2012-08-28 10:03:33 UTC
  • Revision ID: package-import@ubuntu.com-20120828100333-oz3n5kpav4z0tl27
Tags: 2.3.21+quantal1
New upstream release for Quantal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2012 eBox Technologies S.L.
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License, version 2, as
5
 
# published by the Free Software Foundation.
6
 
#
7
 
# This program is distributed in the hope that it will be useful,
8
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
# GNU General Public License for more details.
11
 
#
12
 
# You should have received a copy of the GNU General Public License
13
 
# along with this program; if not, write to the Free Software
14
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 
 
16
 
 
17
 
use strict;
18
 
use warnings;
19
 
 
20
 
use Test::More tests => 28;
21
 
 
22
 
use EBox::TestStubs;
23
 
 
24
 
 
25
 
use lib '../../..';
26
 
 
27
 
use EBox::Types::Test;
28
 
use EBox::Types::Int;
29
 
use EBox::Types::Text;
30
 
 
31
 
 
32
 
 
33
 
sub creationTest
34
 
{
35
 
    my @validCases = (
36
 
                      # no defined bounds
37
 
                      [
38
 
                       value => 0,
39
 
                      ],
40
 
                      [
41
 
                       value => 10,
42
 
                      ],
43
 
                      # negative value as min bound
44
 
                      [
45
 
                       min => -5,
46
 
                       value => 1,
47
 
                      ],
48
 
                      # value between defined bounds
49
 
                      [
50
 
                       min => -8,
51
 
                       max => 2,
52
 
                       value => 1,
53
 
                      ],
54
 
                      # equal than min value
55
 
                      [
56
 
                       min => -4,
57
 
                       value => -4,
58
 
                      ],
59
 
                      # equal than max value
60
 
                      [
61
 
                       max => 5,
62
 
                       value => 5,
63
 
                      ],
64
 
                     );
65
 
 
66
 
    my @deviantCases = (
67
 
                        # default min value must be zero, so no negatives allowed
68
 
                        [
69
 
                         value => -1,
70
 
                        ],
71
 
                        # mix and max mismatch
72
 
                        [
73
 
                         max => 4,
74
 
                         min => 7,
75
 
                         value => 5,
76
 
                        ],
77
 
                        # greater than max
78
 
                        [
79
 
                         min => -1,
80
 
                         max => 0,
81
 
                         value => 1,
82
 
                        ],
83
 
                        # lesser than min
84
 
                        [
85
 
                         min => 2,
86
 
                         value => 1,
87
 
                        ]
88
 
                       );
89
 
 
90
 
 
91
 
 
92
 
    foreach my $case_r (@validCases) {
93
 
        my @params = @{ $case_r };
94
 
        EBox::Types::Test::createOk(
95
 
                                    'EBox::Types::Int',
96
 
                                    fieldName => 'test',
97
 
                                    @params,
98
 
                                    "Checking instance creation with valid parameters and value"
99
 
                                   );
100
 
 
101
 
    }
102
 
 
103
 
    foreach my $case_r (@deviantCases) {
104
 
        my @params = @{ $case_r };
105
 
        EBox::Types::Test::createFail(
106
 
                                      'EBox::Types::Int',
107
 
                                      @params,
108
 
                                      "Checking instance creation raises error when called with invalid parameters and value"
109
 
                                     );
110
 
    }
111
 
 
112
 
}
113
 
 
114
 
sub cmpTest
115
 
{
116
 
    my $four = new EBox::Types::Int(
117
 
                                    fieldName => 'four',
118
 
                                    value    => 4,
119
 
                                   );
120
 
 
121
 
    my $otherFour = new EBox::Types::Int(
122
 
                                         fieldName => 'otherFour',
123
 
                                         value => 4,
124
 
                                        );
125
 
    my $two = new EBox::Types::Int(
126
 
                                    fieldName => 'two',
127
 
                                    value    => 2,
128
 
                                   );
129
 
    my $seven = new EBox::Types::Int(
130
 
                                    fieldName => 'seven',
131
 
                                    value    => 7,
132
 
                                   );
133
 
 
134
 
    
135
 
 
136
 
    my $fourWithMin = new EBox::Types::Int(
137
 
                                    fieldName => 'fourWithMin',
138
 
                                    value    => 4,
139
 
                                    min => -5,
140
 
                                   );
141
 
    my $fourWithMax = new EBox::Types::Int(
142
 
                                    fieldName => 'fourWithMax',
143
 
                                    value    => 4,
144
 
                                    max => 51,
145
 
                                   );
146
 
 
147
 
    my $text = new EBox::Types::Text(
148
 
                                     fieldName => 'text',
149
 
                                     value => 'ea',
150
 
                                    );
151
 
 
152
 
    ok $four->isEqualTo($otherFour), 'checking isEqualTo for equality';
153
 
    ok((not $four->isEqualTo($two)), 'checking isEqualTo for inequality');
154
 
 
155
 
    is $four->cmp($otherFour), 0,
156
 
        'checking cmp method for equality';
157
 
    is $four->cmp($two), 1,
158
 
        'checking cmp method with a lesser other';
159
 
    is $four->cmp($seven), -1,
160
 
        'checking cmp method with a greater other';
161
 
 
162
 
    cmp_ok($four->cmp($fourWithMin), '==', 0,
163
 
           'checking cmp for equalify though the bounds');
164
 
 
165
 
    cmp_ok($four->cmp($fourWithMax), '==', 0,
166
 
           'checking cmp for equalify though the bounds');
167
 
 
168
 
    is $four->cmp($text), undef,
169
 
        'whether different types are incomparable';
170
 
 
171
 
}
172
 
 
173
 
 
174
 
EBox::TestStubs::activateTestStubs();
175
 
creationTest();
176
 
 
177
 
EBox::Types::Test::defaultValueOk('EBox::Types::Int', 4);
178
 
 
179
 
 
180
 
EBox::Types::Test::storeAndRestoreGConfTest('EBox::Types::Int', 4, 1, 4 ,5);
181
 
 
182
 
cmpTest();
183
 
 
184
 
1;