ActorListTest.pm
上传用户:market2
上传日期:2018-11-18
资源大小:18786k
文件大小:3k
源码类别:

外挂编程

开发平台:

Windows_Unix

  1. package ActorListTest;
  2. # TODO: write test for deepCopy()
  3. use strict;
  4. use Test::More;
  5. use ActorList;
  6. use Actor::Player;
  7. use ObjectListTest;
  8. use base qw(ObjectListTest);
  9. sub start {
  10. print "### Starting ActorListTestn";
  11. ActorListTest->new()->run();
  12. }
  13. #########################
  14. my $count = 0;
  15. sub run {
  16. my ($self) = @_;
  17. $self->SUPER::run();
  18. $self->testGetAndRemoveByID();
  19. }
  20. # overloaded
  21. sub init {
  22. my ($self) = @_;
  23. $self->{list} = new ActorList('Actor::Player');
  24. for (my $i = 1; $i <= 6; $i++) {
  25. $self->{"item$i"} = $self->createTestObject();
  26. }
  27. is($self->{list}->size(), 0);
  28. $self->{list}->checkValidity();
  29. }
  30. # overloaded
  31. sub createTestObject {
  32. my $actor = new Actor::Player();
  33. $count++;
  34. $actor->{ID} = pack("V", $count);
  35. return $actor;
  36. }
  37. # overloaded
  38. sub testDuplicate {
  39. # Do nothing; ActorList doesn't allow duplicates.
  40. }
  41. sub testGetAndRemoveByID {
  42. my ($self) = @_;
  43. $self->init();
  44. my $list = $self->{list};
  45. $list->add($self->{item1});
  46. $list->add($self->{item2});
  47. $list->add($self->{item3});
  48. is($list->size(), 3);
  49. ok($list->getByID($self->{item1}{ID}) == $self->{item1});
  50. ok($list->getByID($self->{item2}{ID}) == $self->{item2});
  51. ok($list->getByID($self->{item3}{ID}) == $self->{item3});
  52. ok(!defined $list->getByID($self->{item4}{ID}));
  53. ok(!defined $list->getByID($self->{item5}{ID}));
  54. ok(!defined $list->getByID($self->{item6}{ID}));
  55. $list->checkValidity();
  56. my $result = $list->removeByID($self->{item2}{ID});
  57. ok($result);
  58. is($list->size(), 2);
  59. ok($list->getByID($self->{item1}{ID}) == $self->{item1});
  60. ok(!defined $list->getByID($self->{item2}{ID}));
  61. ok($list->getByID($self->{item3}{ID}) == $self->{item3});
  62. ok(!defined $list->getByID($self->{item4}{ID}));
  63. ok(!defined $list->getByID($self->{item5}{ID}));
  64. ok(!defined $list->getByID($self->{item6}{ID}));
  65. $list->checkValidity();
  66. my $result = $list->removeByID($self->{item2}{ID});
  67. ok(!$result);
  68. is($list->size(), 2);
  69. ok($list->getByID($self->{item1}{ID}) == $self->{item1});
  70. ok(!defined $list->getByID($self->{item2}{ID}));
  71. ok($list->getByID($self->{item3}{ID}) == $self->{item3});
  72. ok(!defined $list->getByID($self->{item4}{ID}));
  73. ok(!defined $list->getByID($self->{item5}{ID}));
  74. ok(!defined $list->getByID($self->{item6}{ID}));
  75. $list->checkValidity();
  76. my $result = $list->removeByID($self->{item4}{ID});
  77. ok(!$result);
  78. is($list->size(), 2);
  79. ok($list->getByID($self->{item1}{ID}) == $self->{item1});
  80. ok(!defined $list->getByID($self->{item2}{ID}));
  81. ok($list->getByID($self->{item3}{ID}) == $self->{item3});
  82. ok(!defined $list->getByID($self->{item4}{ID}));
  83. ok(!defined $list->getByID($self->{item5}{ID}));
  84. ok(!defined $list->getByID($self->{item6}{ID}));
  85. $list->checkValidity();
  86. }
  87. 1;