package TestCase::Object {
  use TestCase::Destructor;
  use SPVM::Util (INT8_MIN, INT8_MAX, INT16_MIN, INT16_MAX, INT32_MIN, INT32_MAX, INT64_MIN, INT64_MAX, FLT_MIN, FLT_MAX, DBL_MIN, DBL_MAX);
  
  has INT32_MAX : int;
  has next : int;

  sub core_func_name_field_name : int () {
    my $self = new TestCase::Object;
    $self->{INT32_MAX} = 1;
    
    unless ($self->{INT32_MAX} == 1) {
      return 0;
    }
    
    return 1;
  }

  sub reserved_word_field_name : int () {
    my $self = new TestCase::Object;
    $self->{next} = 1;
    
    unless ($self->{next} == 1) {
      return 0;
    }
    
    return 1;
  }
  
  sub FLOAT_PRECICE : float () { return 16384.5f; }
  sub DOUBLE_PRECICE : double () { return 65536.5; }

  sub isa_basic : int () {
    my $minimal = TestCase::Minimal->new;
    if ($minimal isa TestCase::Minimal) {
      if (!($minimal isa TestCase)) {
        return 1;
      }
    }
    
    return 0;
  }

  sub destructor : int () {
    my $minimal = TestCase::Minimal->new();
    destructor_call($minimal);
    
    if ($minimal->{x} == 3) {
      return 1;
    }
    return 0;
  }
  
  sub destructor_call : int ($minimal: TestCase::Minimal) {
    my $dest = TestCase::Destructor->new();
    $dest->{minimal} = $minimal;
  }
  
  # object field is initialized zero
  sub object_field_initialized_zero : int () {
    my $obj =TestCase->new;
    if ($obj->{x_byte} == 0) {
      if ($obj->{x_int} == 0) {
        if ($obj->{x_barray} == undef) {
          return 1;
        }
      }
    }
    return 0;
  }

  # object field set and get
  sub object_field_set_and_get : int () {
    my $test_case =TestCase->new;
    
    $test_case->{x_byte} = INT8_MAX();
    $test_case->{x_short} = INT16_MAX();
    $test_case->{x_int} = INT32_MAX();
    $test_case->{x_long} = INT64_MAX();
    $test_case->{x_float} = TestCase->FLOAT_PRECICE();
    $test_case->{x_double} = TestCase->DOUBLE_PRECICE();
    my $minimal = TestCase::Minimal->new();
    $minimal->{x} = 3;
    $test_case->{minimal} = $minimal;
    
    if ((int)$test_case->{x_byte} == (int)INT8_MAX()) {
      if ((int)$test_case->{x_short} == (int)INT16_MAX()) {
        if ($test_case->{x_int} == INT32_MAX()) {
          if ($test_case->{x_long} == INT64_MAX()) {
            if ($test_case->{x_float} == TestCase->FLOAT_PRECICE()) {
              if ($test_case->{x_double} == TestCase->DOUBLE_PRECICE()) {
                if ($test_case->{minimal}->{x} == 3) {
                  return 1;
                }
              }
            }
          }
        }
      }
    }
    return 0;
  }

  # object field set and get
  sub object_field_set_and_get_again : int () {
    my $test_case =TestCase->new;
    
    $test_case->{x_byte} = INT8_MAX();
    $test_case->{x_short} = INT16_MAX();
    $test_case->{x_int} = INT32_MAX();
    $test_case->{x_long} = INT64_MAX();
    $test_case->{x_float} = FLOAT_PRECICE();
    $test_case->{x_double} = DOUBLE_PRECICE();
    my $minimal = TestCase::Minimal->new();
    $minimal->{x} = 3;
    $test_case->{minimal} = $minimal;

    $test_case->{x_byte} = INT8_MAX();
    $test_case->{x_short} = INT16_MAX();
    $test_case->{x_int} = INT32_MAX();
    $test_case->{x_long} = INT64_MAX();
    $test_case->{x_float} = FLOAT_PRECICE();
    $test_case->{x_double} = DOUBLE_PRECICE();
    $test_case->{minimal} = $minimal;

    if ((int)$test_case->{x_byte} == (int)INT8_MAX()) {
      if ((int)$test_case->{x_short} == (int)INT16_MAX()) {
        if ($test_case->{x_int} == INT32_MAX()) {
          if ($test_case->{x_long} == INT64_MAX()) {
            if ($test_case->{x_float} == FLOAT_PRECICE()) {
              if ($test_case->{x_double} == DOUBLE_PRECICE()) {
                if ($test_case->{minimal}->{x} == 3) {
                  return 1;
                }
              }
            }
          }
        }
      }
    }
    return 0;
  }
}