shlist

share and manage lists between multiple people
Log | Files | Refs

commit 9684ad15fecf2a1a1cfaac6529c84f3396398d9a
parent 51f0961d5980da9a7fc61b2500fdf00ce8557dd0
Author: kyle <kyle@0x30.net>
Date:   Sun, 10 Jan 2016 18:48:09 -0700

tests: make client->new() automatically call device_add

- so many tests just want a registered device to start with
- so make this the default
  - to not register when calling ->new(), pass 1 as the only argument
    (eg ->new(1))

Diffstat:
Mserver/tests/client.pm | 7+++++++
Mserver/tests/device_add/test.pl | 5++---
Mserver/tests/friend_add/test.pl | 1-
Mserver/tests/friend_delete/test.pl | 3---
Mserver/tests/friend_delete_unit/test.pl | 1-
Mserver/tests/header/test.pl | 10+++++-----
Mserver/tests/list_add/test.pl | 1-
Mserver/tests/list_join/test.pl | 3---
Mserver/tests/list_join_unit/test.pl | 1-
Mserver/tests/list_leave/test.pl | 1-
Mserver/tests/list_leave_unit/test.pl | 1-
Mserver/tests/list_reference_counting/test.pl | 3---
Mserver/tests/lists_get/test.pl | 2+-
Mserver/tests/lists_get_other/test.pl | 3---
Mserver/tests/multiple_friends_same_other_list/test.pl | 4----
Mserver/tests/two_lists_same_name/test.pl | 1-
16 files changed, 15 insertions(+), 32 deletions(-)

