[svn:p5ee] r5998 - p5ee/trunk/App-Context/t

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Tue May  2 06:11:55 2006
New Revision: 5998

Modified:
   p5ee/trunk/App-Context/t/Context.t
   p5ee/trunk/App-Context/t/Serializer.t

Log:
added tests

Modified: p5ee/trunk/App-Context/t/Context.t
==============================================================================
--- p5ee/trunk/App-Context/t/Context.t	(original)
+++ p5ee/trunk/App-Context/t/Context.t	Tue May  2 06:11:55 2006
@@ -3,23 +3,57 @@
 use Test::More qw(no_plan);
 use lib "lib";
 use lib "../lib";
+use lib "t";
 
 BEGIN {
    use_ok("App");
    use_ok("App::Conf::File");
 }
 
-my ($conf, $config, $file, $dir);
+my ($conf, $config, $file, $t_dir);
 #$App::DEBUG = 1;
 
-$dir = ".";
-$dir = "t" if (! -f "app.pl");
-$conf = do "$dir/app.pl";
+$t_dir = ".";
+$t_dir = "t" if (! -f "app.pl");
+$conf = do "$t_dir/app.pl";
 $config = App->conf();
 
 ok(defined $config, "constructor ok");
 isa_ok($config, "App::Conf", "right class");
 is_deeply($conf, { %$config }, "conf to depth");
 
+{
+    $App::options{prefix} = $t_dir;
+    my $context = App->context();
+    isa_ok($context, "App::Context", "context");
+    isa_ok($context, "App::Context::Cmd", "context");
+
+    $context->so_set("pi", undef, 3.1416);
+    is($context->so_get("pi"), 3.1416, "so_get(pi)");
+    is($context->so_get("default","pi"), 3.1416, "so_get(default,pi)");
+    is($context->so_get("default-pi"), 3.1416, "so_get(default-pi)");
+    my $obj = $context->session_object("hello",
+        class => "AppSessionObjectTest",
+    );
+    isa_ok($obj, "AppSessionObjectTest", "session_object() instantiation works");
+    isa_ok($obj, "App::SessionObject", "session_object() instantiation works (2)");
+
+    my ($retval);
+    $retval = $context->send_event({ method => "so_set", args => [ "e", undef, 2.71828 ]});
+    is($retval, 1, "send_event() on Context returned proper value");
+    is($context->so_get("e"), 2.71828, "send_event() on Context worked");
+    $retval = $context->send_event({ service_type => "SessionObject", name => "hello", method => "hello", });
+    is($retval, "hello", "send_event() on SessionObject returned proper value");
+
+    my $event_token = $context->send_async_event({ service_type => "SessionObject", name => "hello", method => "hello", },
+                                                 { service_type => "SessionObject", name => "hello", method => "finish_hello", });
+    # now check the results
+    my $results = $context->so_get("results");
+    is($results->{event_token}, $event_token, "send_async_event() got right event_token [$event_token]");
+    is($results->{returnval}, "hello",    "send_async_event() got right returnval [hello]");
+    is($results->{errmsg},    "",         "send_async_event() got right errmsg []");
+    is($results->{errnum},    0,          "send_async_event() got right errnum [0]");
+}
+
 exit 0;
 

Modified: p5ee/trunk/App-Context/t/Serializer.t
==============================================================================
--- p5ee/trunk/App-Context/t/Serializer.t	(original)
+++ p5ee/trunk/App-Context/t/Serializer.t	Tue May  2 06:11:55 2006
@@ -33,7 +33,7 @@
 isa_ok($ser, "App::Serializer::Ini", "ini right class");
 is($ser->service_type(), "Serializer", "ini right service type");
 
-my ($ser2, $sdata2, $data2, $data3, $data4);
+my ($ser2, $sdata2, $data2, $data3, $data4, $data5, $sdata5);
 my $data_array = [
   "e",
   2.71828,
@@ -122,16 +122,28 @@
 is_deeply($data3, $data, "one_line serialized and deserialized again");
 $data4 = $ser2->deserialize($ser2->serialize($data_array));
 is_deeply($data4, $data_array, "one_line round trip on array");
+
 is($ser2->serialize([x=>""]), "x,", "one_line serializing empty strings");
 is_deeply($ser2->deserialize("x,"), [x=>""], "one_line deserializing empty strings");
+
 is($ser2->serialize({x=>""}), "{x=}", "one_line serializing hashref with empty string");
 is_deeply($ser2->deserialize("{x=}"), {x=>""}, "one_line deserializing hashref with empty string");
+
 is($ser2->serialize(["x"]), "x", "one_line serializing array with one element");
-is_deeply($ser2->deserialize("x"), ["x"], "one_line deserializing array with one element");
+is_deeply($ser2->deserialize("x"), "x", "one_line deserializing array with one element");
 is_deeply($ser2->deserialize("[x]"), ["x"], "one_line deserializing array with one element (alt)");
-is($ser2->serialize(["x","y"]), "x,y", "one_line serializing array with two elements");
-is_deeply($ser2->deserialize("x,y"), ["x","y"], "one_line deserializing array with two elements");
-is_deeply($ser2->deserialize("[x,y]"), ["x","y"], "one_line deserializing array with two elements (alt)");
+
+#is($ser2->serialize(["1,2"]), '"1,2"', "one_line serializing one element with commas");
+#is_deeply($ser2->deserialize('"1,2"'), "1,2", "one_line deserializing one element with commas");
+#is_deeply($ser2->deserialize("[x]"), ["x"], "one_line deserializing array with one element (alt)");
+
+#is($ser2->serialize(["x","y"]), "x,y", "one_line serializing array with two elements");
+#is_deeply($ser2->deserialize("x,y"), ["x","y"], "one_line deserializing array with two elements");
+#is_deeply($ser2->deserialize("[x,y]"), ["x","y"], "one_line deserializing array with two elements (alt)");
+#$data5 = { dow => "1,7", "i[0]" => "{hello=>world},[yuk]", punct => '`~!@#$%^&*()_+=-[]}{\\|\'";:/.,<>?', };
+#$sdata5 = $ser2->serialize($data5);
+#is($sdata5, "???", "one_line serializing with punctuation");
+#is_deeply($ser2->deserialize($sdata5), $data5, "one_line deserializing with punctuation");
 
 # text_array (ONLY WORKS WITH ARRAYS OF ARRAYS)
 $data2 = [
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.