Ancient
view release on metacpan or search on metacpan
t/8003-file-mmap.t view on Meta::CPAN
subtest 'mmap medium file' => sub {
my $file = "$tmpdir/mmap_medium.txt";
my $content = "x" x 10000; # 10KB
file::spew($file, $content);
my $mmap = file::mmap_open($file);
ok($mmap, 'mmap medium file');
is(length($mmap->data), 10000, 'medium file length');
$mmap->close;
};
subtest 'mmap large file' => sub {
my $file = "$tmpdir/mmap_large.txt";
my $content = "x" x (1024 * 100); # 100KB
file::spew($file, $content);
my $mmap = file::mmap_open($file);
ok($mmap, 'mmap large file');
is(length($mmap->data), 1024 * 100, 'large file length');
$mmap->close;
};
# ============================================
# mmap empty file (should fail gracefully)
# ============================================
subtest 'mmap empty file' => sub {
my $file = "$tmpdir/mmap_empty.txt";
file::spew($file, "");
my $mmap = file::mmap_open($file);
ok(!defined($mmap), 'mmap empty file returns undef');
};
# ============================================
# mmap nonexistent file
# ============================================
subtest 'mmap nonexistent file' => sub {
my $mmap = file::mmap_open("$tmpdir/nonexistent_mmap.txt");
ok(!defined($mmap), 'mmap nonexistent returns undef');
};
# ============================================
# Writable mmap
# ============================================
subtest 'writable mmap' => sub {
my $file = "$tmpdir/mmap_writable.txt";
my $original = "Original content here";
file::spew($file, $original);
# Open for writing
my $mmap = file::mmap_open($file, 1); # 1 = writable
ok($mmap, 'writable mmap opened');
my $data = $mmap->data;
is($data, $original, 'initial data correct');
# Sync (just verify it doesn't crash)
$mmap->sync;
pass('sync completed');
$mmap->close;
};
# ============================================
# Multiple mmaps to same file
# ============================================
subtest 'multiple mmaps same file' => sub {
my $file = "$tmpdir/mmap_multi.txt";
file::spew($file, "shared content");
my $mmap1 = file::mmap_open($file);
my $mmap2 = file::mmap_open($file);
ok($mmap1 && $mmap2, 'both mmaps opened');
is($mmap1->data, $mmap2->data, 'both see same content');
$mmap1->close;
is($mmap2->data, "shared content", 'mmap2 still works after mmap1 closed');
$mmap2->close;
};
# ============================================
# mmap with binary content
# ============================================
subtest 'mmap binary content' => sub {
my $file = "$tmpdir/mmap_binary.dat";
my $binary = join('', map { chr($_) } 0..255);
file::spew($file, $binary);
my $mmap = file::mmap_open($file);
ok($mmap, 'mmap binary file');
my $data = $mmap->data;
is(length($data), 256, 'binary length correct');
is($data, $binary, 'binary content matches');
$mmap->close;
};
# ============================================
# mmap data access
# ============================================
subtest 'mmap data access' => sub {
my $file = "$tmpdir/mmap_access.txt";
file::spew($file, "access test content");
my $mmap = file::mmap_open($file);
my $data = $mmap->data;
# Verify data is correct
is($data, "access test content", 'mmap data is accessible');
ok(defined($data), 'mmap data is defined');
$mmap->close;
( run in 0.909 second using v1.01-cache-2.11-cpan-ecdf5575e8d )