diff --git a/server/tests/client.pm b/server/tests/client.pm @@ -13,6 +13,7 @@ our (%msg_num, @msg_str); sub new { my $class = shift; + my $dont_register = shift || 0; my $self = {}; bless ($self, $class); @@ -45,6 +46,12 @@ sub new { # make sure we don't try and use this without setting it $self->{device_id} = undef; + + # By default register this device immediately + if ($dont_register == 0) { + $self->device_add(rand_phnum()); + } + return $self; } diff --git a/server/tests/device_add/test.pl b/server/tests/device_add/test.pl @@ -5,10 +5,9 @@ use warnings; use client; use test; -my $A = client->new(); # basic sanity check on the device_add message type -$A->device_add(my $phnum = rand_phnum()); - +my $A = client->new(); +my $phnum = $A->phnum; my $devid = $A->device_id(); my $length = length($devid); fail "device id '$devid' not base64" unless ($devid =~ m/^[a-zA-Z0-9+\/=]+$/); diff --git a/server/tests/friend_add/test.pl b/server/tests/friend_add/test.pl @@ -6,7 +6,6 @@ use client; use test; my $A = client->new(); -$A->device_add(rand_phnum()); # first verify that a normal add_friend message succeeds $A->friend_add('54321'); diff --git a/server/tests/friend_delete/test.pl b/server/tests/friend_delete/test.pl @@ -9,9 +9,6 @@ use test; my $A = client->new(); my $B = client->new(); -$A->device_add(rand_phnum()); -$B->device_add(rand_phnum()); - # A friends B, B friends A $A->friend_add($B->phnum()); $B->friend_add($A->phnum()); diff --git a/server/tests/friend_delete_unit/test.pl b/server/tests/friend_delete_unit/test.pl @@ -5,7 +5,6 @@ use client; use test; my $A = client->new(); -$A->device_add(rand_phnum()); # try deleting someone who is not your friend $A->friend_delete('12345', 'err'); diff --git a/server/tests/header/test.pl b/server/tests/header/test.pl @@ -8,21 +8,21 @@ use client; # server will disconnect on header errors. # send an invalid message number -my $client = client->new(); +my $client = client->new(1); $client->send_all(pack('nnn', 0, 47837, 0), 6); # send a bad protocol version -$client = client->new(); +$client = client->new(1); $client->send_all(pack('nnn', 101, 0, 0), 6); # send a message length that's too long -$client = client->new(); +$client = client->new(1); $client->send_all(pack('nnn', 0, 0, 25143), 6); # send a message length that's larger than the actual data sent -$client = client->new(); +$client = client->new(1); $client->send_all(pack('nnnZ*', 0, 0, 5, 'ab'), 9); # send a partial header -$client = client->new(); +$client = client->new(1); $client->send_all(pack('nn', 101, 69), 4); diff --git a/server/tests/list_add/test.pl b/server/tests/list_add/test.pl @@ -7,7 +7,6 @@ use test; use Data::Dumper; my $A = client->new(); -$A->device_add(rand_phnum()); # make sure normal list_add works $A->list_add(my $name = 'this is a new list'); diff --git a/server/tests/list_join/test.pl b/server/tests/list_join/test.pl @@ -8,9 +8,6 @@ use test; my $A = client->new(); my $B = client->new(); -$A->device_add(rand_phnum()); -$B->device_add(rand_phnum()); - # make A and B mutual friends $A->friend_add($B->phnum()); $B->friend_add($A->phnum()); diff --git a/server/tests/list_join_unit/test.pl b/server/tests/list_join_unit/test.pl @@ -6,7 +6,6 @@ use client; use test; my $A = client->new(); -$A->device_add(rand_phnum()); # try joining a list that doesn't exist $A->list_join('somenonexistentlist', 'err'); diff --git a/server/tests/list_leave/test.pl b/server/tests/list_leave/test.pl @@ -6,7 +6,6 @@ use client; use test; my $A = client->new(); -$A->device_add(rand_phnum()); $A->list_add('this list was made for leaving'); $A->list_leave($A->lists(0)->{id}); diff --git a/server/tests/list_leave_unit/test.pl b/server/tests/list_leave_unit/test.pl @@ -6,7 +6,6 @@ use client; use test; my $A = client->new(); -$A->device_add(); # try leaving a list your not in $A->list_leave('somenonexistentlistid', 'err'); diff --git a/server/tests/list_reference_counting/test.pl b/server/tests/list_reference_counting/test.pl @@ -6,11 +6,8 @@ use client; use test; # test list reference counting to make sure they stay alive when needed - my $A = client->new(); my $B = client->new(); -$A->device_add(rand_phnum()); -$B->device_add(rand_phnum()); # A creates a new list $A->list_add('this list will belong to B soon enough'); diff --git a/server/tests/lists_get/test.pl b/server/tests/lists_get/test.pl @@ -12,7 +12,7 @@ use test; # - checks that what's received is what was sent my $A = client->new(); -$A->device_add(my $phnum = rand_phnum()); +my $phnum = $A->phnum(); for ('new list 1', 'new list 2', 'new list 3') { $A->list_add($_); diff --git a/server/tests/lists_get_other/test.pl b/server/tests/lists_get_other/test.pl @@ -14,9 +14,6 @@ use test; my $A = client->new(); my $B = client->new(); -$A->device_add(rand_phnum()); -$B->device_add(rand_phnum()); - $A->friend_add($B->phnum()); $B->friend_add($A->phnum()); diff --git a/server/tests/multiple_friends_same_other_list/test.pl b/server/tests/multiple_friends_same_other_list/test.pl @@ -13,10 +13,6 @@ my $A = client->new(); my $B = client->new(); my $C = client->new(); -$A->device_add(rand_phnum()); -$B->device_add(rand_phnum()); -$C->device_add(rand_phnum()); - # A and B are mutual friends $A->friend_add($B->phnum()); $B->friend_add($A->phnum()); diff --git a/server/tests/two_lists_same_name/test.pl b/server/tests/two_lists_same_name/test.pl @@ -6,7 +6,6 @@ use client; use test; my $A = client->new(); -$A->device_add(rand_phnum()); # check that adding the same list twice works my $name = 'some list thats going to be added twice';