~ubuntu-branches/ubuntu/lucid/libebox/lucid

« back to all changes in this revision

Viewing changes to src/EBox/t/Validate.t

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2008-02-27 13:19:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20080227131928-83zaqqtab1mvhl6u
Tags: upstream-0.11.99
ImportĀ upstreamĀ versionĀ 0.11.99

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
use strict;
3
3
use warnings;
4
4
 
5
 
use Test::More tests => 100;
 
5
use Test::More tests => 115;
6
6
use Test::Exception;
7
7
use Fatal qw(mkdir);
8
8
 
14
14
checkAbsoluteFilePathTest();
15
15
checkIsPrivateDir();
16
16
checkHostTest();
 
17
checkEmailAddressTest();
 
18
checkIP6Test();
17
19
 
18
20
sub checkFilePathTest
19
21
{
149
151
}
150
152
 
151
153
 
 
154
sub checkEmailAddressTest
 
155
{
 
156
  my @straightCases = qw(
 
157
       macaco@monos.org
 
158
       homo.sapiens@primates.com
 
159
       mandrill+colorful@monos.org
 
160
   );
 
161
 
 
162
 
 
163
  my @deviantCases = qw(
 
164
      macaco
 
165
   );
 
166
 
 
167
    foreach my $case (@straightCases) {
 
168
        my $name = "checking validation for straight case: $case";
 
169
        ok EBox::Validate::checkEmailAddress($case), $name;
 
170
    }
 
171
 
 
172
    foreach my $case (@deviantCases) {
 
173
        my $name = "checking validation error for deviant case: $case";
 
174
        ok ! EBox::Validate::checkEmailAddress($case), $name;
 
175
        dies_ok {  EBox::Validate::checkEmailAddress($case, $name) } "$name (with name parameter)";
 
176
    }
 
177
}
 
178
 
 
179
 
 
180
sub checkIP6Test
 
181
{
 
182
  my @valid = (
 
183
               '2001:0db8:0000:0000:0000:0000:1428:57ab',
 
184
               '2001:0db8:0000:0000:0000::1428:57ab',
 
185
               '2001:0db8:0:0:0:0:1428:57ab',
 
186
               '2001:0db8:0:0::1428:57ab',
 
187
               '2001:0db8::1428:57ab',
 
188
               '2001:db8::1428:57ab',
 
189
              );
 
190
 
 
191
  my @invalid = (
 
192
                 'macaco',
 
193
                 '192.168.45.3',
 
194
                );
 
195
 
 
196
 
 
197
  foreach my $ip (@valid) {
 
198
    ok EBox::Validate::checkIP6($ip), 'checking wether checkIP6 recognizes valid addresses';
 
199
  }
 
200
 
 
201
  
 
202
  foreach my $ip (@invalid) {
 
203
    my $errorReturnValue = not EBox::Validate::checkIP6($ip);
 
204
    ok $errorReturnValue, 'checking wether checkIP6 signals invalid values wit its return value';;
 
205
    dies_ok {
 
206
      EBox::Validate::checkIP6($ip, 'error');
 
207
    } 'checking wether checkIP6 signals a invalid value raising exception';
 
208
  }
 
209
 
 
210
 
 
211
}
 
212
 
152
213
1;