Git Product home page Git Product logo

Comments (5)

syohex avatar syohex commented on June 1, 2024

Could you show us test code of this issue ? It is hard to understand without code.

from msgpack-perl.

vicky22291 avatar vicky22291 commented on June 1, 2024
package GenericPacker;
use strict;
use warnings;
use Data::MessagePack;

sub pack_bean {
    my (@stream)  = @_;
    my $msgpack = Data::MessagePack->new();
    my $needed = 1;
    $msgpack->prefer_integer();
    my $packed_bean = $msgpack->pack( \@stream );
    return $packed_bean;
}

sub unpack_bean {
    my ($unpackable_bean) = @_;
    my $msgpack           = Data::MessagePack->new()->utf8(1);
    return $msgpack->unpack($unpackable_bean);
}
1;

Is the actual code being tested.

#!/usr/bin/perl -w
use strict;
use warnings;
use Encode qw(decode encode);
use Test::More tests => 1;
use Data::Dumper;
my $actual = TestHelper::create_sample_data();
my $packed_bean = GenericPacker::pack_bean($actual);
my $final = GenericPacker::unpack_bean($packed_bean);
ok(1);

Is the test code

from msgpack-perl.

syohex avatar syohex commented on June 1, 2024

What is TestHelper module ?

from msgpack-perl.

vicky22291 avatar vicky22291 commented on June 1, 2024

Sorry for the number of iterations on the issue. I am providing a sample code similar to my main code, I couldn't link to the main code, because of some policies in my company.

package MainInput;
use strict;
use warnings;

sub new {
    my $class = shift;
    my $self = {
                 _field1                => shift,
                 _field2 => shift,
                 _field3               => shift
    };
    bless $self, $class;
    return $self;
}

sub set_field1 {
    my ( $self, $field1 ) = @_;
    $self->{_field1} = $field1 if defined $field1;
}

sub get_field1 {
    my ($self) = @_;
    return $self->{_field1};
}

sub has_field1 {
    my ($self) = @_;
    if ( defined $self->{_field1} ) {
        return 1;
    } else {
        return 0;
    }
}

sub set_field2 {
    my ( $self, $field2 ) = @_;
    $self->{_field2} = $field2
      if defined $field2;
}

sub get_field2 {
    my ($self) = @_;
    return $self->{_field2};
}

sub has_field2 {
    my ($self) = @_;
    if ( defined $self->{_field2} ) {
        return 1;
    } else {
        return 0;
    }
}

sub set_field3 {
    my ( $self, $field3 ) = @_;
    $self->{_field3} = $field3 if defined $field3;
}

sub get_field3 {
    my ($self) = @_;
    return $self->{_field3};
}

sub has_field3 {
    my ($self) = @_;
    if ( defined $self->{_field3} ) {
        return 1;
    } else {
        return 0;
    }
}
1;
package FieldInput;
use strict;
use warnings;

sub new {
    my $class = shift;
    my $self = {
                 _field1 => shift,
                 _field2 => shift
    };
    bless $self, $class;
    return $self;
}

sub set_field1 {
    my ( $self, $field1 ) = @_;
    $self->{_field1} = $field1 if defined $field1;
}

sub get_field1 {
    my ($self) = @_;
    return $self->{_field1};
}

sub has_field1 {
    my ($self) = @_;
    if ( defined $self->{_field1} ) {
        return 1;
    } else {
        return 0;
    }
}

sub set_field2 {
    my ( $self, $field2 ) = @_;
    $self->{_field2} = $field2
      if defined $field2;
}

sub get_field2 {
    my ($self) = @_;
    return $self->{_field2};
}

sub has_field2 {
    my ($self) = @_;
    if ( defined $self->{_field2} ) {
        return 1;
    } else {
        return 0;
    }
}
1;

Are the Pojo like modules.

package TestHelper;
use constant FIELD1 => 1;
use constant FIELD2 => 2;
use constant FIELD3 => 3;

sub create_sample_input {
    my $actual = MainInput->new();
    $actual->set_field2( "SomeText" );
    my $rpc = FieldInput->new();
    $rpc->set_operation( "SomeText" );
    $rpc->set_service( "SomeText" );
    $actual->set_field1($rpc);
    my $auth = FieldInput->new();
    $auth->set_encrypted(1);
    $auth->set_signed(1);
    $actual->set_field3($auth);
    return $actual;
}

sub create_sample_value {
    my $input = create_sample_input();

    @stream = ();
    push @stream, [];
    if($input->has_field1()) {
        push @stream, [FIELD1, [[], [FIELD1, $input->get_field1()->get_field1()], [FIELD2, $input->get_field1()->get_field2()]]];
    }
    if($input->has_field2()) {
        push @stream, [FIELD2, $input->get_field2()];
    }
    if($input->has_field3()) {
        push @stream, [FIELD3, [[], [FIELD1, $input->get_field3()->get_field1()], [FIELD2, $input->get_field3()->get_field2()]]];
    }

    return \@stream;
}
1;

Is the test helper.

from msgpack-perl.

syohex avatar syohex commented on June 1, 2024

Your test does not work.

  • TestHelper::create_sample_data is not defined
  • FieldInput::set_operation is not defined
  • FieldInput::set_service is not defined
  • FieldInput::set_encrypted is not defined
  • FieldInput::set_signed is not defined
  • Your test passes blessed object type to Data::MessagePack methods. Data::MessagePack can take basic data types
  • etc

Please create minimized test which works on everywhere. And write failing tests(What value is expected ? What is Data::MessagePack wrong ?). Your test is always passed because it uses only ok(1);.

from msgpack-perl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.