All the tests now pass with the broken out classes
[dbsrgits/DBM-Deep.git] / t / 13_setpack.t
index 8f6d2cc..293806c 100644 (file)
@@ -2,12 +2,13 @@
 # DBM::Deep Test
 ##
 use strict;
-use Test::More tests => 4;
+use Config;
+use Test::More tests => 10;
 use t::common qw( new_fh );
 
 use_ok( 'DBM::Deep' );
 
-my ($before, $after);
+my ($default, $small, $medium, $large);
 
 {
     my ($fh, $filename) = new_fh();
@@ -17,7 +18,34 @@ my ($before, $after);
     );
     $db->{key1} = "value1";
     $db->{key2} = "value2";
-    $before = (stat($db->_fh()))[7];
+    $default = (stat($filename))[7];
+}
+
+{
+    my ($fh, $filename) = new_fh();
+    {
+        my $db = DBM::Deep->new(
+            file => $filename,
+            autoflush => 1,
+            pack_size => 'medium',
+        );
+
+        $db->{key1} = "value1";
+        $db->{key2} = "value2";
+        $medium = (stat($filename))[7];
+    }
+
+    # This tests the header to verify that the pack_size is really there
+    {
+        my $db = DBM::Deep->new(
+            file => $filename,
+        );
+
+        is( $db->{key1}, 'value1', 'Can read key1' );
+        is( $db->{key2}, 'value2', 'Can read key2' );
+    }
+
+    cmp_ok( $medium, '==', $default, "The default is medium" );
 }
 
 {
@@ -31,7 +59,40 @@ my ($before, $after);
 
         $db->{key1} = "value1";
         $db->{key2} = "value2";
-        $after = (stat($db->_fh()))[7];
+        $small = (stat($filename))[7];
+    }
+
+    # This tests the header to verify that the pack_size is really there
+    {
+        my $db = DBM::Deep->new(
+            file => $filename,
+        );
+
+        is( $db->{key1}, 'value1', 'Can read key1' );
+        is( $db->{key2}, 'value2', 'Can read key2' );
+    }
+
+    cmp_ok( $medium, '>', $small, "medium is greater than small" );
+}
+
+eval "pack('Q', 0);";
+my $haveQ = !$@;
+
+SKIP: {
+    skip "Largefile support is not compiled into $^X", 3
+        unless $haveQ;
+
+    my ($fh, $filename) = new_fh();
+    {
+        my $db = DBM::Deep->new(
+            file => $filename,
+            autoflush => 1,
+            pack_size => 'large',
+        );
+
+        $db->{key1} = "value1";
+        $db->{key2} = "value2";
+        $large = (stat($filename))[7];
     }
 
     # This tests the header to verify that the pack_size is really there
@@ -43,6 +104,20 @@ my ($before, $after);
         is( $db->{key1}, 'value1', 'Can read key1' );
         is( $db->{key2}, 'value2', 'Can read key2' );
     }
+    cmp_ok( $medium, '<', $large, "medium is smaller than large" );
 }
 
-cmp_ok( $after, '<', $before, "The new packsize reduced the size of the file" );
+#SKIP: {
+#    skip "Largefile support is compiled into $^X", 3
+#        if $haveQ;
+#
+#    my ($fh, $filename) = new_fh();
+#    {
+#        my $db = DBM::Deep->new(
+#            file => $filename,
+#            autoflush => 1,
+#            pack_size => 'large',
+#        );
+#    }
+#
+#}