void list_rm_(int32_t result, const std::vector<pp::DirectoryEntry>& entries, pp::FileRef ref){
      if(result!=PP_OK){
	listener_->on_save(PNACL_IO_SAVE_ERROR);
	return;
      }
      for(size_t i=0; i<entries.size(); ++i){
	pp::FileRef ref1(file_system_, entries[i].file_ref().GetPath().AsString().c_str());
	if(ref1.Delete(pp::BlockUntilComplete())!=PP_OK)
	  listener_->on_save(PNACL_IO_STORAGE_NOT_READY_ERROR);
      }
      if(ref.Delete(pp::BlockUntilComplete())!=PP_OK)
	  listener_->on_save(PNACL_IO_STORAGE_NOT_READY_ERROR);
      listener_->on_save(PNACL_IO_STORAGE_NOT_READY_ERROR);
    }
int main(){

	int i;

	std::cout << ">>>>>>>>>>refence test<<<<<<<<<<<" << std::endl;

	refenceValue ref1( 1, 1);
	refenceValue ref2( 2, 2);
	refenceValue ref3 = ref2;
	refenceValue ref4(ref2);
	refenceValue *ref5 = new refenceValue(123, 321);
	refenceValue &ref6 = *ref5; 
	*ref5=(ref4);
//	refenceValue& ref4;

	std::cout << "ref1: " << ref1.a << " and " << ref1.b << std::endl;
	std::cout << "ref2: " << ref2.a << " and " << ref2.b << std::endl;
	std::cout << "ref3: " << ref3.a << " and " << ref3.b << std::endl;
	std::cout << "ref4: " << ref4.a << " and " << ref4.b << std::endl;
	std::cout << "ref5: " << ref5->a << " and " << ref5->b << std::endl;

	///dangerous statement.
	delete ref5;

	int *p = new int[10000];
	//memset(p, 0, sizeof(p));
	for(i = 0; i < 10000; i++)
	{
		p[i] = 1;
	}

	std::cout << "i = " << i << ";" << std::endl;

	std::cout << "ref6: " << ref6.a << " and " << ref6.b << std::endl;
	std::cout << std::endl;
	
	setRefenceValue mySetRefe;
	mySetRefe( ref2 );
	std::cout << "ref2: " << ref2.a << " and " << ref2.b << std::endl;
	std::cout << std::endl;

	setValue mySetValue;
	mySetValue( ref1 );
	std::cout << "ref1: " << ref1.a << " and " << ref1.b << std::endl;
	delete p;
}
Exemple #3
0
void TestRef::threading()
{
  
  SimpleEDProductGetter getter;
  
  edm::ProductID id(1, 1U);
  CPPUNIT_ASSERT(id.isValid());
  
  auto prod = std::make_unique<product1_t>();
  prod->push_back(1);
  prod->push_back(2);
  getter.addProduct(id, std::move(prod));
  
  ref1_t ref0(id, 0, &getter);
  ref1_t ref1(id, 1, &getter);

  std::vector<std::thread> threads;
  std::vector<std::exception_ptr> excepPtrs(kNThreads,std::exception_ptr{});
  
  for(unsigned int i=0; i< kNThreads; ++i) {
    threads.emplace_back([&ref0,&ref1,i,&excepPtrs]() {
      --s_threadsStarting;
      while(0 != s_threadsStarting) {}
      try{
        CPPUNIT_ASSERT(*ref0 == 1);
        CPPUNIT_ASSERT(*ref1 == 2);
      } catch(...) {
        excepPtrs[i]=std::current_exception();
      }
    });
  }
  for( auto& t: threads) {
    t.join();
  }
  
  for(auto& e: excepPtrs) {
    if(e) {
      std::rethrow_exception(e);
    }
  }
  
}
/* -----------------------------------------------------------------------------*/
static void reference(void)
{
  long refi, refj; double res;

  for (refj = 0; refj <= benchLoop; refj++) {
    for (refi = 1; refi <= 150000L; refi++) {
      res = ref1 () + ref2 ();
      res = ref1 () - ref2 ();
      res = ref1 () * ref2 ();
      res = ref1 () / ref2 ();
      res = ref2 () + ref1 ();
      res = ref2 () - ref1 ();
    }
  }
}
Exemple #5
0
void TestRefVector::testIteration()
{
    typedef std::vector<double> product_t;
    typedef edm::Ref<product_t> ref_t;
    typedef edm::RefVector<product_t> refvec_t;

    product_t  product;
    product.push_back(1.0);
    product.push_back(0.5);
    product.push_back(2.0);

    refvec_t  refvec;
    CPPUNIT_ASSERT(refvec.size() == 0);
    CPPUNIT_ASSERT(refvec.empty());

    ref_t    ref0(edm::ProductID(1, 1), &product[0], 0, &product);
    refvec.push_back(ref0);

    ref_t    ref1(edm::ProductID(1, 1), &product[1], 1, &product);
    refvec.push_back(ref1);

    ref_t    ref2(edm::ProductID(1, 1), &product[2], 2, &product);
    refvec.push_back(ref2);

    auto iter = refvec.begin();

    CPPUNIT_ASSERT(iter->id() == edm::ProductID(1,1) && iter->key() == 0 && *(iter->get()) == 1.0);
    ++iter;

    CPPUNIT_ASSERT(iter->id() == edm::ProductID(1,1) && iter->key() == 1 && *(iter->get()) == 0.5);
    ++iter;

    CPPUNIT_ASSERT(iter->id() == edm::ProductID(1,1) && iter->key() == 2 && *(iter->get()) == 2.0);
    ++iter;

    CPPUNIT_ASSERT(iter == refvec.end());
}
/***********************************************************************//**
 * @brief Test matrix operations
 *
 * Tests matrix*vector and matrix*matrix multiplication operations.
 ***************************************************************************/
