source: A2P/a2p/test/A2P/SpoolManager.pm @ 3

Last change on this file since 3 was 3, checked in by guillaume, 17 years ago
  • AUTHORS: Ajout des différents contributeurs
  • COPYING: Ajout de la licence GPL v3
  • a2p: Préparation des sources pour leur publication sous GPL
  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1#
2# Copyright (c) 2004-2007 - Consultas, PKG.fr
3#
4# This file is part of A2P.
5#
6# A2P is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# A2P is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with A2P; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19#
20# $Id: SpoolManager.pm 3 2007-10-18 16:20:19Z guillaume $
21#
22
23use strict ;
24use Test ;
25
26require 'test/A2P/Defaults.pm' ;
27
28BEGIN {
29    plan
30        tests  => 30 ,
31        onfail => sub { exit(1) }
32}
33
34$| = 1 ;
35
36our $tie_file ;
37our $test_string ;
38
39our ( $SERVICE_TMP, $SHMDIR, $ADVANCED_DEBUGGING, $LOCKID,
40    $LOGFILENAME, $DEBUG_IN_FILE, $AFPSPOOL );
41our $Progname    = 'TEST-SpoolManager' ;
42
43# Be sure
44unlink $AFPSPOOL unless -d $AFPSPOOL ;
45mkdir $AFPSPOOL unless -d $AFPSPOOL ;
46mkdir $AFPSPOOL.'/.a2p' unless -d $AFPSPOOL.'/.a2p' ;
47
48&info("Loading A2P::SpoolManager library");
49ok require A2P::SpoolManager ;
50
51sub update_prefix ; *update_prefix = \&A2P::SpoolManager::update_prefix ;
52
53&info("Update prefix");
54# Default for $SPOOL_PREFIX is "TRANS ARCHI" ;
55ok join('-',&update_prefix("TRANS ARCHI")), "TRANS-ARCHI" ; #2
56
57sub prefix ; *prefix = \&A2P::SpoolManager::prefix ;
58
59&info("Check file match a prefix");
60ok &prefix("TRANS.TEST"), "TRANS" ;
61ok &prefix("TrANs.TEST"), "TrANs" ;
62ok &prefix("ARCHI.A"), "ARCHI" ;
63ok &prefix("archi."), "" ;
64ok &prefix("TEST"), "" ;
65ok &prefix(""), "" ;
66ok &prefix("none"), "" ;
67ok &prefix("none.TEST.none"), "" ; #10
68
69
70&info("Check get locking");
71
72
73sub openLockingPrefix ;  *openLockingPrefix = \&A2P::SpoolManager::openLockingPrefix ;
74sub lockprefix ;         *lockprefix = \&A2P::SpoolManager::lockprefix ;
75sub unlockprefix ;       *unlockprefix = \&A2P::SpoolManager::unlockprefix ;
76sub closeLockingPrefix ; *closeLockingPrefix = \&A2P::SpoolManager::closeLockingPrefix ;
77
78&info("Check locking on prefix");
79my $hashref = { LockingPrefix => {} };
80my $lockfile = $AFPSPOOL . '/.a2p/TRANS.LCK' ;
81unlink $lockfile ;
82ok ! -e $lockfile ;
83ok &openLockingPrefix($hashref), 1 ;
84ok -e $lockfile ;
85ok exists($hashref->{LockingPrefix}->{TRANS}) ; #14
86ok exists($hashref->{LockingPrefix}->{ARCHI}) ;
87my $TRANS = $hashref->{LockingPrefix}->{TRANS} ;
88my $ARCHI = $hashref->{LockingPrefix}->{ARCHI} ;
89ok (defined($TRANS) and defined($ARCHI));
90ok ref($TRANS), 'GLOB' ;
91ok ref($ARCHI), 'GLOB' ;
92ok &lockprefix($hashref,"TRANS") ; #19
93my $lck = qx(/usr/sbin/lsof -l $lockfile  2>&1 | tee /tmp/test-locking.log 2>&1) ;
94&info("Check lsof result:", $lck, "toward: perl $$ $< [0-9]+wW REG [0-9,]+ 0");
95ok $lck && $lck =~ /perl\s+$$\s+$<\s+\d+wW\s+REG\s+[0-9,]+\s+0\s+/ ;
96ok &unlockprefix($hashref,"TRANS") , 1 ;
97ok exists($hashref->{LockingPrefix}->{TRANS}) ; #22
98ok exists($hashref->{LockingPrefix}->{ARCHI}) ;
99ok &closeLockingPrefix($hashref), 1 ;
100ok ! exists($hashref->{LockingPrefix}->{TRANS}) ;
101ok ! exists($hashref->{LockingPrefix}->{ARCHI}) ; #26
102
103&info("Checklocking when lock file has been deleted");
104&openLockingPrefix($hashref) ;
105unlink $lockfile ;
106ok &lockprefix($hashref,"TRANS") ; #27
107$lck = qx(/usr/sbin/lsof -l $lockfile  2>&1 | tee /tmp/test-locking.log 2>&1) ;
108&info("Check lsof result:", $lck, "toward: perl $$ $< [0-9]+wW REG [0-9,]+ 0");
109ok $lck && $lck =~ /perl\s+$$\s+$<\s+\d+wW\s+REG\s+[0-9,]+\s+0\s+/ ;
110ok &unlockprefix($hashref,"TRANS") , 1 ; #29
111ok &closeLockingPrefix($hashref), 1 ;
112
1131 ;
Note: See TracBrowser for help on using the repository browser.