[svn:parrot] r40927 - in trunk: src/pmc t/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Sep 2 13:32:44 UTC 2009


Author: bacek
Date: Wed Sep  2 13:32:42 2009
New Revision: 40927
URL: https://trac.parrot.org/parrot/changeset/40927

Log:
[t] Add tests for PackfileSegment.type (and fix PackfileRawSegment.type implementation)

Modified:
   trunk/src/pmc/packfileconstanttable.pmc
   trunk/src/pmc/packfilefixuptable.pmc
   trunk/src/pmc/packfilerawsegment.pmc
   trunk/t/pmc/packfilerawsegment.t

Modified: trunk/src/pmc/packfileconstanttable.pmc
==============================================================================
--- trunk/src/pmc/packfileconstanttable.pmc	Wed Sep  2 13:08:09 2009	(r40926)
+++ trunk/src/pmc/packfileconstanttable.pmc	Wed Sep  2 13:32:42 2009	(r40927)
@@ -395,6 +395,20 @@
         return i;
     }
 
+/*
+
+=item C<METHOD type()>
+
+Set segment type.
+
+=cut
+
+*/
+
+    METHOD type() {
+        RETURN(INTVAL PF_CONST_SEG);
+    }
+
 
 }
 /*

Modified: trunk/src/pmc/packfilefixuptable.pmc
==============================================================================
--- trunk/src/pmc/packfilefixuptable.pmc	Wed Sep  2 13:08:09 2009	(r40926)
+++ trunk/src/pmc/packfilefixuptable.pmc	Wed Sep  2 13:32:42 2009	(r40927)
@@ -198,6 +198,20 @@
     }
 
 
+/*
+
+=item C<METHOD type()>
+
+Set segment type.
+
+=cut
+
+*/
+
+    METHOD type() {
+        RETURN(INTVAL PF_FIXUP_SEG);
+    }
+
 }
 /*
 

Modified: trunk/src/pmc/packfilerawsegment.pmc
==============================================================================
--- trunk/src/pmc/packfilerawsegment.pmc	Wed Sep  2 13:08:09 2009	(r40926)
+++ trunk/src/pmc/packfilerawsegment.pmc	Wed Sep  2 13:32:42 2009	(r40927)
@@ -197,7 +197,7 @@
 
 /*
 
-=item C<>
+=item C<METHOD type()>
 
 Set of get segment type.
 
@@ -210,12 +210,14 @@
     METHOD type(INTVAL type :optional, INTVAL got_type :opt_flag) {
         Parrot_PackfileRawSegment_attributes * attrs =
                 PARROT_PACKFILERAWSEGMENT(SELF);
+        INTVAL res;
 
         if (got_type) {
             attrs->type = type;
         }
-            
-        RETURN(INTVAL attrs->type);
+           
+        res = attrs->type;
+        RETURN(INTVAL res);
     }
 
 }

Modified: trunk/t/pmc/packfilerawsegment.t
==============================================================================
--- trunk/t/pmc/packfilerawsegment.t	Wed Sep  2 13:08:09 2009	(r40926)
+++ trunk/t/pmc/packfilerawsegment.t	Wed Sep  2 13:32:42 2009	(r40927)
@@ -22,11 +22,13 @@
 # get_integer_keyed_int doesn't return all zeroes either.
 
 .include 't/pmc/testlib/packfile_common.pir'
+.include 'packfile_segments.pasm'
 .sub 'main' :main
 .include 'test_more.pir'
-    plan(2)
+    plan(5)
     test_elements()
     test_get_integer()
+    test_type()
 .end
 
 # PackfileRawSegment.elements
@@ -60,6 +62,38 @@
     ok($I0, "PackfileRawSegment.get_integer_keyed_int returns some data")
 .end
 
+# PackfileRawSegment.type
+.sub 'test_type'
+    .local pmc pf, pfdir, pfseg, hash, it
+    pf    = _pbc()
+    pfdir = pf.'get_directory'()
+    hash  = new ['Hash']
+    # annotations.pbc contains all available segments. -1 for directory and unknown.
+    # So, in hash we should have 5 elements.
+    it = iter pfdir
+  loop:
+    unless it goto done
+    $S0 = shift it
+    $P0 = pfdir[$S0]
+    $I0 = $P0.'type'()
+    hash[$I0] = 1
+    goto loop
+
+  done:
+    $I0 = elements hash
+    is($I0, 5, "Got all types of Packfile segments")
+
+    # Now create RawSegment and set type.
+    $P0 = new ['PackfileRawSegment']
+    $I0 = $P0.'type'()
+    is($I0, .PF_BYTEC_SEG, "Default type is PF_BYTEC_SEG")
+
+    $P0.'type'(.PF_DEBUG_SEG)
+    $I0 = $P0.'type'()
+    is($I0, .PF_DEBUG_SEG, "Type successfully changed")
+
+.end
+
 
 # Local Variables:
 #   mode: cperl


More information about the parrot-commits mailing list