void TestGMatrixSparse::matrix_operations(void)
{
    // Perform vector multiplication
	GVector test1 = m_test * v_test;

    // Check result
    GVector ref1(g_rows);
    for (int i = 0; i < g_elements; ++i) {
        ref1[g_row[i]] += g_matrix[i] * v_test[g_col[i]];
    }
    bool result = true;
    for (int i = 0; i < g_rows; ++i) {
        if (ref1[i] != test1[i]) {
            result = false;
            break;
        }
    }

    // Test if original matrix and result vector are correct
    test_assert(check_matrix(m_test), "Test source matrix");
    test_assert(result, "Test matrix*vector multiplication",
                "Found:\n"+test1.print()+"\nExpected:\n"+ref1.print());

    // Test incompatible vector multiplication
    test_try("Test incompatible matrix*vector multiplication");
    try {
        GVector test2 = m_bigger * v_test;
        test_try_failure("Expected GException::matrix_vector_mismatch exception.");
    }
    catch (GException::matrix_vector_mismatch &e) {
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }
    
    // Test matrix multiplication
	GMatrixSparse test3 = m_test * m_test.transpose();

    // Check if the result matrix is as expected
    GMatrixSparse ref3(g_rows, g_rows);
    for (int row = 0; row < g_rows; ++row) {
        for (int col = 0; col < g_rows; ++col) {
            double value = 0.0;
            for (int i = 0; i < g_cols; ++i) {
                double ref_value_1 = 0.0;
                double ref_value_2 = 0.0;
                for (int k = 0; k < g_elements; ++k) {
                    if (g_row[k] == row && g_col[k] == i) {
                        ref_value_1 = g_matrix[k];
                        break;
                    }
                }
                for (int k = 0; k < g_elements; ++k) {
                    if (g_row[k] == col && g_col[k] == i) {
                        ref_value_2 = g_matrix[k];
                        break;
                    }
                }
                value += ref_value_1 * ref_value_2;
            }
            ref3(row,col) = value;
            if (test3(row,col) != value) {
                result = false;
                break;
            }
        }
    }

    // Test if original matrix and result matrix are correct
    test_assert(check_matrix(m_test), "Test source matrix");
    test_assert(result, "Test matrix multiplication",
                "Found:\n"+test3.print()+"\nExpected:\n"+ref3.print());
    test_value(test3.rows(), g_rows, "Test number of rows of result matrix");
    test_value(test3.columns(), g_rows, "Test number of columns of result matrix");

    // Test incompatible matrix multiplication
    test_try("Test incompatible matrix multiplication");
    try {
        GMatrixSparse test4 = m_bigger * m_test;
        test_try_failure("Expected GException::matrix_mismatch exception.");
    }
    catch (GException::matrix_mismatch &e) {
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Test another incompatible matrix multiplication
    test_try("Test incompatible matrix multiplication");
    try {
        GMatrixSparse test5 = m_bigger * m_test;
        test_try_failure("Expected GException::matrix_mismatch exception.");
    }
    catch (GException::matrix_mismatch &e) {
        test_try_success();
    }
    catch (std::exception &e) {
        test_try_failure(e);
    }

    // Return
    return;
}
Exemple #7
0
IGL_INLINE void igl::PolyVectorFieldFinder<DerivedV, DerivedF>::computek()
{
  K.setZero(numE);
  // For every non-border edge
  for (unsigned eid=0; eid<numE; ++eid)
  {
    if (!isBorderEdge[eid])
    {
      int fid0 = E2F(eid,0);
      int fid1 = E2F(eid,1);

      Eigen::Matrix<typename DerivedV::Scalar, 1, 3> N0 = FN.row(fid0);
      Eigen::Matrix<typename DerivedV::Scalar, 1, 3> N1 = FN.row(fid1);

      // find common edge on triangle 0 and 1
      int fid0_vc = -1;
      int fid1_vc = -1;
      for (unsigned i=0;i<3;++i)
      {
        if (F2E(fid0,i) == eid)
          fid0_vc = i;
        if (F2E(fid1,i) == eid)
          fid1_vc = i;
      }
      assert(fid0_vc != -1);
      assert(fid1_vc != -1);

      Eigen::Matrix<typename DerivedV::Scalar, 1, 3> common_edge = V.row(F(fid0,(fid0_vc+1)%3)) - V.row(F(fid0,fid0_vc));
      common_edge.normalize();

      // Map the two triangles in a new space where the common edge is the x axis and the N0 the z axis
      Eigen::Matrix<typename DerivedV::Scalar, 3, 3> P;
      Eigen::Matrix<typename DerivedV::Scalar, 1, 3> o = V.row(F(fid0,fid0_vc));
      Eigen::Matrix<typename DerivedV::Scalar, 1, 3> tmp = -N0.cross(common_edge);
      P << common_edge, tmp, N0;
//      P.transposeInPlace();


      Eigen::Matrix<typename DerivedV::Scalar, 3, 3> V0;
      V0.row(0) = V.row(F(fid0,0)) -o;
      V0.row(1) = V.row(F(fid0,1)) -o;
      V0.row(2) = V.row(F(fid0,2)) -o;

      V0 = (P*V0.transpose()).transpose();

//      assert(V0(0,2) < 1e-10);
//      assert(V0(1,2) < 1e-10);
//      assert(V0(2,2) < 1e-10);

      Eigen::Matrix<typename DerivedV::Scalar, 3, 3> V1;
      V1.row(0) = V.row(F(fid1,0)) -o;
      V1.row(1) = V.row(F(fid1,1)) -o;
      V1.row(2) = V.row(F(fid1,2)) -o;
      V1 = (P*V1.transpose()).transpose();

//      assert(V1(fid1_vc,2) < 10e-10);
//      assert(V1((fid1_vc+1)%3,2) < 10e-10);

      // compute rotation R such that R * N1 = N0
      // i.e. map both triangles to the same plane
      double alpha = -atan2(V1((fid1_vc+2)%3,2),V1((fid1_vc+2)%3,1));

      Eigen::Matrix<typename DerivedV::Scalar, 3, 3> R;
      R << 1,          0,            0,
      0, cos(alpha), -sin(alpha) ,
      0, sin(alpha),  cos(alpha);
      V1 = (R*V1.transpose()).transpose();

//      assert(V1(0,2) < 1e-10);
//      assert(V1(1,2) < 1e-10);
//      assert(V1(2,2) < 1e-10);

      // measure the angle between the reference frames
      // k_ij is the angle between the triangle on the left and the one on the right
      Eigen::Matrix<typename DerivedV::Scalar, 1, 3> ref0 = V0.row(1) - V0.row(0);
      Eigen::Matrix<typename DerivedV::Scalar, 1, 3> ref1 = V1.row(1) - V1.row(0);

      ref0.normalize();
      ref1.normalize();

      double ktemp = atan2(ref1(1),ref1(0)) - atan2(ref0(1),ref0(0));

      // just to be sure, rotate ref0 using angle ktemp...
      Eigen::Matrix<typename DerivedV::Scalar, 2, 2> R2;
      R2 << cos(ktemp), -sin(ktemp), sin(ktemp), cos(ktemp);

      Eigen::Matrix<typename DerivedV::Scalar, 1, 2> tmp1 = R2*(ref0.head(2)).transpose();

//      assert(tmp1(0) - ref1(0) < 1e-10);
//      assert(tmp1(1) - ref1(1) < 1e-10);

      K[eid] = ktemp;
    }
  }

}
Exemple #8
0
int
ref2 (void)
{
  return ref1 ();
}
Exemple #9
0
TEST_F(auto_grabTest, testOperator_Pointer) {
	auto_grab<IReferenceCounted> ref1(object);
	IReferenceCounted* ptr = ref1;
}
Exemple #10
0
//---------------------------------------------------------
void Poly3D::SortPoints(const DVec& cent)
//---------------------------------------------------------
{
  // Sort the points by angle from cent which is
  // a point in the plane of the polygon.  This
  // is done in a counter-clockwise direction.

  // If less than 2 points, no need to sort
  if (m_N < 2) {
    return;
  }
  
  // create local cartesian axis
  DVec ref1,ref2,nor,axis1,axis2,vI,vJ,tmp;

  // wrap DM with DMat for utility routines
  int Nr=m_xyz.num_rows(), Nc=m_xyz.num_cols();
  DMat t_xyz; t_xyz.borrow(Nr, Nc, m_xyz.data());
  
  t_xyz.get_col(1) - cent;   ref1 /= ref1.norm(); 


  // get two lines in the plane
  ref1 = t_xyz.get_col(1) - cent;   ref1 /= ref1.norm(); 
  ref2 = t_xyz.get_col(2) - cent;   ref2 /= ref2.norm();

  // normal to the plane (norm = ref1 X ref2)
  nor(1) = ref1(2)*ref2(3) - ref1(3)*ref2(2);
  nor(2) = ref1(3)*ref2(1) - ref1(1)*ref2(3);
  nor(3) = ref1(1)*ref2(2) - ref1(2)*ref2(1);

  nor /= nor.norm();

  // axis definition
  axis1 = ref1;

  // axis2 = norm x axis1
  axis2(1) = nor(2)*axis1(3) - nor(3)*axis1(2);
  axis2(2) = nor(3)*axis1(1) - nor(1)*axis1(3);
  axis2(3) = nor(1)*axis1(2) - nor(2)*axis1(1);

  double costhetaI,sinthetaI, costhetaJ,sinthetaJ, thetaI,thetaJ;

  for (int i=1; i<=m_N; ++i) {
    for (int j=(i+1); j<=m_N; ++j) {
      vI = t_xyz.get_col(i) - cent;
      vJ = t_xyz.get_col(j) - cent;

      costhetaI = vI.inner(axis1);
      sinthetaI = vI.inner(axis2);

      costhetaJ = vJ.inner(axis1);
      sinthetaJ = vJ.inner(axis2);

      thetaI = atan2(sinthetaI, costhetaI);
      thetaJ = atan2(sinthetaJ, costhetaJ);
      
      // sort  minimum angle difference first
      if (thetaJ < thetaI) 
      {
        // swap I and J
      //t_xyz(All, [i j]) = t_xyz(All, [j i]);

        tmp = t_xyz.get_col(i);               // copy column i
        t_xyz.set_col(i, t_xyz.get_col(j));   // overwrite col i
        t_xyz.set_col(j, tmp);                // overwrite col j
      }
    }
  } 
}
Exemple #11
0
/*
	status_t Broadcast(BMessage *message, BMessenger replyTo) const
	@case 3			valid message, several apps, one is B_ARGV_ONLY,
					invalid replyTo
	@results		Should return B_OK and send the message to all (including
					the B_ARGV_ONLY) apps. Replies go to the roster!
*/
void BroadcastTester::BroadcastTestB3()
{
	LaunchContext context;
	BRoster roster;
	// launch app 1
	entry_ref ref1(create_app(appFile1, appType1));
	SimpleAppLauncher caller1(ref1);
	team_id team1;
	CHK(context(caller1, appType1, &team1) == B_OK);
	// launch app 2
	entry_ref ref2(create_app(appFile2, appType2, false, true,
							  B_SINGLE_LAUNCH | B_ARGV_ONLY));
	SimpleAppLauncher caller2(ref2);
	team_id team2;
	CHK(context(caller2, appType2, &team2) == B_OK);
	// launch app 3
	entry_ref ref3(create_app(appFile3, appType3));
	SimpleAppLauncher caller3(ref3);
	team_id team3;
	CHK(context(caller3, appType3, &team3) == B_OK);
	// launch app 4
	entry_ref ref4(create_app(appFile4, appType4));
	SimpleAppLauncher caller4(ref4);
	team_id team4;
	CHK(context(caller4, appType4, &team4) == B_OK);
	// wait for the apps to run
	context.WaitForMessage(team1, MSG_READY_TO_RUN);
	context.WaitForMessage(team2, MSG_READY_TO_RUN);
	context.WaitForMessage(team3, MSG_READY_TO_RUN);
	context.WaitForMessage(team4, MSG_READY_TO_RUN);
	// broadcast a message
	BMessage message(MSG_1);
	BMessenger replyTo;
	CHK(roster.Broadcast(&message, replyTo) == B_OK);
	// wait for the apps to report the receipt of the message
	context.WaitForMessage(team1, MSG_MESSAGE_RECEIVED);
	context.WaitForMessage(team2, MSG_MESSAGE_RECEIVED);
	context.WaitForMessage(team3, MSG_MESSAGE_RECEIVED);
	context.WaitForMessage(team4, MSG_MESSAGE_RECEIVED);
	// check the messages
	context.Terminate();
	// app 1
	int32 cookie = 0;
	CHK(context.CheckNextMessage(caller1, team1, cookie, MSG_STARTED));
	CHK(context.CheckMainArgsMessage(caller1, team1, cookie, &ref1, false));
	CHK(context.CheckNextMessage(caller1, team1, cookie, MSG_READY_TO_RUN));
	CHK(context.CheckMessageMessage(caller1, team1, cookie, &message));
//	CHK(context.CheckNextMessage(caller1, team1, cookie, MSG_2));
	CHK(context.CheckNextMessage(caller1, team1, cookie, MSG_QUIT_REQUESTED));
	CHK(context.CheckNextMessage(caller1, team1, cookie, MSG_TERMINATED));
	// app 2
	cookie = 0;
	CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_STARTED));
	CHK(context.CheckMainArgsMessage(caller2, team2, cookie, &ref2, false));
	CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_READY_TO_RUN));
	CHK(context.CheckMessageMessage(caller2, team2, cookie, &message));
