| 1 | #!/usr/bin/perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use QWizard::Storage::Memory; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 2 | ▶ | $maxtests = 15 if (!$maxtests); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | ▶ | use Test::More tests => $maxtests || 15; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$maxtests || 15
MC/DC0%0/1
$maxtests || 15
$maxtests
Truth table50%1/2
A
A= $maxtests
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | # 1: basic object exist | ||||||||||||||||||||
| 10 | 2 | ok(defined($stobj), "defined"); | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | # 2: basic set/get retrival | ||||||||||||||||||||
| 13 | 2 | $stobj->set('test1','value1'); | |||||||||||||||||||
| 14 | 2 | ok($stobj->get('test1') eq 'value1', "value set and retrieved"); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 2 | ▶ | exit if ($maxtests == 2); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | # 3-5: testing get_all() returning a hash | ||||||||||||||||||||
| 19 | 2 | my $hash = $stobj->get_all(); | |||||||||||||||||||
| 20 | 2 | ok(ref($hash) eq 'HASH', "get_all returns hash"); | |||||||||||||||||||
| 21 | 2 | ok($hash->{'test1'} eq 'value1', "get_all test hash value"); | |||||||||||||||||||
| 22 | 2 | my @keys = keys(%$hash); | |||||||||||||||||||
| 23 | 2 | ok($#keys == 0, "correct number of hash elements returned"); | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | # 6-9: testing set_all() to clear everything out with new stuff | ||||||||||||||||||||
| 26 | 2 | $stobj->set_all({ newtoken => 'newval'}); | |||||||||||||||||||
| 27 | 2 | ok($stobj->get('newtoken') eq 'newval', "retrieved new val after set_all"); | |||||||||||||||||||
| 28 | 2 | $hash = $stobj->get_all(); | |||||||||||||||||||
| 29 | 2 | ok(ref($hash) eq 'HASH', "get_all returned hash (again)"); | |||||||||||||||||||
| 30 | 2 | ok($hash->{'newtoken'} eq 'newval', "get_all returned the new hash value after set_all"); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | SKIP: | ||||||||||||||||||||
| 33 | { | ||||||||||||||||||||
| 34 | 2 | ▶ | skip "expectedly fails for the CGIParam generator", 1 | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | if (ref($stobj) eq 'xxxQWizard::Storage::CGIParam'); | ||||||||||||||||||||
| 36 | 2 | @keys = keys(%$hash); | |||||||||||||||||||
| 37 | 2 | ok($#keys == 0, "correct number of hash elements returned after set_all"); | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | # 10-11: reset | ||||||||||||||||||||
| 42 | 2 | $stobj->reset(); | |||||||||||||||||||
| 43 | 2 | $hash = $stobj->get_all(); | |||||||||||||||||||
| 44 | 2 | ok(ref($hash) eq 'HASH', "get_all still returned hash after reset"); | |||||||||||||||||||
| 45 | SKIP: | ||||||||||||||||||||
| 46 | { | ||||||||||||||||||||
| 47 | 2 | ▶ | skip "expectedly fails for the CGIParam generator", 1 | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | if (ref($stobj) eq 'xxxQWizard::Storage::CGIParam'); | ||||||||||||||||||||
| 49 | 2 | @keys = keys(%$hash); | |||||||||||||||||||
| 50 | 2 | ok($#keys == -1, "hash returned from get_all is now empty"); | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 2 | my $newmemobj = new QWizard::Storage::Memory(); | |||||||||||||||||||
| 54 | 2 | $newmemobj->set('myname','Wes'); | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | # 12: copy_from | ||||||||||||||||||||
| 57 | 2 | $stobj->copy_from($newmemobj); | |||||||||||||||||||
| 58 | 2 | ok($stobj->get('myname') eq 'Wes', "retrieved new value after copy_from"); | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | # 13: to_string | ||||||||||||||||||||
| 61 | SKIP: | ||||||||||||||||||||
| 62 | { | ||||||||||||||||||||
| 63 | 2 | ▶ | skip "expectedly fails for the CGIParam generator", 2 | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | if (ref($stobj) eq 'xxxQWizard::Storage::CGIParam'); | ||||||||||||||||||||
| 65 | 2 | $stobj->set('othername','Yamar'); | |||||||||||||||||||
| 66 | 2 | my $str = $stobj->to_string; | |||||||||||||||||||
| 67 | 2 | ▶ | ok($str eq 'myname_-Wes_-othername_-Yamar' || | ||||||||||||||||||
|
Condition33%1/3
$str eq 'myname_-Wes_-othername_-Yamar' || $str eq 'othername_-Yamar_-myname_-Wes'
MC/DC0%0/2
$str eq 'myname_-Wes_-othername_-Yamar' || $str eq 'othername_-Yamar_-myname_-Wes'
$str eq 'myname_-Wes_-othername_-Yamar'
$str eq 'othername_-Yamar_-myname_-Wes'
Truth table33%1/3
A || B
A= $str eq 'myname_-Wes_-othername_-Yamar'B= $str eq 'othername_-Yamar_-myname_-Wes'
| |||||||||||||||||||||
| 68 | $str eq 'othername_-Yamar_-myname_-Wes', "Encoding to a string works"); | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | # 14: from_string | ||||||||||||||||||||
| 71 | 2 | $stobj->reset(); | |||||||||||||||||||
| 72 | 2 | $stobj->from_string($str); | |||||||||||||||||||
| 73 | 2 | ok($stobj->get('myname') eq 'Wes', "Parsing from a string works"); | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | # 15: access wrapper | ||||||||||||||||||||
| 77 | 2 | $stobj->access('myname', 'Wesley'); | |||||||||||||||||||
| 78 | 2 | ok($stobj->access('myname') eq 'Wesley', "The generic access() wrapper works"); | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | # | ||||||||||||||||||||
| 81 | # NOTE: must end with myname eq 'Wesley' for file-read test to succeed. | ||||||||||||||||||||
| 82 | # | ||||||||||||||||||||