]>
git.defcon.no Git - hermes/blob - api/t/numbers.t
2 # Copyright (c) 2012, Gjøvik University College
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 # * Neither the name of the Gjøvik University College nor the
13 # names of its contributors may be used to endorse or promote products
14 # derived from this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY Gjøvik University College ''AS IS'' AND ANY
17 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 # DISCLAIMED. IN NO EVENT SHALL Gjøvik University College BE LIABLE FOR ANY
20 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 use Test
::More
'no_plan';
31 # Configuration variables defined in tests_common
32 # Make sure those are updated/set correctly..
36 # Further variables defined in tests_common:
41 my ($data, $temp, $test_number_start, $test_number_end);
43 $test_number_end .= int(rand(255))
44 while ( length( $test_number_end ) < 8 );
46 $test_number_end = substr( $test_number_end, 0, 8 );
47 $test_number_start = $test_number_end - 1;
49 $test_number_start = '+47' . $test_number_start;
50 $test_number_end = '+47' . $test_number_end;
52 isa_ok
( $g_ua, 'LWP::UserAgent', '$g_ua');
53 isa_ok
( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
57 $data = exec_apinode
("numbers/list", undef);
58 is
( $data->{'response'}, 'ok', 'numbers/list result');
59 ok
($data->{'list'}, 'numbers/list array');
62 $data = exec_apinode
("numbers/add_range", {
63 'start' => $test_number_end,
64 'end' => $test_number_start,
67 is
( $data->{'response'}, 'failed', 'numbers/add_range invalid result');
70 $data = exec_apinode
("numbers/add_range", {
71 'start' => $test_number_start,
72 'end' => $test_number_end,
74 is
( $data->{'response'}, 'ok', 'numbers/add_range result');
77 $data = exec_apinode
("numbers/inpool", { 'number' => $test_number_start, });
78 is
( $data->{'response'}, 'ok', 'numbers/inpool result');
81 $data = exec_apinode
("numbers/remove", { 'number' => $test_number_start, });
82 is
( $data->{'response'}, 'ok', 'numbers/remove 1 result');
85 $data = exec_apinode
("numbers/remove", { 'number' => $test_number_end, });
86 is
( $data->{'response'}, 'ok', 'numbers/remove 2 result');
89 $data = exec_apinode
("numbers/add", { 'number' => $test_number_start, });
90 is
( $data->{'response'}, 'ok', 'numbers/add result');
93 $data = exec_apinode
("numbers/remove", { 'number' => $test_number_start, });
94 is
( $data->{'response'}, 'ok', 'numbers/remove 3 result');
97 $data = exec_apinode
("numbers/inpool", { 'number' => $test_number_start, });
98 is
( $data->{'response'}, 'failed', 'numbers/remove inpool removed');
101 $data = exec_apinode
("numbers/remove", { 'number' => $test_number_start, });
102 is
( $data->{'response'}, 'failed', 'numbers/remove invalid remove result');