//	CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_2));
	CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_QUIT_REQUESTED));
	CHK(context.CheckNextMessage(caller2, team2, cookie, MSG_TERMINATED));
	// app 3
	cookie = 0;
	CHK(context.CheckNextMessage(caller3, team3, cookie, MSG_STARTED));
	CHK(context.CheckMainArgsMessage(caller3, team3, cookie, &ref3, false));
	CHK(context.CheckNextMessage(caller3, team3, cookie, MSG_READY_TO_RUN));
	CHK(context.CheckMessageMessage(caller3, team3, cookie, &message));
//	CHK(context.CheckNextMessage(caller3, team3, cookie, MSG_2));
	CHK(context.CheckNextMessage(caller3, team3, cookie, MSG_QUIT_REQUESTED));
	CHK(context.CheckNextMessage(caller3, team3, cookie, MSG_TERMINATED));
	// app 4
	cookie = 0;
	CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_STARTED));
	CHK(context.CheckMainArgsMessage(caller4, team4, cookie, &ref4, false));
	CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_READY_TO_RUN));
	CHK(context.CheckMessageMessage(caller4, team4, cookie, &message));
//	CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_2));
	CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_QUIT_REQUESTED));
	CHK(context.CheckNextMessage(caller4, team4, cookie, MSG_TERMINATED));
}
Exemple #12
0
bool CGUIDialogBoxeeCtx::OnMessage(CGUIMessage &message)
{
  switch (message.GetMessage())
  {
  case GUI_MSG_ITEM_LOADED:
  {
    // New data received from the item loader, update existing item
    CFileItemPtr pItem ((CFileItem *)message.GetPointer());
    message.SetPointer(NULL);
    if (pItem) {
      m_item = *pItem;
      CGUIMessage msg(GUI_MSG_LABEL_RESET, GetID(), INFO_HIDDEN_LIST, 0);
      OnMessage(msg);
      
      CGUIMessage winmsg(GUI_MSG_LABEL_ADD, GetID(), INFO_HIDDEN_LIST, 0, 0, pItem);
      OnMessage(winmsg);

      CGUIMessage ref1(GUI_MSG_REFRESH_THUMBS, GetID(), IMG1);
      OnMessage(ref1);

      CGUIMessage ref2(GUI_MSG_REFRESH_THUMBS, GetID(), IMG2);
      OnMessage(ref2);

      CGUIMessage ref3(GUI_MSG_REFRESH_THUMBS, GetID(), IMG3);
      OnMessage(ref3);

      CGUIMessage ref4(GUI_MSG_REFRESH_THUMBS, GetID(), IMG4);
      OnMessage(ref4);
    }

    return true;
  }

  case GUI_MSG_CLICKED:
    {
      unsigned int iControl = message.GetSenderId();
      if (iControl == BTN_MORE_INFO)
      {
        OnMoreInfo();
        return true;
      }
      else if (iControl == BTN_RATE)
      {
        bool bLike;
        if (CGUIDialogBoxeeRate::ShowAndGetInput(bLike))
        {
          BoxeeUtils::Rate(&m_item, bLike);
          g_application.m_guiDialogKaiToast.QueueNotification(CGUIDialogKaiToast::ICON_STAR, "", g_localizeStrings.Get(51034), 5000 , KAI_YELLOW_COLOR, KAI_GREY_COLOR);
        }
      }
      else if (iControl == BTN_SHARE)
      {
        CGUIDialogBoxeeShare *pShare = (CGUIDialogBoxeeShare *)g_windowManager.GetWindow(WINDOW_DIALOG_BOXEE_SHARE);

        if (pShare)
        {
          pShare->SetItem(&m_item);
          pShare->DoModal();
        }
        else
        {
          CLog::Log(LOGERROR,"CGUIDialogBoxeeCtx::OnMessage - GUI_MSG_CLICKED - BTN_SHARE - FAILED to get WINDOW_DIALOG_BOXEE_SHARE (share)");
        }
      }
      else if (iControl == BTN_PRESET)
      {
        if (m_item.GetPropertyBOOL("IsPreset"))
        {
          CGUIDialogYesNo* dlgYesNo = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
          if (dlgYesNo)
          {
            dlgYesNo->SetHeading(51020);
            dlgYesNo->SetLine(0, 51021);
            dlgYesNo->SetLine(1, m_item.GetLabel() + "?");
            dlgYesNo->SetLine(2, "");
            dlgYesNo->DoModal();

            if (dlgYesNo->IsConfirmed())
            {
              g_settings.DeleteSource(GetItemShareType(), m_item.GetProperty("ShareName"), m_item.m_strPath);
              CGUIWindow *pWindow = g_windowManager.GetWindow(g_windowManager.GetActiveWindow());
              if (pWindow)
              {
                CGUIMessage msg(GUI_MSG_REFRESH_APPS, 0, 0);
                pWindow->OnMessage(msg);
              }
            }
          }
        } 
        else
        {
          CMediaSource newShare;
          newShare.strPath = m_item.m_strPath;
          newShare.strName = m_item.GetLabel();
          if (m_item.HasProperty("OriginalThumb") && !m_item.GetProperty("OriginalThumb").IsEmpty())
            newShare.m_strThumbnailImage = m_item.GetProperty("OriginalThumb");
          else
            newShare.m_strThumbnailImage = m_item.GetThumbnailImage();
          newShare.vecPaths.push_back(m_item.m_strPath);
          g_settings.AddShare(GetItemShareType(), newShare);
        }
        Close();
        return true;
      }
      else if (iControl == BTN_QUALITY)
      {
        return HandleQualityList();
    }
    }
    break;
  case GUI_MSG_WINDOW_DEINIT:
  case GUI_MSG_VISUALISATION_UNLOADING:
    {
    }
    break;
  case GUI_MSG_VISUALISATION_LOADED:
    {
    }
  }
  return CGUIDialog::OnMessage(message);
}
Exemple #13
0
int test2(V& v)
{
	typedef typename V::value_type A;
	v.resize(2);
	for (int i = 0; i < 2; i++) {
		v[i] = i;
	}
	std::vector<A> ar({A(10), A(11), A(12), A(13), A(14)});
	v.insert(v.cbegin()+1, ar.begin(), ar.end());

	V ref({A(0), A(10), A(11), A(12), A(13), A(14), A(1)});
	if (!cmp(v, ref)) {
		std::cerr << "Insert begin+1 failed!" << std::endl;
		return 1;
	}

	v.insert(v.cbegin(), ar.begin(), ar.end());
	V ref1({A(10), A(11), A(12), A(13), A(14), A(0), A(10), A(11), A(12), A(13), A(14), A(1)});
	if (!cmp(v, ref1)) {
		std::cerr << "Insert begin failed!" << std::endl;
		return 1;
	}

	v.insert(v.cend(), ar.begin(), ar.end());
	V ref2({A(10), A(11), A(12), A(13), A(14), A(0), A(10), A(11), A(12), A(13), A(14), A(1), A(10), A(11), A(12), A(13), A(14)});
	if (!cmp(v, ref2)) {
		std::cerr << "Insert end failed!" << std::endl;
		return 1;
	}

	v.insert(v.cend(), 2, A(20));
	V ref4({A(10), A(11), A(12), A(13), A(14), A(0), A(10), A(11), A(12), A(13), A(14), A(1), A(10), A(11), A(12), A(13), A(14), A(20), A(20)});
	if (!cmp(v, ref4)) {
		std::cerr << "Insert (count,value) to the end failed!" << std::endl;
		return 1;
	}

	v.emplace(v.cbegin()+5, 21);
	V ref5({A(10), A(11), A(12), A(13), A(14), A(21), A(0), A(10), A(11), A(12), A(13), A(14), A(1), A(10), A(11), A(12), A(13), A(14), A(20), A(20)});
	if (!cmp(v, ref5)) {
		std::cerr << "emplace to begin+5 failed!" << std::endl;
		return 1;
	}

	v.insert(v.cbegin(), 2, A(40));
	V ref6({A(40), A(40), A(10), A(11), A(12), A(13), A(14), A(21), A(0), A(10), A(11), A(12), A(13), A(14), A(1), A(10), A(11), A(12), A(13), A(14), A(20), A(20)});
	if (!cmp(v, ref6)) {
		std::cerr << "emplace to begin+5 failed!" << std::endl;
		return 1;
	}

	v.insert(v.cbegin()+1, 2, A(41));
	V ref7({A(40), A(41), A(41), A(40), A(10), A(11), A(12), A(13), A(14), A(21), A(0), A(10), A(11), A(12), A(13), A(14), A(1), A(10), A(11), A(12), A(13), A(14), A(20), A(20)});
	if (!cmp(v, ref7)) {
		std::cerr << "emplace to begin+5 failed!" << std::endl;
		return 1;
	}

	v.insert(v.cbegin(), std::move(A(100)));
	V ref8({A(100), A(40), A(41), A(41), A(40), A(10), A(11), A(12), A(13), A(14), A(21), A(0), A(10), A(11), A(12), A(13), A(14), A(1), A(10), A(11), A(12), A(13), A(14), A(20), A(20)});
	if (!cmp(v, ref8)) {
		std::cerr << "insert to begin + std::move failed!" << std::endl;
		return 1;
	}

	A a_(101);
	v.insert(v.cbegin()+4, a_);
	V ref9({A(100), A(40), A(41), A(41), A(101), A(40), A(10), A(11), A(12), A(13), A(14), A(21), A(0), A(10), A(11), A(12), A(13), A(14), A(1), A(10), A(11), A(12), A(13), A(14), A(20), A(20)});
	if (!cmp(v, ref9)) {
		std::cerr << "insert to begin + copy failed!" << std::endl;
		return 1;
	}

	v.insert(v.cbegin()+7, {A(60), A(61)});
	V ref10({A(100), A(40), A(41), A(41), A(101), A(40), A(10), A(60), A(61), A(11), A(12), A(13), A(14), A(21), A(0), A(10), A(11), A(12), A(13), A(14), A(1), A(10), A(11), A(12), A(13), A(14), A(20), A(20)});
	if (!cmp(v, ref10)) {
		std::cerr << "insert to begin + copy failed!" << std::endl;
		return 1;
	}
	return 0;
}
Exemple #14
0
int main()
{
    try {
        TestSection("StdTerms");
        TestSubsection("TermGarbage");
        {
            MyTestTerm *term1 = new MyTestTerm(10);
            MyTestTerm2 *term2 = new MyTestTerm2(20);
            SReference ref1(term1);
            SReference ref2(term2);
            SReference ref3(new MyTestTerm(30));
            SReference ref4(new MyTestTerm2(40));
            TEST("constructed", constructed, 4);
            TEST("noone-destructed", destructed, 0);
            ref4 = new MyTestTerm(300);
            TEST("assign_ptr", destructed, 1);
            ref4 = ref1;
            TEST("assign_ref", destructed, 2);
            ref3 = 0;
            TEST("assign_null", destructed, 3);
        }
        TEST("correctness", constructed, destructed);
        {
            constructed = destructed = 0;
            SReference ref1(new MyTestTerm(200));
            SReference ref2(new MyTestTerm(300));
            TESTB("before_assigning_refs",constructed == 2 && destructed == 0);
            ref1 = ref2;
            TEST("after_assigning_refs", destructed, 1);
        }
        TestSubsection("TermType");
        {
            SReference ref5(new MyTestTerm(50));
            TESTB("type-of", ref5->TermType() == MyTestTerm::TypeId);
            TESTB("not-type-of", ref5->TermType() != MyTestTerm2::TypeId);
            TESTB("subtype", ref5->TermType().IsSubtypeOf(SExpression::TypeId));
            TESTB("not-subtype",
                 !(ref5->TermType().IsSubtypeOf(MyTestTerm2::TypeId)));
            SReference ref6(new MyTestTerm22(60));
            TESTB("subtype2_", ref6->TermType() == MyTestTerm22::TypeId);
            TESTB("22subE",
                MyTestTerm22::TypeId.IsSubtypeOf(SExpression::TypeId));
            TESTB("22sub2",
                MyTestTerm22::TypeId.IsSubtypeOf(MyTestTerm2::TypeId));
            TESTB("2subE",
                MyTestTerm2::TypeId.IsSubtypeOf(SExpression::TypeId));
            TESTB("subtype2",
                ref6->TermType().IsSubtypeOf(SExpression::TypeId));
            TESTB("subtype22",
                ref6->TermType().IsSubtypeOf(MyTestTerm2::TypeId));
            TESTB("subtype22_self",
                 ref6->TermType().IsSubtypeOf(MyTestTerm22::TypeId));
            SReference ref7(new MyTestTerm2(70));
            TESTB("not-subtype22",
                 !(ref7->TermType().IsSubtypeOf(MyTestTerm22::TypeId)));
        }
        TestSubsection("TermCasts");
        {
            SReference ref(new MyTestTerm(50));
            SReference ref2(new MyTestTerm2(70));
            TESTB("cast_to_lterm", ref.DynamicCastGetPtr<SExpression>()
                 == ref.GetPtr());
            TESTB("cast_to_lterm2", ref.DynamicCastGetPtr<SExpression>()
                 == ref.GetPtr());
            TESTB("cast_to_itself", ref.DynamicCastGetPtr<MyTestTerm>() ==
                 ref.GetPtr());
            TESTB("failed_cast", ref.DynamicCastGetPtr<MyTestTerm2>()==0);
        }
        TestSubsection("SExpressionCasts");
        {
            SReference ref(new MyTestTerm(50));
            SReference ref2(new MyTestTerm2(70));
            TESTB("cast_to_lterm", ref.DynamicCastGetPtr<SExpression>()
                 == ref.GetPtr());
            TESTB("cast_to_lterm2", ref.DynamicCastGetPtr<SExpression>()
                 == ref.GetPtr());
            TESTB("cast_to_itself", ref.DynamicCastGetPtr<MyTestTerm>()
                 == ref.GetPtr());
            TESTB("failed_cast", ref.DynamicCastGetPtr<MyTestTerm2>()==0);
        }
        TestSubsection("BasicTerms");
        {
            SReference intref(25);
            TESTC("integer_term", intref->TermType(), SExpressionInt::TypeId);
            TEST("integer_value", intref.GetInt(), 25);
            SReference floatref(25.0);
            TESTC("float_term", floatref->TermType(), SExpressionFloat::TypeId);
            TESTC("float_value", floatref.GetFloat(), (intelib_float_t)25.0);
            SReference strref("A_STRING");
            TESTC("pchar_term", strref->TermType(), SExpressionString::TypeId);
            TESTC("pchar_value", strcmp((const char*)strref.GetString(),
                                        "A_STRING"),
                  0);
            SReference charref('a');
            TESTC("char_term", charref->TermType(), SExpressionChar::TypeId);
            TEST("char_value", charref.GetSingleChar(), 'a');

        }
        TestSubsection("SExpressionString");
        {
            SReference strref1(new SExpressionString("A", "B"));
            TEST("concatenation_1_1", strref1.GetString(), "AB");
            SReference strref2(new SExpressionString("AA", "BB"));
            TEST("concatenation_2_2", strref2.GetString(), "AABB");
            SReference strref3(new SExpressionString("AAA", "BBB"));
            TEST("concatenation_3_3", strref3.GetString(), "AAABBB");
            SReference strref4(new SExpressionString("AAAA", "BBBB"));
            TEST("concatenation_4_4", strref4.GetString(), "AAAABBBB");
            SReference strref5(new SExpressionString("AAAAA", "BBBBB"));
            TEST("concatenation_5_5", strref5.GetString(), "AAAAABBBBB");
            SReference strref6(new SExpressionString("A"));
            TEST("construction1", strref6.GetString(), "A");
            SReference strref7(new SExpressionString("AA"));
            TEST("construction2", strref7.GetString(), "AA");
            SReference strref8(new SExpressionString("AAA"));
            TEST("construction3", strref8.GetString(), "AAA");
            SReference strref9(new SExpressionString("AAAA"));
            TEST("construction4", strref9.GetString(), "AAAA");


        }
        TestSubsection("SString");
        {
            SString str1;
            TESTC("default_is_empty", str1.c_str()[0], '\0');
            SString str2("");
            TESTC("empty_strings", str1, str2);
            TESTC("empty_is_empty", str2.c_str()[0], '\0');
            SString str3("AAA");
            SString str4("BBB");
            SString str5 = str3 + str4;
            TEST("string_addition", str5.c_str(), "AAABBB");
            SString str6("CCC");
            str6 += "DDD";
            TEST("string_increment_by_pchar", str6.c_str(), "CCCDDD");
            SString str7("EEE");
            SString str8("FFF");
            str7 += str8;
            TEST("string_increment_by_string", str7.c_str(), "EEEFFF");

            SString str10("Final countdown");
            SString str11("Final");
            str11 += " countdown";
            TESTB("string_equals_itself", str10 == str10);
            TESTB("string_doesnt_differ_from_itself", !(str10 != str10));
            TESTB("two_equal_strings", str10 == str11);
            TESTB("equal_strings_dont_differ", !(str10 != str11));
            SString str12("Another string");
            TESTB("two_non_equal_strings", str11 != str12);
            TESTB("nonequals_non_equal", !(str11 == str12));
            SString str13;
            SString str14("");
            TESTB("empty_strings_equal", str13 == str14);
            TESTB("empty_strings_dont_differ", !(str13 != str14));
            SReference strref("my_string");
            SString str15(strref);
            TEST("string_from_lreference", str15.c_str(), "my_string");
            {
                int flag = 0;
                try {
                    SReference ref(25);
                    SString str(ref);
                }
                catch(IntelibX_not_a_string lx)
                {
                    flag = 0x56;
                }
                TESTB("string_from_int_fails", flag == 0x56);
            }
        }
        TestSubsection("TextRepresentation");
        {
            SReference intref(100);
            TEST("integer_text_rep", intref->TextRepresentation().c_str(),
                 "100");
            char buf[100];
            intelib_float_t fl;
            fl = 100.1;
            SReference fltref(fl);
            snprintf(buf, sizeof(buf), INTELIB_FLOAT_FORMAT, fl);
            TEST("float_text_rep", fltref->TextRepresentation().c_str(),
                 buf);
            fl = 100.0;
            SReference fltref2(fl);
            snprintf(buf, sizeof(buf), INTELIB_FLOAT_FORMAT, fl);
            TEST("float2_text_rep", fltref2->TextRepresentation().c_str(),
                 buf);
            SReference strref("mystring");
            TEST("string_text_rep", strref->TextRepresentation().c_str(),
                 "\"mystring\"");
            SReference unbound;
            SReference unbound2;
            SReference unblist(unbound, unbound2);
            TEST("unbound_text_representation",
                 unblist->TextRepresentation().c_str(),
                 "(#<UNBOUND> . #<UNBOUND>)");
        }
        TestSubsection("DottedPairs");
        {
            SReference pairref(25, 36);
            TEST("pair_25_36", pairref->TextRepresentation().c_str(),
                 "(25 . 36)");
            SReference dotlistref(25, SReference(36, 49));
            TEST("dotlist_25_36_49", dotlistref->TextRepresentation().c_str(),
                 "(25 36 . 49)");
            SReference empty_list_ref(*PTheEmptyList);
            TEST("empty_list_ref", empty_list_ref->TextRepresentation().c_str(),
                 (*PTheEmptyList)->TextRepresentation().c_str());
            TESTB("empty_list_equal_empty", empty_list_ref.GetPtr() ==
                 PTheEmptyList->GetPtr());
            TESTB("dot_list_notequal_empty", dotlistref.GetPtr() !=
                 PTheEmptyList->GetPtr());

            SReference list25ref(25, *PTheEmptyList);
            TEST("list_1_elem", list25ref->TextRepresentation().c_str(),
                 "(25)");
            SReference list_16_25_ref(16, list25ref);
            TEST("cons_with_list", list_16_25_ref->TextRepresentation().c_str(),
                 "(16 25)");
            SReference list_of_lists_ref(list25ref,
                                         SReference(list25ref, *PTheEmptyList));
            TEST("list_of_lists", list_of_lists_ref->TextRepresentation().c_str(),
                 "((25) (25))");

        }
        TestSubsection("SExpressionLabel");
        {
            SExpressionLabel *lab1 = new SExpressionLabel("lab1");
            SReference labref(lab1);
            TEST("label", labref->TextRepresentation().c_str(),
                 "lab1");
            TESTB("label_equality", labref == SReference(lab1));
            SReference labref2(lab1);
            TESTB("label_equality2", labref== labref2);
            SReference ref3(25);
            TESTB("label_non_eq", labref != ref3);

#if 0 // no support for booleans in sexpression core
            TEST("boolean_true", LTheLispBooleanTrue.TextRepresentation().c_str(),
           #if CLSTYLE_BOOLEANS == 0
                 "#T"
           #else
                 "T"
           #endif
                );
#endif
        }
        TestSubsection("SListConstructor");
        {
            SListConstructor L;
            SReference list_int((L|25));
            TEST("list_of_1_int", list_int->TextRepresentation().c_str(),
                 "(25)");
            SReference list_str((L|"abcd"));
            TEST("list_of_1_str", list_str->TextRepresentation().c_str(),
                 "(\"abcd\")");
            intelib_float_t fl = 1.1;
            SReference list_float((L|fl));
            char buf[128];
            snprintf(buf, sizeof(buf), "(" INTELIB_FLOAT_FORMAT ")", fl);
            TEST("list_of_1_float", list_float->TextRepresentation().c_str(),
                 buf);
        }
        TestSubsection("ListConstructionAlgebra");
        {
            SListConstructor L;
            SReference listref((L|25, 36, 49, "abcd", "efgh"));
            TEST("plain_list", listref->TextRepresentation().c_str(),
                 "(25 36 49 \"abcd\" \"efgh\")");
            SReference listref2((L|(L|25), 36, (L|(L|(L|49)))));
            TEST("list_with_lists", listref2->TextRepresentation().c_str(),
                 "((25) 36 (((49))))");
            SReference listref3((L|(L|(L|(L|(L))))));
            TEST("empty_buried_list", listref3->TextRepresentation().c_str(),
                 (SString("((((")+
                  (*PTheEmptyList)->
                  TextRepresentation().c_str()+
                  SString("))))")).c_str());
            SReference dotpairref((L|25 || 36));
            TEST("dotted_pair", dotpairref->TextRepresentation().c_str(),
                 "(25 . 36)");
            SReference dotlistref((L|9, 16, 25)||36);
            TEST("dotted_list", dotlistref->TextRepresentation().c_str(),
                 "(9 16 25 . 36)");
            SReference dotpairref2((L|25)^36);
            TEST("dotted_pair", dotpairref2->TextRepresentation().c_str(),
                 "((25) . 36)");
            SReference dotlistref2((L|9, 16, 25)^36);
            TEST("dotted_list", dotlistref2->TextRepresentation().c_str(),
                 "((9 16 25) . 36)");
            SReference just_a_cons(SReference("abc")^SReference(225));
            TEST("cons_with_^", just_a_cons->TextRepresentation().c_str(),
                 "(\"abc\" . 225)");
            SReference empty(L);
            empty,25;
            TEST("comma_on_empty_list", empty->TextRepresentation().c_str(),
                 "(25)");
        }
        TestSubsection("IsEql");
        {
            SReference five(5);
            TESTB("is_eql_numbers", five.IsEql(5));            
            TESTB("isnt_eql_numbers", !five.IsEql(3));            
            TESTB("isnt_eql_num_to_string", !five.IsEql("abc"));            
            SReference abc("abc");
            TESTB("is_eql_strings", abc.IsEql("abc"));            
            TESTB("isnt_eql_strings", !abc.IsEql("def"));            
            TESTB("isnt_eql_string_to_num", !abc.IsEql(5));            
        }
        TestSubsection("UnboundByDefault");
        {
            SReference unbound;
            TESTB("sreference_unbound", !unbound.GetPtr());

            GenericSReference<MyTestTerm22, IntelibX_wrong_expression_type> p;
            TESTB("gensref_unbound", !p.GetPtr());
        }

#if 0  // no support for booleans
        TestSubsection("Booleans");
        {
            SReference true_ref(LTheLispBooleanTrue);
            TESTB("boolean_true", true_ref->IsTrue());
            SReference false_ref(LTheLispBooleanFalse);
            TESTB("boolean_false", !(false_ref->IsTrue()));
            SReference some_ref(25);
            TESTB("boolean_some", some_ref->IsTrue());

        }
#endif
        TestSubsection("Epilogue");
        TEST("final-cleanup", destructed, constructed);
        TestScore();
    }
    catch(...) {
        printf("Something strange caught\n");
    }
    return 0;
}