Author: infinoid
Date: Sat Jul 19 09:57:02 2008
New Revision: 29610

Added:
   branches/pdd13pbc/t/pmc/packfile.t
Modified:
   branches/pdd13pbc/src/pmc/packfile.pmc
   branches/pdd13pbc/src/pmc/packfiledirectory.pmc

Log:
[PDD13]
* Implement get_directory().
* Fix get_string() so it works.
* Add the beginnings of a test script for the Packfile class.


Modified: branches/pdd13pbc/src/pmc/packfile.pmc
==============================================================================
--- branches/pdd13pbc/src/pmc/packfile.pmc      (original)
+++ branches/pdd13pbc/src/pmc/packfile.pmc      Sat Jul 19 09:57:02 2008
@@ -20,6 +20,7 @@
 */
 
 #include "parrot/parrot.h"
+#include "pmc_packfiledirectory.h"
 
 pmclass Packfile {
 
@@ -64,10 +65,10 @@
     VTABLE STRING *get_string() {
         PackFile *pf = PMC_data_typed(SELF, PackFile *);
         STRING *str = new_string_header(interp, 0);
-        opcode_t length = PackFile_pack_size(interp, pf);
+        opcode_t length = PackFile_pack_size(interp, pf) * sizeof(opcode_t);
         Parrot_allocate_string(interp, str, length);
         PackFile_pack(interp, pf, (opcode_t*)str->strstart);
-        str->bufused = length;
+        str->bufused = str->strlen = length;
         return str;
     }
 
@@ -265,8 +266,11 @@
 =cut
 
 */
-    PMC *get_directory() {
-        real_exception(interp, NULL, E_NotImplementedError, "Not implemented 
yet.");
+    METHOD get_directory() {
+        PackFile *pf = PMC_data_typed(SELF, PackFile *);
+        PMC *dir = pmc_new(interp, enum_class_PackfileDirectory);
+        VTABLE_set_pointer(interp, dir, &pf->directory);
+        RETURN(PMC *dir);
     }
 
 

Modified: branches/pdd13pbc/src/pmc/packfiledirectory.pmc
==============================================================================
--- branches/pdd13pbc/src/pmc/packfiledirectory.pmc     (original)
+++ branches/pdd13pbc/src/pmc/packfiledirectory.pmc     Sat Jul 19 09:57:02 2008
@@ -32,6 +32,23 @@
 
 /*
 
+=item C<void set_pointer(void *dir)>
+
+Initialize this object with a pointer to a Packfile_Directory.
+
+FIXME: This isn't listed as part of the PDD13 API; it is just a hack
+to get Packfile.get_directory() working.
+
+=cut
+
+*/
+    VTABLE void set_pointer(void *dir) {
+        PMC_data(SELF) = dir;
+    }
+
+
+/*
+
 =item C<STRING *pack()>
 
 Serialize the segment.

Added: branches/pdd13pbc/t/pmc/packfile.t
==============================================================================
--- (empty file)
+++ branches/pdd13pbc/t/pmc/packfile.t  Sat Jul 19 09:57:02 2008
@@ -0,0 +1,98 @@
+#!perl
+# Copyright (C) 2006-2008, The Perl Foundation.
+# $Id$
+
+use strict;
+use warnings;
+use lib qw( . lib ../lib ../../lib );
+use Test::More;
+use Parrot::Test tests => 4;
+
+=head1 NAME
+
+t/pmc/packfile.t - test the Packfile PMC
+
+
+=head1 SYNOPSIS
+
+    % prove t/pmc/packfile.t
+
+=head1 DESCRIPTION
+
+Tests the Packfile PMC.
+
+=cut
+
+
+# constructor
+
+pir_output_is( <<'CODE', <<'OUT', 'new' );
+.sub 'test' :main
+    $P0 = new 'Packfile'
+    $I0 = defined $P0
+    say $I0
+.end
+CODE
+1
+OUT
+
+
+# get_integer_keyed_str
+
+pir_output_is( <<'CODE', <<'OUT', 'get_integer_keyed_str' );
+.sub main :main
+    $P0 = new 'Packfile'
+    $S0 = 'version_major'
+    $I0 = $P0[$S0]
+    say $I0
+.end
+CODE
+0
+OUT
+
+
+# get_directory
+
+pir_output_is( <<'CODE', <<'OUT', 'get_directory' );
+.sub 'test' :main
+    $P0 = new 'Packfile'
+    $P1 = $P0.'get_directory'()
+    $I0 = defined $P1
+    say $I0
+.end
+CODE
+1
+OUT
+
+
+# get_string gives us back what set_string_native got
+
+pir_output_is( <<'CODE', <<'OUT', 'set_string_native -> get_string' );
+.sub 'test' :main
+    .include "stat.pasm"
+    $S0 = "runtime/parrot/library/uuid.pbc"
+    $I0 = stat $S0, .STAT_FILESIZE
+    $P0 = open $S0, "<"
+    $S0 = read $P0, $I0
+    close $P0
+    $P0 = new 'Packfile'
+    $P0 = $S0
+    $S1 = $P0
+    $I0 = length $S0
+    $I1 = length $S1
+    eq $I0, $I1, OUT
+    print "not "
+    OUT:
+    say "ok"
+.end
+CODE
+ok
+OUT
+
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Reply via email to