On Sat, 23 Apr 2005, Stas Bekman wrote:
> Randy Kobes wrote:
[ .. ]
> > That'd be nice to clean this up ... I'm wondering
> > though about having, in particular, apr-ext tests for
> > socket.pm
> > sockaddr.pm
> > brigade.pm
> > that simply load the modules. In looking at the corrsponding
> > responses in t/response/TestAPR/, it appears in their
> > current form that all 3 of these require mod_perl to do
> > their work. Might having a corresponding apr-ext test lead
> > some to believe that these function outside of mod_perl, and
> > so in this context their presence could be considered
> > somewhat misleading?
>
> That's correct for the socket modules, as there is no way
> to get the apr socket at the moment but via mod_perl. but
> what's wrong with brigade API? you can create one
> yourself:
>
> $bb = APR::Brigade->new($pool, APR::BucketAlloc->new($pool));
That's right - I don't know why I didn't recognize this
at the time we were refactoring the apr/apr-ext tests.
How about the following diff, which adds a brigade test
to apr-ext?
=================================================================
Index: t/apr-ext/brigade.t
===================================================================
--- t/apr-ext/brigade.t (revision 0)
+++ t/apr-ext/brigade.t (revision 0)
@@ -0,0 +1,11 @@
+#!perl -T
+
+use strict;
+use warnings FATAL => 'all';
+use Apache::Test;
+
+use TestAPRlib::brigade;
+
+plan tests => TestAPRlib::brigade::num_of_tests();
+
+TestAPRlib::brigade::test();
Property changes on: t/apr-ext/brigade.t
___________________________________________________________________
Name: svn:eol-style
+ native
Index: t/response/TestAPR/brigade.pm
===================================================================
--- t/response/TestAPR/brigade.pm (revision 164419)
+++ t/response/TestAPR/brigade.pm (working copy)
@@ -16,13 +16,17 @@
use Apache2::Const -compile => 'OK';
+use TestAPRlib::brigade;
+
sub handler {
my $r = shift;
my $ba = $r->connection->bucket_alloc;
- plan $r, tests => 14;
+ plan $r, tests => 14 + TestAPRlib::brigade::num_of_tests();
+ TestAPRlib::brigade::test();
+
# basic + pool + destroy
{
my $bb = APR::Brigade->new($r->pool, $ba);
Index: t/lib/TestAPRlib/brigade.pm
===================================================================
--- t/lib/TestAPRlib/brigade.pm (revision 0)
+++ t/lib/TestAPRlib/brigade.pm (revision 0)
@@ -0,0 +1,106 @@
+package TestAPRlib::brigade;
+
+# testing APR::Brigade in this tests.
+# Other tests do that too:
+# TestAPR::flatten : flatten()
+# TestAPR::bucket : is_empty(), first(), last()
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestUtil;
+
+use APR::Pool ();
+use APR::Brigade ();
+use APR::Bucket ();
+use APR::BucketAlloc ();
+
+use Apache2::Const -compile => 'OK';
+
+sub num_of_tests {
+ return 14;
+}
+
+sub test {
+
+ my $p = APR::Pool->new();
+ my $ba = APR::BucketAlloc->new($p);
+
+ # basic + pool + destroy
+ {
+ my $bb = APR::Brigade->new($p, $ba);
+
+ t_debug('$bb is defined');
+ ok defined $bb;
+
+ t_debug('$bb ISA APR::Brigade object');
+ ok $bb->isa('APR::Brigade');
+
+ my $pool = $bb->pool;
+
+ t_debug('$pool is defined');
+ ok defined $pool;
+
+ t_debug('$pool ISA APR::Pool object');
+ ok $pool->isa('APR::Pool');
+
+ t_debug("destroy");
+ $bb->destroy;
+ ok 1;
+ }
+
+ # concat / split / length / flatten
+ {
+ my $bb1 = APR::Brigade->new($p, $ba);
+ $bb1->insert_head(APR::Bucket->new($ba, "11"));
+ $bb1->insert_tail(APR::Bucket->new($ba, "12"));
+
+ my $bb2 = APR::Brigade->new($p, $ba);
+ $bb2->insert_head(APR::Bucket->new($ba, "21"));
+ $bb2->insert_tail(APR::Bucket->new($ba, "22"));
+
+ # concat
+ $bb1->concat($bb2);
+ # bb1: 11, 12, 21, 22
+ ok t_cmp($bb1->length, 8, "total data length in bb");
+ my $len = $bb1->flatten(my $data);
+ ok t_cmp($len, 8, "bb flatten/len");
+ ok t_cmp($data, "11122122", "bb flatten/data");
+ t_debug('$bb2 is empty');
+ ok $bb2->is_empty;
+
+ # split
+ my $b = $bb1->first; # 11
+ $b = $bb1->next($b); # 12
+ my $bb3 = $bb1->split($b);
+
+ # bb1: 11, bb3: 12, 21, 22
+ $len = $bb1->flatten($data);
+ ok t_cmp($len, 2, "bb1 flatten/len");
+ ok t_cmp($data, "11", "bb1 flatten/data");
+ $len = $bb3->flatten($data);
+ ok t_cmp($len, 6, "bb3 flatten/len");
+ ok t_cmp($data, "122122", "bb3 flatten/data");
+ }
+
+ # out-of-scope pools
+ {
+ my $bb1 = APR::Brigade->new(APR::Pool->new, $ba);
+ $bb1->insert_head(APR::Bucket->new($ba, "11"));
+ $bb1->insert_tail(APR::Bucket->new($ba, "12"));
+
+ # try to overwrite the temp pool data
+ require APR::Table;
+ my $table = APR::Table::make(APR::Pool->new, 50);
+ $table->set($_ => $_) for 'aa'..'za';
+ # now test that we are still OK
+
+ my $len = $bb1->flatten(my $data);
+ ok t_cmp($data, "1112", "correct data");
+ }
+
+ Apache2::Const::OK;
+}
+
+1;
Property changes on: t/lib/TestAPRlib/brigade.pm
___________________________________________________________________
Name: svn:eol-style
+ native
====================================================================
--
best regards,
randy
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]