#include "gtest/gtest.h"
#include <core.h>
#include "sh2core.h"
#include "debug.h"
#include "yabause.h"
#include "memory_for_test.h"
#include "DynarecSh2.h"

namespace {

class AddTest : public ::testing::Test {
 protected:
   DynarecSh2 * pctx_;

  AddTest() {
    initMemory();
    pctx_ = new DynarecSh2();  
    pctx_->SetCurrentContext();
  }

  virtual ~AddTest() {
    freeMemory();
    delete pctx_;    
  }   

virtual void SetUp() {
  
}

virtual void TearDown() {

}

};

TEST_F(AddTest, normal) {

  pctx_->GetGenRegPtr()[2]=0x00000000; //source
  pctx_->GetGenRegPtr()[3]=0x000000e0; //dest

  // add r1,r2
  memSetWord( 0x06000000, 0x332C );
  memSetWord( 0x06000002, 0x000b );  // rts
  memSetWord( 0x06000004, 0x0009 );  // nop

  pctx_->SET_PC( 0x06000000 );
  pctx_->Execute();

  EXPECT_EQ( 0x00000000, pctx_->GetGenRegPtr()[2] );
  EXPECT_EQ( 0x000000E0, pctx_->GetGenRegPtr()[3] );


  pctx_->GetGenRegPtr()[2]=0xDEADDEAD; //source
  pctx_->GetGenRegPtr()[3]=0x000000e0; //dest

  // add r1,r2
  memSetWord( 0x06000000, 0x332C );
  memSetWord( 0x06000002, 0x000b );  // rts
  memSetWord( 0x06000004, 0x0009 );  // nop

  pctx_->SET_PC( 0x06000000 );
  pctx_->Execute();

  EXPECT_EQ( 0xDEADDEAD, pctx_->GetGenRegPtr()[2] );
  EXPECT_EQ( 0xDEADDF8D, pctx_->GetGenRegPtr()[3] );


  pctx_->GetGenRegPtr()[2]=0xDEADDEAD; //source
  pctx_->GetGenRegPtr()[3]=0xF00000e0; //dest

  // add r1,r2
  memSetWord( 0x06000000, 0x332C );
  memSetWord( 0x06000002, 0x000b );  // rts
  memSetWord( 0x06000004, 0x0009 );  // nop

  pctx_->SET_PC( 0x06000000 );
  pctx_->Execute();

  EXPECT_EQ( 0xDEADDEAD, pctx_->GetGenRegPtr()[2] );
  EXPECT_EQ( 0xCEADDF8D, pctx_->GetGenRegPtr()[3] );
}

}  // namespacegPtr
