File: 50-fuzz-fast-mode.off

package info (click to toggle)
libmediawiki-dumpfile-perl 0.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 464 kB
  • ctags: 274
  • sloc: perl: 2,003; ansic: 508; xml: 268; sql: 47; makefile: 17; sh: 2
file content (48 lines) | stat: -rw-r--r-- 880 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use strict;
use warnings;

use MediaWiki::Dumpfile;
use MediaWiki::DumpFile::Pages;
use MediaWiki::DumpFile::FastPages;

my $input = shift(@ARGV);

my $pages = MediaWiki::DumpFile::Pages->new(input => $input, fast => 1);

my @titles;

print "generating titles\n";
while(my ($title, $text) = $pages->next) {
	push(@titles, $title);
}

while(1) {
	print "starting loop\n";
	
	my @copy = reverse(@titles);
	$pages = MediaWiki::DumpFile::Pages->new(input => $input);
	my $fast = 0;
	
	while(1) {
		my $title;
		
		if (rand(1) > .5) {
			$fast = 1;
		} else {
			$fast = 0;
		}
		
		if ($fast) {
			($title) = $pages->next($fast);
			last unless defined $title;
		} else {
			my $page = $pages->next;
			last unless defined $page;
			$title = $page->title;
		}
		
		die "failed" unless pop(@copy) eq $title;
	}
	
	die "did not read number of entries right" unless scalar(@copy) == 0;
}