~ubuntu-branches/ubuntu/vivid/drizzle/vivid

« back to all changes in this revision

Viewing changes to tests/kewpie/randgen/lib/GenTest/Generator/FromDirectory.pm

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (20.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131029154340-j36v7gxq9tm1gi5f
Tags: 1:7.2.3-2ubuntu1
* Merge from debian, remaining changes:
  - Link against boost_system because of boost_thread.
  - Add required libs to message/include.am
  - Add upstart job and adjust init script to be upstart compatible.
  - Disable -floop-parallelize-all due to gcc-4.8/4.9 compiler ICE
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57732

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# This program is free software; you can redistribute it and/or modify
2
 
# it under the terms of the GNU General Public License as published by
3
 
# the Free Software Foundation; version 2 of the License.
4
 
#
5
 
# This program is distributed in the hope that it will be useful, but
6
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
7
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8
 
# General Public License for more details.
9
 
#
10
 
# You should have received a copy of the GNU General Public License
11
 
# along with this program; if not, write to the Free Software
12
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
13
 
# USA
14
 
 
15
 
package GenTest::Generator::FromDirectory;
16
 
 
17
 
require Exporter;
18
 
@ISA = qw(GenTest::Generator GenTest);
19
 
 
20
 
use strict;
21
 
use GenTest::Constants;
22
 
use GenTest::Generator;
23
 
 
24
 
use constant GENERATOR_DIRECTORY_NAME   => 0;
25
 
use constant GENERATOR_DIRECTORY_HANDLE => 1;
26
 
 
27
 
sub new {
28
 
        my $class = shift;
29
 
 
30
 
        my $generator = $class->SUPER::new({
31
 
                'directory_name'        => GENERATOR_DIRECTORY_NAME
32
 
        }, @_ );
33
 
 
34
 
        opendir($generator->[GENERATOR_DIRECTORY_HANDLE], $generator->[GENERATOR_DIRECTORY_NAME]) or die("Unable to open directory $generator->[GENERATOR_DIRECTORY_NAME]: $!");
35
 
        return $generator;
36
 
}
37
 
 
38
 
sub next {
39
 
        my $generator = shift;
40
 
 
41
 
        while() {
42
 
                my $next_file = readdir($generator->[GENERATOR_DIRECTORY_HANDLE]);
43
 
                if (($next_file eq '.') || ($next_file eq '..')) {
44
 
                        next;
45
 
                } elsif (not defined $next_file) {
46
 
                        closedir($generator->[GENERATOR_DIRECTORY_HANDLE]);
47
 
                        return undef;   # All files have been read
48
 
                } else {
49
 
                        my $next_file = $generator->[GENERATOR_DIRECTORY_NAME].'/'.$next_file;
50
 
                        open(QUERYFILE, $next_file) or die("Unable to open $next_file: $!");
51
 
                        read(QUERYFILE, my $query , -s $next_file);
52
 
                        chomp($query);
53
 
                        return [ $query ];
54
 
                }
55
 
        }
56
 
}
57
 
 
58
 
1;