void tst_QGalleryResource::copy()
{
    const int sampleRateKey = 3;
    const int audioCodecKey = 6;
    const int videoCodecKey = 9;

    const QUrl url1("file:///a/local/video/file.m4v");
    const QUrl url2("http://example.com/video.mpg");

    QMap<int, QVariant> attributes1;
    attributes1.insert(sampleRateKey, 44100);
    attributes1.insert(audioCodecKey, QLatin1String("aac"));
    attributes1.insert(videoCodecKey,  QLatin1String("h264"));

    QMap<int, QVariant> attributes2;
    attributes2.insert(sampleRateKey, 22050);

    QGalleryResource resource1(url1);
    QGalleryResource resource2(url1, attributes1);
    QGalleryResource resource3(url2, attributes2);

    QCOMPARE(resource1.url(), url1);
    QCOMPARE(resource1.attributes().isEmpty(), true);

    QCOMPARE(resource2.url(), url1);
    QCOMPARE(resource2.attributes(), attributes1);

    QCOMPARE(resource3.url(), url2);
    QCOMPARE(resource3.attributes(), attributes2);

    resource1 = resource2;
    QCOMPARE(resource1.url(), url1);
    QCOMPARE(resource1.attributes(), attributes1);

    resource2 = resource3;
    QCOMPARE(resource2.url(), url2);
    QCOMPARE(resource2.attributes(), attributes2);
}
Ejemplo n.º 2
0
//
// Alpha_Hlsl_LineShader::OnRestore                                       - Chapter 15, page 509
//
HRESULT Alpha_Hlsl_LineShader::OnRestore(Scene *pScene)
{
    HRESULT hr = S_OK;

    SAFE_RELEASE(m_pVertexLayout11);
    SAFE_RELEASE(m_pVertexShader);
    SAFE_RELEASE(m_pcbVSMatrices);
    SAFE_RELEASE(m_pcbVSLighting );
    SAFE_RELEASE(m_pcbVSMaterial);
    SAFE_RELEASE(m_pPixelShader);
    SAFE_RELEASE(m_pcbPSMaterial);

	shared_ptr<D3DRenderer11> d3dRenderer11 = static_pointer_cast<D3DRenderer11>(pScene->GetRenderer());

    //========================================================
    // Set up the vertex shader and related constant buffers

    // Compile the vertex shader using the lowest possible profile for broadest feature level support
    ID3DBlob* pVertexShaderBuffer = NULL;

	std::string hlslFileName = "Effects\\Alpha_VS.hlsl";
	Resource resource(hlslFileName.c_str());
	shared_ptr<ResHandle> pResourceHandle = g_pApp->m_ResCache->GetHandle(&resource);  // this actually loads the HLSL file from the zip file **** did i code this yet?
	if(FAILED(d3dRenderer11->CompileShader(pResourceHandle->Buffer(), pResourceHandle->Size(), hlslFileName.c_str(), "Alpha_VSMain", "vs_4_0_level_9_1", &pVertexShaderBuffer)))
	{
		SAFE_RELEASE (pVertexShaderBuffer);
		return hr;
	}

	if(FAILED(g_pDX11W->GetD3D11Device()->CreateVertexShader(pVertexShaderBuffer->GetBufferPointer(),pVertexShaderBuffer->GetBufferSize(), NULL, &m_pVertexShader)))
	{
		SAFE_RELEASE (pVertexShaderBuffer);
		return hr;
	}
        
	if (SUCCEEDED(g_pDX11W->GetD3D11Device()->CreateInputLayout(D3D11VertexLayout_UnlitTextured, ARRAYSIZE(D3D11VertexLayout_UnlitTextured), pVertexShaderBuffer->GetBufferPointer(),
		pVertexShaderBuffer->GetBufferSize(), &m_pVertexLayout11)))
	{
		// Setup constant buffers
		D3D11_BUFFER_DESC Desc;
		Desc.Usage = D3D11_USAGE_DYNAMIC;
		Desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
		Desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
		Desc.MiscFlags = 0;

		Desc.ByteWidth = sizeof(ConstantBuffer_Matrices);
		V_RETURN(g_pDX11W->GetD3D11Device()->CreateBuffer(&Desc, NULL, &m_pcbVSMatrices));

		Desc.ByteWidth = sizeof(ConstantBuffer_Lighting);
		V_RETURN(g_pDX11W->GetD3D11Device()->CreateBuffer(&Desc, NULL, &m_pcbVSLighting));

		Desc.ByteWidth = sizeof(ConstantBuffer_Material);
		V_RETURN(g_pDX11W->GetD3D11Device()->CreateBuffer(&Desc, NULL, &m_pcbVSMaterial));
	}

	SAFE_RELEASE(pVertexShaderBuffer);

    //========================================================
    // Set up the pixel shader and related constant buffers

    // Compile the pixel shader using the lowest possible profile for broadest feature level support
    ID3DBlob* pPixelShaderBuffer = NULL;

    hlslFileName = "Effects\\Alpha_PS.hlsl";
    Resource resource2(hlslFileName.c_str());
    shared_ptr<ResHandle> pResourceHandle2 = g_pApp->m_ResCache->GetHandle(&resource2);  // this actually loads the HLSL file from the zip file
    if(FAILED(d3dRenderer11->CompileShader(pResourceHandle2->Buffer(), pResourceHandle2->Size(), hlslFileName.c_str(), "Alpha_PSMain", "ps_4_0_level_9_1", &pPixelShaderBuffer)))
    {
        SAFE_RELEASE (pPixelShaderBuffer);
        return hr;
    }

    if(SUCCEEDED(g_pDX11W->GetD3D11Device()->CreatePixelShader(pPixelShaderBuffer->GetBufferPointer(),
        pPixelShaderBuffer->GetBufferSize(), NULL, &m_pPixelShader)))
    {
        // Setup constant buffers
        D3D11_BUFFER_DESC Desc;
        Desc.Usage = D3D11_USAGE_DYNAMIC;
        Desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
        Desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
        Desc.MiscFlags = 0;

        Desc.ByteWidth = sizeof( ConstantBuffer_Material );
        hr = g_pDX11W->GetD3D11Device()->CreateBuffer( &Desc, NULL, &m_pcbPSMaterial );
    }

    SAFE_RELEASE(pPixelShaderBuffer);
    return hr;
}
void tst_QMediaResource::equality()
{
    QMediaResource resource1(
            QUrl(QString::fromLatin1("http://test.com/test.mp4")),
            QString::fromLatin1("video/mp4"));
    QMediaResource resource2(
            QUrl(QString::fromLatin1("http://test.com/test.mp4")),
            QString::fromLatin1("video/mp4"));
    QMediaResource resource3(
            QUrl(QString::fromLatin1("file:///thumbs/test.jpg")));
    QMediaResource resource4(
            QUrl(QString::fromLatin1("file:///thumbs/test.jpg")));
    QMediaResource resource5(
            QUrl(QString::fromLatin1("http://test.com/test.mp3")),
            QString::fromLatin1("audio/mpeg"));

    QNetworkRequest request(QUrl("http://test.com/test.mp3"));
    QString requestMimeType("audio/mp3");

    QMediaResource requestResource1(request, requestMimeType);
    QMediaResource requestResource2(request, requestMimeType);

    QCOMPARE(requestResource1 == requestResource2, true);
    QCOMPARE(requestResource1 != requestResource2, false);
    QCOMPARE(requestResource1 != resource5, true);

    QCOMPARE(resource1 == resource2, true);
    QCOMPARE(resource1 != resource2, false);

    QCOMPARE(resource3 == resource4, true);
    QCOMPARE(resource3 != resource4, false);

    QCOMPARE(resource1 == resource3, false);
    QCOMPARE(resource1 != resource3, true);

    QCOMPARE(resource1 == resource5, false);
    QCOMPARE(resource1 != resource5, true);

    resource1.setAudioCodec(QString::fromLatin1("mp3"));
    resource2.setAudioCodec(QString::fromLatin1("aac"));

    // Not equal differing audio codecs.
    QCOMPARE(resource1 == resource2, false);
    QCOMPARE(resource1 != resource2, true);

    resource1.setAudioCodec(QString::fromLatin1("aac"));

    // Equal.
    QCOMPARE(resource1 == resource2, true);
    QCOMPARE(resource1 != resource2, false);

    resource1.setVideoCodec(QString());

    // Equal.
    QCOMPARE(resource1 == resource2, true);
    QCOMPARE(resource1 != resource2, false);

    resource1.setVideoCodec(QString::fromLatin1("h264"));

    // Not equal differing video codecs.
    QCOMPARE(resource1 == resource2, false);
    QCOMPARE(resource1 != resource2, true);

    resource2.setVideoCodec(QString::fromLatin1("h264"));

    // Equal.
    QCOMPARE(resource1 == resource2, true);
    QCOMPARE(resource1 != resource2, false);

    resource2.setDataSize(0);

    // Equal.
    QCOMPARE(resource1 == resource2, true);
    QCOMPARE(resource1 != resource2, false);

    resource1.setDataSize(546423);

    // Not equal differing video codecs.
    QCOMPARE(resource1 == resource2, false);
    QCOMPARE(resource1 != resource2, true);

    resource2.setDataSize(546423);

    // Equal.
    QCOMPARE(resource1 == resource2, true);
    QCOMPARE(resource1 != resource2, false);

    resource1.setAudioBitRate(96000);
    resource1.setSampleRate(48000);
    resource2.setSampleRate(44100);
    resource1.setChannelCount(0);
    resource1.setVideoBitRate(900000);
    resource2.setLanguage(QString::fromLatin1("eng"));

    // Not equal, audio bit rate, sample rate, video bit rate, and
    // language.
    QCOMPARE(resource1 == resource2, false);
    QCOMPARE(resource1 != resource2, true);

    resource2.setAudioBitRate(96000);
    resource1.setSampleRate(44100);

    // Not equal, differing video bit rate, and language.
    QCOMPARE(resource1 == resource2, false);
    QCOMPARE(resource1 != resource2, true);

    resource2.setVideoBitRate(900000);
    resource1.setLanguage(QString::fromLatin1("eng"));

    // Equal
    QCOMPARE(resource1 == resource2, true);
    QCOMPARE(resource1 != resource2, false);

    resource1.setResolution(QSize());

    // Equal
    QCOMPARE(resource1 == resource2, true);
    QCOMPARE(resource1 != resource2, false);

    resource2.setResolution(-1, -1);

    // Equal
    QCOMPARE(resource1 == resource2, true);
    QCOMPARE(resource1 != resource2, false);

    resource1.setResolution(QSize(-640, -480));

    // Not equal, differing resolution.
    QCOMPARE(resource1 == resource2, false);
    QCOMPARE(resource1 != resource2, true);
    resource1.setResolution(QSize(640, 480));
    resource2.setResolution(QSize(800, 600));

    // Not equal, differing resolution.
    QCOMPARE(resource1 == resource2, false);
    QCOMPARE(resource1 != resource2, true);

    resource1.setResolution(800, 600);

    // Equal
    QCOMPARE(resource1 == resource2, true);
    QCOMPARE(resource1 != resource2, false);

    /* equality tests for constructor of QMediaresource(QNetworkrequest,mimeType)*/
    QNetworkRequest request2(QUrl(QString::fromLatin1("http://test.com/test.mp4")));
    QUrl url(QString::fromLatin1("http://test.com/test.mp4"));
    QString mimeType(QLatin1String("video/mp4"));

    QMediaResource resource6(request2,mimeType);
    QMediaResource resource7(request2,mimeType);


    QVERIFY(resource6.request()==request2);
    QVERIFY(resource6.mimeType()==mimeType);


    QVERIFY(resource7.request()==request2);
    QVERIFY(resource7.mimeType()==mimeType);

    QVERIFY(resource6.request()==resource7.request());
    QVERIFY(resource6.mimeType()==resource7.mimeType());

    QVERIFY(resource6==resource7);

    /*for copy constructor*/
    QMediaResource resource8(resource7);

    QVERIFY(resource8.request()==request2);
    QVERIFY(resource8.mimeType()==mimeType);


    QVERIFY(resource7.request()==request2);
    QVERIFY(resource7.mimeType()==mimeType);

    QVERIFY(resource8.request()==resource7.request());
    QVERIFY(resource8.mimeType()==resource7.mimeType());


    QVERIFY(resource8==resource7);

    /*for assign constructor*/

    QMediaResource resource9(request2,mimeType);

    QMediaResource resource10=resource9;

    QVERIFY(resource10.request()==request2);
    QVERIFY(resource10.mimeType()==mimeType);


    QVERIFY(resource9.request()==request2);
    QVERIFY(resource9.mimeType()==mimeType);

    QVERIFY(resource8.request()==resource7.request());
    QVERIFY(resource8.mimeType()==resource7.mimeType());

    QVERIFY(resource8==resource7);
}