Esempio n. 1
0
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;
}
Esempio n. 2
0
void TestQgsMapLayer::layerRef()
{
  // construct from layer
  QgsVectorLayerRef ref( mpLayer );
  QCOMPARE( ref.get(), mpLayer );
  QCOMPARE( ref.layer.data(), mpLayer );
  QCOMPARE( ref.layerId, mpLayer->id() );
  QCOMPARE( ref.name, QStringLiteral( "points" ) );
  QCOMPARE( ref.source, mpLayer->publicSource() );
  QCOMPARE( ref.provider, QStringLiteral( "ogr" ) );

  // bool operator
  QVERIFY( ref );
  // -> operator
  QCOMPARE( ref->id(), mpLayer->id() );

  // verify that layer matches layer
  QVERIFY( ref.layerMatchesSource( mpLayer ) );

  // create a weak reference
  QgsVectorLayerRef ref2( mpLayer->id(), QStringLiteral( "points" ), mpLayer->publicSource(), QStringLiteral( "ogr" ) );
  QVERIFY( !ref2 );
  QVERIFY( !ref2.get() );
  QVERIFY( !ref2.layer.data() );
  QCOMPARE( ref2.layerId, mpLayer->id() );
  QCOMPARE( ref2.name, QStringLiteral( "points" ) );
  QCOMPARE( ref2.source, mpLayer->publicSource() );
  QCOMPARE( ref2.provider, QStringLiteral( "ogr" ) );

  // verify that weak reference matches layer
  QVERIFY( ref2.layerMatchesSource( mpLayer ) );

  // resolve layer using project
  QCOMPARE( ref2.resolve( QgsProject::instance() ), mpLayer );
  QVERIFY( ref2 );
  QCOMPARE( ref2.get(), mpLayer );
  QCOMPARE( ref2.layer.data(), mpLayer );
  QCOMPARE( ref2.layerId, mpLayer->id() );
  QCOMPARE( ref2.name, QStringLiteral( "points" ) );
  QCOMPARE( ref2.source, mpLayer->publicSource() );
  QCOMPARE( ref2.provider, QStringLiteral( "ogr" ) );

  // setLayer
  QgsVectorLayerRef ref3;
  QVERIFY( !ref3.get() );
  ref3.setLayer( mpLayer );
  QCOMPARE( ref3.get(), mpLayer );
  QCOMPARE( ref3.layer.data(), mpLayer );
  QCOMPARE( ref3.layerId, mpLayer->id() );
  QCOMPARE( ref3.name, QStringLiteral( "points" ) );
  QCOMPARE( ref3.source, mpLayer->publicSource() );
  QCOMPARE( ref3.provider, QStringLiteral( "ogr" ) );

  // weak resolve
  QgsVectorLayerRef ref4( QStringLiteral( "badid" ), QStringLiteral( "points" ), mpLayer->publicSource(), QStringLiteral( "ogr" ) );
  QVERIFY( !ref4 );
  QVERIFY( !ref4.resolve( QgsProject::instance() ) );
  QCOMPARE( ref4.resolveWeakly( QgsProject::instance() ), mpLayer );
  QCOMPARE( ref4.get(), mpLayer );
  QCOMPARE( ref4.layer.data(), mpLayer );
  QCOMPARE( ref4.layerId, mpLayer->id() );
  QCOMPARE( ref4.name, QStringLiteral( "points" ) );
  QCOMPARE( ref4.source, mpLayer->publicSource() );
  QCOMPARE( ref4.provider, QStringLiteral( "ogr" ) );

  // try resolving a bad reference
  QgsVectorLayerRef ref5( QStringLiteral( "badid" ), QStringLiteral( "points" ), mpLayer->publicSource(), QStringLiteral( "xxx" ) );
  QVERIFY( !ref5.get() );
  QVERIFY( !ref5.resolve( QgsProject::instance() ) );
  QVERIFY( !ref5.resolveWeakly( QgsProject::instance() ) );
}
Esempio n. 3
0
void RefPtrTest::onEnter()
{
    UnitTestDemo::onEnter();

#if DEBUG
    // TEST(constructors)
    {
        // Default constructor
        RefPtr<Ref> ref1;
        CC_ASSERT(nullptr == ref1.get());

        // Parameter constructor
        RefPtr<__String> ref2(cocos2d::String::create("Hello"));
        CC_ASSERT(strcmp("Hello", ref2->getCString()) == 0);
        CC_ASSERT(2 == ref2->getReferenceCount());

        // Parameter constructor with nullptr
        RefPtr<__String> ref3(nullptr);
        CC_ASSERT((__String*) nullptr == ref3.get());
        
        // Copy constructor
        RefPtr<__String> ref4(ref2);
        CC_ASSERT(strcmp("Hello", ref4->getCString()) == 0);
        CC_ASSERT(3 == ref2->getReferenceCount());
        CC_ASSERT(3 == ref4->getReferenceCount());
        
        // Copy constructor with nullptr reference
        RefPtr<Ref> ref5(ref1);
        CC_ASSERT((Ref*) nullptr == ref5.get());
    }
    
    // TEST(destructor)
    {
        __String * hello = __String::create("Hello");
        CC_ASSERT(1 == hello->getReferenceCount());
        
        {
            RefPtr<Ref> ref(hello);
            CC_ASSERT(2 == hello->getReferenceCount());
        }
        
        CC_ASSERT(1 == hello->getReferenceCount());
    }
    
    // TEST(assignmentOperator)
    {
        // Test basic assignment with pointer
        RefPtr<__String> ref1;
        CC_ASSERT((Ref*) nullptr == ref1.get());
        
        ref1 = __String::create("World");
        CC_ASSERT(strcmp("World", ref1->getCString()) == 0);
        CC_ASSERT(2 == ref1->getReferenceCount());
        
        // Assigment back to nullptr
        __String * world = ref1;
        CC_ASSERT(2 == world->getReferenceCount());
        
        ref1 = nullptr;
        CC_ASSERT(1 == world->getReferenceCount());
        
        // Assignment swapping 
        ref1 = __String::create("Hello");
        CC_ASSERT(strcmp("Hello", ref1->getCString()) == 0);
        CC_ASSERT(2 == ref1->getReferenceCount());
        
        __String * hello = (__String*) ref1;
        CC_ASSERT(2 == hello->getReferenceCount());
        
        ref1 = world;
        CC_ASSERT(1 == hello->getReferenceCount());
        CC_ASSERT(2 == world->getReferenceCount());
        
        // Test assignment with another reference
        RefPtr<__String> ref2 = __String::create("blah");
        __String * blah = ref2;
        CC_ASSERT(2 == blah->getReferenceCount());
        
        ref2 = ref1;
        CC_ASSERT(1 == blah->getReferenceCount());
        CC_ASSERT(3 == world->getReferenceCount());
    }
    
    // TEST(castBackToPointerOperator)
    {
        RefPtr<__String> ref1 = __String::create("Hello");
        __String * helloPtr = ref1;
        Ref * objectPtr = ref1;
        
        CC_ASSERT(helloPtr == objectPtr);
    }
    
    // TEST(dereferenceOperators)
    {
        RefPtr<__String> ref1 = __String::create("Hello");
        CC_ASSERT(strcmp("Hello", ref1->getCString()) == 0);
        CC_ASSERT(strcmp("Hello", (*ref1).getCString()) == 0);
    }
    
    // TEST(convertToBooleanOperator)
    {
        RefPtr<__String> ref1 = __String::create("Hello");
        CC_ASSERT(true == (bool) ref1);
        
        ref1 = nullptr;
        CC_ASSERT(false == (bool) ref1);
    }
    
    // TEST(get)
    {
        RefPtr<__String> ref1 = __String::create("Hello");
        CC_ASSERT(strcmp("Hello", ref1.get()->getCString()) == 0);
        
        ref1.reset();
        CC_ASSERT((__String*) nullptr == ref1.get());
    }
    
    // TEST(reset)
    {
        RefPtr<__String> ref1;
        CC_ASSERT((__String*) nullptr == ref1.get());
        
        ref1.reset();
        CC_ASSERT((__String*) nullptr == ref1.get());
        
        ref1 = __String::create("Hello");
        CC_ASSERT(strcmp("Hello", ref1.get()->getCString()) == 0);
        
        __String * hello = ref1.get();
        CC_ASSERT(2 == hello->getReferenceCount());
        
        ref1.reset();
        CC_ASSERT((__String*) nullptr == ref1.get());
        CC_ASSERT(1 == hello->getReferenceCount());
    }
    
    // TEST(swap)
    {
        RefPtr<__String> ref1;
        RefPtr<__String> ref2;
        
        CC_ASSERT((__String*) nullptr == ref1.get());
        CC_ASSERT((__String*) nullptr == ref2.get());
        
        ref1.swap(ref2);
        
        CC_ASSERT((__String*) nullptr == ref1.get());
        CC_ASSERT((__String*) nullptr == ref2.get());
        
        __String * hello = __String::create("Hello");
        CC_ASSERT(1 == hello->getReferenceCount());
        
        ref1 = hello;
        CC_ASSERT(2 == hello->getReferenceCount());
        
        ref1.swap(ref2);
        CC_ASSERT(2 == hello->getReferenceCount());
        CC_ASSERT((__String*) nullptr == ref1.get());
        CC_ASSERT(strcmp("Hello", ref2->getCString()) == 0);
        
        ref1.swap(ref2);
        CC_ASSERT(2 == hello->getReferenceCount());
        CC_ASSERT(strcmp("Hello", ref1->getCString()) == 0);
        CC_ASSERT((__String*) nullptr == ref2.get());
        
        __String * world = __String::create("World");
        CC_ASSERT(1 == world->getReferenceCount());
        
        ref2 = world;
        CC_ASSERT(2 == world->getReferenceCount());
        
        ref2.swap(ref1);
        CC_ASSERT(strcmp("World", ref1->getCString()) == 0);
        CC_ASSERT(strcmp("Hello", ref2->getCString()) == 0);
        
        CC_ASSERT(2 == hello->getReferenceCount());
        CC_ASSERT(2 == world->getReferenceCount());
        
        ref1.swap(ref2);
        
        CC_ASSERT(strcmp("Hello", ref1->getCString()) == 0);
        CC_ASSERT(strcmp("World", ref2->getCString()) == 0);
        
        CC_ASSERT(2 == hello->getReferenceCount());
        CC_ASSERT(2 == world->getReferenceCount());
    }
    
    // TEST(staticPointerCast)
    {
        RefPtr<__String> ref1 = __String::create("Hello");
        CC_ASSERT(2 == ref1->getReferenceCount());
        
        RefPtr<Ref> ref2 = static_pointer_cast<Ref>(ref1);
        CC_ASSERT(strcmp("Hello", ((__String*) ref2.get())->getCString()) == 0);
        CC_ASSERT(3 == ref1->getReferenceCount());
    }
    
    // TEST(dynamicPointerCast)
    {
        RefPtr<__String> ref1 = cocos2d::String::create("Hello");
        CC_ASSERT(2 == ref1->getReferenceCount());
        
        RefPtr<Ref> ref2 = dynamic_pointer_cast<Ref>(ref1);
        CC_ASSERT(strcmp("Hello", ((__String*) ref2.get())->getCString()) == 0);
        CC_ASSERT(3 == ref1->getReferenceCount());
        
        RefPtr<__String> ref3 = dynamic_pointer_cast<__String>(ref2);
        CC_ASSERT(strcmp("Hello", ref3->getCString()) == 0);
        CC_ASSERT(4 == ref1->getReferenceCount());
        
        RefPtr<cocos2d::Node> ref4 = dynamic_pointer_cast<cocos2d::Node>(ref2);
        CC_ASSERT((Ref*) nullptr == ref4.get());
    }
    
    // TEST(weakAssign)
    {
        RefPtr<__String> ref1;
        
        __String * string1 = new __String("Hello");
        ref1.weakAssign(string1);
        CC_ASSERT(1 == string1->getReferenceCount());
        
        RefPtr<__String> ref2 = ref1;
        CC_ASSERT(2 == string1->getReferenceCount());
        
        __String * string2 = new __String("World");
        ref1.weakAssign(string2);
        
        CC_ASSERT(1 == string1->getReferenceCount());
        CC_ASSERT(1 == ref2->getReferenceCount());
        
        __String * string3 = new __String("Blah");
        RefPtr<__String> ref3;
        ref3.weakAssign(string3);
        CC_ASSERT(1 == string3->getReferenceCount());
        
        string3->retain();
        CC_ASSERT(2 == string3->getReferenceCount());
        
        ref3.weakAssign(nullptr);
        CC_ASSERT(1 == string3->getReferenceCount());
        CC_SAFE_RELEASE_NULL(string3);
    }
    
    // TEST(comparisonOperators)
    {
        RefPtr<Ref> ref1;
        RefPtr<Ref> ref2;
        
        CC_ASSERT(true == (ref1 == ref2));
        CC_ASSERT(false == (ref1 != ref2));
        CC_ASSERT(false == (ref1 < ref2));
        CC_ASSERT(false == (ref1 > ref2));
        CC_ASSERT(true == (ref1 <= ref2));
        CC_ASSERT(true == (ref1 >= ref2));
        
        CC_ASSERT(true == (ref1 == nullptr));
        CC_ASSERT(false == (ref1 != nullptr));
        CC_ASSERT(false == (ref1 < nullptr));
        CC_ASSERT(false == (ref1 > nullptr));
        CC_ASSERT(true == (ref1 <= nullptr));
        CC_ASSERT(true == (ref1 >= nullptr));
        
        CC_ASSERT(false == (ref1 == __String::create("Hello")));
        CC_ASSERT(true == (ref1 != __String::create("Hello")));
        CC_ASSERT(true == (ref1 < __String::create("Hello")));
        CC_ASSERT(false == (ref1 > __String::create("Hello")));
        CC_ASSERT(true == (ref1 <= __String::create("Hello")));
        CC_ASSERT(false == (ref1 >= __String::create("Hello")));
        
        ref1 = __String::create("Hello");
        
        CC_ASSERT(false == (ref1 == ref2));
        CC_ASSERT(true == (ref1 != ref2));
        CC_ASSERT(false == (ref1 < ref2));
        CC_ASSERT(true == (ref1 > ref2));
        CC_ASSERT(false == (ref1 <= ref2));
        CC_ASSERT(true == (ref1 >= ref2));
    }
    
    // TEST(moveConstructor)
    {
        auto someFunc = []() -> RefPtr<__String>
        {
            return __String::create("Hello world!");
        };
        
        // Note: std::move will turn the rvalue into an rvalue reference and thus cause the move constructor to be invoked.
        // Have to use this because the compiler will try and optimize how we handle the return value otherwise and skip the move constructor.
        RefPtr<__String> theString(std::move(someFunc()));
        CC_ASSERT(theString->getReferenceCount() == 2);
        CC_ASSERT(theString->compare("Hello world!") == 0);
        
        __String * theStringPtr = theString;
        theString.reset();
        CC_ASSERT(theStringPtr->getReferenceCount() == 1);
        CC_ASSERT(theStringPtr->compare("Hello world!") == 0);
    }
    
    // TEST(moveAssignmentOperator)
    {
        auto someFunc = []() -> RefPtr<__String>
        {
            return __String::create("Hello world!");
        };
        
        RefPtr<__String> theString(someFunc());
        CC_ASSERT(theString->getReferenceCount() == 2);
        CC_ASSERT(theString->compare("Hello world!") == 0);
        
        theString = someFunc();                             // No need to use std::move here, compiler should figure out that move semantics are appropriate for this statement.
        CC_ASSERT(theString->getReferenceCount() == 2);
        CC_ASSERT(theString->compare("Hello world!") == 0);
    }
#else
    log("RefPtr tests are not executed in release mode");
#endif
}
Esempio n. 4
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));
}
Esempio n. 5
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);
}
Esempio n. 6
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;
}
Esempio n. 7
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;
}