1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the test suite of the Qt Toolkit. |
7 ** This file is part of the test suite of the Qt Toolkit. |
8 ** |
8 ** |
1822 #endif |
1822 #endif |
1823 |
1823 |
1824 void tst_QGL::shareRegister() |
1824 void tst_QGL::shareRegister() |
1825 { |
1825 { |
1826 #ifdef QT_BUILD_INTERNAL |
1826 #ifdef QT_BUILD_INTERNAL |
1827 QGLShareRegister *shareReg = qgl_share_reg(); |
|
1828 QVERIFY(shareReg != 0); |
|
1829 |
|
1830 // Create a context. |
1827 // Create a context. |
1831 QGLWidget *glw1 = new QGLWidget(); |
1828 QGLWidget *glw1 = new QGLWidget(); |
1832 glw1->makeCurrent(); |
1829 glw1->makeCurrent(); |
1833 |
1830 |
1834 // Nothing should be sharing with glw1's context yet. |
1831 // Nothing should be sharing with glw1's context yet. |
1835 QList<const QGLContext *> list; |
1832 QVERIFY(!glw1->isSharing()); |
1836 list = shareReg->shares(glw1->context()); |
|
1837 QCOMPARE(list.size(), 0); |
|
1838 |
1833 |
1839 // Create a guard for the first context. |
1834 // Create a guard for the first context. |
1840 QGLSharedResourceGuard guard(glw1->context()); |
1835 QGLSharedResourceGuard guard(glw1->context()); |
1841 QVERIFY(guard.id() == 0); |
1836 QVERIFY(guard.id() == 0); |
1842 guard.setId(3); |
1837 guard.setId(3); |
1865 |
1860 |
1866 // Guard should still be the same. |
1861 // Guard should still be the same. |
1867 QVERIFY(guard.context() == glw1->context()); |
1862 QVERIFY(guard.context() == glw1->context()); |
1868 QVERIFY(guard.id() == 3); |
1863 QVERIFY(guard.id() == 3); |
1869 |
1864 |
1870 // Now there are two items in the share lists. |
|
1871 list = shareReg->shares(glw1->context()); |
|
1872 QCOMPARE(list.size(), 2); |
|
1873 QVERIFY(list.contains(glw1->context())); |
|
1874 QVERIFY(list.contains(glw2->context())); |
|
1875 list = shareReg->shares(glw2->context()); |
|
1876 QCOMPARE(list.size(), 2); |
|
1877 QVERIFY(list.contains(glw1->context())); |
|
1878 QVERIFY(list.contains(glw2->context())); |
|
1879 |
|
1880 // Check the sharing relationships. |
1865 // Check the sharing relationships. |
1881 QVERIFY(QGLContext::areSharing(glw1->context(), glw1->context())); |
1866 QVERIFY(QGLContext::areSharing(glw1->context(), glw1->context())); |
1882 QVERIFY(QGLContext::areSharing(glw2->context(), glw2->context())); |
1867 QVERIFY(QGLContext::areSharing(glw2->context(), glw2->context())); |
1883 QVERIFY(QGLContext::areSharing(glw1->context(), glw2->context())); |
1868 QVERIFY(QGLContext::areSharing(glw1->context(), glw2->context())); |
1884 QVERIFY(QGLContext::areSharing(glw2->context(), glw1->context())); |
1869 QVERIFY(QGLContext::areSharing(glw2->context(), glw1->context())); |
1899 QVERIFY(!qt_shared_test()->value(glw3->context())); |
1884 QVERIFY(!qt_shared_test()->value(glw3->context())); |
1900 qt_shared_test()->insert(glw3->context(), res3); |
1885 qt_shared_test()->insert(glw3->context(), res3); |
1901 QVERIFY(qt_shared_test()->value(glw1->context()) == res1); |
1886 QVERIFY(qt_shared_test()->value(glw1->context()) == res1); |
1902 QVERIFY(qt_shared_test()->value(glw2->context()) == res1); |
1887 QVERIFY(qt_shared_test()->value(glw2->context()) == res1); |
1903 QVERIFY(qt_shared_test()->value(glw3->context()) == res3); |
1888 QVERIFY(qt_shared_test()->value(glw3->context()) == res3); |
1904 |
|
1905 // First two should still be sharing, but third is in its own list. |
|
1906 list = shareReg->shares(glw1->context()); |
|
1907 QCOMPARE(list.size(), 2); |
|
1908 QVERIFY(list.contains(glw1->context())); |
|
1909 QVERIFY(list.contains(glw2->context())); |
|
1910 list = shareReg->shares(glw2->context()); |
|
1911 QCOMPARE(list.size(), 2); |
|
1912 QVERIFY(list.contains(glw1->context())); |
|
1913 QVERIFY(list.contains(glw2->context())); |
|
1914 list = shareReg->shares(glw3->context()); |
|
1915 QCOMPARE(list.size(), 0); |
|
1916 |
1889 |
1917 // Check the sharing relationships again. |
1890 // Check the sharing relationships again. |
1918 QVERIFY(QGLContext::areSharing(glw1->context(), glw1->context())); |
1891 QVERIFY(QGLContext::areSharing(glw1->context(), glw1->context())); |
1919 QVERIFY(QGLContext::areSharing(glw2->context(), glw2->context())); |
1892 QVERIFY(QGLContext::areSharing(glw2->context(), glw2->context())); |
1920 QVERIFY(QGLContext::areSharing(glw1->context(), glw2->context())); |
1893 QVERIFY(QGLContext::areSharing(glw1->context(), glw2->context())); |
1949 QVERIFY(guard.context() == glw2->context()); |
1922 QVERIFY(guard.context() == glw2->context()); |
1950 QVERIFY(guard.id() == 3); |
1923 QVERIFY(guard.id() == 3); |
1951 QVERIFY(guard3.context() == glw3->context()); |
1924 QVERIFY(guard3.context() == glw3->context()); |
1952 QVERIFY(guard3.id() == 5); |
1925 QVERIFY(guard3.id() == 5); |
1953 |
1926 |
1954 // Re-check the share list for the second context (should be empty now). |
|
1955 list = shareReg->shares(glw2->context()); |
|
1956 QCOMPARE(list.size(), 0); |
|
1957 |
|
1958 // Clean up and check that the resources are properly deleted. |
1927 // Clean up and check that the resources are properly deleted. |
1959 delete glw2; |
1928 delete glw2; |
1960 QCOMPARE(tst_QGLResource::deletions, 1); |
1929 QCOMPARE(tst_QGLResource::deletions, 1); |
1961 delete glw3; |
1930 delete glw3; |
1962 QCOMPARE(tst_QGLResource::deletions, 2); |
1931 QCOMPARE(tst_QGLResource::deletions, 2); |