diff options
Diffstat (limited to 'tests/auto')
175 files changed, 3529 insertions, 2033 deletions
diff --git a/tests/auto/android/runtests_androiddeployqt.pl b/tests/auto/android/runtests_androiddeployqt.pl deleted file mode 100755 index 24b44cf9b2..0000000000 --- a/tests/auto/android/runtests_androiddeployqt.pl +++ /dev/null @@ -1,550 +0,0 @@ -#!/usr/bin/perl -w -############################################################################# -## -## Copyright (C) 2012-2013 BogDan Vatra <bogdan@kde.org> -## Copyright (C) 2016 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the test suite of the Qt Toolkit. -## -## $QT_BEGIN_LICENSE:GPL-EXCEPT$ -## Commercial License Usage -## Licensees holding valid commercial Qt licenses may use this file in -## accordance with the commercial license agreement provided with the -## Software or, alternatively, in accordance with the terms contained in -## a written agreement between you and The Qt Company. For licensing terms -## and conditions see https://www.qt.io/terms-conditions. For further -## information use the contact form at https://www.qt.io/contact-us. -## -## GNU General Public License Usage -## Alternatively, this file may be used under the terms of the GNU -## General Public License version 3 as published by the Free Software -## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -## included in the packaging of this file. Please review the following -## information to ensure the GNU General Public License requirements will -## be met: https://www.gnu.org/licenses/gpl-3.0.html. -## -## $QT_END_LICENSE$ -## -############################################################################# - -use Cwd; -use Cwd 'abs_path'; -use File::Basename; -use File::Temp 'tempdir'; -use File::Path 'remove_tree'; -use Getopt::Long; -use Pod::Usage; -use XML::Simple; -use Term::ANSIColor; - -### default options -my @stack = cwd; -my $device_serial=""; # "-s device_serial"; -my $deployqt_device_serial=""; # "-device device_serial"; -my $log_out="xml"; -my $max_runtime = 5; -my $className="org.qtproject.qt5.android.bindings.QtActivity"; -my $jobs = 4; -my $testsubset = ""; -my $man = 0; -my $help = 0; -my $make_clean = 0; -my $stop_on_fail = 0; -my $time_out=400; -my $android_toolchain_version = "4.8"; -my $host_arch = "linux-x86"; -my $android_sdk_dir = "$ENV{'ANDROID_SDK_ROOT'}"; -my $android_ndk_dir = "$ENV{'ANDROID_NDK_ROOT'}"; -my $android_to_connect = "$ENV{'ANDROID_DEVICE'}"; -my $ant_tool = `which ant`; -my $silent = 0; -chomp $ant_tool; -my $strip_tool=""; -my $readelf_tool=""; -# for ci usage -my @failures = ''; -my $total_tests = 0; -my $total_failed = 0; -my $failed_insignificants = 0; -my $ci_use = 0; -my $start = time(); -my $uninstall = 0; - -GetOptions('h|help' => \$help - , man => \$man - , 's|serial=s' => \$device_serial - , 't|test=s' => \$testsubset - , 'c|clean' => \$make_clean - , 'j|jobs=i' => \$jobs - , 'logtype=s' => \$log_out - , 'runtime=i' => \$max_runtime - , 'sdk=s' => \$android_sdk_dir - , 'ndk=s' => \$android_ndk_dir - , 'toolchain=s' => \$android_toolchain_version - , 'host=s' => \$host_arch - , 'ant=s' => \$ant_tool - , 'strip=s' => \$strip_tool - , 'readelf=s' => \$readelf_tool - , 'testcase=s' => \$testcase - , 'f|fail' => sub { $stop_on_fail = 1 } - , 'silent' => sub { $silent = 1 } - , 'ci' => sub { $ci_use = 1 } - , 'uninstall' => sub { $uninstall = 1 } - ) or pod2usage(2); -pod2usage(1) if $help; -pod2usage(-verbose => 2) if $man; - -if ($ci_use){ - use QMake::Project; -} -my $adb_tool="$android_sdk_dir/platform-tools/adb"; - -# For CI. Nodes are connecting to test devices over IP, which is stored to env variable -if ($android_to_connect ne ""){ - print " Found device to be connected from env: $android_to_connect \n"; - system("$adb_tool disconnect $android_to_connect"); - system("$adb_tool connect $android_to_connect"); - sleep(2);# let it connect - system("$adb_tool -s $android_to_connect reboot &");# adb bug, it blocks forever - sleep(15); # wait for the device to come up again - system("$adb_tool disconnect $android_to_connect");# cleans up the left adb reboot process - system("$adb_tool connect $android_to_connect"); - $device_serial =$android_to_connect; -} - -system("$adb_tool devices") == 0 or die "No device found, please plug/start at least one device/emulator\n"; # make sure we have at least on device attached - -$deployqt_device_serial = "--device $device_serial" if ($device_serial); -$device_serial = "-s $device_serial" if ($device_serial); -$testsubset="/$testsubset" if ($testsubset); - -$strip_tool="$android_ndk_dir/toolchains/arm-linux-androideabi-$android_toolchain_version/prebuilt/$host_arch/bin/arm-linux-androideabi-strip" unless($strip_tool); -$readelf_tool="$android_ndk_dir/toolchains/arm-linux-androideabi-$android_toolchain_version/prebuilt/$host_arch/bin/arm-linux-androideabi-readelf" unless($readelf_tool); -$readelf_tool="$readelf_tool -d -w "; - -sub dir -{ -# print "@stack\n"; -} - -sub pushd ($) -{ - unless ( chdir $_[0] ) - { - warn "Error: $!\n"; - return; - } - unshift @stack, cwd; - dir; -} - -sub popd () -{ - @stack > 1 and shift @stack; - chdir $stack[0]; - dir; -} - -############################## -# Read possible insignificance -# from pro file -############################## -sub check_if_insignificant -{ - return 0 if ( !$ci_use ); - my $case = shift; - my $insignificant = 0; - my $prj = QMake::Project->new( 'Makefile' ); - $insignificant = $prj->test( 'insignificant_test' ); - return $insignificant; -} - -############################## -# Print output from given -# $testresult.txt file -############################## -sub print_output -{ - my $res_file = shift; - my $case = shift; - my $insignificant = shift; - my $print_all = 0; - $total_tests++; - if (-e $res_file) { - open my $file, $res_file or die "Could not open $res_file: $!"; - while (my $line = <$file>) { - if ($line =~ m/^FAIL/) { - print "$line"; - # Pretend to be like the "real" testrunner and print out - # all steps - $print_all = 1; - } - } - close $file; - if ($print_all) { - # In case we are printing all, the test failed - system("cat $res_file"); - if ($insignificant) { - print " Testrunner: $case failed, but it is marked with insignificant_test\n"; - push (@failures ,(basename($case)." [insignificant]")); - $failed_insignificants++; - } else { - $total_failed++; - push (@failures ,(basename($case))); - } - } else { - my $cmd = "sed -n 'x;\$p' ${res_file}"; - my $summary = qx(${cmd}); - if ($summary =~ m/^Totals/) { - print "$summary"; - } else { - print "Error: The log is incomplete. Looks like you have to increase the timeout."; - # The test log seems inclomplete, considering the test as failed. - if ($insignificant) { - print " Testrunner: $case failed, but it is marked with insignificant_test\n"; - push (@failures ,(basename($case)." [insignificant]")); - $failed_insignificants++; - } else { - $total_failed++; - push (@failures ,(basename($case))); - } - } - } - } else { - if ($insignificant) { - print " Failed to execute $case, but it is marked with insignificant_test\n"; - push (@failures ,(basename($case)." [insignificant]")); - $failed_insignificants++; - } else { - print "Failed to execute $case \n"; - $total_failed++; - push (@failures ,(basename($case))); - } - } -} - -############################## -# Print summary of test run -############################## - -sub print_summary -{ - my $total = time()-$start; - my $h = 0; - my $m = 0; - my $s = 0; - my $exit = 0; - print "=== Timing: =================== TEST RUN COMPLETED! ============================\n"; - if ($total > 60*60) { - $h = int($total/60/60); - $s = int($total - $h*60*60); - - $m = int($s/60); - $s = 0; - print "Total: $h hours $m minutes\n"; - } elsif ($total > 60) { - $m = int($total/60); - $s = int($total - $m*60); - print "Total: $m minutes $s seconds\n"; - } else { - $s = int($total); - print "Total: $s seconds\n"; - } - - print "=== Failures: =================================================================="; - foreach my $failed (@failures) { - print $failed."\n"; - $exit = 1; - } - print "=== Totals: ".$total_tests." tests, ".($total_tests-$total_failed). - " passes, ".$failed_insignificants. - " insignificant fails ======================\n"; - return $exit; -} - - -sub waitForProcess -{ - my $process=shift; - my $action=shift; - my $timeout=shift; - my $sleepPeriod=shift; - $sleepPeriod=1 if !defined($sleepPeriod); - print "Waiting for $process ".$timeout*$sleepPeriod." seconds to" if (!$silent); - print $action?" start...\n":" die...\n" if (!$silent); - while ($timeout--) - { - my $output = `$adb_tool $device_serial shell ps 2>&1`; # get current processes - #FIXME check why $output is not matching m/.*S $process\n/ or m/.*S $process$/ (eol) - my $res=($output =~ m/.*S $process/)?1:0; # check the procress - if ($action == $res) - { - print "... succeed\n" if (!$silent); - return 1; - } - sleep($sleepPeriod); - print "timeount in ".$timeout*$sleepPeriod." seconds\n" if (!$silent); - } - print "... failed\n" if (!$silent); - return 0; -} - -my $src_dir_qt=abs_path(dirname($0)."/../../.."); -my $quadruplor_dir="$src_dir_qt/tests/auto/android"; -my $qmake_path="$src_dir_qt/bin/qmake"; -my $androiddeployqt_path="$src_dir_qt/bin/androiddeployqt"; -my $tests_dir="$src_dir_qt/tests$testsubset"; -my $temp_dir=tempdir(CLEANUP => 1); -my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); -my $output_dir=$stack[0]."/".(1900+$year)."-$mon-$mday-$hour:$min"; -mkdir($output_dir); -unlink("latest"); -system(" ln -s $output_dir latest"); -my $sdk_api=0; -my $output = `$adb_tool $device_serial shell getprop`; # get device properties -if ($output =~ m/.*\[ro.build.version.sdk\]: \[(\d+)\]/) -{ - $sdk_api=int($1); - $sdk_api=5 if ($sdk_api>5 && $sdk_api<8); - $sdk_api=9 if ($sdk_api>9); -} - -sub checkXMLOutput -{ - print color 'bold red'; - my $fileName = shift; - my $XMLOutput = eval { XMLin($fileName, ForceArray => 1) }; - if (!defined($XMLOutput)) { - print "Can't parse the $fileName file, probably the test crased.\n"; - print color 'reset'; - die "Stopping\n" if $stop_on_fail; - return; - } - my $testName = $XMLOutput->{name}; - my $fail = 0; - while (my($node_key, $node_valule) = each (%{$XMLOutput})) { - next if $node_key ne "TestFunction"; - while (my($function_key, $function_valule) = each (%{$node_valule})) { - while (my($test_key, $test_valule) = each (%{$function_valule})) { - next if $test_key ne "Incident"; - for my $incident (@{$test_valule}) { - if (($incident->{type} ne "pass") && ($incident->{type} ne "xfail")) { - print "test $testName::$function_key failed $incident->{file}:$incident->{line}\n"; - $fail = 1; - } - } - } - } - } - print color 'reset'; - die "Stopping\n" if $stop_on_fail and $fail; -} - -sub startTest -{ - my $testName = shift; - my $packageName = "org.qtproject.example.tst_$testName"; - my $intentName = "$packageName/org.qtproject.qt5.android.bindings.QtActivity"; - my $output_file = shift; - my $insignificance = shift; - my $get_xml= 0; - my $get_txt= 0; - my $testLib =""; - if ($log_out eq "xml") { - $testLib="-o /data/data/$packageName/output.xml,xml"; - $get_xml = 1; - } elsif ($log_out eq "txt") { - $testLib="-o /data/data/$packageName/output.txt,txt"; - $get_txt = 1; - } else { - $testLib="-o /data/data/$packageName/output.xml,xml -o /data/data/$packageName/output.txt,txt"; - $get_xml = 1; - $get_txt = 1; - } - - my $cmd="${adb_tool} ${device_serial} shell am start -e applicationArguments \"${testLib}\" -n ${intentName}"; - my $res = qx(${cmd}); - print $res if (!$silent); - #wait to start (if it has not started and quit already) - waitForProcess($packageName,1,10); - - #wait to stop - unless(waitForProcess($packageName,0,$time_out,5)) - { - #killProcess($packageName); - print "Someone should kill $packageName\n"; - system("$adb_tool $device_serial uninstall $packageName") if ($uninstall); - return 1; - } - - # Wait for three seconds to allow process to write all data - sleep(3); - - system("$adb_tool $device_serial pull /data/data/$packageName/output.xml $output_dir/$output_file.xml") if ($get_xml); - - system("$adb_tool $device_serial pull /data/data/$packageName/output.txt $output_dir/$output_file.txt") if ($get_txt); - if ($get_txt){ - print "Test results for $packageName:\n"; - my $insig = - print_output("$output_dir/$output_file.txt", $packageName, $insignificance); - } - system("$adb_tool $device_serial uninstall $packageName") if ($uninstall); - - checkXMLOutput("$output_dir/$output_file.xml") if ($get_xml); - return 1; -} - -########### build qt tests and benchmarks ########### -pushd($tests_dir); -print "Building $tests_dir \n"; -system("make distclean") if ($make_clean); -system("$qmake_path -r") == 0 or die "Can't run qmake\n"; #exec qmake -system("make -j$jobs") == 0 or warn "Can't build all tests\n"; #exec make - -my $testsFiles = ""; -if ($testcase) { - $testsFiles=`find . -name libtst_$testcase.so`; # only tests -} else { - $testsFiles=`find . -name libtst_*.so`; # only tests -} - -foreach (split("\n",$testsFiles)) -{ - chomp; #remove white spaces - pushd(abs_path(dirname($_))); # cd to application dir - my $insig = check_if_insignificant(); - my $cmd="make INSTALL_ROOT=${temp_dir} install"; - my $res = qx(${cmd}); - print $res if (!$silent); - my $application=basename(cwd); - if ($silent) { - $cmd="$androiddeployqt_path --install ${deployqt_device_serial} --output ${temp_dir} --deployment debug --verbose --input android-libtst_${application}.so-deployment-settings.json >/dev/null 2>&1"; - } else { - $cmd="$androiddeployqt_path --install ${deployqt_device_serial} --output ${temp_dir} --deployment debug --verbose --input android-libtst_${application}.so-deployment-settings.json"; - } - $res = qx(${cmd}); - print $res if (!$silent); - my $output_name=dirname($_); - $output_name =~ s/\.//; # remove first "." character - $output_name =~ s/\///; # remove first "/" character - $output_name =~ s/\//_/g; # replace all "/" with "_" - $output_name=$application unless($output_name); - $time_out=$max_runtime*60/5; # 5 minutes time out for a normal test - - $applicationLibrary = `find $temp_dir -name libtst_bench_$application.so`; - - if ($applicationLibrary) - { - $time_out=5*60/5; # 10 minutes for a benchmark - $application = "bench_$application"; - } - else - { - $applicationLibrary = `find $temp_dir -name libtst_$application.so`; - } - - if (!$applicationLibrary) - { - print "Can't find application binary libtst_$application.so in $temp_dir!\n"; - } - else - { - startTest($application, "$output_name", $insig) or warn "Can't run $application ...\n"; - } - - popd(); - remove_tree( $temp_dir, {keep_root => 1} ); -} -print_summary() if ($ci_use); -popd(); - -__END__ - -=head1 NAME - -Script to run all qt tests/benchmarks to an android device/emulator - -=head1 SYNOPSIS - -runtests.pl [options] - -=head1 OPTIONS - -=over 8 -=item B<-f --fail> - -Stop the script when test fails. Default 0 - -=item B<-s --serial = serial> - -Device serial number. May be empty if only one device is attached. - -=item B<-t --test = test_subset> - -Tests subset (e.g. benchmarks, auto, auto/qbuffer, etc.). - -=item B<-c --clean> - -Clean tests before building them. - -=item B<-j --jobs = number> - -Make jobs when building tests. - -=item B<--sdk = sdk_path> - -Android SDK path. - -=item B<--ndk = ndk_path> - -Android NDK path. - -=item B<--ant = ant_tool_path> - -Ant tool path. - -=item B<--strip = strip_tool_path> - -Android strip tool path, used to deploy qt libs. - -=item B<--readelf = readelf_tool_path> - -Android readelf tool path, used to check if a test application uses qt OpenGL. - -=item B<--logtype = xml|txt|both> - -The format of log file, default is xml. - -=item B<--runtime = minutes> - -The timeout period before stopping individual tests from running. - -=item B<-silent> - -Suppress output of system commands. - -=item B<-ci> - -Enables checking if test is insignificant or not. Also prints test -summary after all tests has been executed. - -=item B<-uninstall> - -Uninstalls the test after has been executed. - -=item B<-h --help> - -Print a brief help message and exits. - -=item B<--man> - -Prints the manual page and exits. - -=back - -=head1 DESCRIPTION - -B<This program> will run all qt tests/benchmarks to an android device/emulator. - -=cut diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 51d0d2879e..5b10a74d3f 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -146,7 +146,12 @@ endif() expect_pass(test_interface_link_libraries) expect_pass(test_moc_macro_target) -expect_pass(test_add_big_resource) + +if (NOT CMAKE_VERSION VERSION_LESS 3.9) + # The modification of TARGET_OBJECTS needs the following change in cmake + # https://gitlab.kitware.com/cmake/cmake/commit/93c89bc75ceee599ba7c08b8fe1ac5104942054f + expect_pass(test_add_big_resource) +endif() if (NOT CMAKE_VERSION VERSION_LESS 3.8) # With earlier CMake versions, this test would simply run moc multiple times and lead to: diff --git a/tests/auto/cmake/test_add_big_resource/CMakeLists.txt b/tests/auto/cmake/test_add_big_resource/CMakeLists.txt index f928b11278..45ed2c79d5 100644 --- a/tests/auto/cmake/test_add_big_resource/CMakeLists.txt +++ b/tests/auto/cmake/test_add_big_resource/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.9) project(test_add_big_resource) diff --git a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp index 2e698e6615..3c77b1ba0b 100644 --- a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp +++ b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp @@ -88,7 +88,7 @@ QAtomicInt iterations; class PrintFor : public IterateKernel<TestIterator, void> { public: - PrintFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.store(0); } + PrintFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.storeRelaxed(0); } bool runIterations(TestIterator/*beginIterator*/, int begin, int end, void *) { iterations.fetchAndAddRelaxed(end - begin); @@ -107,7 +107,7 @@ public: class SleepPrintFor : public IterateKernel<TestIterator, void> { public: - SleepPrintFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.store(0); } + SleepPrintFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.storeRelaxed(0); } inline bool runIterations(TestIterator/*beginIterator*/, int begin, int end, void *) { QTest::qSleep(200); @@ -127,7 +127,7 @@ public: void tst_QtConcurrentIterateKernel::instantiate() { startThreadEngine(new PrintFor(0, 40)).startBlocking(); - QCOMPARE(iterations.load(), 40); + QCOMPARE(iterations.loadRelaxed(), 40); } void tst_QtConcurrentIterateKernel::cancel() @@ -138,8 +138,8 @@ void tst_QtConcurrentIterateKernel::cancel() f.waitForFinished(); QVERIFY(f.isCanceled()); // the threads might run one iteration each before they are canceled. - QVERIFY2(iterations.load() <= QThread::idealThreadCount(), - (QByteArray::number(iterations.load()) + ' ' + QByteArray::number(QThread::idealThreadCount()))); + QVERIFY2(iterations.loadRelaxed() <= QThread::idealThreadCount(), + (QByteArray::number(iterations.loadRelaxed()) + ' ' + QByteArray::number(QThread::idealThreadCount()))); } } @@ -147,7 +147,7 @@ QAtomicInt counter; class CountFor : public IterateKernel<TestIterator, void> { public: - CountFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.store(0); } + CountFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.storeRelaxed(0); } inline bool runIterations(TestIterator/*beginIterator*/, int begin, int end, void *) { counter.fetchAndAddRelaxed(end - begin); @@ -164,10 +164,10 @@ void tst_QtConcurrentIterateKernel::stresstest() const int iterations = 1000; const int times = 50; for (int i = 0; i < times; ++i) { - counter.store(0); + counter.storeRelaxed(0); CountFor f(0, iterations); f.startBlocking(); - QCOMPARE(counter.load(), iterations); + QCOMPARE(counter.loadRelaxed(), iterations); } } @@ -186,7 +186,7 @@ public: // this class throttles between iterations 100 and 200, // and then records how many threads that run between // iterations 140 and 160. - ThrottleFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.store(0); throttling = false; } + ThrottleFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.storeRelaxed(0); throttling = false; } inline bool runIterations(TestIterator/*beginIterator*/, int begin, int end, void *) { if (200 >= begin && 200 < end) { @@ -217,7 +217,7 @@ public: bool shouldThrottleThread() { - const int load = iterations.load(); + const int load = iterations.loadRelaxed(); return (load > 100 && load < 200); } bool throttling; @@ -226,14 +226,14 @@ public: void tst_QtConcurrentIterateKernel::throttling() { const int totalIterations = 400; - iterations.store(0); + iterations.storeRelaxed(0); threads.clear(); ThrottleFor f(0, totalIterations); f.startBlocking(); - QCOMPARE(iterations.load(), totalIterations); + QCOMPARE(iterations.loadRelaxed(), totalIterations); QCOMPARE(threads.count(), 1); diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp index b5486307a7..383de0b2ce 100644 --- a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp +++ b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp @@ -2181,8 +2181,8 @@ public: void updatePeak() { forever { - const int localPeak = peakInstanceCount.load(); - const int localCurrent = currentInstanceCount.load(); + const int localPeak = peakInstanceCount.loadRelaxed(); + const int localCurrent = currentInstanceCount.loadRelaxed(); if (localCurrent <= localPeak) break; if (peakInstanceCount.testAndSetOrdered(localPeak, localCurrent)) @@ -2220,35 +2220,35 @@ void tst_QtConcurrentMap::throttling() const int allowedTemporaries = QThread::idealThreadCount() * 40; { - currentInstanceCount.store(0); - peakInstanceCount.store(0); + currentInstanceCount.storeRelaxed(0); + peakInstanceCount.storeRelaxed(0); QList<InstanceCounter> instances; for (int i = 0; i < itemcount; ++i) instances.append(InstanceCounter()); - QCOMPARE(currentInstanceCount.load(), itemcount); + QCOMPARE(currentInstanceCount.loadRelaxed(), itemcount); int results = QtConcurrent::blockingMappedReduced(instances, slowMap, fastReduce); QCOMPARE(results, itemcount); - QCOMPARE(currentInstanceCount.load(), itemcount); - QVERIFY(peakInstanceCount.load() < itemcount + allowedTemporaries); + QCOMPARE(currentInstanceCount.loadRelaxed(), itemcount); + QVERIFY(peakInstanceCount.loadRelaxed() < itemcount + allowedTemporaries); } { - QCOMPARE(currentInstanceCount.load(), 0); - peakInstanceCount.store(0); + QCOMPARE(currentInstanceCount.loadRelaxed(), 0); + peakInstanceCount.storeRelaxed(0); QList<InstanceCounter> instances; for (int i = 0; i < itemcount; ++i) instances.append(InstanceCounter()); - QCOMPARE(currentInstanceCount.load(), itemcount); + QCOMPARE(currentInstanceCount.loadRelaxed(), itemcount); int results = QtConcurrent::blockingMappedReduced(instances, fastMap, slowReduce); QCOMPARE(results, itemcount); - QCOMPARE(currentInstanceCount.load(), itemcount); - QVERIFY(peakInstanceCount.load() < itemcount + allowedTemporaries); + QCOMPARE(currentInstanceCount.loadRelaxed(), itemcount); + QVERIFY(peakInstanceCount.loadRelaxed() < itemcount + allowedTemporaries); } } @@ -2380,8 +2380,8 @@ InstanceCounter ic_fn(const InstanceCounter & ic) // assigned over with operator == void tst_QtConcurrentMap::qFutureAssignmentLeak() { - currentInstanceCount.store(0); - peakInstanceCount.store(0); + currentInstanceCount.storeRelaxed(0); + peakInstanceCount.storeRelaxed(0); QFuture<InstanceCounter> future; { QList<InstanceCounter> list; @@ -2400,9 +2400,9 @@ void tst_QtConcurrentMap::qFutureAssignmentLeak() // Use QTRY_COMPARE because QtConcurrent::ThreadEngine::asynchronousFinish() // deletes its internals after signaling finished, so it might still be holding // on to copies of InstanceCounter for a short while. - QTRY_COMPARE(currentInstanceCount.load(), 1000); + QTRY_COMPARE(currentInstanceCount.loadRelaxed(), 1000); future = QFuture<InstanceCounter>(); - QTRY_COMPARE(currentInstanceCount.load(), 0); + QTRY_COMPARE(currentInstanceCount.loadRelaxed(), 0); } inline void increment(int &num) diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp index 39d17e0a24..a4eb2936b5 100644 --- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp +++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp @@ -506,17 +506,17 @@ void tst_QtConcurrentRun::recursive() int levels = 15; for (int i = 0; i < QThread::idealThreadCount(); ++i) { - count.store(0); + count.storeRelaxed(0); QThreadPool::globalInstance()->setMaxThreadCount(i); recursiveRun(levels); - QCOMPARE(count.load(), (int)std::pow(2.0, levels) - 1); + QCOMPARE(count.loadRelaxed(), (int)std::pow(2.0, levels) - 1); } for (int i = 0; i < QThread::idealThreadCount(); ++i) { - count.store(0); + count.storeRelaxed(0); QThreadPool::globalInstance()->setMaxThreadCount(i); recursiveResult(levels); - QCOMPARE(count.load(), (int)std::pow(2.0, levels) - 1); + QCOMPARE(count.loadRelaxed(), (int)std::pow(2.0, levels) - 1); } } @@ -570,7 +570,7 @@ public: static QAtomicInt cancel; void run() override { int iter = 60; - while (--iter && !cancel.load()) + while (--iter && !cancel.loadRelaxed()) QThread::currentThread()->msleep(25); } }; @@ -638,7 +638,7 @@ void tst_QtConcurrentRun::exceptions() caught = true; } - SlowTask::cancel.store(true); + SlowTask::cancel.storeRelaxed(true); QVERIFY2(caught, "did not get exception"); } diff --git a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp index a68f7d5a4e..d4c669cddc 100644 --- a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp +++ b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp @@ -28,6 +28,7 @@ #include <qtconcurrentthreadengine.h> #include <qexception.h> #include <QThread> +#include <QElapsedTimer> #include <QtTest/QtTest> using namespace QtConcurrent; @@ -186,7 +187,7 @@ class ThrottleAlwaysUser : public ThreadEngine<void> public: ThrottleAlwaysUser() { - count.store(initialCount = 100); + count.storeRelaxed(initialCount = 100); finishing = false; } @@ -198,7 +199,7 @@ public: ThreadFunctionResult threadFunction() { forever { - const int local = count.load(); + const int local = count.loadRelaxed(); if (local == 0) { finishing = true; return ThreadFinished; @@ -223,13 +224,13 @@ void tst_QtConcurrentThreadEngine::throttle() for (int i = 0; i < repeats; ++i) { QFuture<void> f = (new ThrottleAlwaysUser())->startAsynchronously(); f.waitForFinished(); - QCOMPARE(count.load(), 0); + QCOMPARE(count.loadRelaxed(), 0); } for (int i = 0; i < repeats; ++i) { ThrottleAlwaysUser t; t.startBlocking(); - QCOMPARE(count.load(), 0); + QCOMPARE(count.loadRelaxed(), 0); } } @@ -382,7 +383,7 @@ void tst_QtConcurrentThreadEngine::cancelQueuedSlowUser() { const int times = 100; - QTime t; + QElapsedTimer t; t.start(); { diff --git a/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp b/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp index fc09d57692..66a752df5d 100644 --- a/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp +++ b/tests/auto/corelib/animation/qabstractanimation/tst_qabstractanimation.cpp @@ -83,6 +83,21 @@ void tst_QAbstractAnimation::destruction() { TestableQAbstractAnimation *anim = new TestableQAbstractAnimation; delete anim; + + // Animations should stop when deleted + auto *stopWhenDeleted = new TestableQAbstractAnimation; + QAbstractAnimation::State lastOldState, lastNewState; + QObject::connect(stopWhenDeleted, &QAbstractAnimation::stateChanged, + [&](QAbstractAnimation::State newState, QAbstractAnimation::State oldState) { + lastNewState = newState; + lastOldState = oldState; + }); + stopWhenDeleted->start(); + QCOMPARE(lastOldState, QAbstractAnimation::Stopped); + QCOMPARE(lastNewState, QAbstractAnimation::Running); + delete stopWhenDeleted; + QCOMPARE(lastOldState, QAbstractAnimation::Running); + QCOMPARE(lastNewState, QAbstractAnimation::Stopped); } void tst_QAbstractAnimation::currentLoop() diff --git a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp index 0848a4160f..5c7737085e 100644 --- a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp +++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp @@ -174,9 +174,9 @@ void tst_qfloat16::qNan() QVERIFY(qIsInf(-inf)); QVERIFY(qIsInf(2.f*inf)); QVERIFY(qIsInf(inf*2.f)); - // QTBUG-75812: QEMU's over-optimized arm64 flakily fails 1/inf == 0 :-( + // QTBUG-75812: QEMU/arm64 compiler over-optimizes, so flakily fails 1/inf == 0 :-( if (qfloat16(9.785e-4f) == qfloat16(9.794e-4f)) - QCOMPARE(qfloat16(1.f/inf), qfloat16(0.f)); + QCOMPARE(qfloat16(1.f) / inf, qfloat16(0.f)); #ifdef Q_CC_INTEL QEXPECT_FAIL("", "ICC optimizes zero * anything to zero", Continue); #endif diff --git a/tests/auto/corelib/global/qglobal/qglobal.pro b/tests/auto/corelib/global/qglobal/qglobal.pro index b105769430..e4453affa5 100644 --- a/tests/auto/corelib/global/qglobal/qglobal.pro +++ b/tests/auto/corelib/global/qglobal/qglobal.pro @@ -2,4 +2,6 @@ CONFIG += testcase TARGET = tst_qglobal QT = core testlib SOURCES = tst_qglobal.cpp qglobal.c -contains(QT_CONFIG, c++1z): CONFIG += c++1z +qtConfig(c++11): CONFIG += c++11 +qtConfig(c++14): CONFIG += c++14 +qtConfig(c++1z): CONFIG += c++1z diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 5e5492de59..b33dec8a61 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -464,7 +464,7 @@ typedef int (Empty::*memFun) (); QCOMPARE(Q_ALIGNOF(type), size_t(alignment)); \ /* Compare to native operator for compilers that support it, otherwise... erm... check consistency! :-) */ \ - QCOMPARE(QT_EMULATED_ALIGNOF(type), Q_ALIGNOF(type)); \ + QCOMPARE(alignof(type), Q_ALIGNOF(type)); \ } while (false) /**/ @@ -517,7 +517,7 @@ void tst_QGlobal::qAlignOf() TEST_AlignOf_impl(AlignmentInStruct<double>, Q_ALIGNOF(AlignmentInStruct<qint64>)); // 32-bit x86 ABI, Clang disagrees with gcc -#if !defined(Q_PROCESSOR_X86_32) || !defined(Q_CC_CLANG) +#if !defined(Q_PROCESSOR_X86_32) || !defined(Q_CC_CLANG) || defined(Q_OS_ANDROID) TEST_AlignOf_impl(qint64 [5], Q_ALIGNOF(qint64)); #else TEST_AlignOf_impl(qint64 [5], Q_ALIGNOF(AlignmentInStruct<qint64>)); diff --git a/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp index 2d7db813dd..820a0b999b 100644 --- a/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp +++ b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp @@ -145,7 +145,7 @@ void tst_QGlobalStatic::exception() exceptionCaught = true; } QVERIFY(exceptionCaught); - QCOMPARE(Q_QGS_throwingGS::guard.load(), 0); + QCOMPARE(Q_QGS_throwingGS::guard.loadRelaxed(), 0); QVERIFY(!throwingGS.exists()); QVERIFY(!throwingGS.isDestroyed()); } @@ -154,10 +154,10 @@ QBasicAtomicInt exceptionControlVar = Q_BASIC_ATOMIC_INITIALIZER(1); Q_GLOBAL_STATIC_WITH_ARGS(ThrowingType, exceptionGS, (exceptionControlVar)) void tst_QGlobalStatic::catchExceptionAndRetry() { - if (exceptionControlVar.load() != 1) + if (exceptionControlVar.loadRelaxed() != 1) QSKIP("This test cannot be run more than once"); - ThrowingType::constructedCount.store(0); - ThrowingType::destructedCount.store(0); + ThrowingType::constructedCount.storeRelaxed(0); + ThrowingType::destructedCount.storeRelaxed(0); bool exceptionCaught = false; try { @@ -165,11 +165,11 @@ void tst_QGlobalStatic::catchExceptionAndRetry() } catch (int) { exceptionCaught = true; } - QCOMPARE(ThrowingType::constructedCount.load(), 1); + QCOMPARE(ThrowingType::constructedCount.loadRelaxed(), 1); QVERIFY(exceptionCaught); exceptionGS(); - QCOMPARE(ThrowingType::constructedCount.load(), 2); + QCOMPARE(ThrowingType::constructedCount.loadRelaxed(), 2); } QBasicAtomicInt threadStressTestControlVar = Q_BASIC_ATOMIC_INITIALIZER(5); @@ -194,9 +194,9 @@ void tst_QGlobalStatic::threadStressTest() } }; - ThrowingType::constructedCount.store(0); - ThrowingType::destructedCount.store(0); - int expectedConstructionCount = threadStressTestControlVar.load() + 1; + ThrowingType::constructedCount.storeRelaxed(0); + ThrowingType::destructedCount.storeRelaxed(0); + int expectedConstructionCount = threadStressTestControlVar.loadRelaxed() + 1; if (expectedConstructionCount <= 0) QSKIP("This test cannot be run more than once"); diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index d10d879130..e4b783ad6f 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -48,7 +48,9 @@ private slots: void defaultHandler(); void installMessageHandler(); +#if QT_DEPRECATED_SINCE(5, 0) void installMsgHandler(); +#endif void installBothHandler(); #ifdef QT_BUILD_INTERNAL @@ -112,7 +114,9 @@ void tst_qmessagehandler::initTestCase() void tst_qmessagehandler::cleanup() { +#if QT_DEPRECATED_SINCE(5, 0) qInstallMsgHandler(0); +#endif qInstallMessageHandler((QtMessageHandler)0); s_type = QtFatalMsg; s_file = 0; @@ -143,6 +147,7 @@ void tst_qmessagehandler::installMessageHandler() QCOMPARE((void*)myHandler, (void*)customMessageHandler); } +#if QT_DEPRECATED_SINCE(5, 0) void tst_qmessagehandler::installMsgHandler() { QtMsgHandler oldHandler = qInstallMsgHandler(customMsgHandler); @@ -158,6 +163,7 @@ void tst_qmessagehandler::installMsgHandler() QtMsgHandler myHandler = qInstallMsgHandler(oldHandler); QCOMPARE((void*)myHandler, (void*)customMsgHandler); } +#endif void tst_qmessagehandler::installBothHandler() { @@ -870,12 +876,14 @@ void tst_qmessagehandler::setMessagePattern() #endif // make sure there is no QT_MESSAGE_PATTERN in the environment - QStringList environment = m_baseEnvironment; - QMutableListIterator<QString> iter(environment); - while (iter.hasNext()) { - if (iter.next().startsWith("QT_MESSAGE_PATTERN")) - iter.remove(); - } + QStringList environment; + environment.reserve(m_baseEnvironment.size()); + const auto doesNotStartWith = [](QLatin1String s) { + return [s](const QString &str) { return !str.startsWith(s); }; + }; + std::copy_if(m_baseEnvironment.cbegin(), m_baseEnvironment.cend(), + std::back_inserter(environment), + doesNotStartWith(QLatin1String("QT_MESSAGE_PATTERN"))); process.setEnvironment(environment); process.start(appExe); diff --git a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp index 64557f1460..e238be1de3 100644 --- a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp +++ b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp @@ -57,7 +57,7 @@ static const double RandomValueFP = double(0.3010463714599609); static void setRNGControl(uint v) { #ifdef QT_BUILD_INTERNAL - qt_randomdevice_control.store(v); + qt_randomdevice_control.storeRelaxed(v); #else Q_UNUSED(v); #endif diff --git a/tests/auto/corelib/io/largefile/tst_largefile.cpp b/tests/auto/corelib/io/largefile/tst_largefile.cpp index f459f62c91..e6d2f10c16 100644 --- a/tests/auto/corelib/io/largefile/tst_largefile.cpp +++ b/tests/auto/corelib/io/largefile/tst_largefile.cpp @@ -28,7 +28,6 @@ #include <QTest> -#include <QtAlgorithms> #include <QFile> #include <QFileInfo> #include <QRandomGenerator> diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 4428be08d4..734694abeb 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1036,7 +1036,9 @@ void tst_QFileInfo::systemFiles() QCOMPARE(fi.metadataChangeTime(), fi.lastModified()); // On Windows, they're the same QVERIFY(fi.birthTime().isValid()); QVERIFY(fi.birthTime() <= fi.lastModified()); +#if QT_DEPRECATED_SINCE(5, 10) QCOMPARE(fi.created(), fi.birthTime()); // On Windows, they're the same +#endif } void tst_QFileInfo::compare_data() @@ -1261,7 +1263,7 @@ void tst_QFileInfo::fakeFileTimes_data() QTest::newRow("early") << QDateTime(QDate(1901, 12, 14), QTime(12, 0)); // QTBUG-12006 claims XP handled this (2010-Mar-26 8:46:10) wrong due to an MS API bug: - QTest::newRow("XP-bug") << QDateTime::fromTime_t(1269593170); + QTest::newRow("XP-bug") << QDateTime::fromSecsSinceEpoch(1269593170); } void tst_QFileInfo::fakeFileTimes() @@ -1915,7 +1917,8 @@ void tst_QFileInfo::owner() DWORD bufSize = 1024; if (GetUserNameW(usernameBuf, &bufSize)) { userName = QString::fromWCharArray(usernameBuf); - if (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && IsUserAdmin()) { + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista + && IsUserAdmin()) { // Special case : If the user is a member of Administrators group, all files // created by the current user are owned by the Administrators group. LPLOCALGROUP_USERS_INFO_0 pBuf = NULL; @@ -2042,7 +2045,9 @@ static void stateCheck(const QFileInfo &info, const QString &dirname, const QStr QCOMPARE(info.permissions(), QFile::Permissions()); +#if QT_DEPRECATED_SINCE(5, 10) QVERIFY(!info.created().isValid()); +#endif QVERIFY(!info.birthTime().isValid()); QVERIFY(!info.metadataChangeTime().isValid()); QVERIFY(!info.lastRead().isValid()); diff --git a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp index b98a98df9c..bac7a69e0f 100644 --- a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp +++ b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp @@ -197,15 +197,23 @@ void tst_QFileSelector::urlConvenience_data() QString test("/test");// '/' is here so dir string can also be selector string QString custom1("custom1"); + QString testWithQueryAndFragment("/test?query#Fragment"); QTest::newRow("qrc") << QUrl("qrc:///extras/test") << (QStringList() << custom1) << QUrl(QString("qrc:///extras/") + QLatin1Char(selectorIndicator) + custom1 + test); + QTest::newRow("qrc with query and fragment") << QUrl(QString::fromLatin1("qrc:///extras%1").arg(testWithQueryAndFragment)) << (QStringList() << custom1) + << QUrl(QString("qrc:///extras/") + QLatin1Char(selectorIndicator) + custom1 + testWithQueryAndFragment); QString fileBasePath = QFINDTESTDATA("extras/test"); QString fileSelectedPath = QFINDTESTDATA(QString("extras/") + QLatin1Char(selectorIndicator) + custom1 + QString("/test")); QTest::newRow("file") << QUrl::fromLocalFile(fileBasePath) << (QStringList() << custom1) << QUrl::fromLocalFile(fileSelectedPath); + // do not strip off the query and fragment + QString strUrlWithFragment = QString("file://") + testWithQueryAndFragment; + QTest::newRow("file with query and fragment") << QUrl(strUrlWithFragment) << (QStringList()) << QUrl(strUrlWithFragment); + strUrlWithFragment = QString("file:") + testWithQueryAndFragment; + QTest::newRow("file with query and fragment too") << QUrl(strUrlWithFragment) << (QStringList()) << QUrl(strUrlWithFragment); // http://qt-project.org/images/qtdn/sprites-combined-latest.png is chosen as a representative real world URL // But note that this test is checking that http urls are NOT selected so it shouldn't be checked diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp index eeeb3bc6e2..8703b15dda 100644 --- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp +++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp @@ -496,7 +496,7 @@ void tst_QLockFile::noPermissionsWindows() QSKIP("This test is for desktop Windows only"); #endif #ifdef Q_OS_WIN - if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS7) + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows7) QSKIP("This test requires at least Windows 7"); #endif if (const int p = processProperties()) { diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index c51994c1c1..e799369c8a 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -32,6 +32,7 @@ #include <QtTest/QtTest> #include <QtCore/QProcess> #include <QtCore/QDir> +#include <QtCore/QElapsedTimer> #include <QtCore/QFile> #include <QtCore/QThread> #include <QtCore/QTemporaryDir> @@ -150,6 +151,13 @@ private slots: void failToStartEmptyArgs_data(); void failToStartEmptyArgs(); +#if QT_DEPRECATED_SINCE(5, 13) + void crashTest2_deprecated(); + void restartProcessDeadlock_deprecated(); + void waitForReadyReadInAReadyReadSlot_deprecated(); + void finishProcessBeforeReadingDone_deprecated(); +#endif + protected slots: void readFromProcess(); void exitLoopSlot(); @@ -186,12 +194,20 @@ void tst_QProcess::getSetCheck() QProcess obj1; // ProcessChannelMode QProcess::readChannelMode() // void QProcess::setProcessChannelMode(ProcessChannelMode) +#if QT_DEPRECATED_SINCE(5, 13) obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::SeparateChannels)); QCOMPARE(QProcess::ProcessChannelMode(QProcess::SeparateChannels), obj1.readChannelMode()); obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::MergedChannels)); QCOMPARE(QProcess::ProcessChannelMode(QProcess::MergedChannels), obj1.readChannelMode()); obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::ForwardedChannels)); QCOMPARE(QProcess::ProcessChannelMode(QProcess::ForwardedChannels), obj1.readChannelMode()); +#endif + obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::SeparateChannels)); + QCOMPARE(QProcess::ProcessChannelMode(QProcess::SeparateChannels), obj1.processChannelMode()); + obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::MergedChannels)); + QCOMPARE(QProcess::ProcessChannelMode(QProcess::MergedChannels), obj1.processChannelMode()); + obj1.setProcessChannelMode(QProcess::ProcessChannelMode(QProcess::ForwardedChannels)); + QCOMPARE(QProcess::ProcessChannelMode(QProcess::ForwardedChannels), obj1.processChannelMode()); // ProcessChannel QProcess::readChannel() // void QProcess::setReadChannel(ProcessChannel) @@ -334,12 +350,14 @@ void tst_QProcess::crashTest() qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); QSignalSpy spy(process.data(), &QProcess::errorOccurred); - QSignalSpy spy2(process.data(), static_cast<QProcessErrorSignal>(&QProcess::error)); - QSignalSpy spy3(process.data(), static_cast<QProcessFinishedSignal2>(&QProcess::finished)); - + QSignalSpy spy2(process.data(), static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); + +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy spy3(process.data(), static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy3.isValid()); +#endif QVERIFY(process->waitForFinished(30000)); @@ -347,10 +365,12 @@ void tst_QProcess::crashTest() QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed); QCOMPARE(spy2.count(), 1); - QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed); + QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy2.at(0).at(1).constData()), QProcess::CrashExit); +#if QT_DEPRECATED_SINCE(5, 6) QCOMPARE(spy3.count(), 1); - QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy3.at(0).at(1).constData()), QProcess::CrashExit); + QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy3.at(0).at(0).constData()), QProcess::Crashed); +#endif QCOMPARE(process->exitStatus(), QProcess::CrashExit); @@ -378,7 +398,7 @@ void tst_QProcess::crashTest2() QVERIFY(spy.isValid()); QVERIFY(spy2.isValid()); - QObject::connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + QObject::connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), this, &tst_QProcess::exitLoopSlot); QTestEventLoop::instance().enterLoop(30); @@ -420,7 +440,7 @@ void tst_QProcess::echoTest() process.write(input); - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); do { QVERIFY(process.isOpen()); @@ -479,7 +499,7 @@ void tst_QProcess::echoTest2() QVERIFY(spy1.isValid()); QVERIFY(spy2.isValid()); - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); forever { QTestEventLoop::instance().enterLoop(1); @@ -644,9 +664,11 @@ void tst_QProcess::readTimeoutAndThenCrash() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); QSignalSpy spy(&process, &QProcess::errorOccurred); - QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy.isValid()); +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy2.isValid()); +#endif process.kill(); @@ -655,8 +677,10 @@ void tst_QProcess::readTimeoutAndThenCrash() QCOMPARE(spy.count(), 1); QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed); +#if QT_DEPRECATED_SINCE(5, 6) QCOMPARE(spy2.count(), 1); QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed); +#endif } void tst_QProcess::waitForFinished() @@ -696,12 +720,11 @@ void tst_QProcess::deadWhileReading() void tst_QProcess::restartProcessDeadlock() { - // The purpose of this test is to detect whether restarting a // process in the finished() connected slot causes a deadlock // because of the way QProcessManager uses its locks. QProcess process; - connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), this, &tst_QProcess::restartProcess); process.start("testProcessEcho/testProcessEcho"); @@ -709,7 +732,7 @@ void tst_QProcess::restartProcessDeadlock() QCOMPARE(process.write("", 1), qlonglong(1)); QVERIFY(process.waitForFinished(5000)); - QObject::disconnect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), nullptr, nullptr); + QObject::disconnect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), nullptr, nullptr); QCOMPARE(process.write("", 1), qlonglong(1)); QVERIFY(process.waitForFinished(5000)); @@ -1026,7 +1049,7 @@ void tst_QProcess::mergedChannels() { QProcess process; process.setProcessChannelMode(QProcess::MergedChannels); - QCOMPARE(process.readChannelMode(), QProcess::MergedChannels); + QCOMPARE(process.processChannelMode(), QProcess::MergedChannels); process.start("testProcessEcho2/testProcessEcho2"); @@ -1154,7 +1177,7 @@ protected: exitCode = 90210; QProcess process; - connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), this, &TestThread::catchExitCode, Qt::DirectConnection); process.start("testProcessEcho/testProcessEcho"); @@ -1228,7 +1251,7 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlot() { QProcess process; connect(&process, &QIODevice::readyRead, this, &tst_QProcess::waitForReadyReadInAReadyReadSlotSlot); - connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), this, &tst_QProcess::exitLoopSlot); bytesAvailable = 0; @@ -1467,15 +1490,19 @@ void tst_QProcess::failToStart() QProcess process; QSignalSpy stateSpy(&process, &QProcess::stateChanged); QSignalSpy errorSpy(&process, &QProcess::errorOccurred); - QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); - QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); - + QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(stateSpy.isValid()); QVERIFY(errorSpy.isValid()); - QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); + +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QVERIFY(errorSpy2.isValid()); +#endif +#if QT_DEPRECATED_SINCE(5, 13) + QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); QVERIFY(finishedSpy2.isValid()); +#endif // OS X and HP-UX have a really low default process limit (~100), so spawning // to many processes here will cause test failures later on. @@ -1490,7 +1517,9 @@ void tst_QProcess::failToStart() for (int j = 0; j < 8; ++j) { for (int i = 0; i < attempts; ++i) { QCOMPARE(errorSpy.count(), j * attempts + i); +#if QT_DEPRECATED_SINCE(5, 6) QCOMPARE(errorSpy2.count(), j * attempts + i); +#endif process.start("/blurp"); switch (j) { @@ -1515,9 +1544,13 @@ void tst_QProcess::failToStart() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), j * attempts + i + 1); - QCOMPARE(errorSpy2.count(), j * attempts + i + 1); QCOMPARE(finishedSpy.count(), 0); +#if QT_DEPRECATED_SINCE(5, 6) + QCOMPARE(errorSpy2.count(), j * attempts + i + 1); +#endif +#if QT_DEPRECATED_SINCE(5, 13) QCOMPARE(finishedSpy2.count(), 0); +#endif int it = j * attempts + i + 1; @@ -1536,14 +1569,18 @@ void tst_QProcess::failToStartWithWait() QProcess process; QEventLoop loop; QSignalSpy errorSpy(&process, &QProcess::errorOccurred); - QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); - QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); - + QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); - QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); + +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QVERIFY(errorSpy2.isValid()); +#endif +#if QT_DEPRECATED_SINCE(5, 13) + QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); QVERIFY(finishedSpy2.isValid()); +#endif for (int i = 0; i < 50; ++i) { process.start("/blurp", QStringList() << "-v" << "-debug"); @@ -1551,9 +1588,14 @@ void tst_QProcess::failToStartWithWait() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), i + 1); - QCOMPARE(errorSpy2.count(), i + 1); QCOMPARE(finishedSpy.count(), 0); +#if QT_DEPRECATED_SINCE(5, 6) + QCOMPARE(errorSpy2.count(), i + 1); +#endif +#if QT_DEPRECATED_SINCE(5, 13) QCOMPARE(finishedSpy2.count(), 0); +#endif + } } @@ -1565,14 +1607,18 @@ void tst_QProcess::failToStartWithEventLoop() QProcess process; QEventLoop loop; QSignalSpy errorSpy(&process, &QProcess::errorOccurred); - QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); - QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); - + QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); QVERIFY(errorSpy.isValid()); - QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy.isValid()); + +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QVERIFY(errorSpy2.isValid()); +#endif +#if QT_DEPRECATED_SINCE(5, 13) + QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); QVERIFY(finishedSpy2.isValid()); +#endif // The error signal may be emitted before start() returns connect(&process, &QProcess::errorOccurred, &loop, &QEventLoop::quit, Qt::QueuedConnection); @@ -1585,9 +1631,13 @@ void tst_QProcess::failToStartWithEventLoop() QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(errorSpy.count(), i + 1); - QCOMPARE(errorSpy2.count(), i + 1); QCOMPARE(finishedSpy.count(), 0); +#if QT_DEPRECATED_SINCE(5, 6) + QCOMPARE(errorSpy2.count(), i + 1); +#endif +#if QT_DEPRECATED_SINCE(5, 13) QCOMPARE(finishedSpy2.count(), 0); +#endif } } @@ -1605,8 +1655,12 @@ void tst_QProcess::failToStartEmptyArgs() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); QProcess process; - QSignalSpy errorSpy(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QSignalSpy errorSpy(&process, static_cast<QProcessErrorSignal>(&QProcess::errorOccurred)); QVERIFY(errorSpy.isValid()); +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QVERIFY(errorSpy2.isValid()); +#endif switch (startOverload) { case 0: @@ -1624,6 +1678,9 @@ void tst_QProcess::failToStartEmptyArgs() QVERIFY(!process.waitForStarted()); QCOMPARE(errorSpy.count(), 1); +#if QT_DEPRECATED_SINCE(5, 6) + QCOMPARE(errorSpy2.count(), 1); +#endif QCOMPARE(process.error(), QProcess::FailedToStart); } @@ -1855,24 +1912,32 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess() QProcess process; QSignalSpy errorSpy(&process, &QProcess::errorOccurred); + QSignalSpy finishedSpy(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); + QVERIFY(errorSpy.isValid()); + QVERIFY(finishedSpy.isValid()); + +#if QT_DEPRECATED_SINCE(5, 6) QSignalSpy errorSpy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); + QVERIFY(errorSpy2.isValid()); +#endif +#if QT_DEPRECATED_SINCE(5, 13) QSignalSpy finishedSpy1(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished)); - QSignalSpy finishedSpy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); - - QVERIFY(errorSpy.isValid()); - QVERIFY(errorSpy2.isValid()); QVERIFY(finishedSpy1.isValid()); - QVERIFY(finishedSpy2.isValid()); +#endif QVERIFY(!process.waitForReadyRead()); // used to crash process.start("doesntexist"); QVERIFY(!process.waitForReadyRead()); QCOMPARE(errorSpy.count(), 1); QCOMPARE(errorSpy.at(0).at(0).toInt(), 0); + QCOMPARE(finishedSpy.count(), 0); +#if QT_DEPRECATED_SINCE(5, 6) QCOMPARE(errorSpy2.count(), 1); QCOMPARE(errorSpy2.at(0).at(0).toInt(), 0); +#endif +#if QT_DEPRECATED_SINCE(5, 13) QCOMPARE(finishedSpy1.count(), 0); - QCOMPARE(finishedSpy2.count(), 0); +#endif } void tst_QProcess::setStandardInputFile() @@ -2072,7 +2137,7 @@ void tst_QProcess::fileWriterProcess() stdinStr += line; } - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); const QString fileName = m_temporaryDir.path() + QLatin1String("/fileWriterProcess.txt"); const QString binary = QDir::currentPath() + QLatin1String("/fileWriterProcess/fileWriterProcess"); @@ -2303,14 +2368,18 @@ void tst_QProcess::invalidProgramString() qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); QSignalSpy spy(&process, &QProcess::errorOccurred); - QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy.isValid()); +#if QT_DEPRECATED_SINCE(5, 6) + QSignalSpy spy2(&process, static_cast<QProcessErrorSignal>(&QProcess::error)); QVERIFY(spy2.isValid()); +#endif process.start(programString); QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(spy.count(), 1); +#if QT_DEPRECATED_SINCE(5, 6) QCOMPARE(spy2.count(), 1); +#endif QVERIFY(!QProcess::startDetached(programString)); } @@ -2364,7 +2433,7 @@ void tst_QProcess::finishProcessBeforeReadingDone() QProcess process; BlockOnReadStdOut blocker(&process); QEventLoop loop; - connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + connect(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished), &loop, &QEventLoop::quit); process.start("testProcessOutput/testProcessOutput"); QVERIFY(process.waitForStarted()); @@ -2510,5 +2579,106 @@ void tst_QProcess::processEventsInAReadyReadSlot() QVERIFY(process.waitForFinished()); } +#if QT_DEPRECATED_SINCE(5, 13) + +void tst_QProcess::crashTest2_deprecated() +{ + QProcess process; + process.start("testProcessCrash/testProcessCrash"); + QVERIFY(process.waitForStarted(5000)); + + qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError"); + qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus"); + + QSignalSpy spy(&process, static_cast<QProcessErrorSignal>(&QProcess::errorOccurred)); + QSignalSpy spy2(&process, static_cast<QProcessFinishedSignal2>(&QProcess::finished)); + + QVERIFY(spy.isValid()); + QVERIFY(spy2.isValid()); + + QObject::connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + this, &tst_QProcess::exitLoopSlot); + + QTestEventLoop::instance().enterLoop(30); + if (QTestEventLoop::instance().timeout()) + QFAIL("Failed to detect crash : operation timed out"); + + QCOMPARE(spy.count(), 1); + QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy.at(0).at(0).constData()), QProcess::Crashed); + + QCOMPARE(spy2.count(), 1); + QCOMPARE(*static_cast<const QProcess::ExitStatus *>(spy2.at(0).at(1).constData()), QProcess::CrashExit); + + QCOMPARE(process.exitStatus(), QProcess::CrashExit); +} + +void tst_QProcess::restartProcessDeadlock_deprecated() +{ + // The purpose of this test is to detect whether restarting a + // process in the finished() connected slot causes a deadlock + // because of the way QProcessManager uses its locks. + QProcess process; + connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + this, &tst_QProcess::restartProcess); + + process.start("testProcessEcho/testProcessEcho"); + + QCOMPARE(process.write("", 1), qlonglong(1)); + QVERIFY(process.waitForFinished(5000)); + + QObject::disconnect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), nullptr, nullptr); + + QCOMPARE(process.write("", 1), qlonglong(1)); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); +} + +void tst_QProcess::waitForReadyReadInAReadyReadSlot_deprecated() +{ + QProcess process; + connect(&process, &QIODevice::readyRead, this, &tst_QProcess::waitForReadyReadInAReadyReadSlotSlot); + connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + this, &tst_QProcess::exitLoopSlot); + bytesAvailable = 0; + + process.start("testProcessEcho/testProcessEcho"); + QVERIFY(process.waitForStarted(5000)); + + QSignalSpy spy(&process, &QProcess::readyRead); + QVERIFY(spy.isValid()); + process.write("foo"); + QTestEventLoop::instance().enterLoop(30); + QVERIFY(!QTestEventLoop::instance().timeout()); + + QCOMPARE(spy.count(), 1); + + process.disconnect(); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); + QVERIFY(process.bytesAvailable() > bytesAvailable); +} + +void tst_QProcess::finishProcessBeforeReadingDone_deprecated() +{ + QProcess process; + BlockOnReadStdOut blocker(&process); + QEventLoop loop; + connect(&process, static_cast<QProcessFinishedSignal1>(&QProcess::finished), + &loop, &QEventLoop::quit); + process.start("testProcessOutput/testProcessOutput"); + QVERIFY(process.waitForStarted()); + loop.exec(); + QStringList lines = QString::fromLocal8Bit(process.readAllStandardOutput()).split( + QRegExp(QStringLiteral("[\r\n]")), QString::SkipEmptyParts); + QVERIFY(!lines.isEmpty()); + QCOMPARE(lines.last(), QStringLiteral("10239 -this is a number")); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QCOMPARE(process.exitCode(), 0); +} + +#endif + QTEST_MAIN(tst_QProcess) #include "tst_qprocess.moc" diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 0b50c391b8..df1dbebbf2 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -55,6 +55,10 @@ private slots: void checkStructure(); void searchPath_data(); void searchPath(); +#if QT_DEPRECATED_SINCE(5, 13) + void searchPath_deprecated_data(); + void searchPath_deprecated(); +#endif void doubleSlashInRoot(); void setLocale(); void lastModified(); @@ -420,6 +424,58 @@ void tst_QResourceEngine::checkStructure() void tst_QResourceEngine::searchPath_data() { + auto searchPath = QFileInfo(QFINDTESTDATA("testqrc")).canonicalFilePath(); + + QTest::addColumn<QString>("searchPathPrefix"); + QTest::addColumn<QString>("searchPath"); + QTest::addColumn<QString>("file"); + QTest::addColumn<QByteArray>("expected"); + + QTest::newRow("no_search_path") + << QString() + << QString() + << ":search_file.txt" + << QByteArray("root\n"); + QTest::newRow("path1") + << "searchpath1" + << searchPath + << "searchpath1:searchpath1/search_file.txt" + << QByteArray("path1\n"); + QTest::newRow("no_search_path2") + << QString() + << QString() + << ":/search_file.txt" + << QByteArray("root\n"); + QTest::newRow("path2") + << "searchpath2" + << searchPath + "/searchpath2" + << "searchpath2:search_file.txt" + << QByteArray("path2\n"); +} + +void tst_QResourceEngine::searchPath() +{ + QFETCH(QString, searchPathPrefix); + QFETCH(QString, searchPath); + QFETCH(QString, file); + QFETCH(QByteArray, expected); + + if (!searchPath.isEmpty()) + QDir::addSearchPath(searchPathPrefix, searchPath); + QFile qf(file); + QVERIFY(qf.open(QFile::ReadOnly)); + QByteArray actual = qf.readAll(); + + actual.replace('\r', ""); + + QCOMPARE(actual, expected); + qf.close(); +} + +#if QT_DEPRECATED_SINCE(5, 13) + +void tst_QResourceEngine::searchPath_deprecated_data() +{ QTest::addColumn<QString>("searchPath"); QTest::addColumn<QString>("file"); QTest::addColumn<QByteArray>("expected"); @@ -438,7 +494,7 @@ void tst_QResourceEngine::searchPath_data() << QByteArray("path2\n"); } -void tst_QResourceEngine::searchPath() +void tst_QResourceEngine::searchPath_deprecated() { QFETCH(QString, searchPath); QFETCH(QString, file); @@ -456,6 +512,8 @@ void tst_QResourceEngine::searchPath() qf.close(); } +#endif + void tst_QResourceEngine::checkUnregisterResource_data() { QTest::addColumn<QString>("rcc_file"); diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 8b69518ef7..a71a68e457 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -311,8 +311,11 @@ void tst_QSettings::initTestCase() void tst_QSettings::cleanupTestFiles() { - QSettings::setSystemIniPath(settingsPath("__system__")); - QSettings::setUserIniPath(settingsPath("__user__")); + QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, settingsPath("__system__")); + QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, settingsPath("__system__")); + + QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, settingsPath("__user__")); + QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, settingsPath("__user__")); QDir settingsDir(settingsPath()); if (settingsDir.exists()) diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 155f5b953d..56d924dcc6 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -32,7 +32,7 @@ #include <qstandardpaths.h> #include <qfileinfo.h> #include <qsysinfo.h> -#include <qregexp.h> +#include <qregularexpression.h> #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) # include <qt_windows.h> #endif @@ -566,7 +566,8 @@ void tst_qstandardpaths::testAllWritableLocations() void tst_qstandardpaths::testCleanPath() { - const QRegExp filter(QStringLiteral("\\\\")); +#if QT_CONFIG(regularexpression) + const QRegularExpression filter(QStringLiteral("\\\\")); QVERIFY(filter.isValid()); for (int i = 0; i <= QStandardPaths::GenericCacheLocation; ++i) { const QStringList paths = QStandardPaths::standardLocations(QStandardPaths::StandardLocation(i)); @@ -574,6 +575,9 @@ void tst_qstandardpaths::testCleanPath() qPrintable(QString::fromLatin1("Backslash found in %1 %2") .arg(i).arg(paths.join(QLatin1Char(','))))); } +#else + QSKIP("regularexpression feature disabled"); +#endif } void tst_qstandardpaths::testXdgPathCleanup() diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index 67d8c55b04..00417fffa0 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -569,13 +569,7 @@ void tst_QTemporaryFile::rename() void tst_QTemporaryFile::renameFdLeak() { -#ifdef Q_OS_UNIX - -# if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) - ChdirOnReturn cor(QDir::currentPath()); - QDir::setCurrent(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); -# endif - +#if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID) const QByteArray sourceFile = QFile::encodeName(QFINDTESTDATA(__FILE__)); QVERIFY(!sourceFile.isEmpty()); // Test this on Unix only diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index daaa5516cd..3123c42326 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -2192,10 +2192,12 @@ void tst_QUrl::schemeValidator_data() QTest::newRow("percent-encoded") << "%68%74%%74%70://example.com" << false << "%68%74%%74%70"; static const char controls[] = "!\"$&'()*,;<=>[\\]^_`{|}~"; - for (size_t i = 0; i < sizeof(controls) - 1; ++i) - QTest::newRow(("with-" + QByteArray(1, controls[i])).constData()) - << QString("pre%1post://example.com/").arg(QLatin1Char(controls[i])) - << false << QString("pre%1post").arg(QLatin1Char(controls[i])); + for (char control : controls) { + const QString scheme = QLatin1String("pre") + QLatin1Char(control) + QLatin1String("post"); + QTest::newRow((QByteArrayLiteral("with-") + control).constData()) + << (scheme + QLatin1String("://example.com/")) + << false << scheme; + } } void tst_QUrl::schemeValidator() @@ -4074,13 +4076,12 @@ public: QVector<QUrl> m_urls; }; -static const UrlStorage * s_urlStorage = 0; +static const UrlStorage * s_urlStorage = nullptr; void tst_QUrl::testThreadingHelper() { const UrlStorage* storage = s_urlStorage; - for (int i = 0 ; i < storage->m_urls.size(); ++i ) { - const QUrl& u = storage->m_urls.at(i); + for (const auto &u : storage->m_urls) { // QVERIFY/QCOMPARE trigger race conditions in helgrind if (!u.isValid()) qFatal("invalid url"); diff --git a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp index dbc7173028..354190e754 100644 --- a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp +++ b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp @@ -153,7 +153,7 @@ QAbstractItemModel *ModelsToTest::createModel(const QString &modelType) QStandardItemModel *standardItemModel = new QStandardItemModel; model->setSourceModel(standardItemModel); populateTestArea(model); - model->setFilterRegExp(QRegExp("(^$|I.*)")); + model->setFilterRegularExpression(QRegularExpression("(^$|I.*)")); return model; } diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index 1cc671a917..f78f5bc138 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -2264,7 +2264,7 @@ void tst_QItemSelectionModel::layoutChangedWithAllSelected1() QCOMPARE(model.rowCount(), 3); QCOMPARE(proxy.rowCount(), 3); - proxy.setFilterRegExp( QRegExp("f")); + proxy.setFilterRegularExpression(QRegularExpression("f")); QCOMPARE(proxy.rowCount(), 2); QList<QPersistentModelIndex> indexList; @@ -2276,7 +2276,7 @@ void tst_QItemSelectionModel::layoutChangedWithAllSelected1() foreach(QPersistentModelIndex index, indexList) QVERIFY(selection.isSelected(index)); - proxy.setFilterRegExp(QRegExp()); + proxy.setFilterRegularExpression(QRegularExpression()); QCOMPARE(proxy.rowCount(), 3); //let's check the selection hasn't changed diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index d68cefc807..39c90f69b4 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -775,49 +775,49 @@ private slots: QCoreApplicationPrivate *privateClass = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(qApp)); { - QCOMPARE(privateClass->quitLockRef.load(), 0); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 0); // Test with a lock active so that the refcount doesn't drop to zero during these tests, causing a quit. // (until we exit the scope) QEventLoopLocker locker; - QCOMPARE(privateClass->quitLockRef.load(), 1); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 1); JobObject *job1 = new JobObject(this); - QCOMPARE(privateClass->quitLockRef.load(), 2); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 2); delete job1; - QCOMPARE(privateClass->quitLockRef.load(), 1); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 1); job1 = new JobObject(this); - QCOMPARE(privateClass->quitLockRef.load(), 2); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 2); JobObject *job2 = new JobObject(this); - QCOMPARE(privateClass->quitLockRef.load(), 3); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 3); delete job1; - QCOMPARE(privateClass->quitLockRef.load(), 2); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 2); JobObject *job3 = new JobObject(job2); Q_UNUSED(job3); - QCOMPARE(privateClass->quitLockRef.load(), 3); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 3); JobObject *job4 = new JobObject(job2); Q_UNUSED(job4); - QCOMPARE(privateClass->quitLockRef.load(), 4); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 4); delete job2; - QCOMPARE(privateClass->quitLockRef.load(), 1); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 1); } - QCOMPARE(privateClass->quitLockRef.load(), 0); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 0); } }; diff --git a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp index 482ed8d130..1f0b8d4b4e 100644 --- a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp +++ b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp @@ -638,16 +638,16 @@ void tst_QEventLoop::testQuitLock() QEventLoopPrivate* privateClass = static_cast<QEventLoopPrivate*>(QObjectPrivate::get(&eventLoop)); - QCOMPARE(privateClass->quitLockRef.load(), 0); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 0); JobObject *job1 = new JobObject(&eventLoop, this); job1->start(500); - QCOMPARE(privateClass->quitLockRef.load(), 1); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 1); eventLoop.exec(); - QCOMPARE(privateClass->quitLockRef.load(), 0); + QCOMPARE(privateClass->quitLockRef.loadRelaxed(), 0); job1 = new JobObject(&eventLoop, this); diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index 89a06b358e..026c6a6324 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -520,7 +520,7 @@ public slots: QVector<QtTestObject *> o5, QList<QtTestObject *> o6) { slotResult = QLatin1String("slotWithRegistrableArgument:") + o1->slotResult + o2->slotResult - + o3->slotResult + o4.data()->slotResult + QString::number(o5.size()) + + o3->slotResult + o4.toStrongRef()->slotResult + QString::number(o5.size()) + QString::number(o6.size()); } diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 28458c43c7..12c29a6e13 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -1807,16 +1807,36 @@ void tst_QMetaType::automaticTemplateRegistration() QCOMPARE(extractedPtr.data()->objectName(), sp.data()->objectName()); \ } +#if QT_DEPRECATED_SINCE(5, 0) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QObject, WeakPointerToQObject, qWeakPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QFile, WeakPointerToQObject, qWeakPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, QTemporaryFile, WeakPointerToQObject, qWeakPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QWeakPointer, MyObject, WeakPointerToQObject, qWeakPointerFromVariant) +#endif TEST_NONOWNING_SMARTPOINTER(QPointer, QObject, TrackingPointerToQObject, qPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QPointer, QFile, TrackingPointerToQObject, qPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QPointer, QTemporaryFile, TrackingPointerToQObject, qPointerFromVariant) TEST_NONOWNING_SMARTPOINTER(QPointer, MyObject, TrackingPointerToQObject, qPointerFromVariant) #undef TEST_NONOWNING_SMARTPOINTER + + +#define TEST_WEAK_SMARTPOINTER(ELEMENT_TYPE, FLAG_TEST) \ + { \ + ELEMENT_TYPE elem; \ + QSharedPointer < ELEMENT_TYPE > shared(new ELEMENT_TYPE); \ + QWeakPointer < ELEMENT_TYPE > sp(shared); \ + sp.toStrongRef()->setObjectName("Test name"); \ + QVariant v = QVariant::fromValue(sp); \ + QCOMPARE(v.typeName(), "QWeakPointer<" #ELEMENT_TYPE ">"); \ + QVERIFY(QMetaType::typeFlags(::qMetaTypeId<QWeakPointer < ELEMENT_TYPE > >()) & QMetaType::FLAG_TEST); \ + } + + TEST_WEAK_SMARTPOINTER(QObject, WeakPointerToQObject) + TEST_WEAK_SMARTPOINTER(QFile, WeakPointerToQObject) + TEST_WEAK_SMARTPOINTER(QTemporaryFile, WeakPointerToQObject) + TEST_WEAK_SMARTPOINTER(MyObject, WeakPointerToQObject) +#undef TEST_WEAK_SMARTPOINTER } template <typename T> diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h index 6bda9638f7..22bcb69ac9 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h @@ -236,7 +236,7 @@ template<> struct TestValueFactory<QMetaType::QRegExp> { template<> struct TestValueFactory<QMetaType::QRegularExpression> { static QRegularExpression *create() { -#ifndef QT_NO_REGEXP +#if QT_CONFIG(regularexpression) return new QRegularExpression("abc.*def"); #else return 0; diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 7c9d8a476a..1778bf24bc 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -81,7 +81,9 @@ private slots: void senderTest(); void declareInterface(); void qpointerResetBeforeDestroyedSignal(); +#ifndef QT_NO_USERDATA void testUserData(); +#endif void childDeletesItsSibling(); void dynamicProperties(); void floatProperty(); @@ -2338,6 +2340,7 @@ void tst_QObject::declareInterface() } +#ifndef QT_NO_USERDATA class CustomData : public QObjectUserData { public: @@ -2380,6 +2383,7 @@ void tst_QObject::testUserData() QCOMPARE(data->id, id); } } +#endif // QT_NO_USERDATA class DestroyedListener : public QObject { diff --git a/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp index 55deb8eb1a..fa2d5e3723 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp +++ b/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp @@ -34,6 +34,7 @@ #include <QSharedMemory> #include <QTest> #include <QThread> +#include <QElapsedTimer> #define EXISTING_SHARE "existing" #define EXISTING_SIZE 1024 @@ -645,7 +646,7 @@ public: char *memory = (char*)producer.data(); memory[1] = '0'; - QTime timer; + QElapsedTimer timer; timer.start(); int i = 0; while (i < 5 && timer.elapsed() < 5000) { diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index b7c87418c7..262dbea913 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -38,6 +38,7 @@ #include <qtimer.h> #include <qthread.h> +#include <qelapsedtimer.h> #if defined Q_OS_UNIX #include <unistd.h> @@ -526,7 +527,7 @@ public: QBasicTimer m_timer; int m_interval; - QTime m_startedTime; + QElapsedTimer m_elapsedTimer; QEventLoop eventLoop; inline RestartedTimerFiresTooSoonObject() @@ -538,7 +539,7 @@ public: static int interval = 1000; m_interval = interval; - m_startedTime.start(); + m_elapsedTimer.start(); m_timer.start(interval, this); // alternate between single-shot and 1 sec @@ -552,7 +553,7 @@ public: m_timer.stop(); - int elapsed = m_startedTime.elapsed(); + int elapsed = m_elapsedTimer.elapsed(); if (elapsed < m_interval / 2) { // severely too early! @@ -590,10 +591,10 @@ public: public slots: void longLastingSlot() { - // Don't use timers for this, because we are testing them. - QTime time; - time.start(); - while (time.elapsed() < 200) { + // Don't use QTimer for this, because we are testing it. + QElapsedTimer control; + control.start(); + while (control.elapsed() < 200) { for (int c = 0; c < 100000; c++) {} // Mindless looping. } if (++count >= 2) { diff --git a/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp b/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp index 40a29c723c..b3efa97dbd 100644 --- a/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp +++ b/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp @@ -310,7 +310,7 @@ struct TranslateThread : public QThread void run() { bool startSignalled = false; - while (terminate.load() == 0) { + while (terminate.loadRelaxed() == 0) { const QString result = QCoreApplication::translate("QPushButton", "Hello %n world(s)!", 0, 0); if (!startSignalled) { diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index c75e4ef035..5d06f6e8c8 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -402,6 +402,8 @@ QT_WARNING_POP QVERIFY( var6.isNull() ); QVariant varLL( (qlonglong)0 ); QVERIFY( !varLL.isNull() ); + +#if QT_DEPRECATED_SINCE(5, 9) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED QVariant var7(QString::null); @@ -412,6 +414,7 @@ QT_WARNING_DISABLE_DEPRECATED var7 = QVariant::fromValue<QString>(QString::null); QT_WARNING_POP QVERIFY(var7.isNull()); +#endif QVariant var8(QMetaType::Nullptr, nullptr); QVERIFY(var8.isNull()); @@ -433,6 +436,9 @@ QT_WARNING_POP QVERIFY(var11.isNull()); QVERIFY(QVariant::fromValue<int*>(nullptr).isNull()); + + QVariant var12(QVariant::fromValue<QString>(QString())); + QVERIFY(var12.isNull()); } void tst_QVariant::swap() @@ -2871,6 +2877,7 @@ void tst_QVariant::qvariant_cast_QObject_wrapper() QVERIFY(spVar.canConvert<QObject*>()); QCOMPARE(f, spVar.value<QObject*>()); } +#if QT_DEPRECATED_SINCE(5, 0) { QFile *f = new QFile(this); QT_WARNING_PUSH @@ -2881,6 +2888,15 @@ QT_WARNING_POP QVERIFY(spVar.canConvert<QObject*>()); QCOMPARE(f, spVar.value<QObject*>()); } +#endif + { + QFile *f = new QFile(this); + QSharedPointer<QObject> sp(f); + QWeakPointer<QObject> wp = sp; + QVariant wpVar = QVariant::fromValue(wp); + QVERIFY(wpVar.canConvert<QObject*>()); + QCOMPARE(f, wpVar.value<QObject*>()); + } { QFile *f = new QFile(this); QSharedPointer<QFile> sp(f); diff --git a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp index c9c9202a80..e0d09b0813 100644 --- a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp +++ b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp @@ -30,7 +30,7 @@ #include <QtTest/QtTest> #include <qdir.h> #include <qlibrary.h> -#include <QtCore/QRegExp> +#include <QtCore/QRegularExpression> // Helper macros to let us know if some suffixes and prefixes are valid @@ -414,10 +414,12 @@ void tst_QLibrary::errorString() QFAIL(qPrintable(QString("Unknown operation: %1").arg(operation))); break; } - QRegExp re(errorString); +#if QT_CONFIG(regularexpression) + QRegularExpression re(QRegularExpression::anchoredPattern(errorString)); QString libErrorString = lib.errorString(); + QVERIFY2(re.match(libErrorString).hasMatch(), qPrintable(libErrorString)); +#endif QVERIFY(!lib.isLoaded() || lib.unload()); - QVERIFY2(re.exactMatch(libErrorString), qPrintable(libErrorString)); QCOMPARE(ok, success); } diff --git a/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp b/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp index a290c012df..aa85a7c35b 100644 --- a/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp +++ b/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp @@ -41,7 +41,6 @@ class tst_QPlugin : public QObject Q_OBJECT QDir dir; - QString invalidPluginName; public: tst_QPlugin(); @@ -64,15 +63,14 @@ void tst_QPlugin::initTestCase() QVERIFY2(dir.exists(), qPrintable(QString::fromLatin1("Cannot find the 'plugins' directory starting from '%1'"). arg(QDir::toNativeSeparators(QDir::currentPath())))); - - const auto fileNames = dir.entryList({"*invalid*"}, QDir::Files); - if (!fileNames.isEmpty()) - invalidPluginName = dir.absoluteFilePath(fileNames.first()); } void tst_QPlugin::loadDebugPlugin() { const auto fileNames = dir.entryList(QStringList() << "*debug*", QDir::Files); + if (fileNames.isEmpty()) + QSKIP("No debug plugins found - skipping test"); + for (const QString &fileName : fileNames) { if (!QLibrary::isLibrary(fileName)) continue; @@ -100,6 +98,9 @@ void tst_QPlugin::loadDebugPlugin() void tst_QPlugin::loadReleasePlugin() { const auto fileNames = dir.entryList(QStringList() << "*release*", QDir::Files); + if (fileNames.isEmpty()) + QSKIP("No release plugins found - skipping test"); + for (const QString &fileName : fileNames) { if (!QLibrary::isLibrary(fileName)) continue; @@ -227,7 +228,13 @@ static qsizetype locateMetadata(const uchar *data, qsizetype len) void tst_QPlugin::scanInvalidPlugin() { - QVERIFY(!invalidPluginName.isEmpty()); + const auto fileNames = dir.entryList({"*invalid*"}, QDir::Files); + QString invalidPluginName; + if (fileNames.isEmpty()) + QSKIP("No invalid plugin found - skipping test"); + else + invalidPluginName = dir.absoluteFilePath(fileNames.first()); + // copy the file QFileInfo fn(invalidPluginName); diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp index b06000d9c4..c4a366d7c6 100644 --- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp +++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp @@ -549,7 +549,8 @@ void tst_QPluginLoader::staticPlugins() } QVERIFY(found); - QCOMPARE(metaData.value("version").toInt(), QT_VERSION); + // We don't store the patch release version anymore (since 5.13) + QCOMPARE(metaData.value("version").toInt() / 0x100, QT_VERSION / 0x100); QCOMPARE(metaData.value("IID").toString(), "SomeIID"); QCOMPARE(metaData.value("ExtraMetaData"), QJsonArray({ "StaticPlugin", "foo" })); QCOMPARE(metaData.value("URI").toString(), "qt.test.pluginloader.staticplugin"); diff --git a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp index 19cdd42a74..b8778e4e98 100644 --- a/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/serialization/qdatastream/tst_qdatastream.cpp @@ -113,6 +113,11 @@ private slots: void stream_QRegExp_data(); void stream_QRegExp(); +#if QT_CONFIG(regularexpression) + void stream_QRegularExpression_data(); + void stream_QRegularExpression(); +#endif + void stream_Map_data(); void stream_Map(); @@ -185,6 +190,7 @@ private slots: void floatingPointPrecision(); + void compatibility_Qt5(); void compatibility_Qt3(); void compatibility_Qt2(); @@ -220,6 +226,9 @@ private: void writeQSize(QDataStream *s); void writeQString(QDataStream* dev); void writeQRegExp(QDataStream* dev); +#if QT_CONFIG(regularexpression) + void writeQRegularExpression(QDataStream *dev); +#endif void writeMap(QDataStream* dev); void writeHash(QDataStream* dev); void writeqint64(QDataStream *s); @@ -249,6 +258,9 @@ private: void readQSize(QDataStream *s); void readQString(QDataStream *s); void readQRegExp(QDataStream *s); +#if QT_CONFIG(regularexpression) + void readQRegularExpression(QDataStream *s); +#endif void readMap(QDataStream *s); void readHash(QDataStream *s); void readqint64(QDataStream *s); @@ -271,17 +283,17 @@ static int NColorRoles[] = { QPalette::HighlightedText + 1, // Qt_4_0, Qt_4_1 QPalette::HighlightedText + 1, // Qt_4_2 QPalette::AlternateBase + 1, // Qt_4_3 - QPalette::PlaceholderText + 1, // Qt_4_4 - QPalette::PlaceholderText + 1, // Qt_4_5 - QPalette::PlaceholderText + 1, // Qt_4_6 - QPalette::PlaceholderText + 1, // Qt_5_0 - QPalette::PlaceholderText + 1, // Qt_5_1 - QPalette::PlaceholderText + 1, // Qt_5_2 - QPalette::PlaceholderText + 1, // Qt_5_3 - QPalette::PlaceholderText + 1, // Qt_5_4 - QPalette::PlaceholderText + 1, // Qt_5_5 - QPalette::PlaceholderText + 1, // Qt_5_6 - 0 // add the correct value for Qt_5_7 here later + QPalette::ToolTipText + 1, // Qt_4_4 + QPalette::ToolTipText + 1, // Qt_4_5 + QPalette::ToolTipText + 1, // Qt_4_6, Qt_4_7, Qt_4_8, Qt_4_9 + QPalette::ToolTipText + 1, // Qt_5_0 + QPalette::ToolTipText + 1, // Qt_5_1 + QPalette::ToolTipText + 1, // Qt_5_2, Qt_5_3 + QPalette::ToolTipText + 1, // Qt_5_4, Qt_5_5 + QPalette::ToolTipText + 1, // Qt_5_6, Qt_5_7, Qt_5_8, Qt_5_9, Qt_5_10, Qt_5_11 + QPalette::PlaceholderText + 1, // Qt_5_12 + QPalette::PlaceholderText + 1, // Qt_5_13 + 0 // add the correct value for Qt_5_14 here later }; // Testing get/set functions @@ -560,6 +572,69 @@ void tst_QDataStream::readQRegExp(QDataStream *s) // ************************************ +#if QT_CONFIG(regularexpression) +static QRegularExpression QRegularExpressionData(int index) +{ + switch (index) { + case 0: return QRegularExpression(); + case 1: return QRegularExpression(""); + case 2: return QRegularExpression("A", QRegularExpression::CaseInsensitiveOption); + case 3: return QRegularExpression(QRegularExpression::wildcardToRegularExpression("ABCDE FGHI")); + case 4: return QRegularExpression(QRegularExpression::anchoredPattern("This is a long string"), QRegularExpression::CaseInsensitiveOption); + case 5: return QRegularExpression("And again a string with a \nCRLF", QRegularExpression::CaseInsensitiveOption); + case 6: return QRegularExpression("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRESTUVWXYZ 1234567890 ~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/", QRegularExpression::InvertedGreedinessOption); + } + return QRegularExpression("foo"); +} +#define MAX_QREGULAREXPRESSION_DATA 7 + +void tst_QDataStream::stream_QRegularExpression_data() +{ + stream_data(MAX_QREGULAREXPRESSION_DATA); +} + +void tst_QDataStream::stream_QRegularExpression() +{ + STREAM_IMPL(QRegularExpression); +} + +void tst_QDataStream::writeQRegularExpression(QDataStream* s) +{ + QRegularExpression test(QRegularExpressionData(dataIndex(QTest::currentDataTag()))); + *s << test; + *s << QString("Her er det noe tekst"); + *s << test; + *s << QString("nonempty"); + *s << test; + *s << QVariant(test); +} + +void tst_QDataStream::readQRegularExpression(QDataStream *s) +{ + QRegularExpression R; + QString S; + QVariant V; + QRegularExpression test(QRegularExpressionData(dataIndex(QTest::currentDataTag()))); + + *s >> R; + + QCOMPARE(R, test); + *s >> S; + QCOMPARE(S, QString("Her er det noe tekst")); + *s >> R; + QCOMPARE(R, test); + *s >> S; + QCOMPARE(S, QString("nonempty")); + *s >> R; + QCOMPARE(R, test); + *s >> V; + QCOMPARE(V.type(), QVariant::RegularExpression); + QCOMPARE(V.toRegularExpression(), test); +} +#endif //QT_CONFIG(regularexpression) + +// ************************************ + typedef QMap<int, QString> Map; static Map MapData(int index) @@ -3245,6 +3320,37 @@ void tst_QDataStream::streamRealDataTypes() } } +void tst_QDataStream::compatibility_Qt5() +{ + QLinearGradient gradient(QPointF(0,0), QPointF(1,1)); + gradient.setColorAt(0, Qt::red); + gradient.setColorAt(1, Qt::blue); + + QBrush brush(gradient); + QPalette palette; + palette.setBrush(QPalette::Button, brush); + palette.setColor(QPalette::Light, Qt::green); + + QByteArray stream; + { + QDataStream out(&stream, QIODevice::WriteOnly); + out.setVersion(QDataStream::Qt_5_7); + out << palette; + out << brush; + } + QBrush in_brush; + QPalette in_palette; + { + QDataStream in(stream); + in.setVersion(QDataStream::Qt_5_7); + in >> in_palette; + in >> in_brush; + } + QCOMPARE(in_brush.style(), Qt::LinearGradientPattern); + QCOMPARE(in_palette.brush(QPalette::Button).style(), Qt::LinearGradientPattern); + QCOMPARE(in_palette.color(QPalette::Light), QColor(Qt::green)); +} + void tst_QDataStream::compatibility_Qt3() { QByteArray ba("hello"); diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index c4fb623130..32306e8003 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -35,6 +35,7 @@ #include <QBuffer> #include <QByteArray> #include <QDebug> +#include <QElapsedTimer> #include <QFile> #include <QTcpSocket> #include <QTemporaryDir> @@ -996,7 +997,7 @@ struct CompareIndicesForArray void tst_QTextStream::performance() { // Phase #1 - test speed of reading a huge text file with QFile. - QTime stopWatch; + QElapsedTimer stopWatch; const int N = 3; const char * readMethods[N] = { diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 0312cff5da..72a6f0360d 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -1737,13 +1737,13 @@ protected: if (e->type() != QEvent::Type(QEvent::User+2)) return false; StringEvent *se = static_cast<StringEvent*>(e); - return (m_value == se->value) && (!m_cond.isValid() || (m_cond.indexIn(m_value) != -1)); + return (m_value == se->value) && (!m_cond.isValid() || m_cond.match(m_value).hasMatch()); } virtual void onTransition(QEvent *) {} private: QString m_value; - QRegExp m_cond; + QRegularExpression m_cond; }; class StringEventPoster : public QState diff --git a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp index cc197cabba..bef491d5f0 100644 --- a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp +++ b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp @@ -31,6 +31,7 @@ #include <QAtomicInt> #include <QCoreApplication> +#include <QElapsedTimer> #include <limits.h> @@ -104,12 +105,12 @@ static void warningFreeHelperTemplate() assemblyMarker<1>(&i); // the loads sometimes generate no assembly output - i.load(); + i.loadRelaxed(); assemblyMarker<11>(&i); i.loadAcquire(); assemblyMarker<12>(&i); - i.store(newValue); + i.storeRelaxed(newValue); assemblyMarker<21>(&i); i.storeRelease(newValue); assemblyMarker<22>(&i); @@ -281,9 +282,9 @@ void tst_QAtomicInt::constructor() { QFETCH(int, value); QAtomicInt atomic1(value); - QCOMPARE(atomic1.load(), value); + QCOMPARE(atomic1.loadRelaxed(), value); QAtomicInt atomic2 = value; - QCOMPARE(atomic2.load(), value); + QCOMPARE(atomic2.loadRelaxed(), value); } void tst_QAtomicInt::copy_constructor_data() @@ -293,16 +294,16 @@ void tst_QAtomicInt::copy_constructor() { QFETCH(int, value); QAtomicInt atomic1(value); - QCOMPARE(atomic1.load(), value); + QCOMPARE(atomic1.loadRelaxed(), value); QAtomicInt atomic2(atomic1); - QCOMPARE(atomic2.load(), value); + QCOMPARE(atomic2.loadRelaxed(), value); QAtomicInt atomic3 = atomic1; - QCOMPARE(atomic3.load(), value); + QCOMPARE(atomic3.loadRelaxed(), value); QAtomicInt atomic4(atomic2); - QCOMPARE(atomic4.load(), value); + QCOMPARE(atomic4.loadRelaxed(), value); QAtomicInt atomic5 = atomic2; - QCOMPARE(atomic5.load(), value); + QCOMPARE(atomic5.loadRelaxed(), value); } void tst_QAtomicInt::assignment_operator_data() @@ -326,13 +327,13 @@ void tst_QAtomicInt::assignment_operator() { QAtomicInt atomic1 = value; atomic1 = newval; - QCOMPARE(atomic1.load(), newval); + QCOMPARE(atomic1.loadRelaxed(), newval); atomic1 = value; - QCOMPARE(atomic1.load(), value); + QCOMPARE(atomic1.loadRelaxed(), value); QAtomicInt atomic2 = newval; atomic1 = atomic2; - QCOMPARE(atomic1.load(), atomic2.load()); + QCOMPARE(atomic1.loadRelaxed(), atomic2.loadRelaxed()); } } @@ -400,7 +401,7 @@ void tst_QAtomicInt::ref() QFETCH(int, value); QAtomicInt x = value; QTEST(x.ref() ? 1 : 0, "result"); - QTEST(x.load(), "expected"); + QTEST(x.loadRelaxed(), "expected"); } void tst_QAtomicInt::deref_data() @@ -419,7 +420,7 @@ void tst_QAtomicInt::deref() QFETCH(int, value); QAtomicInt x = value; QTEST(x.deref() ? 1 : 0, "result"); - QTEST(x.load(), "expected"); + QTEST(x.loadRelaxed(), "expected"); } void tst_QAtomicInt::isTestAndSetNative() @@ -635,25 +636,25 @@ void tst_QAtomicInt::fetchAndStore() { QAtomicInt atomic = value; QCOMPARE(atomic.fetchAndStoreRelaxed(newval), value); - QCOMPARE(atomic.load(), newval); + QCOMPARE(atomic.loadRelaxed(), newval); } { QAtomicInt atomic = value; QCOMPARE(atomic.fetchAndStoreAcquire(newval), value); - QCOMPARE(atomic.load(), newval); + QCOMPARE(atomic.loadRelaxed(), newval); } { QAtomicInt atomic = value; QCOMPARE(atomic.fetchAndStoreRelease(newval), value); - QCOMPARE(atomic.load(), newval); + QCOMPARE(atomic.loadRelaxed(), newval); } { QAtomicInt atomic = value; QCOMPARE(atomic.fetchAndStoreOrdered(newval), value); - QCOMPARE(atomic.load(), newval); + QCOMPARE(atomic.loadRelaxed(), newval); } } @@ -772,28 +773,28 @@ void tst_QAtomicInt::fetchAndAdd() QAtomicInt atomic = value1; result = atomic.fetchAndAddRelaxed(value2); QCOMPARE(result, value1); - QCOMPARE(atomic.load(), value1 + value2); + QCOMPARE(atomic.loadRelaxed(), value1 + value2); } { QAtomicInt atomic = value1; result = atomic.fetchAndAddAcquire(value2); QCOMPARE(result, value1); - QCOMPARE(atomic.load(), value1 + value2); + QCOMPARE(atomic.loadRelaxed(), value1 + value2); } { QAtomicInt atomic = value1; result = atomic.fetchAndAddRelease(value2); QCOMPARE(result, value1); - QCOMPARE(atomic.load(), value1 + value2); + QCOMPARE(atomic.loadRelaxed(), value1 + value2); } { QAtomicInt atomic = value1; result = atomic.fetchAndAddOrdered(value2); QCOMPARE(result, value1); - QCOMPARE(atomic.load(), value1 + value2); + QCOMPARE(atomic.loadRelaxed(), value1 + value2); } } @@ -851,14 +852,14 @@ void tst_QAtomicInt::operators() void tst_QAtomicInt::testAndSet_loop() { - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); int iterations = 10000000; QAtomicInt val=0; for (int i = 0; i < iterations; ++i) { - int v = val.load(); + int v = val.loadRelaxed(); QVERIFY(val.testAndSetRelaxed(v, v+1)); if ((i % 1000) == 999) { if (stopWatch.elapsed() > 60 * 1000) { @@ -881,7 +882,7 @@ void tst_QAtomicInt::fetchAndAdd_loop() QAtomicInt val=0; for (int i = 0; i < iterations; ++i) { const int prev = val.fetchAndAddRelaxed(1); - QCOMPARE(prev, val.load() -1); + QCOMPARE(prev, val.loadRelaxed() -1); } } @@ -919,7 +920,7 @@ void tst_QAtomicInt::fetchAndAdd_threadedLoop() t1.wait(); t2.wait(); - QCOMPARE(val.load(), 0); + QCOMPARE(val.loadRelaxed(), 0); } QTEST_MAIN(tst_QAtomicInt) diff --git a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp index 3a98732f9d..bfe2a60088 100644 --- a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp +++ b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp @@ -270,13 +270,13 @@ void tst_QAtomicIntegerXX::constructor() QFETCH(LargeInt, value); QAtomicInteger<T> atomic(value); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QAtomicInteger<T> atomic2 = value; - QCOMPARE(atomic2.load(), T(value)); + QCOMPARE(atomic2.loadRelaxed(), T(value)); - QVERIFY(atomic.load() >= std::numeric_limits<T>::min()); - QVERIFY(atomic.load() <= std::numeric_limits<T>::max()); + QVERIFY(atomic.loadRelaxed() >= std::numeric_limits<T>::min()); + QVERIFY(atomic.loadRelaxed() <= std::numeric_limits<T>::max()); } void tst_QAtomicIntegerXX::copy() @@ -285,17 +285,17 @@ void tst_QAtomicIntegerXX::copy() QAtomicInteger<T> atomic(value); QAtomicInteger<T> copy(atomic); - QCOMPARE(copy.load(), atomic.load()); + QCOMPARE(copy.loadRelaxed(), atomic.loadRelaxed()); QAtomicInteger<T> copy2 = atomic; - QCOMPARE(copy2.load(), atomic.load()); + QCOMPARE(copy2.loadRelaxed(), atomic.loadRelaxed()); // move QAtomicInteger<T> copy3(std::move(copy)); - QCOMPARE(copy3.load(), atomic.load()); + QCOMPARE(copy3.loadRelaxed(), atomic.loadRelaxed()); QAtomicInteger<T> copy4 = std::move(copy2); - QCOMPARE(copy4.load(), atomic.load()); + QCOMPARE(copy4.loadRelaxed(), atomic.loadRelaxed()); } void tst_QAtomicIntegerXX::assign() @@ -305,24 +305,24 @@ void tst_QAtomicIntegerXX::assign() QAtomicInteger<T> atomic(value); QAtomicInteger<T> copy; copy = atomic; - QCOMPARE(copy.load(), atomic.load()); + QCOMPARE(copy.loadRelaxed(), atomic.loadRelaxed()); QAtomicInteger<T> copy2; copy2 = atomic; // operator=(const QAtomicInteger &) - QCOMPARE(copy2.load(), atomic.load()); + QCOMPARE(copy2.loadRelaxed(), atomic.loadRelaxed()); QAtomicInteger<T> copy2bis; - copy2bis = atomic.load(); // operator=(T) - QCOMPARE(copy2bis.load(), atomic.load()); + copy2bis = atomic.loadRelaxed(); // operator=(T) + QCOMPARE(copy2bis.loadRelaxed(), atomic.loadRelaxed()); // move QAtomicInteger<T> copy3; copy3 = std::move(copy); - QCOMPARE(copy3.load(), atomic.load()); + QCOMPARE(copy3.loadRelaxed(), atomic.loadRelaxed()); QAtomicInteger<T> copy4; copy4 = std::move(copy2); - QCOMPARE(copy4.load(), atomic.load()); + QCOMPARE(copy4.loadRelaxed(), atomic.loadRelaxed()); } void tst_QAtomicIntegerXX::operatorInteger() @@ -331,7 +331,7 @@ void tst_QAtomicIntegerXX::operatorInteger() QAtomicInteger<T> atomic(value); T val2 = atomic; - QCOMPARE(val2, atomic.load()); + QCOMPARE(val2, atomic.loadRelaxed()); QCOMPARE(val2, T(value)); } @@ -346,7 +346,7 @@ void tst_QAtomicIntegerXX::loadAcquireStoreRelease() QCOMPARE(atomic.loadAcquire(), T(~value)); atomic.storeRelease(value); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); } void tst_QAtomicIntegerXX::refDeref() @@ -364,16 +364,16 @@ void tst_QAtomicIntegerXX::refDeref() QAtomicInteger<T> atomic(value); if (!needToPreventOverflow) { QCOMPARE(atomic.ref(), (nextValue != 0)); - QCOMPARE(atomic.load(), nextValue); + QCOMPARE(atomic.loadRelaxed(), nextValue); QCOMPARE(atomic.deref(), (value != 0)); } - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); if (!needToPreventUnderflow) { QCOMPARE(atomic.deref(), (prevValue != 0)); - QCOMPARE(atomic.load(), prevValue); + QCOMPARE(atomic.loadRelaxed(), prevValue); QCOMPARE(atomic.ref(), (value != 0)); } - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); if (!needToPreventOverflow) { QCOMPARE(++atomic, nextValue); @@ -392,7 +392,7 @@ void tst_QAtomicIntegerXX::refDeref() QCOMPARE(atomic--, T(value)); QCOMPARE(atomic++, prevValue); } - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); } void tst_QAtomicIntegerXX::testAndSet() @@ -402,16 +402,16 @@ void tst_QAtomicIntegerXX::testAndSet() QAtomicInteger<T> atomic(value); QVERIFY(atomic.testAndSetRelaxed(value, newValue)); - QCOMPARE(atomic.load(), newValue); + QCOMPARE(atomic.loadRelaxed(), newValue); QVERIFY(!atomic.testAndSetRelaxed(value, newValue)); QVERIFY(atomic.testAndSetRelaxed(newValue, value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QVERIFY(atomic.testAndSetAcquire(value, newValue)); - QCOMPARE(atomic.load(), newValue); + QCOMPARE(atomic.loadRelaxed(), newValue); QVERIFY(!atomic.testAndSetAcquire(value, newValue)); QVERIFY(atomic.testAndSetAcquire(newValue, value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QVERIFY(atomic.testAndSetRelease(value, newValue)); QCOMPARE(atomic.loadAcquire(), newValue); @@ -434,18 +434,18 @@ void tst_QAtomicIntegerXX::testAndSet3() QAtomicInteger<T> atomic(value); QVERIFY(atomic.testAndSetRelaxed(value, newValue, oldValue)); - QCOMPARE(atomic.load(), newValue); + QCOMPARE(atomic.loadRelaxed(), newValue); QVERIFY(!atomic.testAndSetRelaxed(value, newValue, oldValue)); QCOMPARE(oldValue, newValue); QVERIFY(atomic.testAndSetRelaxed(newValue, value, oldValue)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QVERIFY(atomic.testAndSetAcquire(value, newValue, oldValue)); - QCOMPARE(atomic.load(), newValue); + QCOMPARE(atomic.loadRelaxed(), newValue); QVERIFY(!atomic.testAndSetAcquire(value, newValue, oldValue)); QCOMPARE(oldValue, newValue); QVERIFY(atomic.testAndSetAcquire(newValue, value, oldValue)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QVERIFY(atomic.testAndSetRelease(value, newValue, oldValue)); QCOMPARE(atomic.loadAcquire(), newValue); @@ -469,14 +469,14 @@ void tst_QAtomicIntegerXX::fetchAndStore() QAtomicInteger<T> atomic(value); QCOMPARE(atomic.fetchAndStoreRelaxed(newValue), T(value)); - QCOMPARE(atomic.load(), newValue); + QCOMPARE(atomic.loadRelaxed(), newValue); QCOMPARE(atomic.fetchAndStoreRelaxed(value), newValue); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndStoreAcquire(newValue), T(value)); - QCOMPARE(atomic.load(), newValue); + QCOMPARE(atomic.loadRelaxed(), newValue); QCOMPARE(atomic.fetchAndStoreAcquire(value), newValue); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndStoreRelease(newValue), T(value)); QCOMPARE(atomic.loadAcquire(), newValue); @@ -509,29 +509,29 @@ void tst_QAtomicIntegerXX::fetchAndAdd() if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), T(value)); - QCOMPARE(atomic.load(), newValue1); + QCOMPARE(atomic.loadRelaxed(), newValue1); QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), newValue1); } - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), T(value)); - QCOMPARE(atomic.load(), newValue2); + QCOMPARE(atomic.loadRelaxed(), newValue2); QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), newValue2); } - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndAddAcquire(parcel1), T(value)); - QCOMPARE(atomic.load(), newValue1); + QCOMPARE(atomic.loadRelaxed(), newValue1); QCOMPARE(atomic.fetchAndAddAcquire(parcel2), newValue1); } - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndAddAcquire(parcel2), T(value)); - QCOMPARE(atomic.load(), newValue2); + QCOMPARE(atomic.loadRelaxed(), newValue2); QCOMPARE(atomic.fetchAndAddAcquire(parcel1), newValue2); } - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndAddRelease(parcel1), T(value)); @@ -590,29 +590,29 @@ void tst_QAtomicIntegerXX::fetchAndSub() if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), T(value)); - QCOMPARE(atomic.load(), newValue1); + QCOMPARE(atomic.loadRelaxed(), newValue1); QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), newValue1); } - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), T(value)); - QCOMPARE(atomic.load(), newValue2); + QCOMPARE(atomic.loadRelaxed(), newValue2); QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), newValue2); } - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndSubAcquire(parcel1), T(value)); - QCOMPARE(atomic.load(), newValue1); + QCOMPARE(atomic.loadRelaxed(), newValue1); QCOMPARE(atomic.fetchAndSubAcquire(parcel2), newValue1); } - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndSubAcquire(parcel2), T(value)); - QCOMPARE(atomic.load(), newValue2); + QCOMPARE(atomic.loadRelaxed(), newValue2); QCOMPARE(atomic.fetchAndSubAcquire(parcel1), newValue2); } - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndSubRelease(parcel1), T(value)); @@ -662,32 +662,32 @@ void tst_QAtomicIntegerXX::fetchAndOr() QCOMPARE(atomic.fetchAndOrRelaxed(zero), T(value)); QCOMPARE(atomic.fetchAndOrRelaxed(one), T(value)); - QCOMPARE(atomic.load(), T(value | 1)); + QCOMPARE(atomic.loadRelaxed(), T(value | 1)); QCOMPARE(atomic.fetchAndOrRelaxed(minusOne), T(value | 1)); - QCOMPARE(atomic.load(), minusOne); + QCOMPARE(atomic.loadRelaxed(), minusOne); - atomic.store(value); + atomic.storeRelaxed(value); QCOMPARE(atomic.fetchAndOrAcquire(zero), T(value)); QCOMPARE(atomic.fetchAndOrAcquire(one), T(value)); - QCOMPARE(atomic.load(), T(value | 1)); + QCOMPARE(atomic.loadRelaxed(), T(value | 1)); QCOMPARE(atomic.fetchAndOrAcquire(minusOne), T(value | 1)); - QCOMPARE(atomic.load(), minusOne); + QCOMPARE(atomic.loadRelaxed(), minusOne); - atomic.store(value); + atomic.storeRelaxed(value); QCOMPARE(atomic.fetchAndOrRelease(zero), T(value)); QCOMPARE(atomic.fetchAndOrRelease(one), T(value)); - QCOMPARE(atomic.load(), T(value | 1)); + QCOMPARE(atomic.loadRelaxed(), T(value | 1)); QCOMPARE(atomic.fetchAndOrRelease(minusOne), T(value | 1)); - QCOMPARE(atomic.load(), minusOne); + QCOMPARE(atomic.loadRelaxed(), minusOne); - atomic.store(value); + atomic.storeRelaxed(value); QCOMPARE(atomic.fetchAndOrOrdered(zero), T(value)); QCOMPARE(atomic.fetchAndOrOrdered(one), T(value)); - QCOMPARE(atomic.load(), T(value | 1)); + QCOMPARE(atomic.loadRelaxed(), T(value | 1)); QCOMPARE(atomic.fetchAndOrOrdered(minusOne), T(value | 1)); - QCOMPARE(atomic.load(), minusOne); + QCOMPARE(atomic.loadRelaxed(), minusOne); - atomic.store(value); + atomic.storeRelaxed(value); QCOMPARE(atomic |= zero, T(value)); QCOMPARE(atomic |= one, T(value | 1)); QCOMPARE(atomic |= minusOne, minusOne); @@ -703,37 +703,37 @@ void tst_QAtomicIntegerXX::fetchAndAnd() T minusOne = T(~0); QCOMPARE(atomic.fetchAndAndRelaxed(minusOne), T(value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndAndRelaxed(f), T(value)); - QCOMPARE(atomic.load(), T(value & 0xf)); + QCOMPARE(atomic.loadRelaxed(), T(value & 0xf)); QCOMPARE(atomic.fetchAndAndRelaxed(zero), T(value & 0xf)); - QCOMPARE(atomic.load(), zero); + QCOMPARE(atomic.loadRelaxed(), zero); - atomic.store(value); + atomic.storeRelaxed(value); QCOMPARE(atomic.fetchAndAndAcquire(minusOne), T(value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndAndAcquire(f), T(value)); - QCOMPARE(atomic.load(), T(value & 0xf)); + QCOMPARE(atomic.loadRelaxed(), T(value & 0xf)); QCOMPARE(atomic.fetchAndAndAcquire(zero), T(value & 0xf)); - QCOMPARE(atomic.load(), zero); + QCOMPARE(atomic.loadRelaxed(), zero); - atomic.store(value); + atomic.storeRelaxed(value); QCOMPARE(atomic.fetchAndAndRelease(minusOne), T(value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndAndRelease(f), T(value)); - QCOMPARE(atomic.load(), T(value & 0xf)); + QCOMPARE(atomic.loadRelaxed(), T(value & 0xf)); QCOMPARE(atomic.fetchAndAndRelease(zero), T(value & 0xf)); - QCOMPARE(atomic.load(), zero); + QCOMPARE(atomic.loadRelaxed(), zero); - atomic.store(value); + atomic.storeRelaxed(value); QCOMPARE(atomic.fetchAndAndOrdered(minusOne), T(value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndAndOrdered(f), T(value)); - QCOMPARE(atomic.load(), T(value & 0xf)); + QCOMPARE(atomic.loadRelaxed(), T(value & 0xf)); QCOMPARE(atomic.fetchAndAndOrdered(zero), T(value & 0xf)); - QCOMPARE(atomic.load(), zero); + QCOMPARE(atomic.loadRelaxed(), zero); - atomic.store(value); + atomic.storeRelaxed(value); QCOMPARE(atomic &= minusOne, T(value)); QCOMPARE(atomic &= f, T(value & 0xf)); QCOMPARE(atomic &= zero, zero); @@ -749,48 +749,48 @@ void tst_QAtomicIntegerXX::fetchAndXor() T minusOne = T(~0); QCOMPARE(atomic.fetchAndXorRelaxed(zero), T(value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndXorRelaxed(pattern), T(value)); - QCOMPARE(atomic.load(), T(value ^ pattern)); + QCOMPARE(atomic.loadRelaxed(), T(value ^ pattern)); QCOMPARE(atomic.fetchAndXorRelaxed(pattern), T(value ^ pattern)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndXorRelaxed(minusOne), T(value)); - QCOMPARE(atomic.load(), T(~value)); + QCOMPARE(atomic.loadRelaxed(), T(~value)); QCOMPARE(atomic.fetchAndXorRelaxed(minusOne), T(~value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndXorAcquire(zero), T(value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndXorAcquire(pattern), T(value)); - QCOMPARE(atomic.load(), T(value ^ pattern)); + QCOMPARE(atomic.loadRelaxed(), T(value ^ pattern)); QCOMPARE(atomic.fetchAndXorAcquire(pattern), T(value ^ pattern)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndXorAcquire(minusOne), T(value)); - QCOMPARE(atomic.load(), T(~value)); + QCOMPARE(atomic.loadRelaxed(), T(~value)); QCOMPARE(atomic.fetchAndXorAcquire(minusOne), T(~value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndXorRelease(zero), T(value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndXorRelease(pattern), T(value)); - QCOMPARE(atomic.load(), T(value ^ pattern)); + QCOMPARE(atomic.loadRelaxed(), T(value ^ pattern)); QCOMPARE(atomic.fetchAndXorRelease(pattern), T(value ^ pattern)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndXorRelease(minusOne), T(value)); - QCOMPARE(atomic.load(), T(~value)); + QCOMPARE(atomic.loadRelaxed(), T(~value)); QCOMPARE(atomic.fetchAndXorRelease(minusOne), T(~value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndXorOrdered(zero), T(value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndXorOrdered(pattern), T(value)); - QCOMPARE(atomic.load(), T(value ^ pattern)); + QCOMPARE(atomic.loadRelaxed(), T(value ^ pattern)); QCOMPARE(atomic.fetchAndXorOrdered(pattern), T(value ^ pattern)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic.fetchAndXorOrdered(minusOne), T(value)); - QCOMPARE(atomic.load(), T(~value)); + QCOMPARE(atomic.loadRelaxed(), T(~value)); QCOMPARE(atomic.fetchAndXorOrdered(minusOne), T(~value)); - QCOMPARE(atomic.load(), T(value)); + QCOMPARE(atomic.loadRelaxed(), T(value)); QCOMPARE(atomic ^= zero, T(value)); QCOMPARE(atomic ^= pattern, T(value ^ pattern)); diff --git a/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp b/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp index 0200473cae..a699cf6202 100644 --- a/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp +++ b/tests/auto/corelib/thread/qatomicpointer/tst_qatomicpointer.cpp @@ -75,7 +75,7 @@ void tst_QAtomicPointer::warningFreeHelper() QBasicAtomicPointer<WFHC> p = Q_BASIC_ATOMIC_INITIALIZER(0); - p.load()->bar(); + p.loadRelaxed()->bar(); WFHC *expectedValue = 0; WFHC *newValue = 0; @@ -119,15 +119,15 @@ void tst_QAtomicPointer::constructor() { void *one = this; QAtomicPointer<void> atomic1 = one; - QCOMPARE(atomic1.load(), one); + QCOMPARE(atomic1.loadRelaxed(), one); void *two = &one; QAtomicPointer<void> atomic2 = two; - QCOMPARE(atomic2.load(), two); + QCOMPARE(atomic2.loadRelaxed(), two); void *three = &two; QAtomicPointer<void> atomic3 = three; - QCOMPARE(atomic3.load(), three); + QCOMPARE(atomic3.loadRelaxed(), three); } void tst_QAtomicPointer::copy_constructor() @@ -135,20 +135,20 @@ void tst_QAtomicPointer::copy_constructor() void *one = this; QAtomicPointer<void> atomic1 = one; QAtomicPointer<void> atomic1_copy = atomic1; - QCOMPARE(atomic1_copy.load(), one); - QCOMPARE(atomic1_copy.load(), atomic1.load()); + QCOMPARE(atomic1_copy.loadRelaxed(), one); + QCOMPARE(atomic1_copy.loadRelaxed(), atomic1.loadRelaxed()); void *two = &one; QAtomicPointer<void> atomic2 = two; QAtomicPointer<void> atomic2_copy = atomic2; - QCOMPARE(atomic2_copy.load(), two); - QCOMPARE(atomic2_copy.load(), atomic2.load()); + QCOMPARE(atomic2_copy.loadRelaxed(), two); + QCOMPARE(atomic2_copy.loadRelaxed(), atomic2.loadRelaxed()); void *three = &two; QAtomicPointer<void> atomic3 = three; QAtomicPointer<void> atomic3_copy = atomic3; - QCOMPARE(atomic3_copy.load(), three); - QCOMPARE(atomic3_copy.load(), atomic3.load()); + QCOMPARE(atomic3_copy.loadRelaxed(), three); + QCOMPARE(atomic3_copy.loadRelaxed(), atomic3.loadRelaxed()); } void tst_QAtomicPointer::assignment_operator() @@ -161,17 +161,17 @@ void tst_QAtomicPointer::assignment_operator() QAtomicPointer<void> atomic2 = two; QAtomicPointer<void> atomic3 = three; - QCOMPARE(atomic1.load(), one); - QCOMPARE(atomic2.load(), two); - QCOMPARE(atomic3.load(), three); + QCOMPARE(atomic1.loadRelaxed(), one); + QCOMPARE(atomic2.loadRelaxed(), two); + QCOMPARE(atomic3.loadRelaxed(), three); atomic1 = two; atomic2 = three; atomic3 = one; - QCOMPARE(atomic1.load(), two); - QCOMPARE(atomic2.load(), three); - QCOMPARE(atomic3.load(), one); + QCOMPARE(atomic1.loadRelaxed(), two); + QCOMPARE(atomic2.loadRelaxed(), three); + QCOMPARE(atomic3.loadRelaxed(), one); } void tst_QAtomicPointer::isTestAndSetNative() @@ -234,17 +234,17 @@ void tst_QAtomicPointer::testAndSet() QAtomicPointer<void> atomic2 = two; QAtomicPointer<void> atomic3 = three; - QCOMPARE(atomic1.load(), one); - QCOMPARE(atomic2.load(), two); - QCOMPARE(atomic3.load(), three); + QCOMPARE(atomic1.loadRelaxed(), one); + QCOMPARE(atomic2.loadRelaxed(), two); + QCOMPARE(atomic3.loadRelaxed(), three); QVERIFY(atomic1.testAndSetRelaxed(one, two)); QVERIFY(atomic2.testAndSetRelaxed(two, three)); QVERIFY(atomic3.testAndSetRelaxed(three, one)); - QCOMPARE(atomic1.load(), two); - QCOMPARE(atomic2.load(), three); - QCOMPARE(atomic3.load(), one); + QCOMPARE(atomic1.loadRelaxed(), two); + QCOMPARE(atomic2.loadRelaxed(), three); + QCOMPARE(atomic3.loadRelaxed(), one); } { @@ -252,17 +252,17 @@ void tst_QAtomicPointer::testAndSet() QAtomicPointer<void> atomic2 = two; QAtomicPointer<void> atomic3 = three; - QCOMPARE(atomic1.load(), one); - QCOMPARE(atomic2.load(), two); - QCOMPARE(atomic3.load(), three); + QCOMPARE(atomic1.loadRelaxed(), one); + QCOMPARE(atomic2.loadRelaxed(), two); + QCOMPARE(atomic3.loadRelaxed(), three); QVERIFY(atomic1.testAndSetAcquire(one, two)); QVERIFY(atomic2.testAndSetAcquire(two, three)); QVERIFY(atomic3.testAndSetAcquire(three, one)); - QCOMPARE(atomic1.load(), two); - QCOMPARE(atomic2.load(), three); - QCOMPARE(atomic3.load(), one); + QCOMPARE(atomic1.loadRelaxed(), two); + QCOMPARE(atomic2.loadRelaxed(), three); + QCOMPARE(atomic3.loadRelaxed(), one); } { @@ -270,17 +270,17 @@ void tst_QAtomicPointer::testAndSet() QAtomicPointer<void> atomic2 = two; QAtomicPointer<void> atomic3 = three; - QCOMPARE(atomic1.load(), one); - QCOMPARE(atomic2.load(), two); - QCOMPARE(atomic3.load(), three); + QCOMPARE(atomic1.loadRelaxed(), one); + QCOMPARE(atomic2.loadRelaxed(), two); + QCOMPARE(atomic3.loadRelaxed(), three); QVERIFY(atomic1.testAndSetRelease(one, two)); QVERIFY(atomic2.testAndSetRelease(two, three)); QVERIFY(atomic3.testAndSetRelease(three, one)); - QCOMPARE(atomic1.load(), two); - QCOMPARE(atomic2.load(), three); - QCOMPARE(atomic3.load(), one); + QCOMPARE(atomic1.loadRelaxed(), two); + QCOMPARE(atomic2.loadRelaxed(), three); + QCOMPARE(atomic3.loadRelaxed(), one); } { @@ -288,17 +288,17 @@ void tst_QAtomicPointer::testAndSet() QAtomicPointer<void> atomic2 = two; QAtomicPointer<void> atomic3 = three; - QCOMPARE(atomic1.load(), one); - QCOMPARE(atomic2.load(), two); - QCOMPARE(atomic3.load(), three); + QCOMPARE(atomic1.loadRelaxed(), one); + QCOMPARE(atomic2.loadRelaxed(), two); + QCOMPARE(atomic3.loadRelaxed(), three); QVERIFY(atomic1.testAndSetOrdered(one, two)); QVERIFY(atomic2.testAndSetOrdered(two, three)); QVERIFY(atomic3.testAndSetOrdered(three, one)); - QCOMPARE(atomic1.load(), two); - QCOMPARE(atomic2.load(), three); - QCOMPARE(atomic3.load(), one); + QCOMPARE(atomic1.loadRelaxed(), two); + QCOMPARE(atomic2.loadRelaxed(), three); + QCOMPARE(atomic3.loadRelaxed(), one); } } @@ -362,17 +362,17 @@ void tst_QAtomicPointer::fetchAndStore() QAtomicPointer<void> atomic2 = two; QAtomicPointer<void> atomic3 = three; - QCOMPARE(atomic1.load(), one); - QCOMPARE(atomic2.load(), two); - QCOMPARE(atomic3.load(), three); + QCOMPARE(atomic1.loadRelaxed(), one); + QCOMPARE(atomic2.loadRelaxed(), two); + QCOMPARE(atomic3.loadRelaxed(), three); QCOMPARE(atomic1.fetchAndStoreRelaxed(two), one); QCOMPARE(atomic2.fetchAndStoreRelaxed(three), two); QCOMPARE(atomic3.fetchAndStoreRelaxed(one), three); - QCOMPARE(atomic1.load(), two); - QCOMPARE(atomic2.load(), three); - QCOMPARE(atomic3.load(), one); + QCOMPARE(atomic1.loadRelaxed(), two); + QCOMPARE(atomic2.loadRelaxed(), three); + QCOMPARE(atomic3.loadRelaxed(), one); } { @@ -380,17 +380,17 @@ void tst_QAtomicPointer::fetchAndStore() QAtomicPointer<void> atomic2 = two; QAtomicPointer<void> atomic3 = three; - QCOMPARE(atomic1.load(), one); - QCOMPARE(atomic2.load(), two); - QCOMPARE(atomic3.load(), three); + QCOMPARE(atomic1.loadRelaxed(), one); + QCOMPARE(atomic2.loadRelaxed(), two); + QCOMPARE(atomic3.loadRelaxed(), three); QCOMPARE(atomic1.fetchAndStoreAcquire(two), one); QCOMPARE(atomic2.fetchAndStoreAcquire(three), two); QCOMPARE(atomic3.fetchAndStoreAcquire(one), three); - QCOMPARE(atomic1.load(), two); - QCOMPARE(atomic2.load(), three); - QCOMPARE(atomic3.load(), one); + QCOMPARE(atomic1.loadRelaxed(), two); + QCOMPARE(atomic2.loadRelaxed(), three); + QCOMPARE(atomic3.loadRelaxed(), one); } { @@ -398,17 +398,17 @@ void tst_QAtomicPointer::fetchAndStore() QAtomicPointer<void> atomic2 = two; QAtomicPointer<void> atomic3 = three; - QCOMPARE(atomic1.load(), one); - QCOMPARE(atomic2.load(), two); - QCOMPARE(atomic3.load(), three); + QCOMPARE(atomic1.loadRelaxed(), one); + QCOMPARE(atomic2.loadRelaxed(), two); + QCOMPARE(atomic3.loadRelaxed(), three); QCOMPARE(atomic1.fetchAndStoreRelease(two), one); QCOMPARE(atomic2.fetchAndStoreRelease(three), two); QCOMPARE(atomic3.fetchAndStoreRelease(one), three); - QCOMPARE(atomic1.load(), two); - QCOMPARE(atomic2.load(), three); - QCOMPARE(atomic3.load(), one); + QCOMPARE(atomic1.loadRelaxed(), two); + QCOMPARE(atomic2.loadRelaxed(), three); + QCOMPARE(atomic3.loadRelaxed(), one); } { @@ -416,17 +416,17 @@ void tst_QAtomicPointer::fetchAndStore() QAtomicPointer<void> atomic2 = two; QAtomicPointer<void> atomic3 = three; - QCOMPARE(atomic1.load(), one); - QCOMPARE(atomic2.load(), two); - QCOMPARE(atomic3.load(), three); + QCOMPARE(atomic1.loadRelaxed(), one); + QCOMPARE(atomic2.loadRelaxed(), two); + QCOMPARE(atomic3.loadRelaxed(), three); QCOMPARE(atomic1.fetchAndStoreOrdered(two), one); QCOMPARE(atomic2.fetchAndStoreOrdered(three), two); QCOMPARE(atomic3.fetchAndStoreOrdered(one), three); - QCOMPARE(atomic1.load(), two); - QCOMPARE(atomic2.load(), three); - QCOMPARE(atomic3.load(), one); + QCOMPARE(atomic1.loadRelaxed(), two); + QCOMPARE(atomic2.loadRelaxed(), three); + QCOMPARE(atomic3.loadRelaxed(), one); } } @@ -530,60 +530,60 @@ void tst_QAtomicPointer::fetchAndAdd() // cast to void* in order to avoid QCOMPARE to compare string content of the char* QCOMPARE(static_cast<void*>(pointer1.fetchAndAddRelaxed(valueToAdd)), static_cast<void*>(pc)); QCOMPARE(static_cast<void*>(pointer1.fetchAndAddRelaxed(-valueToAdd)), static_cast<void*>(pc + valueToAdd)); - QCOMPARE(static_cast<void*>(pointer1.load()), static_cast<void*>(pc)); + QCOMPARE(static_cast<void*>(pointer1.loadRelaxed()), static_cast<void*>(pc)); QAtomicPointer<short> pointer2 = ps; QCOMPARE(pointer2.fetchAndAddRelaxed(valueToAdd), ps); QCOMPARE(pointer2.fetchAndAddRelaxed(-valueToAdd), ps + valueToAdd); - QCOMPARE(pointer2.load(), ps); + QCOMPARE(pointer2.loadRelaxed(), ps); QAtomicPointer<int> pointer3 = pi; QCOMPARE(pointer3.fetchAndAddRelaxed(valueToAdd), pi); QCOMPARE(pointer3.fetchAndAddRelaxed(-valueToAdd), pi + valueToAdd); - QCOMPARE(pointer3.load(), pi); + QCOMPARE(pointer3.loadRelaxed(), pi); } { QAtomicPointer<char> pointer1 = pc; QCOMPARE(static_cast<void*>(pointer1.fetchAndAddAcquire(valueToAdd)), static_cast<void*>(pc)); QCOMPARE(static_cast<void*>(pointer1.fetchAndAddAcquire(-valueToAdd)), static_cast<void*>(pc + valueToAdd)); - QCOMPARE(static_cast<void*>(pointer1.load()), static_cast<void*>(pc)); + QCOMPARE(static_cast<void*>(pointer1.loadRelaxed()), static_cast<void*>(pc)); QAtomicPointer<short> pointer2 = ps; QCOMPARE(pointer2.fetchAndAddAcquire(valueToAdd), ps); QCOMPARE(pointer2.fetchAndAddAcquire(-valueToAdd), ps + valueToAdd); - QCOMPARE(pointer2.load(), ps); + QCOMPARE(pointer2.loadRelaxed(), ps); QAtomicPointer<int> pointer3 = pi; QCOMPARE(pointer3.fetchAndAddAcquire(valueToAdd), pi); QCOMPARE(pointer3.fetchAndAddAcquire(-valueToAdd), pi + valueToAdd); - QCOMPARE(pointer3.load(), pi); + QCOMPARE(pointer3.loadRelaxed(), pi); } { QAtomicPointer<char> pointer1 = pc; QCOMPARE(static_cast<void*>(pointer1.fetchAndAddRelease(valueToAdd)), static_cast<void*>(pc)); QCOMPARE(static_cast<void*>(pointer1.fetchAndAddRelease(-valueToAdd)), static_cast<void*>(pc + valueToAdd)); - QCOMPARE(static_cast<void*>(pointer1.load()), static_cast<void*>(pc)); + QCOMPARE(static_cast<void*>(pointer1.loadRelaxed()), static_cast<void*>(pc)); QAtomicPointer<short> pointer2 = ps; QCOMPARE(pointer2.fetchAndAddRelease(valueToAdd), ps); QCOMPARE(pointer2.fetchAndAddRelease(-valueToAdd), ps + valueToAdd); - QCOMPARE(pointer2.load(), ps); + QCOMPARE(pointer2.loadRelaxed(), ps); QAtomicPointer<int> pointer3 = pi; QCOMPARE(pointer3.fetchAndAddRelease(valueToAdd), pi); QCOMPARE(pointer3.fetchAndAddRelease(-valueToAdd), pi + valueToAdd); - QCOMPARE(pointer3.load(), pi); + QCOMPARE(pointer3.loadRelaxed(), pi); } { QAtomicPointer<char> pointer1 = pc; QCOMPARE(static_cast<void*>(pointer1.fetchAndAddOrdered(valueToAdd)), static_cast<void*>(pc)); QCOMPARE(static_cast<void*>(pointer1.fetchAndAddOrdered(-valueToAdd)), static_cast<void*>(pc + valueToAdd)); - QCOMPARE(static_cast<void*>(pointer1.load()), static_cast<void*>(pc)); + QCOMPARE(static_cast<void*>(pointer1.loadRelaxed()), static_cast<void*>(pc)); QAtomicPointer<short> pointer2 = ps; QCOMPARE(pointer2.fetchAndAddOrdered(valueToAdd), ps); QCOMPARE(pointer2.fetchAndAddOrdered(-valueToAdd), ps + valueToAdd); - QCOMPARE(pointer2.load(), ps); + QCOMPARE(pointer2.loadRelaxed(), ps); QAtomicPointer<int> pointer3 = pi; QCOMPARE(pointer3.fetchAndAddOrdered(valueToAdd), pi); QCOMPARE(pointer3.fetchAndAddOrdered(-valueToAdd), pi + valueToAdd); - QCOMPARE(pointer3.load(), pi); + QCOMPARE(pointer3.loadRelaxed(), pi); } } @@ -598,34 +598,34 @@ template <typename T> void constAndVolatile_helper() QAtomicPointer<T> atomic2 = two; QAtomicPointer<T> atomic3 = three; - QVERIFY(atomic1.load() == one); - QVERIFY(atomic2.load() == two); - QVERIFY(atomic3.load() == three); + QVERIFY(atomic1.loadRelaxed() == one); + QVERIFY(atomic2.loadRelaxed() == two); + QVERIFY(atomic3.loadRelaxed() == three); QVERIFY(atomic1.fetchAndStoreRelaxed(two) == one); QVERIFY(atomic2.fetchAndStoreRelaxed(three) == two); QVERIFY(atomic3.fetchAndStoreRelaxed(one) == three); - QVERIFY(atomic1.load() == two); - QVERIFY(atomic2.load() == three); - QVERIFY(atomic3.load() == one); + QVERIFY(atomic1.loadRelaxed() == two); + QVERIFY(atomic2.loadRelaxed() == three); + QVERIFY(atomic3.loadRelaxed() == one); } { QAtomicPointer<T> atomic1 = one; QAtomicPointer<T> atomic2 = two; QAtomicPointer<T> atomic3 = three; - QVERIFY(atomic1.load() == one); - QVERIFY(atomic2.load() == two); - QVERIFY(atomic3.load() == three); + QVERIFY(atomic1.loadRelaxed() == one); + QVERIFY(atomic2.loadRelaxed() == two); + QVERIFY(atomic3.loadRelaxed() == three); QVERIFY(atomic1.testAndSetRelaxed(one, two)); QVERIFY(atomic2.testAndSetRelaxed(two, three)); QVERIFY(atomic3.testAndSetRelaxed(three, one)); - QVERIFY(atomic1.load() == two); - QVERIFY(atomic2.load() == three); - QVERIFY(atomic3.load() == one); + QVERIFY(atomic1.loadRelaxed() == two); + QVERIFY(atomic2.loadRelaxed() == three); + QVERIFY(atomic3.loadRelaxed() == one); } } diff --git a/tests/auto/corelib/thread/qfuture/qfuture.pro b/tests/auto/corelib/thread/qfuture/qfuture.pro index b1667760d6..1f21130af7 100644 --- a/tests/auto/corelib/thread/qfuture/qfuture.pro +++ b/tests/auto/corelib/thread/qfuture/qfuture.pro @@ -3,3 +3,4 @@ TARGET = tst_qfuture QT = core core-private testlib SOURCES = tst_qfuture.cpp DEFINES += QT_STRICT_ITERATORS +DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp index b8c82c2ea0..a42454124e 100644 --- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp +++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp @@ -49,6 +49,24 @@ struct ResultStoreInt : QtPrivate::ResultStoreBase ~ResultStoreInt() { clear<int>(); } }; +class LambdaThread : public QThread +{ +public: + LambdaThread(std::function<void ()> fn) + :m_fn(fn) + { + + } + + void run() override + { + m_fn(); + } + +private: + std::function<void ()> m_fn; +}; + class tst_QFuture: public QObject { Q_OBJECT @@ -67,6 +85,7 @@ private slots: void resultsAsList(); void implicitConversions(); void iterators(); + void iteratorsThread(); void pause(); void throttling(); void voidConversions(); @@ -1144,6 +1163,54 @@ void tst_QFuture::iterators() } } } +void tst_QFuture::iteratorsThread() +{ + const int expectedResultCount = 10; + const int delay = 10; + QFutureInterface<int> futureInterface; + + // Create result producer thread. The results are + // produced with delays in order to make the consumer + // wait. + QSemaphore sem; + LambdaThread thread = {[=, &futureInterface, &sem](){ + for (int i = 1; i <= expectedResultCount; i += 2) { + int result = i; + futureInterface.reportResult(&result); + result = i + 1; + futureInterface.reportResult(&result); + } + + sem.acquire(2); + futureInterface.reportFinished(); + }}; + + futureInterface.reportStarted(); + QFuture<int> future = futureInterface.future(); + + // Iterate over results while the thread is producing them. + thread.start(); + int resultCount = 0; + int resultSum = 0; + for (int result : future) { + sem.release(); + ++resultCount; + resultSum += result; + } + thread.wait(); + + QCOMPARE(resultCount, expectedResultCount); + QCOMPARE(resultSum, expectedResultCount * (expectedResultCount + 1) / 2); + + // Reverse iterate + resultSum = 0; + QFutureIterator<int> it(future); + it.toBack(); + while (it.hasPrevious()) + resultSum += it.previous(); + + QCOMPARE(resultSum, expectedResultCount * (expectedResultCount + 1) / 2); +} class SignalSlotObject : public QObject { diff --git a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp index b2ef516b4e..a322a1c11d 100644 --- a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp +++ b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include <QCoreApplication> #include <QDebug> +#include <QElapsedTimer> #include <QtTest/QtTest> #include <QtConcurrent> @@ -878,7 +879,7 @@ void tst_QFutureWatcher::incrementalFilterResults() void tst_QFutureWatcher::qfutureSynchronizer() { int taskCount = 1000; - QTime t; + QElapsedTimer t; t.start(); { diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index 7fb9a861d7..749aa45916 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -69,7 +69,8 @@ private slots: static const int iterations = 100; QAtomicInt lockCount(0); -QMutex normalMutex, recursiveMutex(QMutex::Recursive); +QMutex normalMutex; +QRecursiveMutex recursiveMutex; QSemaphore testsTurn; QSemaphore threadsTurn; @@ -993,9 +994,9 @@ public: QMutex mutex; QWaitCondition cond; - QMutex &test_mutex; + QRecursiveMutex &test_mutex; - inline rmutex_Thread(QMutex &m) : test_mutex(m) { } + inline rmutex_Thread(QRecursiveMutex &m) : test_mutex(m) { } void run() { @@ -1024,7 +1025,7 @@ void tst_QMutex::lock_unlock_locked_tryLock() QMutex mutex; mutex_Thread thread(mutex); - QMutex rmutex(QMutex::Recursive); + QRecursiveMutex rmutex; rmutex_Thread rthread(rmutex); for (int i = 0; i < iterations; ++i) { @@ -1132,7 +1133,7 @@ void tst_QMutex::stressTest() for (int i = 1; i < threadCount; ++i) QVERIFY(threads[i].wait(10000)); QCOMPARE(StressTestThread::errorCount, 0); - qDebug("locked %d times", int(StressTestThread::lockCount.load())); + qDebug("locked %d times", int(StressTestThread::lockCount.loadRelaxed())); } class TryLockRaceThread : public QThread @@ -1286,28 +1287,28 @@ public: quint64 i = 0; while (t.elapsed() < one_minute) { i++; - uint nb = (i * 9 + lockCount.load() * 13) % threadCount; + uint nb = (i * 9 + lockCount.loadRelaxed() * 13) % threadCount; QMutexLocker locker(&mutex[nb]); - if (sentinel[nb].load()) errorCount.ref(); + if (sentinel[nb].loadRelaxed()) errorCount.ref(); if (sentinel[nb].fetchAndAddRelaxed(5)) errorCount.ref(); if (!sentinel[nb].testAndSetRelaxed(5, 0)) errorCount.ref(); - if (sentinel[nb].load()) errorCount.ref(); + if (sentinel[nb].loadRelaxed()) errorCount.ref(); lockCount.ref(); - nb = (nb * 17 + i * 5 + lockCount.load() * 3) % threadCount; + nb = (nb * 17 + i * 5 + lockCount.loadRelaxed() * 3) % threadCount; if (mutex[nb].tryLock()) { - if (sentinel[nb].load()) errorCount.ref(); + if (sentinel[nb].loadRelaxed()) errorCount.ref(); if (sentinel[nb].fetchAndAddRelaxed(16)) errorCount.ref(); if (!sentinel[nb].testAndSetRelaxed(16, 0)) errorCount.ref(); - if (sentinel[nb].load()) errorCount.ref(); + if (sentinel[nb].loadRelaxed()) errorCount.ref(); lockCount.ref(); mutex[nb].unlock(); } - nb = (nb * 15 + i * 47 + lockCount.load() * 31) % threadCount; + nb = (nb * 15 + i * 47 + lockCount.loadRelaxed() * 31) % threadCount; if (mutex[nb].tryLock(2)) { - if (sentinel[nb].load()) errorCount.ref(); + if (sentinel[nb].loadRelaxed()) errorCount.ref(); if (sentinel[nb].fetchAndAddRelaxed(53)) errorCount.ref(); if (!sentinel[nb].testAndSetRelaxed(53, 0)) errorCount.ref(); - if (sentinel[nb].load()) errorCount.ref(); + if (sentinel[nb].loadRelaxed()) errorCount.ref(); lockCount.ref(); mutex[nb].unlock(); } @@ -1327,8 +1328,8 @@ void tst_QMutex::moreStress() QVERIFY(threads[0].wait(one_minute + 10000)); for (int i = 1; i < threadCount; ++i) QVERIFY(threads[i].wait(10000)); - qDebug("locked %d times", MoreStressTestThread::lockCount.load()); - QCOMPARE(MoreStressTestThread::errorCount.load(), 0); + qDebug("locked %d times", MoreStressTestThread::lockCount.loadRelaxed()); + QCOMPARE(MoreStressTestThread::errorCount.loadRelaxed(), 0); } diff --git a/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp b/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp index 67db5d1458..c83e186ca7 100644 --- a/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp +++ b/tests/auto/corelib/thread/qmutexlocker/tst_qmutexlocker.cpp @@ -36,7 +36,7 @@ class tst_QMutexLockerThread : public QThread { public: - QMutex mutex; + QRecursiveMutex mutex; QSemaphore semaphore, testSemaphore; void waitForTest() @@ -45,10 +45,6 @@ public: testSemaphore.acquire(); } - tst_QMutexLockerThread() - : mutex(QMutex::Recursive) - { - } }; class tst_QMutexLocker : public QObject diff --git a/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp b/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp index 8e97229752..47bae585a1 100644 --- a/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp +++ b/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp @@ -29,6 +29,7 @@ #include <QtTest/QtTest> #include <qcoreapplication.h> #include <qreadwritelock.h> +#include <qelapsedtimer.h> #include <qmutex.h> #include <qthread.h> #include <qwaitcondition.h> @@ -237,7 +238,7 @@ void tst_QReadWriteLock::tryReadLock() testsTurn.release(); threadsTurn.acquire(); - QTime timer; + QElapsedTimer timer; timer.start(); QVERIFY(!readWriteLock.tryLockForRead(1000)); QVERIFY(timer.elapsed() >= 1000); @@ -457,7 +458,7 @@ public: void run() { testRwlock.lockForWrite(); - while(release.load()==false) { + while (release.loadRelaxed() == false) { RWTESTSLEEP } testRwlock.unlock(); @@ -477,7 +478,7 @@ public: void run() { testRwlock.lockForRead(); - while(release.load()==false) { + while (release.loadRelaxed() == false) { RWTESTSLEEP } testRwlock.unlock(); @@ -500,7 +501,7 @@ public: int holdTime; int waitTime; bool print; - QTime t; + QElapsedTimer t; inline ReadLockLoopThread(QReadWriteLock &l, int runTime, int holdTime=0, int waitTime=0, bool print=false) :testRwlock(l) ,runTime(runTime) @@ -536,7 +537,7 @@ public: int holdTime; int waitTime; bool print; - QTime t; + QElapsedTimer t; inline WriteLockLoopThread(QReadWriteLock &l, int runTime, int holdTime=0, int waitTime=0, bool print=false) :testRwlock(l) ,runTime(runTime) @@ -574,7 +575,7 @@ public: int runTime; int waitTime; int maxval; - QTime t; + QElapsedTimer t; inline WriteLockCountThread(QReadWriteLock &l, int runTime, int waitTime, int maxval) :testRwlock(l) ,runTime(runTime) @@ -615,7 +616,7 @@ public: QReadWriteLock &testRwlock; int runTime; int waitTime; - QTime t; + QElapsedTimer t; inline ReadLockCountThread(QReadWriteLock &l, int runTime, int waitTime) :testRwlock(l) ,runTime(runTime) @@ -676,7 +677,7 @@ void tst_QReadWriteLock::multipleReadersBlockRelease() { QReadWriteLock testLock; - release.store(false); + release.storeRelaxed(false); threadDone=false; ReadLockReleasableThread rlt1(testLock); ReadLockReleasableThread rlt2(testLock); @@ -686,7 +687,7 @@ void tst_QReadWriteLock::multipleReadersBlockRelease() WriteLockThread wlt(testLock); wlt.start(); sleep(1); - release.store(true); + release.storeRelaxed(true); wlt.wait(); rlt1.wait(); rlt2.wait(); @@ -873,7 +874,7 @@ void tst_QReadWriteLock::deleteOnUnlock() DeleteOnUnlockThread thread2(&lock, &startup, &waitMutex); - QTime t; + QElapsedTimer t; t.start(); while(t.elapsed() < 4000) { lock = new QReadWriteLock(); @@ -899,7 +900,7 @@ void tst_QReadWriteLock::uncontendedLocks() uint count=0; int millisecs=1000; { - QTime t; + QElapsedTimer t; t.start(); while(t.elapsed() <millisecs) { @@ -908,7 +909,7 @@ void tst_QReadWriteLock::uncontendedLocks() } { QReadWriteLock rwlock; - QTime t; + QElapsedTimer t; t.start(); while(t.elapsed() <millisecs) { @@ -919,7 +920,7 @@ void tst_QReadWriteLock::uncontendedLocks() } { QReadWriteLock rwlock; - QTime t; + QElapsedTimer t; t.start(); while(t.elapsed() <millisecs) { diff --git a/tests/auto/corelib/thread/qthread/BLACKLIST b/tests/auto/corelib/thread/qthread/BLACKLIST index d75249454f..ccf530362c 100644 --- a/tests/auto/corelib/thread/qthread/BLACKLIST +++ b/tests/auto/corelib/thread/qthread/BLACKLIST @@ -1,2 +1,4 @@ [wait3_slowDestructor] windows +[sleep] +windows ci diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp index f72b662c94..7be2f48758 100644 --- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp +++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp @@ -29,7 +29,7 @@ #include <QtTest/QtTest> #include <qcoreapplication.h> -#include <qdatetime.h> +#include <qelapsedtimer.h> #include <qmutex.h> #include <qthread.h> #include <qtimer.h> @@ -110,6 +110,12 @@ private slots: enum { one_minute = 60 * 1000, five_minutes = 5 * one_minute }; +template <class Int> +static QString msgElapsed(Int elapsed) +{ + return QString::fromLatin1("elapsed: %1").arg(elapsed); +} + class SignalRecorder : public QObject { Q_OBJECT @@ -121,7 +127,7 @@ public: { } bool wasActivated() - { return activationCount.load() > 0; } + { return activationCount.loadRelaxed() > 0; } public slots: void slot(); @@ -244,8 +250,8 @@ public: QMutexLocker locker(&mutex); elapsed = 0; - QTime time; - time.start(); + QElapsedTimer timer; + timer.start(); switch (sleepType) { case Second: sleep(interval); @@ -257,7 +263,7 @@ public: usleep(interval); break; } - elapsed = time.elapsed(); + elapsed = timer.elapsed(); cond.wakeOne(); } @@ -591,7 +597,7 @@ void tst_QThread::sleep() thread.interval = 2; thread.start(); QVERIFY(thread.wait(five_minutes)); - QVERIFY(thread.elapsed >= 2000); + QVERIFY2(thread.elapsed >= 2000, qPrintable(msgElapsed(thread.elapsed))); } void tst_QThread::msleep() @@ -601,11 +607,10 @@ void tst_QThread::msleep() thread.interval = 120; thread.start(); QVERIFY(thread.wait(five_minutes)); -#if defined (Q_OS_WIN) - // Since the resolution of QTime is so coarse... - QVERIFY(thread.elapsed >= 100); +#if defined (Q_OS_WIN) // May no longer be needed + QVERIFY2(thread.elapsed >= 100, qPrintable(msgElapsed(thread.elapsed))); #else - QVERIFY(thread.elapsed >= 120); + QVERIFY2(thread.elapsed >= 120, qPrintable(msgElapsed(thread.elapsed))); #endif } @@ -616,11 +621,10 @@ void tst_QThread::usleep() thread.interval = 120000; thread.start(); QVERIFY(thread.wait(five_minutes)); -#if defined (Q_OS_WIN) - // Since the resolution of QTime is so coarse... - QVERIFY(thread.elapsed >= 100); +#if defined (Q_OS_WIN) // May no longer be needed + QVERIFY2(thread.elapsed >= 100, qPrintable(msgElapsed(thread.elapsed))); #else - QVERIFY(thread.elapsed >= 120); + QVERIFY2(thread.elapsed >= 120, qPrintable(msgElapsed(thread.elapsed))); #endif } @@ -902,7 +906,7 @@ void tst_QThread::adoptMultipleThreads() QTestEventLoop::instance().enterLoop(5); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(recorder.activationCount.load(), numThreads); + QCOMPARE(recorder.activationCount.loadRelaxed(), numThreads); } void tst_QThread::adoptMultipleThreadsOverlap() @@ -939,7 +943,7 @@ void tst_QThread::adoptMultipleThreadsOverlap() QTestEventLoop::instance().enterLoop(5); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(recorder.activationCount.load(), numThreads); + QCOMPARE(recorder.activationCount.loadRelaxed(), numThreads); } // Disconnects on WinCE @@ -948,9 +952,9 @@ void tst_QThread::stressTest() if (EmulationDetector::isRunningArmOnX86()) QSKIP("Qemu uses too much memory for each thread. Test would run out of memory."); - QTime t; - t.start(); - while (t.elapsed() < one_minute) { + QElapsedTimer timer; + timer.start(); + while (timer.elapsed() < one_minute) { Current_Thread t; t.start(); t.wait(one_minute); @@ -1067,13 +1071,15 @@ void tst_QThread::wait2() timer.start(); QVERIFY(!thread.wait(Waiting_Thread::WaitTime)); qint64 elapsed = timer.elapsed(); // On Windows, we sometimes get (WaitTime - 9). - QVERIFY2(elapsed >= Waiting_Thread::WaitTime - 10, qPrintable(QString::fromLatin1("elapsed: %1").arg(elapsed))); + QVERIFY2(elapsed >= Waiting_Thread::WaitTime - 10, + qPrintable(msgElapsed(elapsed))); timer.start(); thread.cond1.wakeOne(); QVERIFY(thread.wait(/*Waiting_Thread::WaitTime * 1.4*/)); elapsed = timer.elapsed(); - QVERIFY2(elapsed - Waiting_Thread::WaitTime >= -1, qPrintable(QString::fromLatin1("elapsed: %1").arg(elapsed))); + QVERIFY2(elapsed - Waiting_Thread::WaitTime >= -1, + qPrintable(msgElapsed(elapsed))); } @@ -1210,7 +1216,7 @@ class DummyEventDispatcher : public QAbstractEventDispatcher { public: DummyEventDispatcher() : QAbstractEventDispatcher() {} bool processEvents(QEventLoop::ProcessEventsFlags) { - visited.store(true); + visited.storeRelaxed(true); emit awake(); QCoreApplication::sendPostedEvents(); return false; @@ -1272,7 +1278,7 @@ void tst_QThread::customEventDispatcher() QMetaObject::invokeMethod(&obj, "visit", Qt::QueuedConnection); loop.exec(); // test that the ED has really been used - QVERIFY(ed->visited.load()); + QVERIFY(ed->visited.loadRelaxed()); QPointer<DummyEventDispatcher> weak_ed(ed); QVERIFY(!weak_ed.isNull()); diff --git a/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp b/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp index d27884197a..3826fa148e 100644 --- a/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp +++ b/tests/auto/corelib/thread/qthreadonce/qthreadonce.cpp @@ -32,7 +32,7 @@ #include "qmutex.h" -Q_GLOBAL_STATIC_WITH_ARGS(QMutex, onceInitializationMutex, (QMutex::Recursive)) +Q_GLOBAL_STATIC(QRecursiveMutex, onceInitializationMutex) enum QOnceExtra { MustRunCode = 0x01, diff --git a/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp b/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp index a9af182ed8..710288af9e 100644 --- a/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp +++ b/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp @@ -56,7 +56,7 @@ class SingletonObject: public QObject Q_OBJECT public: static int runCount; - SingletonObject() { val.store(42); ++runCount; } + SingletonObject() { val.storeRelaxed(42); ++runCount; } ~SingletonObject() { } QBasicAtomicInt val; @@ -112,7 +112,7 @@ void tst_QThreadOnce::sameThread() QCOMPARE(controlVariable, 1); static QSingleton<SingletonObject> s; - QTEST((int)s->val.load(), "expectedValue"); + QTEST((int)s->val.loadRelaxed(), "expectedValue"); s->val.ref(); QCOMPARE(SingletonObject::runCount, 1); @@ -134,7 +134,7 @@ void tst_QThreadOnce::multipleThreads() QCOMPARE(controlVariable, 0); // nothing must have set them yet SingletonObject::runCount = 0; - IncrementThread::runCount.store(0); + IncrementThread::runCount.storeRelaxed(0); // wait for all of them to be ready sem2.acquire(NumberOfThreads); @@ -145,7 +145,7 @@ void tst_QThreadOnce::multipleThreads() delete parent; QCOMPARE(controlVariable, 1); - QCOMPARE((int)IncrementThread::runCount.load(), NumberOfThreads); + QCOMPARE((int)IncrementThread::runCount.loadRelaxed(), NumberOfThreads); QCOMPARE(SingletonObject::runCount, 1); } diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index 27b49602fc..112c36952c 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -27,7 +27,7 @@ ** ****************************************************************************/ #include <QtTest/QtTest> -#include <qdatetime.h> +#include <qelapsedtimer.h> #include <qthreadpool.h> #include <qstring.h> #include <qmutex.h> @@ -220,16 +220,16 @@ class TestTask : public QRunnable public: void run() { - ran.store(true); + ran.storeRelaxed(true); } }; void tst_QThreadPool::runTask() { QThreadPool manager; - ran.store(false); + ran.storeRelaxed(false); manager.start(new TestTask()); - QTRY_VERIFY(ran.load()); + QTRY_VERIFY(ran.loadRelaxed()); } /* @@ -237,9 +237,9 @@ void tst_QThreadPool::runTask() */ void tst_QThreadPool::singleton() { - ran.store(false); + ran.storeRelaxed(false); QThreadPool::globalInstance()->start(new TestTask()); - QTRY_VERIFY(ran.load()); + QTRY_VERIFY(ran.loadRelaxed()); } QAtomicInt *value = 0; @@ -344,7 +344,7 @@ void tst_QThreadPool::expiryTimeout() // run the task threadPool.start(&task); QVERIFY(task.semaphore.tryAcquire(1, 10000)); - QCOMPARE(task.runCount.load(), 1); + QCOMPARE(task.runCount.loadRelaxed(), 1); QVERIFY(!task.thread->wait(100)); // thread should expire QThread *firstThread = task.thread; @@ -353,7 +353,7 @@ void tst_QThreadPool::expiryTimeout() // run task again, thread should be restarted threadPool.start(&task); QVERIFY(task.semaphore.tryAcquire(1, 10000)); - QCOMPARE(task.runCount.load(), 2); + QCOMPARE(task.runCount.loadRelaxed(), 2); QVERIFY(!task.thread->wait(100)); // thread should expire again QVERIFY(task.thread->wait(10000)); @@ -382,7 +382,7 @@ void tst_QThreadPool::expiryTimeoutRace() // QTBUG-3786 QThread::msleep(50); // exactly the same as the expiry timeout } QVERIFY(task.semaphore.tryAcquire(numTasks, 10000)); - QCOMPARE(task.runCount.load(), numTasks); + QCOMPARE(task.runCount.loadRelaxed(), numTasks); QVERIFY(threadPool.waitForDone(2000)); } @@ -685,7 +685,7 @@ void tst_QThreadPool::reserveAndStart() // QTBUG-21051 QCOMPARE(threadpool->activeThreadCount(), 2); task->waitForStarted.acquire(); task->waitBeforeDone.release(); - QTRY_COMPARE(task->count.load(), 1); + QTRY_COMPARE(task->count.loadRelaxed(), 1); QTRY_COMPARE(threadpool->activeThreadCount(), 1); // now the thread is waiting, but tryStart() will fail since activeThreadCount() >= maxThreadCount() @@ -698,7 +698,7 @@ void tst_QThreadPool::reserveAndStart() // QTBUG-21051 QTRY_COMPARE(threadpool->activeThreadCount(), 2); task->waitForStarted.acquire(); task->waitBeforeDone.release(); - QTRY_COMPARE(task->count.load(), 2); + QTRY_COMPARE(task->count.loadRelaxed(), 2); QTRY_COMPARE(threadpool->activeThreadCount(), 1); threadpool->releaseThread(); @@ -721,14 +721,14 @@ class CountingRunnable : public QRunnable void tst_QThreadPool::start() { const int runs = 1000; - count.store(0); + count.storeRelaxed(0); { QThreadPool threadPool; for (int i = 0; i< runs; ++i) { threadPool.start(new CountingRunnable()); } } - QCOMPARE(count.load(), runs); + QCOMPARE(count.loadRelaxed(), runs); } void tst_QThreadPool::tryStart() @@ -747,7 +747,7 @@ void tst_QThreadPool::tryStart() } }; - count.store(0); + count.storeRelaxed(0); WaitingTask task; QThreadPool threadPool; @@ -757,7 +757,7 @@ void tst_QThreadPool::tryStart() QVERIFY(!threadPool.tryStart(&task)); task.semaphore.release(threadPool.maxThreadCount()); threadPool.waitForDone(); - QCOMPARE(count.load(), threadPool.maxThreadCount()); + QCOMPARE(count.loadRelaxed(), threadPool.maxThreadCount()); } QMutex mutex; @@ -775,7 +775,7 @@ void tst_QThreadPool::tryStartPeakThreadCount() { QMutexLocker lock(&mutex); activeThreads.ref(); - peakActiveThreads.store(qMax(peakActiveThreads.load(), activeThreads.load())); + peakActiveThreads.storeRelaxed(qMax(peakActiveThreads.loadRelaxed(), activeThreads.loadRelaxed())); } QTest::qWait(100); @@ -793,13 +793,13 @@ void tst_QThreadPool::tryStartPeakThreadCount() if (threadPool.tryStart(&task) == false) QTest::qWait(10); } - QCOMPARE(peakActiveThreads.load(), QThread::idealThreadCount()); + QCOMPARE(peakActiveThreads.loadRelaxed(), QThread::idealThreadCount()); for (int i = 0; i < 20; ++i) { if (threadPool.tryStart(&task) == false) QTest::qWait(10); } - QCOMPARE(peakActiveThreads.load(), QThread::idealThreadCount()); + QCOMPARE(peakActiveThreads.loadRelaxed(), QThread::idealThreadCount()); } void tst_QThreadPool::tryStartCount() @@ -877,27 +877,27 @@ void tst_QThreadPool::priorityStart() sem.release(); QVERIFY(threadPool.waitForDone()); - QCOMPARE(firstStarted.load(), expected); + QCOMPARE(firstStarted.loadRelaxed(), expected); } void tst_QThreadPool::waitForDone() { - QTime total, pass; + QElapsedTimer total, pass; total.start(); QThreadPool threadPool; while (total.elapsed() < 10000) { int runs; - count.store(runs = 0); + count.storeRelaxed(runs = 0); pass.restart(); while (pass.elapsed() < 100) { threadPool.start(new CountingRunnable()); ++runs; } threadPool.waitForDone(); - QCOMPARE(count.load(), runs); + QCOMPARE(count.loadRelaxed(), runs); - count.store(runs = 0); + count.storeRelaxed(runs = 0); pass.restart(); while (pass.elapsed() < 100) { threadPool.start(new CountingRunnable()); @@ -905,7 +905,7 @@ void tst_QThreadPool::waitForDone() runs += 2; } threadPool.waitForDone(); - QCOMPARE(count.load(), runs); + QCOMPARE(count.loadRelaxed(), runs); } } @@ -953,14 +953,14 @@ void tst_QThreadPool::clear() QThreadPool threadPool; threadPool.setMaxThreadCount(10); int runs = 2 * threadPool.maxThreadCount(); - count.store(0); + count.storeRelaxed(0); for (int i = 0; i <= runs; i++) { threadPool.start(new BlockingRunnable(sem)); } threadPool.clear(); sem.release(threadPool.maxThreadCount()); threadPool.waitForDone(); - QCOMPARE(count.load(), threadPool.maxThreadCount()); + QCOMPARE(count.loadRelaxed(), threadPool.maxThreadCount()); } void tst_QThreadPool::cancel() @@ -1008,7 +1008,7 @@ void tst_QThreadPool::cancel() // and cause an early return: const QSemaphoreReleaser semReleaser(sem, runs); - count.store(0); + count.storeRelaxed(0); QAtomicInt dtorCounter = 0; QAtomicInt runCounter = 0; for (int i = 0; i < runs; i++) { @@ -1025,12 +1025,12 @@ void tst_QThreadPool::cancel() } runnables[0]->dummy = 0; //valgrind will catch this if cancel() is crazy enough to delete currently running jobs runnables[runs-1]->dummy = 0; - QCOMPARE(dtorCounter.load(), runs - threadPool.maxThreadCount() - 1); + QCOMPARE(dtorCounter.loadRelaxed(), runs - threadPool.maxThreadCount() - 1); sem.release(threadPool.maxThreadCount()); threadPool.waitForDone(); - QCOMPARE(runCounter.load(), threadPool.maxThreadCount()); - QCOMPARE(count.load(), threadPool.maxThreadCount()); - QCOMPARE(dtorCounter.load(), runs - 2); + QCOMPARE(runCounter.loadRelaxed(), threadPool.maxThreadCount()); + QCOMPARE(count.loadRelaxed(), threadPool.maxThreadCount()); + QCOMPARE(dtorCounter.loadRelaxed(), runs - 2); delete runnables[0]; //if the pool deletes them then we'll get double-free crash delete runnables[runs-1]; } @@ -1080,7 +1080,7 @@ void tst_QThreadPool::tryTake() // and cause an early return: const QSemaphoreReleaser semReleaser(sem, Runs); - count.store(0); + count.storeRelaxed(0); QAtomicInt dtorCounter = 0; QAtomicInt runCounter = 0; for (int i = 0; i < Runs; i++) { @@ -1102,23 +1102,23 @@ void tst_QThreadPool::tryTake() } runnables[0]->dummy = 0; // valgrind will catch this if tryTake() is crazy enough to delete currently running jobs - QCOMPARE(dtorCounter.load(), int(Runs - MaxThreadCount)); + QCOMPARE(dtorCounter.loadRelaxed(), int(Runs - MaxThreadCount)); sem.release(MaxThreadCount); threadPool.waitForDone(); - QCOMPARE(runCounter.load(), int(MaxThreadCount)); - QCOMPARE(count.load(), int(MaxThreadCount)); - QCOMPARE(dtorCounter.load(), int(Runs - 1)); + QCOMPARE(runCounter.loadRelaxed(), int(MaxThreadCount)); + QCOMPARE(count.loadRelaxed(), int(MaxThreadCount)); + QCOMPARE(dtorCounter.loadRelaxed(), int(Runs - 1)); delete runnables[0]; // if the pool deletes them then we'll get double-free crash } void tst_QThreadPool::destroyingWaitsForTasksToFinish() { - QTime total, pass; + QElapsedTimer total, pass; total.start(); while (total.elapsed() < 10000) { int runs; - count.store(runs = 0); + count.storeRelaxed(runs = 0); { QThreadPool threadPool; pass.restart(); @@ -1127,9 +1127,9 @@ void tst_QThreadPool::destroyingWaitsForTasksToFinish() ++runs; } } - QCOMPARE(count.load(), runs); + QCOMPARE(count.loadRelaxed(), runs); - count.store(runs = 0); + count.storeRelaxed(runs = 0); { QThreadPool threadPool; pass.restart(); @@ -1139,7 +1139,7 @@ void tst_QThreadPool::destroyingWaitsForTasksToFinish() runs += 2; } } - QCOMPARE(count.load(), runs); + QCOMPARE(count.loadRelaxed(), runs); } } @@ -1204,7 +1204,7 @@ void tst_QThreadPool::stressTest() } }; - QTime total; + QElapsedTimer total; total.start(); while (total.elapsed() < 30000) { Task t; diff --git a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp index ef5d3452d5..3538d90803 100644 --- a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp +++ b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp @@ -359,7 +359,7 @@ void tst_QThreadStorage::leakInDestructor() QVERIFY(tls.hasLocalData()); } }; - int c = SPointer::count.load(); + int c = SPointer::count.loadRelaxed(); QThreadStorage<ThreadStorageLocalDataTester *> tls; @@ -383,7 +383,7 @@ void tst_QThreadStorage::leakInDestructor() QVERIFY(t3.wait()); //check all the constructed things have been destructed - QCOMPARE(int(SPointer::count.load()), c); + QCOMPARE(int(SPointer::count.loadRelaxed()), c); } class ThreadStorageResetLocalDataTester { @@ -411,7 +411,7 @@ void tst_QThreadStorage::resetInDestructor() QVERIFY(ThreadStorageResetLocalDataTesterTls()->hasLocalData()); } }; - int c = SPointer::count.load(); + int c = SPointer::count.loadRelaxed(); Thread t1; Thread t2; @@ -424,7 +424,7 @@ void tst_QThreadStorage::resetInDestructor() QVERIFY(t3.wait()); //check all the constructed things have been destructed - QCOMPARE(int(SPointer::count.load()), c); + QCOMPARE(int(SPointer::count.loadRelaxed()), c); } @@ -475,7 +475,7 @@ void tst_QThreadStorage::valueBased() QThreadStorage<QString> tlsString; QThreadStorage<int> tlsInt; - int c = SPointer::count.load(); + int c = SPointer::count.loadRelaxed(); Thread t1(tlsSPointer, tlsString, tlsInt); Thread t2(tlsSPointer, tlsString, tlsInt); @@ -495,7 +495,7 @@ void tst_QThreadStorage::valueBased() QVERIFY(t2.wait()); QVERIFY(t3.wait()); - QCOMPARE(c, int(SPointer::count.load())); + QCOMPARE(c, int(SPointer::count.loadRelaxed())); } diff --git a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp index 126cb6b180..5363231895 100644 --- a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp +++ b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp @@ -481,7 +481,7 @@ void tst_QWaitCondition::wakeOne() } mutex.unlock(); - QCOMPARE(count.load(), ThreadCount); + QCOMPARE(count.loadRelaxed(), ThreadCount); // wake up threads one at a time for (x = 0; x < ThreadCount; ++x) { @@ -502,10 +502,10 @@ void tst_QWaitCondition::wakeOne() } QCOMPARE(exited, 1); - QCOMPARE(count.load(), ThreadCount - (x + 1)); + QCOMPARE(count.loadRelaxed(), ThreadCount - (x + 1)); } - QCOMPARE(count.load(), 0); + QCOMPARE(count.loadRelaxed(), 0); // QReadWriteLock QReadWriteLock readWriteLock; @@ -530,7 +530,7 @@ void tst_QWaitCondition::wakeOne() } readWriteLock.unlock(); - QCOMPARE(count.load(), ThreadCount); + QCOMPARE(count.loadRelaxed(), ThreadCount); // wake up threads one at a time for (x = 0; x < ThreadCount; ++x) { @@ -551,10 +551,10 @@ void tst_QWaitCondition::wakeOne() } QCOMPARE(exited, 1); - QCOMPARE(count.load(), ThreadCount - (x + 1)); + QCOMPARE(count.loadRelaxed(), ThreadCount - (x + 1)); } - QCOMPARE(count.load(), 0); + QCOMPARE(count.loadRelaxed(), 0); } // wake up threads, two at a time @@ -585,7 +585,7 @@ void tst_QWaitCondition::wakeOne() } mutex.unlock(); - QCOMPARE(count.load(), ThreadCount); + QCOMPARE(count.loadRelaxed(), ThreadCount); // wake up threads one at a time for (x = 0; x < ThreadCount; x += 2) { @@ -608,10 +608,10 @@ void tst_QWaitCondition::wakeOne() } QCOMPARE(exited, 2); - QCOMPARE(count.load(), ThreadCount - (x + 2)); + QCOMPARE(count.loadRelaxed(), ThreadCount - (x + 2)); } - QCOMPARE(count.load(), 0); + QCOMPARE(count.loadRelaxed(), 0); // QReadWriteLock QReadWriteLock readWriteLock; @@ -636,7 +636,7 @@ void tst_QWaitCondition::wakeOne() } readWriteLock.unlock(); - QCOMPARE(count.load(), ThreadCount); + QCOMPARE(count.loadRelaxed(), ThreadCount); // wake up threads one at a time for (x = 0; x < ThreadCount; x += 2) { @@ -659,10 +659,10 @@ void tst_QWaitCondition::wakeOne() } QCOMPARE(exited, 2); - QCOMPARE(count.load(), ThreadCount - (x + 2)); + QCOMPARE(count.loadRelaxed(), ThreadCount - (x + 2)); } - QCOMPARE(count.load(), 0); + QCOMPARE(count.loadRelaxed(), 0); } } @@ -692,7 +692,7 @@ void tst_QWaitCondition::wakeAll() } mutex.unlock(); - QCOMPARE(count.load(), ThreadCount); + QCOMPARE(count.loadRelaxed(), ThreadCount); // wake up all threads at once mutex.lock(); @@ -707,7 +707,7 @@ void tst_QWaitCondition::wakeAll() } QCOMPARE(exited, ThreadCount); - QCOMPARE(count.load(), 0); + QCOMPARE(count.loadRelaxed(), 0); // QReadWriteLock QReadWriteLock readWriteLock; @@ -728,7 +728,7 @@ void tst_QWaitCondition::wakeAll() } readWriteLock.unlock(); - QCOMPARE(count.load(), ThreadCount); + QCOMPARE(count.loadRelaxed(), ThreadCount); // wake up all threads at once readWriteLock.lockForWrite(); @@ -743,7 +743,7 @@ void tst_QWaitCondition::wakeAll() } QCOMPARE(exited, ThreadCount); - QCOMPARE(count.load(), 0); + QCOMPARE(count.loadRelaxed(), 0); } } diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 0ef494b229..73384c35f4 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -91,7 +91,7 @@ private slots: void negativeYear() const; void printNegativeYear() const; void roundtripGermanLocale() const; -#if QT_CONFIG(textdate) +#if QT_CONFIG(textdate) && QT_DEPRECATED_SINCE(5, 10) void shortDayName() const; void standaloneShortDayName() const; void longDayName() const; @@ -1473,7 +1473,7 @@ void tst_QDate::roundtripGermanLocale() const theDateTime.fromString(theDateTime.toString(Qt::TextDate), Qt::TextDate); } -#if QT_CONFIG(textdate) +#if QT_CONFIG(textdate) && QT_DEPRECATED_SINCE(5, 10) QT_WARNING_PUSH // the methods tested here are all deprecated QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 6f0aebb071..ac1b903aa1 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -61,6 +61,10 @@ private slots: void timeSpec(); void toSecsSinceEpoch_data(); void toSecsSinceEpoch(); +#if QT_DEPRECATED_SINCE(5, 8) + void toTime_t_data(); + void toTime_t(); +#endif void daylightSavingsTimeChange_data(); void daylightSavingsTimeChange(); void springForward_data(); @@ -147,6 +151,7 @@ private slots: void systemTimeZoneChange() const; void invalid() const; + void range() const; void macTypes(); @@ -1689,6 +1694,34 @@ void tst_QDateTime::toSecsSinceEpoch() QDateTime datetime = dt( dateTimeStr ); qint64 asSecsSinceEpoch = datetime.toSecsSinceEpoch(); + QCOMPARE(asSecsSinceEpoch, datetime.toMSecsSinceEpoch() / 1000); + + QDateTime datetime2 = QDateTime::fromSecsSinceEpoch(asSecsSinceEpoch); + QCOMPARE(datetime, datetime2); +} + +#if QT_DEPRECATED_SINCE(5, 8) +void tst_QDateTime::toTime_t_data() +{ + QTest::addColumn<QString>("dateTimeStr"); + QTest::addColumn<bool>("res"); + + QTest::newRow( "data1" ) << str( 1800, 1, 1, 12, 0, 0 ) << false; + QTest::newRow( "data2" ) << str( 1969, 1, 1, 12, 0, 0 ) << false; + QTest::newRow( "data3" ) << str( 2002, 1, 1, 12, 0, 0 ) << true; + QTest::newRow( "data4" ) << str( 2002, 6, 1, 12, 0, 0 ) << true; + QTest::newRow( "data5" ) << QString("INVALID") << false; + QTest::newRow( "data6" ) << str( 2038, 1, 1, 12, 0, 0 ) << true; + QTest::newRow( "data7" ) << str( 2063, 4, 5, 12, 0, 0 ) << true; // the day of First Contact + QTest::newRow( "data8" ) << str( 2107, 1, 1, 12, 0, 0 ) + << bool( sizeof(uint) > 32 && sizeof(time_t) > 32 ); +} + +void tst_QDateTime::toTime_t() +{ + QFETCH( QString, dateTimeStr ); + QDateTime datetime = dt( dateTimeStr ); + uint asTime_t = datetime.toTime_t(); QFETCH( bool, res ); if (res) { @@ -1696,15 +1729,13 @@ void tst_QDateTime::toSecsSinceEpoch() } else { QVERIFY( asTime_t == (uint)-1 ); } - QCOMPARE(asSecsSinceEpoch, datetime.toMSecsSinceEpoch() / 1000); if ( asTime_t != (uint) -1 ) { QDateTime datetime2 = QDateTime::fromTime_t( asTime_t ); QCOMPARE(datetime, datetime2); } - QDateTime datetime2 = QDateTime::fromSecsSinceEpoch(asSecsSinceEpoch); - QCOMPARE(datetime, datetime2); } +#endif void tst_QDateTime::daylightSavingsTimeChange_data() { @@ -2489,17 +2520,20 @@ void tst_QDateTime::fromString_LOCALE_ILDATE() void tst_QDateTime::fromStringToStringLocale_data() { + QTest::addColumn<QLocale>("locale"); QTest::addColumn<QDateTime>("dateTime"); - QTest::newRow("data0") << QDateTime(QDate(1999, 1, 18), QTime(11, 49, 00)); + QTest::newRow("frFR") << QLocale(QLocale::French, QLocale::France) << QDateTime(QDate(1999, 1, 18), QTime(11, 49, 00)); + QTest::newRow("spCO") << QLocale(QLocale::Spanish, QLocale::Colombia) << QDateTime(QDate(1999, 1, 18), QTime(11, 49, 00)); } void tst_QDateTime::fromStringToStringLocale() { + QFETCH(QLocale, locale); QFETCH(QDateTime, dateTime); QLocale def; - QLocale::setDefault(QLocale(QLocale::French, QLocale::France)); + QLocale::setDefault(locale); #define ROUNDTRIP(format) \ QCOMPARE(QDateTime::fromString(dateTime.toString(format), format), dateTime) @@ -3472,6 +3506,15 @@ void tst_QDateTime::invalid() const QCOMPARE(tzDate.timeSpec(), Qt::TimeZone); } +void tst_QDateTime::range() const +{ + using Bounds = std::numeric_limits<qint64>; + QCOMPARE(QDateTime::fromMSecsSinceEpoch(Bounds::min() + 1, Qt::UTC).date().year(), + int(QDateTime::YearRange::First)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(Bounds::max() - 1, Qt::UTC).date().year(), + int(QDateTime::YearRange::Last)); +} + void tst_QDateTime::macTypes() { #ifndef Q_OS_MAC diff --git a/tests/auto/corelib/tools/collections/collections.pro b/tests/auto/corelib/tools/collections/collections.pro index 5c04515fa0..b074fa9338 100644 --- a/tests/auto/corelib/tools/collections/collections.pro +++ b/tests/auto/corelib/tools/collections/collections.pro @@ -5,3 +5,4 @@ QT = core testlib # This test does not work with strict iterators DEFINES -= QT_STRICT_ITERATORS +DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index 734b018b39..e79a4dba29 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -67,7 +67,6 @@ void foo() #include <algorithm> -#include "qalgorithms.h" #include "qbitarray.h" #include "qbytearray.h" #include "qcache.h" @@ -76,7 +75,7 @@ void foo() #include "qlist.h" #include "qmap.h" #include "qpair.h" -#include "qregexp.h" +#include "qregularexpression.h" #include "qset.h" #include "qstack.h" #include "qstring.h" @@ -105,7 +104,9 @@ private slots: void map(); void bitArray(); void cache(); +#if QT_CONFIG(regularexpression) void regexp(); +#endif void pair(); void sharableQList(); void sharableQLinkedList(); @@ -189,16 +190,6 @@ void tst_Collections::list() QVERIFY(list.size() == 6); QVERIFY(list.end() - list.begin() == list.size()); -#if !defined(Q_CC_MSVC) && !defined(Q_CC_SUN) - QVERIFY(std::binary_search(list.begin(), list.end(), 2) == true); - QVERIFY(std::binary_search(list.begin(), list.end(), 9) == false); -#endif - QVERIFY(qBinaryFind(list.begin(), list.end(), 2) == list.begin() + 1); - QVERIFY(qLowerBound(list.begin(), list.end(), 2) == list.begin() + 1); - QVERIFY(qUpperBound(list.begin(), list.end(), 2) == list.begin() + 2); - QVERIFY(qBinaryFind(list.begin(), list.end(), 9) == list.end()); - QVERIFY(qLowerBound(list.begin(), list.end(), 9) == list.end()); - QVERIFY(qUpperBound(list.begin(), list.end(), 9) == list.end()); { int sum = 0; QListIterator<int> i(list); @@ -994,16 +985,8 @@ void tst_Collections::vector() v.append(2); QVERIFY(*v.begin() == 2); v.prepend(1); - - v << 3 << 4 << 5 << 6; - QVERIFY(std::binary_search(v.begin(), v.end(), 2) == true); - QVERIFY(std::binary_search(v.begin(), v.end(), 9) == false); - QVERIFY(qBinaryFind(v.begin(), v.end(), 2) == v.begin() + 1); - QVERIFY(qLowerBound(v.begin(), v.end(), 2) == v.begin() + 1); - QVERIFY(qUpperBound(v.begin(), v.end(), 2) == v.begin() + 2); - QVERIFY(qBinaryFind(v.begin(), v.end(), 9) == v.end()); - QVERIFY(qLowerBound(v.begin(), v.end(), 9) == v.end()); - QVERIFY(qUpperBound(v.begin(), v.end(), 9) == v.end()); + QVERIFY(*v.begin() == 1); + QVERIFY(*(v.begin() + 1) == 2); v.clear(); v << 1 << 2 << 3; @@ -1368,7 +1351,7 @@ void tst_Collections::hash() { typedef QHash<QString, QString> Hash; Hash hash; - QString key; + QString key = QLatin1String(" "); for (int i = 0; i < 10; ++i) { key[0] = i + '0'; for (int j = 0; j < 10; ++j) { @@ -2011,13 +1994,17 @@ void tst_Collections::qstring() QString nonNull = ""; QVERIFY(null.left(10).isNull()); QVERIFY(null.mid(0).isNull()); + QVERIFY(null.isNull()); + QVERIFY(!nonNull.isNull()); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(null == QString::null); QVERIFY(QString::null == null); QVERIFY(nonNull != QString::null); QVERIFY(QString::null != nonNull); QVERIFY(null == nonNull); QVERIFY(QString::null == QString::null); +#endif QString fill = "123"; fill.fill('a'); @@ -2285,13 +2272,15 @@ void tst_Collections::cache() } +#if QT_CONFIG(regularexpression) void tst_Collections::regexp() { - QRegExp rx("^\\d\\d?$"); - QVERIFY(rx.indexIn("123") == -1); - QVERIFY(rx.indexIn("-6") == -1); - QVERIFY(rx.indexIn("6") == 0) ; + QRegularExpression rx("^\\d\\d?$"); + QVERIFY(!rx.match("123").hasMatch()); + QVERIFY(!rx.match("-6").hasMatch()); + QVERIFY(rx.match("6").hasMatch()) ; } +#endif void tst_Collections::pair() { diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp index 06db0e8546..18432e51a6 100644 --- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp +++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp @@ -48,6 +48,11 @@ class tst_QAlgorithms : public QObject { Q_OBJECT private slots: + void swap(); + void swap2(); + void convenienceAPI(); + +#if QT_DEPRECATED_SINCE(5, 2) void test_qLowerBound_data(); void test_qLowerBound(); void test_qUpperBound_data(); @@ -55,19 +60,23 @@ private slots: void test_qBinaryFind_data(); void test_qBinaryFind(); void qBinaryFindOneEntry(); - void swap(); - void swap2(); void sortEmptyList(); void sortedList(); void sortAPItest(); void stableSortTest(); void stableSortCorrectnessTest_data(); void stableSortCorrectnessTest(); - void convenienceAPI(); + void convenienceAPI_deprecated(); void qCountIterators() const; void qCountContainer() const; void binaryFindOnLargeContainer() const; +#if Q_TEST_PERFORMANCE + void performance(); +#endif + +#endif // QT_DEPRECATED_SINCE(5, 2) + void popCount08_data() { popCount_data_impl(sizeof(quint8 )); } void popCount16_data() { popCount_data_impl(sizeof(quint16)); } void popCount32_data() { popCount_data_impl(sizeof(quint32)); } @@ -96,9 +105,6 @@ private slots: void countLeading64() { countLeading_impl<quint64>(); } private: -#if Q_TEST_PERFORMANCE - void performance(); -#endif void popCount_data_impl(size_t sizeof_T_Int); template <typename T_Int> void popCount_impl(); @@ -112,6 +118,8 @@ private: void countLeading_impl(); }; +#if QT_DEPRECATED_SINCE(5, 2) + class TestInt { public: @@ -172,7 +180,7 @@ ResultSet testRun(ContainerType &container, Algorithm &algorithm, int millisecs) { TestInt::lessThanRefCount = 0; int count = 0; - QTime t; + QElapsedTimer t; t.start(); while(t.elapsed() < millisecs) { ++count; @@ -257,6 +265,8 @@ void testAlgorithm(Algorithm algorithm, QStringList &dataSetTypes) } #endif +#endif // QT_DEPRECATED_SINCE(5, 2) + void tst_QAlgorithms::swap() { { @@ -391,6 +401,17 @@ void tst_QAlgorithms::swap2() } } +void tst_QAlgorithms::convenienceAPI() +{ + // Compile-test for QAlgorithm convenience functions. + + QList<int *> pointerList; + qDeleteAll(pointerList); + qDeleteAll(pointerList.begin(), pointerList.end()); +} + +#if QT_DEPRECATED_SINCE(5, 2) + void tst_QAlgorithms::sortEmptyList() { // Only test if it crashes @@ -676,7 +697,7 @@ void tst_QAlgorithms::stableSortCorrectnessTest() QVERIFY(isSorted(sorted)); } -void tst_QAlgorithms::convenienceAPI() +void tst_QAlgorithms::convenienceAPI_deprecated() { // Compile-test for QAlgorithm convenience functions. QList<int> list, list2; @@ -716,10 +737,6 @@ void tst_QAlgorithms::convenienceAPI() qBinaryFind(list, 1); qBinaryFind(list.begin(), list.end(), 1); qBinaryFind(list.begin(), list.end(), 1, qLess<int>()); - - QList<int *> pointerList; - qDeleteAll(pointerList); - qDeleteAll(pointerList.begin(), pointerList.end()); } template <typename DataType> @@ -1041,6 +1058,8 @@ void tst_QAlgorithms::binaryFindOnLargeContainer() const QCOMPARE(foundIt.pos(), 1073987655); } +#endif // QT_DEPRECATED_SINCE(5, 2) + // alternative implementation of qPopulationCount for comparison: static Q_DECL_CONSTEXPR const uint bitsSetInNibble[] = { 0, 1, 1, 2, 1, 2, 2, 3, diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index 6ae2aab5b9..25e2f21d03 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -91,7 +91,7 @@ void tst_QArrayData::referenceCounting() // Reference counting initialized to 1 (owned) QArrayData array = { { Q_BASIC_ATOMIC_INITIALIZER(1) }, 0, 0, 0, 0 }; - QCOMPARE(array.ref.atomic.load(), 1); + QCOMPARE(array.ref.atomic.loadRelaxed(), 1); QVERIFY(!array.ref.isStatic()); #if !defined(QT_NO_UNSHARABLE_CONTAINERS) @@ -99,19 +99,19 @@ void tst_QArrayData::referenceCounting() #endif QVERIFY(array.ref.ref()); - QCOMPARE(array.ref.atomic.load(), 2); + QCOMPARE(array.ref.atomic.loadRelaxed(), 2); QVERIFY(array.ref.deref()); - QCOMPARE(array.ref.atomic.load(), 1); + QCOMPARE(array.ref.atomic.loadRelaxed(), 1); QVERIFY(array.ref.ref()); - QCOMPARE(array.ref.atomic.load(), 2); + QCOMPARE(array.ref.atomic.loadRelaxed(), 2); QVERIFY(array.ref.deref()); - QCOMPARE(array.ref.atomic.load(), 1); + QCOMPARE(array.ref.atomic.loadRelaxed(), 1); QVERIFY(!array.ref.deref()); - QCOMPARE(array.ref.atomic.load(), 0); + QCOMPARE(array.ref.atomic.loadRelaxed(), 0); // Now would be a good time to free/release allocated data } @@ -121,17 +121,17 @@ void tst_QArrayData::referenceCounting() // Reference counting initialized to 0 (non-sharable) QArrayData array = { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, 0 }; - QCOMPARE(array.ref.atomic.load(), 0); + QCOMPARE(array.ref.atomic.loadRelaxed(), 0); QVERIFY(!array.ref.isStatic()); QVERIFY(!array.ref.isSharable()); QVERIFY(!array.ref.ref()); // Reference counting fails, data should be copied - QCOMPARE(array.ref.atomic.load(), 0); + QCOMPARE(array.ref.atomic.loadRelaxed(), 0); QVERIFY(!array.ref.deref()); - QCOMPARE(array.ref.atomic.load(), 0); + QCOMPARE(array.ref.atomic.loadRelaxed(), 0); // Free/release data } @@ -141,7 +141,7 @@ void tst_QArrayData::referenceCounting() // Reference counting initialized to -1 (static read-only data) QArrayData array = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 }; - QCOMPARE(array.ref.atomic.load(), -1); + QCOMPARE(array.ref.atomic.loadRelaxed(), -1); QVERIFY(array.ref.isStatic()); #if !defined(QT_NO_UNSHARABLE_CONTAINERS) @@ -149,10 +149,10 @@ void tst_QArrayData::referenceCounting() #endif QVERIFY(array.ref.ref()); - QCOMPARE(array.ref.atomic.load(), -1); + QCOMPARE(array.ref.atomic.loadRelaxed(), -1); QVERIFY(array.ref.deref()); - QCOMPARE(array.ref.atomic.load(), -1); + QCOMPARE(array.ref.atomic.loadRelaxed(), -1); } } @@ -168,8 +168,8 @@ void tst_QArrayData::sharedNullEmpty() QVERIFY(empty->ref.isStatic()); QVERIFY(empty->ref.isShared()); - QCOMPARE(null->ref.atomic.load(), -1); - QCOMPARE(empty->ref.atomic.load(), -1); + QCOMPARE(null->ref.atomic.loadRelaxed(), -1); + QCOMPARE(empty->ref.atomic.loadRelaxed(), -1); #if !defined(QT_NO_UNSHARABLE_CONTAINERS) QVERIFY(null->ref.isSharable()); @@ -179,14 +179,14 @@ void tst_QArrayData::sharedNullEmpty() QVERIFY(null->ref.ref()); QVERIFY(empty->ref.ref()); - QCOMPARE(null->ref.atomic.load(), -1); - QCOMPARE(empty->ref.atomic.load(), -1); + QCOMPARE(null->ref.atomic.loadRelaxed(), -1); + QCOMPARE(empty->ref.atomic.loadRelaxed(), -1); QVERIFY(null->ref.deref()); QVERIFY(empty->ref.deref()); - QCOMPARE(null->ref.atomic.load(), -1); - QCOMPARE(empty->ref.atomic.load(), -1); + QCOMPARE(null->ref.atomic.loadRelaxed(), -1); + QCOMPARE(empty->ref.atomic.loadRelaxed(), -1); QVERIFY(null != empty); @@ -1625,6 +1625,18 @@ void tst_QArrayData::literals() QCOMPARE(const_(v)[i], char('A' + i)); QCOMPARE(const_(v)[10], char('\0')); } + + { + struct LiteralType { + int value; + Q_DECL_CONSTEXPR LiteralType(int v = 0) : value(v) {} + }; + + QArrayDataPointer<LiteralType> d = Q_ARRAY_LITERAL(LiteralType, LiteralType(0), LiteralType(1), LiteralType(2)); + QCOMPARE(d->size, 3); + for (int i = 0; i < 3; ++i) + QCOMPARE(d->data()[i].value, i); + } } // Variadic Q_ARRAY_LITERAL need to be available in the current configuration. diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp index 987b3058e3..90dfcaef25 100644 --- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp +++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp @@ -1935,7 +1935,7 @@ void tst_QByteArray::repeatedSignature() const { /* repated() should be a const member. */ const QByteArray string; - string.repeated(3); + (void)string.repeated(3); } void tst_QByteArray::repeated() const @@ -2127,7 +2127,7 @@ void tst_QByteArray::movablity() { QFETCH(QByteArray, array); - QVERIFY(!QTypeInfo<QByteArray>::isStatic); + Q_STATIC_ASSERT(!QTypeInfo<QByteArray>::isStatic); const int size = array.size(); const bool isEmpty = array.isEmpty(); @@ -2139,7 +2139,7 @@ void tst_QByteArray::movablity() // we need only memory space not the instance memSpace.~QByteArray(); // move array -> memSpace - memcpy(&memSpace, &array, sizeof(QByteArray)); + memcpy((void *)&memSpace, (const void *)&array, sizeof(QByteArray)); // reconstruct empty QByteArray new (&array) QByteArray; @@ -2149,8 +2149,8 @@ void tst_QByteArray::movablity() QCOMPARE(memSpace.capacity(), capacity); // try to not crash - memSpace.toLower(); - memSpace.toUpper(); + (void)memSpace.toLower(); + (void)memSpace.toUpper(); memSpace.prepend('a'); memSpace.append("b", 1); memSpace.squeeze(); @@ -2166,7 +2166,7 @@ void tst_QByteArray::movablity() // move back memSpace -> array array.~QByteArray(); - memcpy(&array, &memSpace, sizeof(QByteArray)); + memcpy((void *)&array, (const void *)&memSpace, sizeof(QByteArray)); // reconstruct empty QByteArray new (&memSpace) QByteArray; diff --git a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp index b9bcecd607..513c811788 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp @@ -74,10 +74,12 @@ int main(int argc, char *argv[]) hiddenOption.setDescription(QStringLiteral("THIS SHOULD NEVER APPEAR")); hiddenOption.setFlags(QCommandLineOption::HiddenFromHelp); parser.addOption(hiddenOption); +#if QT_DEPRECATED_SINCE(5, 8) QCommandLineOption hiddenOption2(QStringList() << QStringLiteral("hidden2")); hiddenOption2.setDescription(QStringLiteral("NEITHER SHOULD THIS")); hiddenOption2.setHidden(true); parser.addOption(hiddenOption2); +#endif // This program supports different options depending on the "command" (first argument). // Call parse() to find out the positional arguments. diff --git a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp index 9b45e17a28..f305d63d46 100644 --- a/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp +++ b/tests/auto/corelib/tools/qcontiguouscache/tst_qcontiguouscache.cpp @@ -244,7 +244,7 @@ public: return *this; } - int refCount() const { return d->ref.load(); } + int refCount() const { return d->ref.loadRelaxed(); } private: RefCountingClassData *d; }; diff --git a/tests/auto/corelib/tools/qhash/qhash.pro b/tests/auto/corelib/tools/qhash/qhash.pro index 79ffd4e9d1..e96c0d1bf1 100644 --- a/tests/auto/corelib/tools/qhash/qhash.pro +++ b/tests/auto/corelib/tools/qhash/qhash.pro @@ -2,3 +2,5 @@ CONFIG += testcase TARGET = tst_qhash QT = core testlib SOURCES = $$PWD/tst_qhash.cpp + +DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index d70d488e96..f0aaad98bd 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -273,7 +273,7 @@ void tst_QHash::insert1() { typedef QHash<QString, QString> Hash; Hash hash; - QString key; + QString key = QLatin1String(" "); for (int i = 0; i < 10; ++i) { key[0] = i + '0'; for (int j = 0; j < 10; ++j) { diff --git a/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp b/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp index dcfb0aa042..cf46159251 100644 --- a/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp +++ b/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp @@ -45,6 +45,7 @@ class tst_QLatin1String : public QObject private Q_SLOTS: void at(); + void arg() const; void midLeftRight(); void nullString(); void emptyString(); @@ -63,6 +64,47 @@ void tst_QLatin1String::at() QCOMPARE(l1[l1.size() - 1], QLatin1Char('d')); } +void tst_QLatin1String::arg() const +{ +#define CHECK1(pattern, arg1, expected) \ + do { \ + auto p = QLatin1String(pattern); \ + QCOMPARE(p.arg(QLatin1String(arg1)), expected); \ + QCOMPARE(p.arg(QStringViewLiteral(arg1)), expected); \ + QCOMPARE(p.arg(QStringLiteral(arg1)), expected); \ + QCOMPARE(p.arg(QString(QLatin1String(arg1))), expected); \ + } while (false) \ + /*end*/ +#define CHECK2(pattern, arg1, arg2, expected) \ + do { \ + auto p = QLatin1String(pattern); \ + QCOMPARE(p.arg(QLatin1String(arg1), QLatin1String(arg2)), expected); \ + QCOMPARE(p.arg(QStringViewLiteral(arg1), QLatin1String(arg2)), expected); \ + QCOMPARE(p.arg(QLatin1String(arg1), QStringViewLiteral(arg2)), expected); \ + QCOMPARE(p.arg(QStringViewLiteral(arg1), QStringViewLiteral(arg2)), expected); \ + } while (false) \ + /*end*/ + + CHECK1("", "World", ""); + CHECK1("%1", "World", "World"); + CHECK1("!%1?", "World", "!World?"); + CHECK1("%1%1", "World", "WorldWorld"); + CHECK1("%1%2", "World", "World%2"); + CHECK1("%2%1", "World", "%2World"); + + CHECK2("", "Hello", "World", ""); + CHECK2("%1", "Hello", "World", "Hello"); + CHECK2("!%1, %2?", "Hello", "World", "!Hello, World?"); + CHECK2("%1%1", "Hello", "World", "HelloHello"); + CHECK2("%1%2", "Hello", "World", "HelloWorld"); + CHECK2("%2%1", "Hello", "World", "WorldHello"); + +#undef CHECK2 +#undef CHECK1 + + QCOMPARE(QLatin1String(" %2 %2 %1 %3 ").arg(QLatin1Char('c'), QChar::CarriageReturn, u'C'), " \r \r c C "); +} + void tst_QLatin1String::midLeftRight() { const QLatin1String l1("Hello World"); diff --git a/tests/auto/corelib/tools/qline/tst_qline.cpp b/tests/auto/corelib/tools/qline/tst_qline.cpp index 915a24a1f6..0418daf640 100644 --- a/tests/auto/corelib/tools/qline/tst_qline.cpp +++ b/tests/auto/corelib/tools/qline/tst_qline.cpp @@ -53,8 +53,10 @@ private slots: void testNormalVector(); void testNormalVector_data(); +#if QT_DEPRECATED_SINCE(5, 14) void testAngle(); void testAngle_data(); +#endif void testAngle2(); void testAngle2_data(); @@ -378,6 +380,7 @@ void tst_QLine::testNormalVector() QCOMPARE(n.dy(), qreal(nvy)); } +#if QT_DEPRECATED_SINCE(5, 14) void tst_QLine::testAngle_data() { QTest::addColumn<double>("xa1"); @@ -426,6 +429,7 @@ void tst_QLine::testAngle() double resultAngle = a.angle(b); QCOMPARE(qRound(resultAngle), qRound(angle)); } +#endif void tst_QLine::testAngle2_data() { diff --git a/tests/auto/corelib/tools/qmap/qmap.pro b/tests/auto/corelib/tools/qmap/qmap.pro index 27820a76c8..2cc772720d 100644 --- a/tests/auto/corelib/tools/qmap/qmap.pro +++ b/tests/auto/corelib/tools/qmap/qmap.pro @@ -2,3 +2,5 @@ CONFIG += testcase TARGET = tst_qmap QT = core testlib SOURCES = $$PWD/tst_qmap.cpp + +DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp index a98d37d733..a8111af6c1 100644 --- a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp +++ b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp @@ -834,6 +834,13 @@ void tst_QRegExp::testEscapingWildcard_data(){ QTest::newRow("a true '\\' in input") << "\\Qt;" << "\\Qt;" << true; QTest::newRow("two true '\\' in input") << "\\\\Qt;" << "\\\\Qt;" << true; QTest::newRow("a '\\' at the end") << "\\\\Qt;\\" << "\\\\Qt;\\" << true; + + QTest::newRow("[]\\] matches ]") << "[]\\]" << "]" << true; + QTest::newRow("[]\\] matches \\") << "[]\\]" << "\\" << true; + QTest::newRow("[]\\] does not match [") << "[]\\]" << "[" << false; + QTest::newRow("[]\\]a matches ]a") << "[]\\]a" << "]a" << true; + QTest::newRow("[]\\]a matches \\a") << "[]\\]a" << "\\a" << true; + QTest::newRow("[]\\]a does not match [a") << "[]\\]a" << "[a" << false; } void tst_QRegExp::testEscapingWildcard(){ diff --git a/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp b/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp index b943b04e23..ea94cc2999 100644 --- a/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp +++ b/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp @@ -327,7 +327,7 @@ struct RefCounted ~RefCounted() { - QVERIFY( ref.load() == 0 ); + QVERIFY( ref.loadRelaxed() == 0 ); instanceCount.deref(); } @@ -369,13 +369,13 @@ void scopedPointerComparisonTest(const A1 &a1, const A2 &a2, const B &b) void tst_QScopedPointer::comparison() { - QCOMPARE( RefCounted::instanceCount.load(), 0 ); + QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 0 ); { RefCounted *a = new RefCounted; RefCounted *b = new RefCounted; - QCOMPARE( RefCounted::instanceCount.load(), 2 ); + QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 2 ); QScopedPointer<RefCounted> pa1(a); QScopedPointer<RefCounted> pa2(a); @@ -387,16 +387,16 @@ void tst_QScopedPointer::comparison() pa2.take(); - QCOMPARE( RefCounted::instanceCount.load(), 2 ); + QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 2 ); } - QCOMPARE( RefCounted::instanceCount.load(), 0 ); + QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 0 ); { RefCounted *a = new RefCounted[42]; RefCounted *b = new RefCounted[43]; - QCOMPARE( RefCounted::instanceCount.load(), 85 ); + QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 85 ); QScopedArrayPointer<RefCounted> pa1(a); QScopedArrayPointer<RefCounted> pa2(a); @@ -406,10 +406,10 @@ void tst_QScopedPointer::comparison() pa2.take(); - QCOMPARE( RefCounted::instanceCount.load(), 85 ); + QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 85 ); } - QCOMPARE( RefCounted::instanceCount.load(), 0 ); + QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 0 ); { // QScopedSharedPointer is an internal helper class -- it is unsupported! @@ -417,42 +417,42 @@ void tst_QScopedPointer::comparison() RefCounted *a = new RefCounted; RefCounted *b = new RefCounted; - QCOMPARE( RefCounted::instanceCount.load(), 2 ); + QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 2 ); QSharedDataPointer<RefCounted> pa1(a); QSharedDataPointer<RefCounted> pa2(a); QSharedDataPointer<RefCounted> pb(b); - QCOMPARE( a->ref.load(), 2 ); - QCOMPARE( b->ref.load(), 1 ); - QCOMPARE( RefCounted::instanceCount.load(), 2 ); + QCOMPARE( a->ref.loadRelaxed(), 2 ); + QCOMPARE( b->ref.loadRelaxed(), 1 ); + QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 2 ); scopedPointerComparisonTest(pa1, pa2, pb); - QCOMPARE( RefCounted::instanceCount.load(), 2 ); + QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 2 ); } - QCOMPARE( RefCounted::instanceCount.load(), 0 ); + QCOMPARE( RefCounted::instanceCount.loadRelaxed(), 0 ); } void tst_QScopedPointer::array() { - int instCount = RefCounted::instanceCount.load(); + int instCount = RefCounted::instanceCount.loadRelaxed(); { QScopedArrayPointer<RefCounted> array; array.reset(new RefCounted[42]); - QCOMPARE(instCount + 42, RefCounted::instanceCount.load()); + QCOMPARE(instCount + 42, RefCounted::instanceCount.loadRelaxed()); } - QCOMPARE(instCount, RefCounted::instanceCount.load()); + QCOMPARE(instCount, RefCounted::instanceCount.loadRelaxed()); { QScopedArrayPointer<RefCounted> array(new RefCounted[42]); - QCOMPARE(instCount + 42, RefCounted::instanceCount.load()); + QCOMPARE(instCount + 42, RefCounted::instanceCount.loadRelaxed()); array.reset(new RefCounted[28]); - QCOMPARE(instCount + 28, RefCounted::instanceCount.load()); + QCOMPARE(instCount + 28, RefCounted::instanceCount.loadRelaxed()); array.reset(0); - QCOMPARE(instCount, RefCounted::instanceCount.load()); + QCOMPARE(instCount, RefCounted::instanceCount.loadRelaxed()); } - QCOMPARE(instCount, RefCounted::instanceCount.load()); + QCOMPARE(instCount, RefCounted::instanceCount.loadRelaxed()); } diff --git a/tests/auto/corelib/tools/qset/qset.pro b/tests/auto/corelib/tools/qset/qset.pro index 10ae3307d1..d0c6337147 100644 --- a/tests/auto/corelib/tools/qset/qset.pro +++ b/tests/auto/corelib/tools/qset/qset.pro @@ -2,3 +2,5 @@ CONFIG += testcase TARGET = tst_qset QT = core testlib SOURCES = tst_qset.cpp + +DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 42792b5310..f3c647515a 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -40,6 +40,7 @@ #include "nontracked.h" #include "wrapper.h" +#include <memory> #include <stdlib.h> #include <time.h> @@ -74,8 +75,10 @@ private slots: void functionCallDownCast(); void upCast(); void qobjectWeakManagement(); +#if QT_DEPRECATED_SINCE(5, 0) void noSharedPointerFromWeakQObject(); void sharedPointerFromQObjectWithWeak(); +#endif void weakQObjectFromSharedPointer(); void objectCast(); void objectCastStdSharedPtr(); @@ -231,6 +234,12 @@ struct NoDefaultConstructorRRef1 NoDefaultConstructorRRef1(int &&i) : i(i) {} }; +struct NoDefaultConstructorRRef2 +{ + std::unique_ptr<int> i; + NoDefaultConstructorRRef2(std::unique_ptr<int> &&i) : i(std::move(i)) {} +}; + void tst_QSharedPointer::basics_data() { QTest::addColumn<bool>("isNull"); @@ -287,8 +296,8 @@ void tst_QSharedPointer::basics() QVERIFY(! (ptr == otherData)); QVERIFY(! (otherData == ptr)); } - QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.load() == 1); - QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.load() == 1); + QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.loadRelaxed() == 1); + QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.loadRelaxed() == 1); { // create another object: @@ -300,8 +309,8 @@ void tst_QSharedPointer::basics() // otherData is deleted here } - QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.load() == 1); - QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.load() == 1); + QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.loadRelaxed() == 1); + QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.loadRelaxed() == 1); { // create a copy: @@ -318,8 +327,8 @@ void tst_QSharedPointer::basics() QCOMPARE(copy.get(), aData); QVERIFY(copy == aData); } - QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.load() == 1); - QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.load() == 1); + QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.loadRelaxed() == 1); + QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.loadRelaxed() == 1); { // create a weak reference: @@ -351,8 +360,8 @@ void tst_QSharedPointer::basics() QCOMPARE(strong.data(), aData); QCOMPARE(strong.get(), aData); } - QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.load() == 1); - QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.load() == 1); + QVERIFY(!refCountData(ptr) || refCountData(ptr)->weakref.loadRelaxed() == 1); + QVERIFY(!refCountData(ptr) || refCountData(ptr)->strongref.loadRelaxed() == 1); // aData is deleted here } @@ -836,15 +845,15 @@ void tst_QSharedPointer::upCast() QVERIFY(baseptr == derivedptr); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); { QWeakPointer<DerivedData> derivedptr = qWeakPointerCast<DerivedData>(baseptr); QVERIFY(baseptr == derivedptr); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); { QWeakPointer<Data> weakptr = baseptr; @@ -852,16 +861,16 @@ void tst_QSharedPointer::upCast() QVERIFY(baseptr == derivedptr); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); { QSharedPointer<DerivedData> derivedptr = baseptr.staticCast<DerivedData>(); QVERIFY(baseptr == derivedptr); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); } class OtherObject: public QObject @@ -875,6 +884,78 @@ void tst_QSharedPointer::qobjectWeakManagement() QWeakPointer<QObject> weak; weak = QWeakPointer<QObject>(); QVERIFY(weak.isNull()); + QVERIFY(weak.toStrongRef().isNull()); + } + + { + QObject *obj = new QObject; + QSharedPointer<QObject> shared(obj); + QWeakPointer<QObject> weak(shared); + QVERIFY(!weak.isNull()); + QVERIFY(weak.toStrongRef() == obj); + + // now delete + shared.reset(); + QVERIFY(weak.isNull()); + } + safetyCheck(); + + { + // same, bit with operator= + QObject *obj = new QObject; + QSharedPointer<QObject> shared(obj); + QWeakPointer<QObject> weak; + weak = shared; + QVERIFY(!weak.isNull()); + QVERIFY(weak.toStrongRef() == obj); + + // now delete + shared.reset(); + QVERIFY(weak.isNull()); + } + safetyCheck(); + + { + // with two QWeakPointers + QObject *obj = new QObject; + QSharedPointer<QObject> shared(obj); + QWeakPointer<QObject> weak(shared); + + { + QWeakPointer<QObject> weak2(shared); + QVERIFY(!weak2.isNull()); + QVERIFY(weak == weak2); + } + QVERIFY(!weak.isNull()); + + shared.reset(); + QVERIFY(weak.isNull()); + } + safetyCheck(); + + { + // same, but delete the pointer while two QWeakPointers exist + QObject *obj = new QObject; + QSharedPointer<QObject> shared(obj); + QWeakPointer<QObject> weak(shared); + + { + QWeakPointer<QObject> weak2(shared); + QVERIFY(!weak2.isNull()); + + shared.reset(); + QVERIFY(weak.isNull()); + QVERIFY(weak2.isNull()); + } + QVERIFY(weak.isNull()); + } + safetyCheck(); + +#if QT_DEPRECATED_SINCE(5, 0) + { + QWeakPointer<QObject> weak; + weak = QWeakPointer<QObject>(); + QVERIFY(weak.isNull()); QVERIFY(!weak.data()); } @@ -965,8 +1046,10 @@ void tst_QSharedPointer::qobjectWeakManagement() QVERIFY(weak.isNull()); } safetyCheck(); +#endif } +#if QT_DEPRECATED_SINCE(5, 0) void tst_QSharedPointer::noSharedPointerFromWeakQObject() { // you're not allowed to create a QSharedPointer from an unmanaged QObject @@ -1000,18 +1083,32 @@ void tst_QSharedPointer::sharedPointerFromQObjectWithWeak() } QVERIFY(weak.isNull()); } +#endif void tst_QSharedPointer::weakQObjectFromSharedPointer() { - // this is the inverse of the above: you're allowed to create a QWeakPointer - // from a managed QObject - QSharedPointer<QObject> shared(new QObject); - QWeakPointer<QObject> weak = shared.data(); - QVERIFY(!weak.isNull()); +#if QT_DEPRECATED_SINCE(5, 0) + { + // this is the inverse of the above: you're allowed to create a QWeakPointer + // from a managed QObject + QSharedPointer<QObject> shared(new QObject); + QWeakPointer<QObject> weak = shared.data(); + QVERIFY(!weak.isNull()); - // delete: - shared.clear(); - QVERIFY(weak.isNull()); + // delete: + shared.clear(); + QVERIFY(weak.isNull()); + } +#endif + { + QSharedPointer<QObject> shared(new QObject); + QWeakPointer<QObject> weak = shared; + QVERIFY(!weak.isNull()); + + // delete: + shared.clear(); + QVERIFY(weak.isNull()); + } } void tst_QSharedPointer::objectCast() @@ -1290,8 +1387,8 @@ void tst_QSharedPointer::dynamicCast() QCOMPARE(derivedptr.data(), aData); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); { QWeakPointer<Data> weakptr = baseptr; @@ -1300,8 +1397,8 @@ void tst_QSharedPointer::dynamicCast() QCOMPARE(derivedptr.data(), aData); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); { QSharedPointer<DerivedData> derivedptr = baseptr.dynamicCast<DerivedData>(); @@ -1309,8 +1406,8 @@ void tst_QSharedPointer::dynamicCast() QCOMPARE(derivedptr.data(), aData); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); } void tst_QSharedPointer::dynamicCastDifferentPointers() @@ -1325,8 +1422,8 @@ void tst_QSharedPointer::dynamicCastDifferentPointers() QCOMPARE(derivedptr.data(), aData); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); { QWeakPointer<Data> weakptr = baseptr; @@ -1335,8 +1432,8 @@ void tst_QSharedPointer::dynamicCastDifferentPointers() QCOMPARE(derivedptr.data(), aData); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); { QSharedPointer<DiffPtrDerivedData> derivedptr = baseptr.dynamicCast<DiffPtrDerivedData>(); @@ -1344,8 +1441,8 @@ void tst_QSharedPointer::dynamicCastDifferentPointers() QCOMPARE(derivedptr.data(), aData); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); { Stuffing *nakedptr = dynamic_cast<Stuffing *>(baseptr.data()); @@ -1370,8 +1467,8 @@ void tst_QSharedPointer::dynamicCastVirtualBase() QCOMPARE(derivedptr.data(), aData); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); { QWeakPointer<Data> weakptr = baseptr; @@ -1380,8 +1477,8 @@ void tst_QSharedPointer::dynamicCastVirtualBase() QCOMPARE(derivedptr.data(), aData); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); { QSharedPointer<VirtualDerived> derivedptr = baseptr.dynamicCast<VirtualDerived>(); @@ -1389,8 +1486,8 @@ void tst_QSharedPointer::dynamicCastVirtualBase() QCOMPARE(derivedptr.data(), aData); QCOMPARE(static_cast<Data *>(derivedptr.data()), baseptr.data()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); } void tst_QSharedPointer::dynamicCastFailure() @@ -1402,15 +1499,15 @@ void tst_QSharedPointer::dynamicCastFailure() QSharedPointer<DerivedData> derivedptr = qSharedPointerDynamicCast<DerivedData>(baseptr); QVERIFY(derivedptr.isNull()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); { QSharedPointer<DerivedData> derivedptr = baseptr.dynamicCast<DerivedData>(); QVERIFY(derivedptr.isNull()); } - QCOMPARE(int(refCountData(baseptr)->weakref.load()), 1); - QCOMPARE(int(refCountData(baseptr)->strongref.load()), 1); + QCOMPARE(int(refCountData(baseptr)->weakref.loadRelaxed()), 1); + QCOMPARE(int(refCountData(baseptr)->strongref.loadRelaxed()), 1); } void tst_QSharedPointer::dynamicCastFailureNoLeak() @@ -1779,8 +1876,8 @@ void tst_QSharedPointer::creating() QCOMPARE(Data::destructorCounter, 1); // valgrind will complain here if something happened to the pointer - QVERIFY(d->weakref.load() == 1); - QVERIFY(d->strongref.load() == 0); + QVERIFY(d->weakref.loadRelaxed() == 1); + QVERIFY(d->strongref.loadRelaxed() == 0); } safetyCheck(); @@ -1865,15 +1962,20 @@ void tst_QSharedPointer::creatingVariadic() QCOMPARE(&ptr->i, &i); } { - NoDefaultConstructorRRef1(1); // control check - QSharedPointer<NoDefaultConstructorRRef1> ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(1); - QCOMPARE(ptr->i, 1); - NoDefaultConstructorRRef1(std::move(i)); // control check - ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(std::move(i)); + QSharedPointer<NoDefaultConstructorRRef1> ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(std::move(i)); QCOMPARE(ptr->i, i); } { + NoDefaultConstructorRRef2(std::unique_ptr<int>(new int(1))); // control check + QSharedPointer<NoDefaultConstructorRRef2> ptr = QSharedPointer<NoDefaultConstructorRRef2>::create(std::unique_ptr<int>(new int(1))); + QCOMPARE(*ptr->i, 1); + + std::unique_ptr<int> p(new int(i)); + ptr = QSharedPointer<NoDefaultConstructorRRef2>::create(std::move(p)); + QCOMPARE(*ptr->i, i); + } + { QString text("Hello, World"); NoDefaultConstructorRef2(text, 1); // control check QSharedPointer<NoDefaultConstructorRef2> ptr = QSharedPointer<NoDefaultConstructorRef2>::create(text, 1); @@ -2010,7 +2112,7 @@ void tst_QSharedPointer::threadStressTest() for (int r = 0; r < 5; ++r) { QVector<QThread*> allThreads(6 * qMax(strongThreadCount, weakThreadCount) + 3, 0); QSharedPointer<ThreadData> base = QSharedPointer<ThreadData>(new ThreadData(&counter)); - counter.store(0); + counter.storeRelaxed(0); // set the pointers for (int i = 0; i < strongThreadCount; ++i) { @@ -2044,8 +2146,8 @@ void tst_QSharedPointer::threadStressTest() // verify that the count is the right range int minValue = strongThreadCount; int maxValue = strongThreadCount + weakThreadCount; - QVERIFY(counter.load() >= minValue); - QVERIFY(counter.load() <= maxValue); + QVERIFY(counter.loadRelaxed() >= minValue); + QVERIFY(counter.loadRelaxed() <= maxValue); } } @@ -2364,6 +2466,7 @@ void tst_QSharedPointer::qvariantCast() // Intentionally does not compile. // QSharedPointer<int> sop = qSharedPointerFromVariant<int>(v); +#if QT_DEPRECATED_SINCE(5, 0) v = QVariant::fromValue(sp.toWeakRef()); { @@ -2407,6 +2510,7 @@ void tst_QSharedPointer::qvariantCast() QWeakPointer<QThread> other = qWeakPointerFromVariant<QThread>(v); QVERIFY(!other); } +#endif } class SomeClass : public QEnableSharedFromThis<SomeClass> diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 79f5a8c46d..e4aa00f500 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -521,7 +521,9 @@ private slots: void stringRef_local8Bit_data(); void stringRef_local8Bit(); void fromLatin1(); +#if QT_DEPRECATED_SINCE(5, 0) void fromAscii(); +#endif void fromUcs4(); void toUcs4(); void arg(); @@ -4284,9 +4286,9 @@ void tst_QString::fromLocal8Bit_data() //QTest::newRow("null5") << QByteArray() << 5 << QString(); //QTest::newRow("empty-1") << QByteArray("\0abcd", 5) << -1 << QString(); //QTest::newRow("empty0") << QByteArray() << 0 << QString(); - //QTest::newRow("empty5") << QByteArray("\0abcd", 5) << 5 << QString::fromAscii("\0abcd", 5); - //QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << -1 << QString::fromAscii("ab"); - //QTest::newRow("other5") << QByteArray("ab\0cd", 5) << 5 << QString::fromAscii("ab\0cd", 5); + //QTest::newRow("empty5") << QByteArray("\0abcd", 5) << 5 << QString::fromLatin1("\0abcd", 5); + //QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << -1 << QString::fromLatin1("ab"); + //QTest::newRow("other5") << QByteArray("ab\0cd", 5) << 5 << QString::fromLatin1("ab\0cd", 5); } void tst_QString::fromLocal8Bit() @@ -4590,6 +4592,7 @@ void tst_QString::fromLatin1() QVERIFY(a.size() == 5); } +#if QT_DEPRECATED_SINCE(5, 0) void tst_QString::fromAscii() { QString a; @@ -4610,6 +4613,7 @@ void tst_QString::fromAscii() a = QString::fromAscii("\0abcd", 5); QVERIFY(a.size() == 5); } +#endif void tst_QString::fromUcs4() { diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp index a74ae2eb71..24382a2b61 100644 --- a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com> +** Copyright (C) 2019 Mail.ru Group. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -526,6 +527,47 @@ private Q_SLOTS: void contains_QStringView_QStringRef() { contains_impl<QStringView, QStringRef>(); } void contains_QStringView_QStringView_data() { contains_data(); } void contains_QStringView_QStringView() { contains_impl<QStringView, QStringView>(); } + +private: + template <typename Haystack, typename Needle> void lastIndexOf_impl() const; + void lastIndexOf_data(); + +private Q_SLOTS: + void lastIndexOf_QString_QString_data() { lastIndexOf_data(); } + void lastIndexOf_QString_QString() { lastIndexOf_impl<QString, QString>(); } + void lastIndexOf_QString_QLatin1String_data() { lastIndexOf_data(); } + void lastIndexOf_QString_QLatin1String() { lastIndexOf_impl<QString, QLatin1String>(); } + void lastIndexOf_QString_QStringRef_data() { lastIndexOf_data(); } + void lastIndexOf_QString_QStringRef() { lastIndexOf_impl<QString, QStringRef>(); } + void lastIndexOf_QString_QStringView_data() { lastIndexOf_data(); } + void lastIndexOf_QString_QStringView() { lastIndexOf_impl<QString, QStringView>(); } + + void lastIndexOf_QLatin1String_QString_data() { lastIndexOf_data(); } + void lastIndexOf_QLatin1String_QString() { lastIndexOf_impl<QLatin1String, QString>(); } + void lastIndexOf_QLatin1String_QLatin1String_data() { lastIndexOf_data(); } + void lastIndexOf_QLatin1String_QLatin1String() { lastIndexOf_impl<QLatin1String, QLatin1String>(); } + void lastIndexOf_QLatin1String_QStringRef_data() { lastIndexOf_data(); } + void lastIndexOf_QLatin1String_QStringRef() { lastIndexOf_impl<QLatin1String, QStringRef>(); } + void lastIndexOf_QLatin1String_QStringView_data() { lastIndexOf_data(); } + void lastIndexOf_QLatin1String_QStringView() { lastIndexOf_impl<QLatin1String, QStringView>(); } + + void lastIndexOf_QStringRef_QString_data() { lastIndexOf_data(); } + void lastIndexOf_QStringRef_QString() { lastIndexOf_impl<QStringRef, QString>(); } + void lastIndexOf_QStringRef_QLatin1String_data() { lastIndexOf_data(); } + void lastIndexOf_QStringRef_QLatin1String() { lastIndexOf_impl<QStringRef, QLatin1String>(); } + void lastIndexOf_QStringRef_QStringRef_data() { lastIndexOf_data(); } + void lastIndexOf_QStringRef_QStringRef() { lastIndexOf_impl<QStringRef, QStringRef>(); } + void lastIndexOf_QStringRef_QStringView_data() { lastIndexOf_data(); } + void lastIndexOf_QStringRef_QStringView() { lastIndexOf_impl<QStringRef, QStringView>(); } + + void lastIndexOf_QStringView_QString_data() { lastIndexOf_data(); } + void lastIndexOf_QStringView_QString() { lastIndexOf_impl<QStringView, QString>(); } + void lastIndexOf_QStringView_QLatin1String_data() { lastIndexOf_data(); } + void lastIndexOf_QStringView_QLatin1String() { lastIndexOf_impl<QStringView, QLatin1String>(); } + void lastIndexOf_QStringView_QStringRef_data() { lastIndexOf_data(); } + void lastIndexOf_QStringView_QStringRef() { lastIndexOf_impl<QStringView, QStringRef>(); } + void lastIndexOf_QStringView_QStringView_data() { lastIndexOf_data(); } + void lastIndexOf_QStringView_QStringView() { lastIndexOf_impl<QStringView, QStringView>(); } }; void tst_QStringApiSymmetry::compare_data(bool hasConceptOfNullAndEmpty) @@ -1626,6 +1668,118 @@ void tst_QStringApiSymmetry::contains_impl() const } } +void tst_QStringApiSymmetry::lastIndexOf_data() +{ + QTest::addColumn<QString>("haystackU16"); + QTest::addColumn<QLatin1String>("haystackL1"); + QTest::addColumn<QString>("needleU16"); + QTest::addColumn<QLatin1String>("needleL1"); + QTest::addColumn<qsizetype>("startpos"); + QTest::addColumn<qsizetype>("resultCS"); + QTest::addColumn<qsizetype>("resultCIS"); + + constexpr qsizetype zeroPos = 0; + constexpr qsizetype minus1Pos = -1; + + QTest::addRow("haystack: null, needle: null") << null << QLatin1String() + << null << QLatin1String() << minus1Pos << minus1Pos << minus1Pos; + QTest::addRow("haystack: empty, needle: null") << empty << QLatin1String("") + << null << QLatin1String() << minus1Pos << minus1Pos << minus1Pos; + QTest::addRow("haystack: a, needle: null") << a << QLatin1String("a") + << null << QLatin1String() << minus1Pos << zeroPos << zeroPos; + QTest::addRow("haystack: null, needle: empty") << null << QLatin1String() + << empty << QLatin1String("") << minus1Pos << minus1Pos << minus1Pos; + QTest::addRow("haystack: a, needle: empty") << a << QLatin1String("a") + << empty << QLatin1String("") << minus1Pos << zeroPos << zeroPos; + QTest::addRow("haystack: empty, needle: empty") << empty << QLatin1String("") + << empty << QLatin1String("") << minus1Pos << minus1Pos << minus1Pos; + QTest::addRow("haystack: empty, needle: a") << empty << QLatin1String("") + << a << QLatin1String("a") << minus1Pos << minus1Pos << minus1Pos; + QTest::addRow("haystack: null, needle: a") << null << QLatin1String() + << a << QLatin1String("a") << minus1Pos << minus1Pos << minus1Pos; + + QTest::addRow("haystack: a, needle: null") << a << QLatin1String("a") + << null << QLatin1String() << qsizetype(1) << qsizetype(1) << qsizetype(1); + QTest::addRow("haystack: a, needle: empty") << a << QLatin1String("a") + << empty << QLatin1String("") << qsizetype(1) << qsizetype(1) << qsizetype(1); + QTest::addRow("haystack: a, needle: null") << a << QLatin1String("a") + << null << QLatin1String() << qsizetype(2) << minus1Pos << minus1Pos; + QTest::addRow("haystack: a, needle: empty") << a << QLatin1String("a") + << empty << QLatin1String("") << qsizetype(2) << minus1Pos << minus1Pos; + +#define ROW(h, n, st, cs, cis) \ + QTest::addRow("haystack: %s, needle: %s", #h, #n) << h << QLatin1String(#h) \ + << n << QLatin1String(#n) \ + << qsizetype(st) << qsizetype(cs) << qsizetype(cis) + + ROW(asd, asdf, -1, -1, -1); + + ROW(ABCDEFGHIEfGEFG, G, -1, 14, 14); + ROW(ABCDEFGHIEfGEFG, g, -1, -1, 14); + ROW(ABCDEFGHIEfGEFG, G, -3, 11, 11); + ROW(ABCDEFGHIEfGEFG, g, -3, -1, 11); + ROW(ABCDEFGHIEfGEFG, G, -5, 6, 6); + ROW(ABCDEFGHIEfGEFG, g, -5, -1, 6); + ROW(ABCDEFGHIEfGEFG, G, 14, 14, 14); + ROW(ABCDEFGHIEfGEFG, g, 14, -1, 14); + ROW(ABCDEFGHIEfGEFG, G, 13, 11, 11); + ROW(ABCDEFGHIEfGEFG, g, 13, -1, 11); + ROW(ABCDEFGHIEfGEFG, G, 15, -1, -1); + ROW(ABCDEFGHIEfGEFG, g, 15, -1, -1); + ROW(ABCDEFGHIEfGEFG, B, 14, 1, 1); + ROW(ABCDEFGHIEfGEFG, b, 14, -1, 1); + ROW(ABCDEFGHIEfGEFG, B, -1, 1, 1); + ROW(ABCDEFGHIEfGEFG, b, -1, -1, 1); + ROW(ABCDEFGHIEfGEFG, B, 1, 1, 1); + ROW(ABCDEFGHIEfGEFG, b, 1, -1, 1); + ROW(ABCDEFGHIEfGEFG, B, 0, -1, -1); + ROW(ABCDEFGHIEfGEFG, b, 0, -1, -1); + ROW(ABCDEFGHIEfGEFG, A, 0, 0, 0); + ROW(ABCDEFGHIEfGEFG, a, 0, -1, 0); + ROW(ABCDEFGHIEfGEFG, A, -15, 0, 0); + ROW(ABCDEFGHIEfGEFG, a, -15, -1, 0); + + ROW(ABCDEFGHIEfGEFG, efg, 0, -1, -1); + ROW(ABCDEFGHIEfGEFG, efg, 15, -1, -1); + ROW(ABCDEFGHIEfGEFG, efg, -15, -1, -1); + ROW(ABCDEFGHIEfGEFG, efg, 14, -1, 12); + ROW(ABCDEFGHIEfGEFG, efg, 12, -1, 12); + ROW(ABCDEFGHIEfGEFG, efg, -12, -1, -1); + ROW(ABCDEFGHIEfGEFG, efg, 11, -1, 9); +#undef ROW +} + +template <typename Haystack, typename Needle> +void tst_QStringApiSymmetry::lastIndexOf_impl() const +{ + QFETCH(const QString, haystackU16); + QFETCH(const QLatin1String, haystackL1); + QFETCH(const QString, needleU16); + QFETCH(const QLatin1String, needleL1); + QFETCH(const qsizetype, startpos); + QFETCH(const qsizetype, resultCS); + QFETCH(const qsizetype, resultCIS); + + const auto haystackU8 = haystackU16.toUtf8(); + const auto needleU8 = needleU16.toUtf8(); + + const auto haystack = make<Haystack>(QStringRef(&haystackU16), haystackL1, haystackU8); + const auto needle = make<Needle>(QStringRef(&needleU16), needleL1, needleU8); + + using size_type = typename Haystack::size_type; + + QCOMPARE(haystack.lastIndexOf(needle, startpos), size_type(resultCS)); + QCOMPARE(haystack.lastIndexOf(needle, startpos, Qt::CaseSensitive), size_type(resultCS)); + QCOMPARE(haystack.lastIndexOf(needle, startpos, Qt::CaseInsensitive), size_type(resultCIS)); + + if (needle.size() == 1) + { + QCOMPARE(haystack.lastIndexOf(needle[0], startpos), size_type(resultCS)); + QCOMPARE(haystack.lastIndexOf(needle[0], startpos, Qt::CaseSensitive), size_type(resultCS)); + QCOMPARE(haystack.lastIndexOf(needle[0], startpos, Qt::CaseInsensitive), size_type(resultCIS)); + } +} + QTEST_APPLESS_MAIN(tst_QStringApiSymmetry) #include "tst_qstringapisymmetry.moc" diff --git a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp index 2b5aa8e98b..66d4744454 100644 --- a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp +++ b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp @@ -259,6 +259,12 @@ void tst_QStringList::filter() list5 = list5.filter( QRegularExpression("[i]ll") ); list6 << "Bill Gates" << "Bill Clinton"; QCOMPARE( list5, list6 ); + + QStringList list7, list8; + list7 << "Bill Gates" << "Joe Blow" << "Bill Clinton"; + list7 = list7.filter( QStringView(QString("Bill")) ); + list8 << "Bill Gates" << "Bill Clinton"; + QCOMPARE( list7, list8 ); } void tst_QStringList::sort() @@ -316,6 +322,16 @@ void tst_QStringList::replaceInStrings() list10 << "Bill Clinton" << "Bill Gates"; list9.replaceInStrings( QRegularExpression("^(.*), (.*)$"), "\\2 \\1" ); QCOMPARE( list9, list10 ); + + QStringList list11, list12, list13, list14; + list11 << "alpha" << "beta" << "gamma" << "epsilon"; + list12 << "alpha" << "beta" << "gamma" << "epsilon"; + list13 << "alpha" << "beta" << "gamma" << "epsilon"; + list11.replaceInStrings( QStringView(QString("a")), QStringView(QString("o")) ); + list12.replaceInStrings( QStringView(QString("a")), QString("o") ); + list13.replaceInStrings( QString("a"), QStringView(QString("o")) ); + list14 << "olpho" << "beto" << "gommo" << "epsilon"; + QCOMPARE( list11, list12 ); } void tst_QStringList::contains() @@ -427,6 +443,7 @@ void tst_QStringList::join() const QCOMPARE(input.join(separator), expectedResult); QCOMPARE(input.join(QLatin1String(separator.toLatin1())), expectedResult); + QCOMPARE(input.join(QStringView(separator)), expectedResult); } void tst_QStringList::join_data() const diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp index 581e9152e6..6f01947131 100644 --- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp +++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp @@ -596,7 +596,10 @@ void tst_QStringRef::startsWith() QVERIFY(!ref.startsWith("C")); QVERIFY(!ref.startsWith("ABCDEF")); QVERIFY(ref.startsWith("")); + QVERIFY(ref.startsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.startsWith(QString::null)); +#endif QVERIFY(ref.startsWith('A')); QVERIFY(ref.startsWith(QLatin1Char('A'))); QVERIFY(ref.startsWith(QChar('A'))); @@ -623,7 +626,10 @@ void tst_QStringRef::startsWith() QVERIFY(!ref.startsWith("c", Qt::CaseInsensitive)); QVERIFY(!ref.startsWith("abcdef", Qt::CaseInsensitive)); QVERIFY(ref.startsWith("", Qt::CaseInsensitive)); + QVERIFY(ref.startsWith(QString(), Qt::CaseInsensitive)); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.startsWith(QString::null, Qt::CaseInsensitive)); +#endif QVERIFY(ref.startsWith('a', Qt::CaseInsensitive)); QVERIFY(ref.startsWith('A', Qt::CaseInsensitive)); QVERIFY(ref.startsWith(QLatin1Char('a'), Qt::CaseInsensitive)); @@ -656,7 +662,10 @@ void tst_QStringRef::startsWith() const QString a = QString::fromLatin1(""); CREATE_REF(a); QVERIFY(ref.startsWith("")); + QVERIFY(ref.startsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.startsWith(QString::null)); +#endif QVERIFY(!ref.startsWith("ABC")); QVERIFY(ref.startsWith(QLatin1String(""))); @@ -670,7 +679,10 @@ void tst_QStringRef::startsWith() { const QStringRef ref; QVERIFY(!ref.startsWith("")); + QVERIFY(ref.startsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.startsWith(QString::null)); +#endif QVERIFY(!ref.startsWith("ABC")); QVERIFY(!ref.startsWith(QLatin1String(""))); @@ -693,7 +705,10 @@ void tst_QStringRef::endsWith() QVERIFY(!ref.endsWith("C")); QVERIFY(!ref.endsWith("ABCDEF")); QVERIFY(ref.endsWith("")); + QVERIFY(ref.endsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.endsWith(QString::null)); +#endif QVERIFY(ref.endsWith('B')); QVERIFY(ref.endsWith(QLatin1Char('B'))); QVERIFY(ref.endsWith(QChar('B'))); @@ -720,7 +735,10 @@ void tst_QStringRef::endsWith() QVERIFY(!ref.endsWith("c", Qt::CaseInsensitive)); QVERIFY(!ref.endsWith("abcdef", Qt::CaseInsensitive)); QVERIFY(ref.endsWith("", Qt::CaseInsensitive)); + QVERIFY(ref.endsWith(QString(), Qt::CaseInsensitive)); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.endsWith(QString::null, Qt::CaseInsensitive)); +#endif QVERIFY(ref.endsWith('b', Qt::CaseInsensitive)); QVERIFY(ref.endsWith('B', Qt::CaseInsensitive)); QVERIFY(ref.endsWith(QLatin1Char('b'), Qt::CaseInsensitive)); @@ -754,7 +772,10 @@ void tst_QStringRef::endsWith() const QString a = QString::fromLatin1(""); CREATE_REF(a); QVERIFY(ref.endsWith("")); + QVERIFY(ref.endsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.endsWith(QString::null)); +#endif QVERIFY(!ref.endsWith("ABC")); QVERIFY(!ref.endsWith(QLatin1Char(0))); QVERIFY(!ref.endsWith(QLatin1Char('x'))); @@ -768,7 +789,10 @@ void tst_QStringRef::endsWith() { QStringRef ref; QVERIFY(!ref.endsWith("")); + QVERIFY(ref.endsWith(QString())); +#if QT_DEPRECATED_SINCE(5, 9) QVERIFY(ref.endsWith(QString::null)); +#endif QVERIFY(!ref.endsWith("ABC")); QVERIFY(!ref.endsWith(QLatin1String(""))); diff --git a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp index e800a0d794..794f39708a 100644 --- a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp +++ b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp @@ -134,6 +134,8 @@ private Q_SLOTS: void literals() const; void at() const; + void arg() const; + void fromQString() const; void fromQStringRef() const; @@ -425,6 +427,47 @@ void tst_QStringView::at() const QCOMPARE(sv.at(4), QChar('o')); QCOMPARE(sv[4], QChar('o')); } +void tst_QStringView::arg() const +{ +#define CHECK1(pattern, arg1, expected) \ + do { \ + auto p = QStringViewLiteral(pattern); \ + QCOMPARE(p.arg(QLatin1String(arg1)), expected); \ + QCOMPARE(p.arg(QStringViewLiteral(arg1)), expected); \ + QCOMPARE(p.arg(QStringLiteral(arg1)), expected); \ + QCOMPARE(p.arg(QString(QLatin1String(arg1))), expected); \ + } while (false) \ + /*end*/ +#define CHECK2(pattern, arg1, arg2, expected) \ + do { \ + auto p = QStringViewLiteral(pattern); \ + QCOMPARE(p.arg(QLatin1String(arg1), QLatin1String(arg2)), expected); \ + QCOMPARE(p.arg(QStringViewLiteral(arg1), QLatin1String(arg2)), expected); \ + QCOMPARE(p.arg(QLatin1String(arg1), QStringViewLiteral(arg2)), expected); \ + QCOMPARE(p.arg(QStringViewLiteral(arg1), QStringViewLiteral(arg2)), expected); \ + } while (false) \ + /*end*/ + + CHECK1("", "World", ""); + CHECK1("%1", "World", "World"); + CHECK1("!%1?", "World", "!World?"); + CHECK1("%1%1", "World", "WorldWorld"); + CHECK1("%1%2", "World", "World%2"); + CHECK1("%2%1", "World", "%2World"); + + CHECK2("", "Hello", "World", ""); + CHECK2("%1", "Hello", "World", "Hello"); + CHECK2("!%1, %2?", "Hello", "World", "!Hello, World?"); + CHECK2("%1%1", "Hello", "World", "HelloHello"); + CHECK2("%1%2", "Hello", "World", "HelloWorld"); + CHECK2("%2%1", "Hello", "World", "WorldHello"); + +#undef CHECK2 +#undef CHECK1 + + QCOMPARE(QStringViewLiteral(" %2 %2 %1 %3 ").arg(QLatin1Char('c'), QChar::CarriageReturn, u'C'), " \r \r c C "); +} + void tst_QStringView::fromQString() const { QString null; diff --git a/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp b/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp index 5467d438a3..a46011ff6c 100644 --- a/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp +++ b/tests/auto/corelib/tools/qtextboundaryfinder/tst_qtextboundaryfinder.cpp @@ -192,7 +192,7 @@ static void doTestData(const QString &testString, const QList<int> &expectedBrea // test toPreviousBoundary() { QList<int> expectedBreakPositionsRev = expectedBreakPositions; - std::sort(expectedBreakPositionsRev.begin(), expectedBreakPositionsRev.end(), qGreater<int>()); + std::sort(expectedBreakPositionsRev.begin(), expectedBreakPositionsRev.end(), std::greater<int>()); QList<int> actualBreakPositions; boundaryFinder.toEnd(); @@ -539,6 +539,13 @@ void tst_QTextBoundaryFinder::sentenceBoundaries_manual_data() QTest::newRow("data3") << testString << expectedBreakPositions; } + { + QString testString(QString::fromUtf8("Doing TEST, doing another test.")); + QList<int> expectedBreakPositions; + expectedBreakPositions << 0 << 31; + + QTest::newRow("data4") << testString << expectedBreakPositions; + } } void tst_QTextBoundaryFinder::sentenceBoundaries_manual() diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index fff8c75a90..070c25368b 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -57,6 +57,7 @@ private slots: void initializeListComplex(); void insertMove(); void nonCopyable(); + void implicitDefaultCtor(); private: template<typename T> @@ -1078,5 +1079,11 @@ void tst_QVarLengthArray::nonCopyable() QVERIFY(ptr6 == vec.at(5).get()); } +void tst_QVarLengthArray::implicitDefaultCtor() +{ + QVarLengthArray<int> def = {}; + QCOMPARE(def.size(), 0); +} + QTEST_APPLESS_MAIN(tst_QVarLengthArray) #include "tst_qvarlengtharray.moc" diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp index 11c255b184..3256130472 100644 --- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp +++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp @@ -2882,7 +2882,7 @@ void tst_QVector::detachThreadSafety() const struct : QThread { void run() override { - QVector<T> copy(*detachThreadSafetyData<T>()->load()); + QVector<T> copy(*detachThreadSafetyData<T>()->loadRelaxed()); QVERIFY(!copy.isDetached()); detachThreadSafetyLock.release(); detachThreadSafetyLock.acquire(100); diff --git a/tests/auto/dbus/qdbusthreading/tst_qdbusthreading.cpp b/tests/auto/dbus/qdbusthreading/tst_qdbusthreading.cpp index 018b7c2a35..b4690268c8 100644 --- a/tests/auto/dbus/qdbusthreading/tst_qdbusthreading.cpp +++ b/tests/auto/dbus/qdbusthreading/tst_qdbusthreading.cpp @@ -197,8 +197,8 @@ tst_QDBusThreading::tst_QDBusThreading() void tst_QDBusThreading::joinThreads() { - threadJoin.acquire(threadJoinCount.load()); - threadJoinCount.store(0); + threadJoin.acquire(threadJoinCount.loadRelaxed()); + threadJoinCount.storeRelaxed(0); } bool tst_QDBusThreading::waitForSignal(QObject *obj, const char *signal, int delay) diff --git a/tests/auto/gui/gui.pro b/tests/auto/gui/gui.pro index e0c8123f26..c90fc48251 100644 --- a/tests/auto/gui/gui.pro +++ b/tests/auto/gui/gui.pro @@ -13,6 +13,7 @@ SUBDIRS = \ text \ util \ itemmodels \ + rhi !qtConfig(opengl)|winrt: SUBDIRS -= qopengl qopenglconfig diff --git a/tests/auto/gui/image/qimagereader/images/qticon16.png b/tests/auto/gui/image/qimagereader/images/qticon16.png Binary files differnew file mode 100644 index 0000000000..b6b01a4d64 --- /dev/null +++ b/tests/auto/gui/image/qimagereader/images/qticon16.png diff --git a/tests/auto/gui/image/qimagereader/images/qticon16@2x.png b/tests/auto/gui/image/qimagereader/images/qticon16@2x.png Binary files differnew file mode 100644 index 0000000000..205461daf0 --- /dev/null +++ b/tests/auto/gui/image/qimagereader/images/qticon16@2x.png diff --git a/tests/auto/gui/image/qimagereader/images/qticon16@3x.png b/tests/auto/gui/image/qimagereader/images/qticon16@3x.png Binary files differnew file mode 100644 index 0000000000..de92658241 --- /dev/null +++ b/tests/auto/gui/image/qimagereader/images/qticon16@3x.png diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp index 1cf01133b2..d17a171728 100644 --- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp @@ -164,6 +164,9 @@ private slots: void preserveTexts_data(); void preserveTexts(); + void devicePixelRatio_data(); + void devicePixelRatio(); + private: QString prefix; QTemporaryDir m_temporaryDir; @@ -1976,6 +1979,28 @@ void tst_QImageReader::preserveTexts() QCOMPARE(r.text(key3), text3.simplified()); } +void tst_QImageReader::devicePixelRatio_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::addColumn<QSize>("size"); + QTest::addColumn<qreal>("dpr"); + + QTest::newRow("1x") << "qticon16.png" << QSize(16, 16) << 1.0; + QTest::newRow("2x") << "qticon16@2x.png" << QSize(32, 32) << 2.0; + QTest::newRow("3x") << "qticon16@3x.png" << QSize(48, 48) << 3.0; +} + +void tst_QImageReader::devicePixelRatio() +{ + QFETCH(QString, fileName); + QFETCH(QSize, size); + QFETCH(qreal, dpr); + + QImageReader r(":/images/" + fileName); + QImage img = r.read(); + QCOMPARE(img.size(), size); + QCOMPARE(img.devicePixelRatio(), dpr); +} QTEST_MAIN(tst_QImageReader) #include "tst_qimagereader.moc" diff --git a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp index 2deb84fa5f..b6921fc0bb 100644 --- a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp +++ b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp @@ -311,12 +311,14 @@ void tst_QStandardItem::getSetFlags() item.setCheckable(true); QCOMPARE(item.checkState(), Qt::Checked); +#if QT_DEPRECATED_SINCE(5, 6) // deprecated API item.setTristate(true); QVERIFY(item.isTristate()); QVERIFY(item.flags() & Qt::ItemIsTristate); item.setTristate(false); QVERIFY(!(item.flags() & Qt::ItemIsTristate)); +#endif } void tst_QStandardItem::getSetRowAndColumnCount() diff --git a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp index 9a4c560a08..87a47bd93b 100644 --- a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp +++ b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp @@ -155,7 +155,7 @@ void tst_QKeyEvent::modifiers_data() modifierCombinations.append(modifierCombination); } - qSort(modifierCombinations.begin(), modifierCombinations.end(), orderByModifier); + std::sort(modifierCombinations.begin(), modifierCombinations.end(), orderByModifier); QTest::addColumn<Qt::KeyboardModifiers>("modifiers"); foreach (const QVector<int> combination, modifierCombinations) { diff --git a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp index f8b6bf064a..874468c954 100644 --- a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp +++ b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp @@ -86,7 +86,7 @@ static const MacSpecialKey * const MacSpecialKeyEntriesEnd = entries + NumEntrie static QChar macSymbolForQtKey(int key) { - const MacSpecialKey *i = qBinaryFind(entries, MacSpecialKeyEntriesEnd, key); + const MacSpecialKey *i = std::lower_bound(entries, MacSpecialKeyEntriesEnd, key); if (i == MacSpecialKeyEntriesEnd) return QChar(); return QChar(i->macSymbol); diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp index 69c961c1a1..c90348e91a 100644 --- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp +++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp @@ -189,6 +189,10 @@ void tst_QPainterPath::reserveAndCapacity() p.reserve(0); QVERIFY(p.capacity() >= 1000); + + QPainterPath p2; + p2.reserve(10); + QVERIFY(p.capacity() >= 10); } Q_DECLARE_METATYPE(QPainterPath) diff --git a/tests/auto/gui/rhi/qrhi/data/texture.frag b/tests/auto/gui/rhi/qrhi/data/texture.frag new file mode 100644 index 0000000000..e6021fe905 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/texture.frag @@ -0,0 +1,12 @@ +#version 440 + +layout(location = 0) in vec2 v_texcoord; + +layout(location = 0) out vec4 fragColor; + +layout(binding = 1) uniform sampler2D tex; + +void main() +{ + fragColor = texture(tex, v_texcoord); +} diff --git a/tests/auto/gui/rhi/qrhi/data/texture.vert b/tests/auto/gui/rhi/qrhi/data/texture.vert new file mode 100644 index 0000000000..de486cb772 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/data/texture.vert @@ -0,0 +1,18 @@ +#version 440 + +layout(location = 0) in vec4 position; +layout(location = 1) in vec2 texcoord; + +layout(location = 0) out vec2 v_texcoord; + +layout(std140, binding = 0) uniform buf { + mat4 mvp; +} ubuf; + +out gl_PerVertex { vec4 gl_Position; }; + +void main() +{ + v_texcoord = texcoord; + gl_Position = ubuf.mvp * position; +} diff --git a/tests/auto/gui/rhi/qrhi/qrhi.pro b/tests/auto/gui/rhi/qrhi/qrhi.pro new file mode 100644 index 0000000000..58000ed514 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/qrhi.pro @@ -0,0 +1,8 @@ +TARGET = tst_qrhi +CONFIG += testcase + +QT += testlib gui-private + +SOURCES += tst_qrhi.cpp + +RESOURCES += qrhi.qrc diff --git a/tests/auto/gui/rhi/qrhi/qrhi.qrc b/tests/auto/gui/rhi/qrhi/qrhi.qrc new file mode 100644 index 0000000000..f161d8aad6 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/qrhi.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>data</file> + </qresource> +</RCC> diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp new file mode 100644 index 0000000000..897613d525 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp @@ -0,0 +1,246 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QThread> +#include <QFile> +#include <QOffscreenSurface> +#include <QtGui/private/qrhi_p.h> +#include <QtGui/private/qrhinull_p.h> + +#if QT_CONFIG(opengl) +# include <QtGui/private/qrhigles2_p.h> +# define TST_GL +#endif + +#if QT_CONFIG(vulkan) +# include <QVulkanInstance> +# include <QtGui/private/qrhivulkan_p.h> +# define TST_VK +#endif + +#ifdef Q_OS_WIN +#include <QtGui/private/qrhid3d11_p.h> +# define TST_D3D11 +#endif + +#ifdef Q_OS_DARWIN +# include <QtGui/private/qrhimetal_p.h> +# define TST_MTL +#endif + +Q_DECLARE_METATYPE(QRhi::Implementation) +Q_DECLARE_METATYPE(QRhiInitParams *) + +class tst_QRhi : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void cleanupTestCase(); + + void create_data(); + void create(); + +private: + struct { + QRhiNullInitParams null; +#ifdef TST_GL + QRhiGles2InitParams gl; +#endif +#ifdef TST_VK + QRhiVulkanInitParams vk; +#endif +#ifdef TST_D3D11 + QRhiD3D11InitParams d3d; +#endif +#ifdef TST_MTL + QRhiMetalInitParams mtl; +#endif + } initParams; + +#ifdef TST_VK + QVulkanInstance vulkanInstance; +#endif + QOffscreenSurface *fallbackSurface = nullptr; +}; + +void tst_QRhi::initTestCase() +{ +#ifdef TST_GL + fallbackSurface = QRhiGles2InitParams::newFallbackSurface(); + initParams.gl.fallbackSurface = fallbackSurface; +#endif + +#ifdef TST_VK + vulkanInstance.create(); + initParams.vk.inst = &vulkanInstance; +#endif +} + +void tst_QRhi::cleanupTestCase() +{ +#ifdef TST_VK + vulkanInstance.destroy(); +#endif + + delete fallbackSurface; +} + +void tst_QRhi::create_data() +{ + QTest::addColumn<QRhi::Implementation>("impl"); + QTest::addColumn<QRhiInitParams *>("initParams"); + + QTest::newRow("Null") << QRhi::Null << static_cast<QRhiInitParams *>(&initParams.null); +#ifdef TST_GL + QTest::newRow("OpenGL") << QRhi::OpenGLES2 << static_cast<QRhiInitParams *>(&initParams.gl); +#endif +#ifdef TST_VK + if (vulkanInstance.isValid()) + QTest::newRow("Vulkan") << QRhi::Vulkan << static_cast<QRhiInitParams *>(&initParams.vk); +#endif +#ifdef TST_D3D11 + QTest::newRow("Direct3D 11") << QRhi::D3D11 << static_cast<QRhiInitParams *>(&initParams.d3d); +#endif +#ifdef TST_MTL + QTest::newRow("Metal") << QRhi::Metal << static_cast<QRhiInitParams *>(&initParams.mtl); +#endif +} + +static int aligned(int v, int a) +{ + return (v + a - 1) & ~(a - 1); +} + +void tst_QRhi::create() +{ + // Merely attempting to create a QRhi should survive, with an error when + // not supported. (of course, there is always a chance we encounter a crash + // due to some random graphics stack...) + + QFETCH(QRhi::Implementation, impl); + QFETCH(QRhiInitParams *, initParams); + + QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr)); + + if (rhi) { + QCOMPARE(rhi->backend(), impl); + QCOMPARE(rhi->thread(), QThread::currentThread()); + + int cleanupOk = 0; + QRhi *rhiPtr = rhi.data(); + auto cleanupFunc = [rhiPtr, &cleanupOk](QRhi *dyingRhi) { + if (rhiPtr == dyingRhi) + cleanupOk += 1; + }; + rhi->addCleanupCallback(cleanupFunc); + rhi->runCleanup(); + QCOMPARE(cleanupOk, 1); + cleanupOk = 0; + rhi->addCleanupCallback(cleanupFunc); + + QRhiResourceUpdateBatch *resUpd = rhi->nextResourceUpdateBatch(); + QVERIFY(resUpd); + resUpd->release(); + + QVERIFY(!rhi->supportedSampleCounts().isEmpty()); + QVERIFY(rhi->supportedSampleCounts().contains(1)); + + QVERIFY(rhi->ubufAlignment() > 0); + QCOMPARE(rhi->ubufAligned(123), aligned(123, rhi->ubufAlignment())); + + QCOMPARE(rhi->mipLevelsForSize(QSize(512, 300)), 10); + QCOMPARE(rhi->sizeForMipLevel(0, QSize(512, 300)), QSize(512, 300)); + QCOMPARE(rhi->sizeForMipLevel(1, QSize(512, 300)), QSize(256, 150)); + QCOMPARE(rhi->sizeForMipLevel(2, QSize(512, 300)), QSize(128, 75)); + QCOMPARE(rhi->sizeForMipLevel(9, QSize(512, 300)), QSize(1, 1)); + + const bool fbUp = rhi->isYUpInFramebuffer(); + const bool ndcUp = rhi->isYUpInNDC(); + const bool d0to1 = rhi->isClipDepthZeroToOne(); + const QMatrix4x4 corrMat = rhi->clipSpaceCorrMatrix(); + if (impl == QRhi::OpenGLES2) { + QVERIFY(fbUp); + QVERIFY(ndcUp); + QVERIFY(!d0to1); + QVERIFY(corrMat.isIdentity()); + } else if (impl == QRhi::Vulkan) { + QVERIFY(!fbUp); + QVERIFY(!ndcUp); + QVERIFY(d0to1); + QVERIFY(!corrMat.isIdentity()); + } else if (impl == QRhi::D3D11) { + QVERIFY(!fbUp); + QVERIFY(ndcUp); + QVERIFY(d0to1); + QVERIFY(!corrMat.isIdentity()); + } else if (impl == QRhi::Metal) { + QVERIFY(!fbUp); + QVERIFY(ndcUp); + QVERIFY(d0to1); + QVERIFY(!corrMat.isIdentity()); + } + + const int texMin = rhi->resourceLimit(QRhi::TextureSizeMin); + const int texMax = rhi->resourceLimit(QRhi::TextureSizeMax); + const int maxAtt = rhi->resourceLimit(QRhi::MaxColorAttachments); + QVERIFY(texMin >= 1); + QVERIFY(texMax >= texMin); + QVERIFY(maxAtt >= 1); + + QVERIFY(rhi->nativeHandles()); + QVERIFY(rhi->profiler()); + + const QRhi::Feature features[] = { + QRhi::MultisampleTexture, + QRhi::MultisampleRenderBuffer, + QRhi::DebugMarkers, + QRhi::Timestamps, + QRhi::Instancing, + QRhi::CustomInstanceStepRate, + QRhi::PrimitiveRestart, + QRhi::NonDynamicUniformBuffers, + QRhi::NonFourAlignedEffectiveIndexBufferOffset, + QRhi::NPOTTextureRepeat, + QRhi::RedOrAlpha8IsRed, + QRhi::ElementIndexUint + }; + for (size_t i = 0; i <sizeof(features) / sizeof(QRhi::Feature); ++i) + rhi->isFeatureSupported(features[i]); + + QVERIFY(rhi->isTextureFormatSupported(QRhiTexture::RGBA8)); + + rhi.reset(); + QCOMPARE(cleanupOk, 1); + } +} + +#include <tst_qrhi.moc> +QTEST_MAIN(tst_QRhi) diff --git a/tests/auto/gui/rhi/qshader/data/color.vert b/tests/auto/gui/rhi/qshader/data/color.vert new file mode 100644 index 0000000000..c92f71b9e1 --- /dev/null +++ b/tests/auto/gui/rhi/qshader/data/color.vert @@ -0,0 +1,18 @@ +#version 440 + +layout(location = 0) in vec4 position; +layout(location = 1) in vec3 color; +layout(location = 0) out vec3 v_color; + +layout(std140, binding = 0) uniform buf { + mat4 mvp; + float opacity; +} ubuf; + +out gl_PerVertex { vec4 gl_Position; }; + +void main() +{ + v_color = color; + gl_Position = ubuf.mvp * position; +} diff --git a/tests/auto/gui/rhi/qshader/data/color.vert.qsb b/tests/auto/gui/rhi/qshader/data/color.vert.qsb Binary files differnew file mode 100644 index 0000000000..7d02d823d2 --- /dev/null +++ b/tests/auto/gui/rhi/qshader/data/color.vert.qsb diff --git a/tests/auto/gui/rhi/qshader/data/color_simple.vert.qsb b/tests/auto/gui/rhi/qshader/data/color_simple.vert.qsb Binary files differnew file mode 100644 index 0000000000..c82ba7e8e7 --- /dev/null +++ b/tests/auto/gui/rhi/qshader/data/color_simple.vert.qsb diff --git a/tests/auto/gui/rhi/qshader/qshader.pro b/tests/auto/gui/rhi/qshader/qshader.pro new file mode 100644 index 0000000000..5d9ef8304d --- /dev/null +++ b/tests/auto/gui/rhi/qshader/qshader.pro @@ -0,0 +1,8 @@ +TARGET = tst_qshader +CONFIG += testcase + +QT += testlib gui-private + +SOURCES += tst_qshader.cpp + +RESOURCES += qshader.qrc diff --git a/tests/auto/gui/rhi/qshader/qshader.qrc b/tests/auto/gui/rhi/qshader/qshader.qrc new file mode 100644 index 0000000000..f161d8aad6 --- /dev/null +++ b/tests/auto/gui/rhi/qshader/qshader.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>data</file> + </qresource> +</RCC> diff --git a/tests/auto/gui/rhi/qshader/tst_qshader.cpp b/tests/auto/gui/rhi/qshader/tst_qshader.cpp new file mode 100644 index 0000000000..21f0cc7895 --- /dev/null +++ b/tests/auto/gui/rhi/qshader/tst_qshader.cpp @@ -0,0 +1,233 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QFile> +#include <QtGui/private/qshaderdescription_p_p.h> +#include <QtGui/private/qshader_p_p.h> + +class tst_QShader : public QObject +{ + Q_OBJECT + +private slots: + void simpleCompileCheckResults(); + void genVariants(); + void shaderDescImplicitSharing(); + void bakedShaderImplicitSharing(); +}; + +static QShader getShader(const QString &name) +{ + QFile f(name); + if (f.open(QIODevice::ReadOnly)) + return QShader::fromSerialized(f.readAll()); + + return QShader(); +} + +void tst_QShader::simpleCompileCheckResults() +{ + QShader s = getShader(QLatin1String(":/data/color_simple.vert.qsb")); + QVERIFY(s.isValid()); + QCOMPARE(s.availableShaders().count(), 1); + + const QShaderCode shader = s.shader(QShaderKey(QShader::SpirvShader, + QShaderVersion(100))); + QVERIFY(!shader.shader().isEmpty()); + QCOMPARE(shader.entryPoint(), QByteArrayLiteral("main")); + + const QShaderDescription desc = s.description(); + QVERIFY(desc.isValid()); + QCOMPARE(desc.inputVariables().count(), 2); + for (const QShaderDescription::InOutVariable &v : desc.inputVariables()) { + switch (v.location) { + case 0: + QCOMPARE(v.name, QLatin1String("position")); + QCOMPARE(v.type, QShaderDescription::Vec4); + break; + case 1: + QCOMPARE(v.name, QLatin1String("color")); + QCOMPARE(v.type, QShaderDescription::Vec3); + break; + default: + QVERIFY(false); + break; + } + } + QCOMPARE(desc.outputVariables().count(), 1); + for (const QShaderDescription::InOutVariable &v : desc.outputVariables()) { + switch (v.location) { + case 0: + QCOMPARE(v.name, QLatin1String("v_color")); + QCOMPARE(v.type, QShaderDescription::Vec3); + break; + default: + QVERIFY(false); + break; + } + } + QCOMPARE(desc.uniformBlocks().count(), 1); + const QShaderDescription::UniformBlock blk = desc.uniformBlocks().first(); + QCOMPARE(blk.blockName, QLatin1String("buf")); + QCOMPARE(blk.structName, QLatin1String("ubuf")); + QCOMPARE(blk.size, 68); + QCOMPARE(blk.binding, 0); + QCOMPARE(blk.descriptorSet, 0); + QCOMPARE(blk.members.count(), 2); + for (int i = 0; i < blk.members.count(); ++i) { + const QShaderDescription::BlockVariable v = blk.members[i]; + switch (i) { + case 0: + QCOMPARE(v.offset, 0); + QCOMPARE(v.size, 64); + QCOMPARE(v.name, QLatin1String("mvp")); + QCOMPARE(v.type, QShaderDescription::Mat4); + QCOMPARE(v.matrixStride, 16); + break; + case 1: + QCOMPARE(v.offset, 64); + QCOMPARE(v.size, 4); + QCOMPARE(v.name, QLatin1String("opacity")); + QCOMPARE(v.type, QShaderDescription::Float); + break; + default: + QVERIFY(false); + break; + } + } +} + +void tst_QShader::genVariants() +{ + QShader s = getShader(QLatin1String(":/data/color.vert.qsb")); + // spirv, glsl 100, glsl 330, glsl 120, hlsl 50, msl 12 + // + batchable variants + QVERIFY(s.isValid()); + QCOMPARE(s.availableShaders().count(), 2 * 6); + + int batchableVariantCount = 0; + int batchableGlslVariantCount = 0; + for (const QShaderKey &key : s.availableShaders()) { + if (key.sourceVariant() == QShader::BatchableVertexShader) { + ++batchableVariantCount; + if (key.source() == QShader::GlslShader) { + ++batchableGlslVariantCount; + const QByteArray src = s.shader(key).shader(); + QVERIFY(src.contains(QByteArrayLiteral("_qt_order * "))); + } + } + } + QCOMPARE(batchableVariantCount, 6); + QCOMPARE(batchableGlslVariantCount, 3); +} + +void tst_QShader::shaderDescImplicitSharing() +{ + QShader s = getShader(QLatin1String(":/data/color_simple.vert.qsb")); + QVERIFY(s.isValid()); + QCOMPARE(s.availableShaders().count(), 1); + QVERIFY(s.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); + + QShaderDescription d0 = s.description(); + QVERIFY(d0.isValid()); + QCOMPARE(d0.inputVariables().count(), 2); + QCOMPARE(d0.outputVariables().count(), 1); + QCOMPARE(d0.uniformBlocks().count(), 1); + + QShaderDescription d1 = d0; + QVERIFY(QShaderDescriptionPrivate::get(&d0) == QShaderDescriptionPrivate::get(&d1)); + QCOMPARE(d0.inputVariables().count(), 2); + QCOMPARE(d0.outputVariables().count(), 1); + QCOMPARE(d0.uniformBlocks().count(), 1); + QCOMPARE(d1.inputVariables().count(), 2); + QCOMPARE(d1.outputVariables().count(), 1); + QCOMPARE(d1.uniformBlocks().count(), 1); + + d1.detach(); + QVERIFY(QShaderDescriptionPrivate::get(&d0) != QShaderDescriptionPrivate::get(&d1)); + QCOMPARE(d0.inputVariables().count(), 2); + QCOMPARE(d0.outputVariables().count(), 1); + QCOMPARE(d0.uniformBlocks().count(), 1); + QCOMPARE(d1.inputVariables().count(), 2); + QCOMPARE(d1.outputVariables().count(), 1); + QCOMPARE(d1.uniformBlocks().count(), 1); +} + +void tst_QShader::bakedShaderImplicitSharing() +{ + QShader s0 = getShader(QLatin1String(":/data/color_simple.vert.qsb")); + QVERIFY(s0.isValid()); + QCOMPARE(s0.availableShaders().count(), 1); + QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); + + { + QShader s1 = s0; + QVERIFY(QShaderPrivate::get(&s0) == QShaderPrivate::get(&s1)); + QCOMPARE(s0.availableShaders().count(), 1); + QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); + QCOMPARE(s1.availableShaders().count(), 1); + QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); + QCOMPARE(s0.stage(), s1.stage()); + QCOMPARE(s0, s1); + + s1.detach(); + QVERIFY(QShaderPrivate::get(&s0) != QShaderPrivate::get(&s1)); + QCOMPARE(s0.availableShaders().count(), 1); + QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); + QCOMPARE(s1.availableShaders().count(), 1); + QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); + QCOMPARE(s0.stage(), s1.stage()); + QCOMPARE(s0, s1); + } + + { + QShader s1 = s0; + QVERIFY(QShaderPrivate::get(&s0) == QShaderPrivate::get(&s1)); + QCOMPARE(s0.stage(), s1.stage()); + + s1.setStage(QShader::FragmentStage); // call a setter to trigger a detach + QVERIFY(QShaderPrivate::get(&s0) != QShaderPrivate::get(&s1)); + QCOMPARE(s0.availableShaders().count(), 1); + QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); + QCOMPARE(s1.availableShaders().count(), 1); + QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100)))); + QShaderDescription d0 = s0.description(); + QCOMPARE(d0.inputVariables().count(), 2); + QCOMPARE(d0.outputVariables().count(), 1); + QCOMPARE(d0.uniformBlocks().count(), 1); + QShaderDescription d1 = s1.description(); + QCOMPARE(d1.inputVariables().count(), 2); + QCOMPARE(d1.outputVariables().count(), 1); + QCOMPARE(d1.uniformBlocks().count(), 1); + QVERIFY(s0 != s1); + } +} + +#include <tst_qshader.moc> +QTEST_MAIN(tst_QShader) diff --git a/tests/auto/gui/rhi/rhi.pro b/tests/auto/gui/rhi/rhi.pro new file mode 100644 index 0000000000..cc548b7b8a --- /dev/null +++ b/tests/auto/gui/rhi/rhi.pro @@ -0,0 +1,4 @@ +TEMPLATE=subdirs +SUBDIRS= \ + qshader \ + qrhi diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index 9acf877790..901284e131 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -609,37 +609,37 @@ void tst_QFont::sharing() QFont f; f.setStyleHint(QFont::Serif); f.exactMatch(); // loads engine - QCOMPARE(QFontPrivate::get(f)->ref.load(), 1); + QCOMPARE(QFontPrivate::get(f)->ref.loadRelaxed(), 1); QVERIFY(QFontPrivate::get(f)->engineData); - QCOMPARE(QFontPrivate::get(f)->engineData->ref.load(), 1 + refs_by_cache); + QCOMPARE(QFontPrivate::get(f)->engineData->ref.loadRelaxed(), 1 + refs_by_cache); QFont f2(f); QCOMPARE(QFontPrivate::get(f2), QFontPrivate::get(f)); - QCOMPARE(QFontPrivate::get(f2)->ref.load(), 2); + QCOMPARE(QFontPrivate::get(f2)->ref.loadRelaxed(), 2); QVERIFY(QFontPrivate::get(f2)->engineData); QCOMPARE(QFontPrivate::get(f2)->engineData, QFontPrivate::get(f)->engineData); - QCOMPARE(QFontPrivate::get(f2)->engineData->ref.load(), 1 + refs_by_cache); + QCOMPARE(QFontPrivate::get(f2)->engineData->ref.loadRelaxed(), 1 + refs_by_cache); f2.setKerning(!f.kerning()); QVERIFY(QFontPrivate::get(f2) != QFontPrivate::get(f)); - QCOMPARE(QFontPrivate::get(f2)->ref.load(), 1); + QCOMPARE(QFontPrivate::get(f2)->ref.loadRelaxed(), 1); QVERIFY(QFontPrivate::get(f2)->engineData); QCOMPARE(QFontPrivate::get(f2)->engineData, QFontPrivate::get(f)->engineData); - QCOMPARE(QFontPrivate::get(f2)->engineData->ref.load(), 2 + refs_by_cache); + QCOMPARE(QFontPrivate::get(f2)->engineData->ref.loadRelaxed(), 2 + refs_by_cache); f2 = f; QCOMPARE(QFontPrivate::get(f2), QFontPrivate::get(f)); - QCOMPARE(QFontPrivate::get(f2)->ref.load(), 2); + QCOMPARE(QFontPrivate::get(f2)->ref.loadRelaxed(), 2); QVERIFY(QFontPrivate::get(f2)->engineData); QCOMPARE(QFontPrivate::get(f2)->engineData, QFontPrivate::get(f)->engineData); - QCOMPARE(QFontPrivate::get(f2)->engineData->ref.load(), 1 + refs_by_cache); + QCOMPARE(QFontPrivate::get(f2)->engineData->ref.loadRelaxed(), 1 + refs_by_cache); if (f.pointSize() > 0) f2.setPointSize(f.pointSize() * 2 / 3); else f2.setPixelSize(f.pixelSize() * 2 / 3); QVERIFY(QFontPrivate::get(f2) != QFontPrivate::get(f)); - QCOMPARE(QFontPrivate::get(f2)->ref.load(), 1); + QCOMPARE(QFontPrivate::get(f2)->ref.loadRelaxed(), 1); QVERIFY(!QFontPrivate::get(f2)->engineData); QVERIFY(QFontPrivate::get(f2)->engineData != QFontPrivate::get(f)->engineData); } diff --git a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp index 785cc3fef2..3d3211c7a2 100644 --- a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp +++ b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp @@ -217,7 +217,7 @@ void tst_QFontCache::clear() #ifdef QT_BUILD_INTERNAL QList<QFontEngine *> leakedEngines = QFontEngine_stopCollectingEngines(); -for (int i = 0; i < leakedEngines.size(); ++i) qWarning() << i << leakedEngines.at(i) << leakedEngines.at(i)->ref.load(); +for (int i = 0; i < leakedEngines.size(); ++i) qWarning() << i << leakedEngines.at(i) << leakedEngines.at(i)->ref.loadRelaxed(); // and we are not leaking! QCOMPARE(leakedEngines.size(), 0); #endif diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 97546c34fd..591fafc7fb 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -188,6 +188,9 @@ private slots: void lineHeightType(); void cssLineHeightMultiplier(); + + void fontTagFace(); + private: void backgroundImage_checkExpectedHtml(const QTextDocument &doc); void buildRegExpData(); @@ -319,6 +322,15 @@ void tst_QTextDocument::find_data() QTest::newRow("nbsp") << "Hello" + QString(QChar(QChar::Nbsp)) +"World" << " " << int(QTextDocument::FindCaseSensitively) << 0 << 5 << 6; QTest::newRow("from-the-end") << "Hello World" << "Hello World" << int(QTextDocument::FindCaseSensitively| QTextDocument::FindBackward) << 11 << 0 << 11; + + QTest::newRow("bw-cross-paras-1") << "a1\na2\nb1" << "a" << int(QTextDocument::FindBackward) << 7 << 3 << 4; + QTest::newRow("bw-cross-paras-2") << "a1\na2\nb1" << "a" << int(QTextDocument::FindBackward) << 6 << 3 << 4; + QTest::newRow("bw-cross-paras-3") << "a1\na2\nb1" << "a" << int(QTextDocument::FindBackward) << 5 << 3 << 4; + QTest::newRow("bw-cross-paras-4") << "a1\na2\nb1" << "a" << int(QTextDocument::FindBackward) << 3 << 0 << 1; + QTest::newRow("bw-cross-paras-5") << "xa\n\nb1" << "a" << int(QTextDocument::FindBackward) << 5 << 1 << 2; + QTest::newRow("bw-cross-paras-6") << "xa\n\nb1" << "a" << int(QTextDocument::FindBackward) << 4 << 1 << 2; + QTest::newRow("bw-cross-paras-7") << "xa\n\nb1" << "a" << int(QTextDocument::FindBackward) << 3 << 1 << 2; + QTest::newRow("bw-cross-paras-8") << "xa\n\nb1" << "a" << int(QTextDocument::FindBackward) << 2 << 1 << 2; } void tst_QTextDocument::find() @@ -855,6 +867,18 @@ void tst_QTextDocument::toHtml_data() { CREATE_DOC_AND_CURSOR(); + QTextCharFormat fmt; + fmt.setFontFamily("Times"); + fmt.setFontFamilies(QStringList{ "Times", "serif" }); + cursor.insertText("Blah", fmt); + + QTest::newRow("font-family-with-fallback") << QTextDocumentFragment(&doc) + << QString("<p DEFAULTBLOCKSTYLE><span style=\" font-family:'Times','serif';\">Blah</span></p>"); + } + + { + CREATE_DOC_AND_CURSOR(); + QTextBlockFormat fmt; fmt.setNonBreakableLines(true); cursor.insertBlock(fmt); @@ -3477,5 +3501,26 @@ void tst_QTextDocument::cssLineHeightMultiplier() } } +void tst_QTextDocument::fontTagFace() +{ + { + QTextDocument td; + td.setHtml("<html><body><font face='Times'>Foobar</font></body></html>"); + QTextFragment fragment = td.begin().begin().fragment(); + QTextCharFormat format = fragment.charFormat(); + QCOMPARE(format.fontFamily(), QLatin1String("Times")); + } + + { + QTextDocument td; + td.setHtml("<html><body><font face='Times, serif'>Foobar</font></body></html>"); + QTextFragment fragment = td.begin().begin().fragment(); + QTextCharFormat format = fragment.charFormat(); + QCOMPARE(format.fontFamily(), QLatin1String("Times")); + QStringList expectedFamilies = { QLatin1String("Times"), QLatin1String("serif") }; + QCOMPARE(format.fontFamilies().toStringList(), expectedFamilies); + } +} + QTEST_MAIN(tst_QTextDocument) #include "tst_qtextdocument.moc" diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp index 3a118f8c91..664ca98a3f 100644 --- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp +++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp @@ -34,6 +34,7 @@ #include <qtextdocumentfragment.h> #include <qtexttable.h> #include <qtextlist.h> +#include <qregularexpression.h> #include <qdebug.h> #include <private/qtextdocument_p.h> @@ -1925,7 +1926,7 @@ void tst_QTextDocumentFragment::html_nobr() QString text = doc->begin().begin().fragment().text(); QString expectedText = input; - expectedText.replace(QRegExp("\\s+"), QString(QChar::Nbsp)); + expectedText.replace(QRegularExpression("\\s+"), QString(QChar::Nbsp)); QCOMPARE(text, expectedText); } diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h index bf632c9846..77298342af 100644 --- a/tests/auto/network-settings.h +++ b/tests/auto/network-settings.h @@ -109,8 +109,8 @@ public: static bool compareReplyFtp(QByteArray const& actual) { // output would be e.g. "220 (vsFTPd 2.3.5)\r\n221 Goodbye.\r\n" - QRegExp ftpVersion(QStringLiteral("220 \\(vsFTPd \\d+\\.\\d+.\\d+\\)\\r\\n221 Goodbye.\\r\\n")); - return ftpVersion.exactMatch(actual); + QRegularExpression ftpVersion(QRegularExpression::anchoredPattern(QStringLiteral("220 \\(vsFTPd \\d+\\.\\d+.\\d+\\)\\r\\n221 Goodbye.\\r\\n"))); + return ftpVersion.match(actual).hasMatch(); } static bool hasIPv6() diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp index 53d0e7a694..e24370fc87 100644 --- a/tests/auto/network/access/http2/tst_http2.cpp +++ b/tests/auto/network/access/http2/tst_http2.cpp @@ -340,7 +340,7 @@ void tst_Http2::flowControlServerSide() clearHTTP2State(); serverPort = 0; - nRequests = 30; + nRequests = 10; const Http2::RawSettings serverSettings = {{Settings::MAX_CONCURRENT_STREAMS_ID, 7}}; diff --git a/tests/auto/network/access/qftp/tst_qftp.cpp b/tests/auto/network/access/qftp/tst_qftp.cpp index e07588d6c6..a04c2ae01d 100644 --- a/tests/auto/network/access/qftp/tst_qftp.cpp +++ b/tests/auto/network/access/qftp/tst_qftp.cpp @@ -43,6 +43,7 @@ #include <QtNetwork/private/qnetworksession_p.h> #include <QTcpServer> #include <QHostInfo> +#include <QElapsedTimer> #include <QTcpSocket> #include "../../../network-settings.h" @@ -2160,7 +2161,7 @@ void tst_QFtp::qtbug7359Crash() QFtp ftp; ftp.connectToHost("127.0.0.1"); - QTime t; + QElapsedTimer t; int elapsed; t.start(); @@ -2365,7 +2366,7 @@ void tst_QFtp::loginURL() ftp = newFtp(); addCommand(QFtp::ConnectToHost, - ftp->connectToHost(QHostInfo::localHostName(), port)); + ftp->connectToHost("127.0.0.1", port)); addCommand(QFtp::Login, ftp->login(user, password)); QTestEventLoop::instance().enterLoop(5); @@ -2373,7 +2374,7 @@ void tst_QFtp::loginURL() ftp = nullptr; server.stopServer(); if (QTestEventLoop::instance().timeout()) - QFAIL(msgTimedOut(QHostInfo::localHostName(), port)); + QFAIL(msgTimedOut("127.0.0.1", port)); QCOMPARE(server.getRawUser(), rawUser); QCOMPARE(server.getRawPassword(), rawPass); diff --git a/tests/auto/network/access/qnetworkreply/certs/qt-test-server-cacert.pem b/tests/auto/network/access/qnetworkreply/certs/qt-test-server-cacert.pem index 25bd4046e8..c5aea0d7c9 100644 --- a/tests/auto/network/access/qnetworkreply/certs/qt-test-server-cacert.pem +++ b/tests/auto/network/access/qnetworkreply/certs/qt-test-server-cacert.pem @@ -1,17 +1,17 @@ -----BEGIN CERTIFICATE----- -MIICrTCCAhYCCQCdDn5rci6VDjANBgkqhkiG9w0BAQQFADCBmjEOMAwGA1UEChMF -Tm9raWExFDASBgNVBAsTC1F0IFNvZnR3YXJlMSIwIAYJKoZIhvcNAQkBFhNub2Jv -ZHlAbm9kb21haW4ub3JnMQ0wCwYDVQQHEwRPc2xvMQ0wCwYDVQQIEwRPc2xvMQsw -CQYDVQQGEwJOTzEjMCEGA1UEAxMacXQtdGVzdC1zZXJ2ZXIucXQtdGVzdC1uZXQw -HhcNMDkwNzEwMDc0MTIzWhcNMTkwNzA4MDc0MTIzWjCBmjEOMAwGA1UEChMFTm9r -aWExFDASBgNVBAsTC1F0IFNvZnR3YXJlMSIwIAYJKoZIhvcNAQkBFhNub2JvZHlA -bm9kb21haW4ub3JnMQ0wCwYDVQQHEwRPc2xvMQ0wCwYDVQQIEwRPc2xvMQswCQYD -VQQGEwJOTzEjMCEGA1UEAxMacXQtdGVzdC1zZXJ2ZXIucXQtdGVzdC1uZXQwgZ8w -DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAM2q22/WNMmn8cC+5EEYGeICySLmp9W6 -Ay6eKHr0Xxp3X3epETuPfvAuxp7rOtkS18EMUegkUj8jw0IMEcbyHKFC/rTCaYOt -93CxGBXMIChiMPAsFeYzGa/D6xzAkfcRaJRQ+Ek3CDLXPnXfo7xpABXezYcPXAJr -gsgBfWrwHdxzAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAy7YOLCZABQy2Ygkchq1I -+TUpvMn+gLwAyW8TNErM1V4lNY2+K78RawzKx3SqM97ymCy4TD45EA3A2gmi32NI -xSKBNjFyzngUqsXBdcSasALiowlZCiJrGwlGX5qCkBlxXvJeUEbuJLPYVl5FBjXZ -6o00K4cSPCqtqUez7WSmDZU= +MIICpzCCAhACCQCzAF1hyRVzAjANBgkqhkiG9w0BAQUFADCBlzELMAkGA1UEBhMC +Tk8xDTALBgNVBAgTBE9zbG8xDTALBgNVBAcTBE9zbG8xDjAMBgNVBAoTBU5va2lh +MTUwMwYDVQQLFCxRdCBTb2Z0d2FyZS9lbWFpbEFkZHJlc3M9bm9ib2R5QG5vZG9t +YWluLm9yZzEjMCEGA1UEAxMacXQtdGVzdC1zZXJ2ZXIucXQtdGVzdC1uZXQwHhcN +MTkwNjI0MTI0OTIxWhcNMjIwNjIzMTI0OTIxWjCBlzELMAkGA1UEBhMCTk8xDTAL +BgNVBAgTBE9zbG8xDTALBgNVBAcTBE9zbG8xDjAMBgNVBAoTBU5va2lhMTUwMwYD +VQQLFCxRdCBTb2Z0d2FyZS9lbWFpbEFkZHJlc3M9bm9ib2R5QG5vZG9tYWluLm9y +ZzEjMCEGA1UEAxMacXQtdGVzdC1zZXJ2ZXIucXQtdGVzdC1uZXQwgZ8wDQYJKoZI +hvcNAQEBBQADgY0AMIGJAoGBAM2q22/WNMmn8cC+5EEYGeICySLmp9W6Ay6eKHr0 +Xxp3X3epETuPfvAuxp7rOtkS18EMUegkUj8jw0IMEcbyHKFC/rTCaYOt93CxGBXM +IChiMPAsFeYzGa/D6xzAkfcRaJRQ+Ek3CDLXPnXfo7xpABXezYcPXAJrgsgBfWrw +HdxzAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEASCKbqEX5ysC549mq90ydk4jyDW3m +PUyet01fKpcRqVs+OJxdExFBTra3gho6WzzpTSPsuX2ZKOLF5k6KkCvdCGvhC1Kv +HHPIExurfzvdlSRzj6HbKyPuSfxyOloH0bBp7/Gg5RIuBPKlbmfbnTLtwEjhhbMU +SoYI8HZd3HfY87c= -----END CERTIFICATE----- diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 550d80501e..1afd8af7b0 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -32,8 +32,11 @@ #include <QtCore/QDataStream> #include <QtCore/QUrl> #include <QtCore/QEventLoop> +#include <QtCore/QElapsedTimer> #include <QtCore/QFile> #include <QtCore/QRandomGenerator> +#include <QtCore/QRegularExpression> +#include <QtCore/QRegularExpressionMatch> #include <QtCore/QSharedPointer> #include <QtCore/QScopedPointer> #include <QtCore/QTemporaryFile> @@ -1147,7 +1150,7 @@ protected: } // now write in "blocking mode", this is where the rate measuring starts - QTime timer; + QElapsedTimer timer; timer.start(); //const qint64 writtenBefore = dataIndex; //qint64 measuredTotalBytes = wantedSize - writtenBefore; @@ -1246,7 +1249,7 @@ protected: } qint64 bytesRead = 0; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); do { if (device->bytesAvailable() == 0) { @@ -4147,10 +4150,10 @@ void tst_QNetworkReply::ioGetFromHttpWithCache() request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, false); QFETCH(QStringList, extraHttpHeaders); - QStringListIterator it(extraHttpHeaders); - while (it.hasNext()) { - QString header = it.next(); - QString value = it.next(); + QVERIFY(extraHttpHeaders.size() % 2 == 0); + for (auto it = extraHttpHeaders.cbegin(), end = extraHttpHeaders.cend(); it != end; /*double-stepping*/) { + QString header = *it++; + QString value = *it++; request.setRawHeader(header.toLatin1(), value.toLatin1()); // To latin1? Deal with it! } @@ -5148,8 +5151,8 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp() const int rate = 200; // in kB per sec RateControlledReader reader(server, reply.data(), rate, bufferSize); - QTime loopTime; - loopTime.start(); + QElapsedTimer loopTimer; + loopTimer.start(); const int result = waitForFinish(reply); if (notEnoughDataForFastSender) { @@ -5159,7 +5162,7 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp() QVERIFY2(result == Success, msgWaitForFinished(reply)); - const int elapsedTime = loopTime.elapsed(); + const int elapsedTime = loopTimer.elapsed(); server.wait(); reader.wrapUp(); @@ -5445,12 +5448,12 @@ void tst_QNetworkReply::rateControl() RateControlledReader reader(sender, reply.data(), rate, 20); // this test is designed to run for 25 seconds at most - QTime loopTime; - loopTime.start(); + QElapsedTimer loopTimer; + loopTimer.start(); QVERIFY2(waitForFinish(reply) == Success, msgWaitForFinished(reply)); - int elapsedTime = loopTime.elapsed(); + int elapsedTime = loopTimer.elapsed(); if (!errorSpy.isEmpty()) { qDebug() << "ERROR!" << errorSpy[0][0] << reply->errorString(); @@ -6120,8 +6123,8 @@ void tst_QNetworkReply::httpConnectionCount() } int pendingConnectionCount = 0; - QTime time; - time.start(); + QElapsedTimer timer; + timer.start(); while(pendingConnectionCount <= 20) { QTestEventLoop::instance().enterLoop(1); @@ -6133,7 +6136,7 @@ void tst_QNetworkReply::httpConnectionCount() } // at max. wait 10 sec - if (time.elapsed() > 10000) + if (timer.elapsed() > 10000) break; } @@ -7910,9 +7913,10 @@ void tst_QNetworkReply::synchronousAuthenticationCache() "Content-Type: text/plain\r\n" "\r\n" "auth"; - QRegExp rx("Authorization: Basic ([^\r\n]*)\r\n"); - if (rx.indexIn(receivedData) > 0) { - if (QByteArray::fromBase64(rx.cap(1).toLatin1()) == "login:password") { + QRegularExpression rx("Authorization: Basic ([^\r\n]*)\r\n"); + QRegularExpressionMatch match = rx.match(receivedData); + if (match.hasMatch()) { + if (QByteArray::fromBase64(match.captured(1).toLatin1()) == "login:password") { dataToTransmit = "HTTP/1.0 200 OK\r\n" "Content-Type: text/plain\r\n" diff --git a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp index 01168cc0d6..ffc63ee46a 100644 --- a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp +++ b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp @@ -32,7 +32,7 @@ #include <qcoreapplication.h> #include <qdatastream.h> #include <qhostaddress.h> -#include <qdatetime.h> +#include <qelapsedtimer.h> #ifdef Q_OS_UNIX #include <unistd.h> @@ -403,7 +403,7 @@ void tst_PlatformSocketEngine::udpLoopbackPerformance() QHostAddress localhost = QHostAddress::LocalHost; qlonglong readBytes = 0; - QTime timer; + QElapsedTimer timer; timer.start(); while (timer.elapsed() < 5000) { udpSocket2.write(message1.data(), message1.size()); @@ -462,7 +462,7 @@ void tst_PlatformSocketEngine::tcpLoopbackPerformance() QByteArray message1(messageSize, '@'); QByteArray answer(messageSize, '@'); - QTime timer; + QElapsedTimer timer; timer.start(); qlonglong readBytes = 0; while (timer.elapsed() < 5000) { diff --git a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp index cdc6fef663..64241014d7 100644 --- a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp +++ b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp @@ -38,6 +38,7 @@ #include <qhostaddress.h> #include <qtcpsocket.h> #include <qdebug.h> +#include <qelapsedtimer.h> #include <qtcpserver.h> #include "../../../network-settings.h" @@ -397,7 +398,7 @@ void tst_QHttpSocketEngine::tcpLoopbackPerformance() QByteArray message1(messageSize, '@'); QByteArray answer(messageSize, '@'); - QTime timer; + QElapsedTimer timer; timer.start(); qlonglong readBytes = 0; while (timer.elapsed() < 30000) { @@ -629,7 +630,7 @@ void tst_QHttpSocketEngine::downloadBigFile() bytesAvailable = 0; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); QTestEventLoop::instance().enterLoop(60); diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index f53c75c6a4..732f7eef00 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -32,6 +32,7 @@ #include <qtextstream.h> #include <qdatastream.h> +#include <qelapsedtimer.h> #include <QtNetwork/qlocalsocket.h> #include <QtNetwork/qlocalserver.h> @@ -1031,7 +1032,7 @@ void tst_QLocalSocket::waitForDisconnect() QLocalSocket *serverSocket = server.nextPendingConnection(); QVERIFY(serverSocket); socket.disconnectFromServer(); - QTime timer; + QElapsedTimer timer; timer.start(); QVERIFY(serverSocket->waitForDisconnected(3000)); QVERIFY(timer.elapsed() < 2000); diff --git a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp index 22ac9aa076..fc5a7d1fab 100644 --- a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp +++ b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp @@ -882,7 +882,7 @@ void tst_QTcpServer::serverAddress_data() QTest::addColumn<QHostAddress>("listenAddress"); QTest::addColumn<QHostAddress>("serverAddress"); #ifdef Q_OS_WIN - if (QSysInfo::windowsVersion() < QSysInfo::WV_6_0) + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::WindowsVista) QTest::newRow("Any") << QHostAddress(QHostAddress::Any) << QHostAddress(QHostAddress::AnyIPv4); //windows XP doesn't support dual stack sockets else #endif diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index abe9845213..7733b0a62b 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -66,7 +66,7 @@ #endif #include <QTextStream> #include <QThread> -#include <QTime> +#include <QElapsedTimer> #include <QTimer> #include <QDebug> // RVCT compiles also unused inline methods @@ -237,7 +237,6 @@ private: qint64 bytesAvailable; qint64 expectedLength; bool readingBody; - QTime timer; QByteArray expectedReplyIMAP_cached; @@ -327,8 +326,8 @@ void tst_QTcpSocket::initTestCase_data() QTest::addColumn<bool>("ssl"); QTest::newRow("WithoutProxy") << false << 0 << false; - //QTest::newRow("WithSocks5Proxy") << true << int(Socks5Proxy) << false; ### temporarily disabled, QTBUG-38385 - //QTest::newRow("WithSocks5ProxyAuth") << true << int(Socks5Proxy | AuthBasic) << false; ### temporarily disabled, QTBUG-38385 + QTest::newRow("WithSocks5Proxy") << true << int(Socks5Proxy) << false; + QTest::newRow("WithSocks5ProxyAuth") << true << int(Socks5Proxy | AuthBasic) << false; QTest::newRow("WithHttpProxy") << true << int(HttpProxy) << false; QTest::newRow("WithHttpProxyBasicAuth") << true << int(HttpProxy | AuthBasic) << false; @@ -336,8 +335,8 @@ void tst_QTcpSocket::initTestCase_data() #ifndef QT_NO_SSL QTest::newRow("WithoutProxy SSL") << false << 0 << true; - //QTest::newRow("WithSocks5Proxy SSL") << true << int(Socks5Proxy) << true; ### temporarily disabled, QTBUG-38385 - //QTest::newRow("WithSocks5AuthProxy SSL") << true << int(Socks5Proxy | AuthBasic) << true; ### temporarily disabled, QTBUG-38385 + QTest::newRow("WithSocks5Proxy SSL") << true << int(Socks5Proxy) << true; + QTest::newRow("WithSocks5AuthProxy SSL") << true << int(Socks5Proxy | AuthBasic) << true; QTest::newRow("WithHttpProxy SSL") << true << int(HttpProxy) << true; QTest::newRow("WithHttpProxyBasicAuth SSL") << true << int(HttpProxy | AuthBasic) << true; @@ -866,7 +865,8 @@ void tst_QTcpSocket::hostNotFound() QCOMPARE(socket->state(), QTcpSocket::UnconnectedState); #ifdef QT_TEST_SERVER QFETCH_GLOBAL(bool, setProxy); - if (setProxy) { + QFETCH_GLOBAL(int, proxyType); + if (setProxy && (proxyType & HttpProxy) == HttpProxy) { QEXPECT_FAIL("", "QTBUG-73953: The version of Squid in the docker container behaves " "differently to the one in the network testing server, returning 503 " "when we expect 404", Continue); @@ -1518,7 +1518,7 @@ void tst_QTcpSocket::downloadBigFile() expectedLength = 0; readingBody = false; - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); enterLoop(600); @@ -2482,7 +2482,7 @@ void tst_QTcpSocket::suddenRemoteDisconnect() QEventLoop loop; connect(&serverProcess, SIGNAL(finished(int)), &loop, SLOT(quit())); connect(&clientProcess, SIGNAL(finished(int)), &loop, SLOT(quit())); - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); QTimer::singleShot(20000, &loop, SLOT(quit())); @@ -2522,7 +2522,7 @@ void tst_QTcpSocket::connectToMultiIP() // rationale: this domain resolves to 3 A-records, 2 of them are // invalid. QTcpSocket should never spend more than 30 seconds per IP, and // 30s*2 = 60s. - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); socket->connectToHost("multi.dev.qt-project.org", 80); QVERIFY(socket->waitForConnected(60500)); @@ -2714,7 +2714,7 @@ void tst_QTcpSocket::taskQtBug5799ConnectionErrorWaitForConnected() QTcpSocket socket; socket.connectToHost(QtNetworkSettings::httpServerName(), 12346); - QTime timer; + QElapsedTimer timer; timer.start(); socket.waitForConnected(10000); QVERIFY2(timer.elapsed() < 9900, "Connection to closed port timed out instead of refusing, something is wrong"); diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index a4b22cb000..0f419e9de4 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -40,6 +40,7 @@ #include <qhostinfo.h> #include <qtcpsocket.h> #include <qmap.h> +#include <qelapsedtimer.h> #include <qnetworkdatagram.h> #include <QNetworkProxy> #include <QNetworkInterface> @@ -922,7 +923,7 @@ void tst_QUdpSocket::performance() client.connectToHost(serverAddress, server.localPort()); QVERIFY(client.waitForConnected(10000)); - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); qint64 nbytes = 0; diff --git a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp index 0c8535f2de..efc0c26076 100644 --- a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp +++ b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp @@ -401,9 +401,7 @@ void tst_QSslCertificate::subjectAlternativeNames() certificate.subjectAlternativeNames(); // verify that each entry in subjAltNames is present in fileContents - QMapIterator<QSsl::AlternativeNameEntryType, QString> it(altSubjectNames); - while (it.hasNext()) { - it.next(); + for (auto it = altSubjectNames.cbegin(), end = altSubjectNames.cend(); it != end; ++it) { QByteArray type; if (it.key() == QSsl::EmailEntry) type = "email"; diff --git a/tests/auto/network/ssl/qsslsocket/certs/qt-test-server-cacert.pem b/tests/auto/network/ssl/qsslsocket/certs/qt-test-server-cacert.pem index 25bd4046e8..c5aea0d7c9 100644 --- a/tests/auto/network/ssl/qsslsocket/certs/qt-test-server-cacert.pem +++ b/tests/auto/network/ssl/qsslsocket/certs/qt-test-server-cacert.pem @@ -1,17 +1,17 @@ -----BEGIN CERTIFICATE----- -MIICrTCCAhYCCQCdDn5rci6VDjANBgkqhkiG9w0BAQQFADCBmjEOMAwGA1UEChMF -Tm9raWExFDASBgNVBAsTC1F0IFNvZnR3YXJlMSIwIAYJKoZIhvcNAQkBFhNub2Jv -ZHlAbm9kb21haW4ub3JnMQ0wCwYDVQQHEwRPc2xvMQ0wCwYDVQQIEwRPc2xvMQsw -CQYDVQQGEwJOTzEjMCEGA1UEAxMacXQtdGVzdC1zZXJ2ZXIucXQtdGVzdC1uZXQw -HhcNMDkwNzEwMDc0MTIzWhcNMTkwNzA4MDc0MTIzWjCBmjEOMAwGA1UEChMFTm9r -aWExFDASBgNVBAsTC1F0IFNvZnR3YXJlMSIwIAYJKoZIhvcNAQkBFhNub2JvZHlA -bm9kb21haW4ub3JnMQ0wCwYDVQQHEwRPc2xvMQ0wCwYDVQQIEwRPc2xvMQswCQYD -VQQGEwJOTzEjMCEGA1UEAxMacXQtdGVzdC1zZXJ2ZXIucXQtdGVzdC1uZXQwgZ8w -DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAM2q22/WNMmn8cC+5EEYGeICySLmp9W6 -Ay6eKHr0Xxp3X3epETuPfvAuxp7rOtkS18EMUegkUj8jw0IMEcbyHKFC/rTCaYOt -93CxGBXMIChiMPAsFeYzGa/D6xzAkfcRaJRQ+Ek3CDLXPnXfo7xpABXezYcPXAJr -gsgBfWrwHdxzAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAy7YOLCZABQy2Ygkchq1I -+TUpvMn+gLwAyW8TNErM1V4lNY2+K78RawzKx3SqM97ymCy4TD45EA3A2gmi32NI -xSKBNjFyzngUqsXBdcSasALiowlZCiJrGwlGX5qCkBlxXvJeUEbuJLPYVl5FBjXZ -6o00K4cSPCqtqUez7WSmDZU= +MIICpzCCAhACCQCzAF1hyRVzAjANBgkqhkiG9w0BAQUFADCBlzELMAkGA1UEBhMC +Tk8xDTALBgNVBAgTBE9zbG8xDTALBgNVBAcTBE9zbG8xDjAMBgNVBAoTBU5va2lh +MTUwMwYDVQQLFCxRdCBTb2Z0d2FyZS9lbWFpbEFkZHJlc3M9bm9ib2R5QG5vZG9t +YWluLm9yZzEjMCEGA1UEAxMacXQtdGVzdC1zZXJ2ZXIucXQtdGVzdC1uZXQwHhcN +MTkwNjI0MTI0OTIxWhcNMjIwNjIzMTI0OTIxWjCBlzELMAkGA1UEBhMCTk8xDTAL +BgNVBAgTBE9zbG8xDTALBgNVBAcTBE9zbG8xDjAMBgNVBAoTBU5va2lhMTUwMwYD +VQQLFCxRdCBTb2Z0d2FyZS9lbWFpbEFkZHJlc3M9bm9ib2R5QG5vZG9tYWluLm9y +ZzEjMCEGA1UEAxMacXQtdGVzdC1zZXJ2ZXIucXQtdGVzdC1uZXQwgZ8wDQYJKoZI +hvcNAQEBBQADgY0AMIGJAoGBAM2q22/WNMmn8cC+5EEYGeICySLmp9W6Ay6eKHr0 +Xxp3X3epETuPfvAuxp7rOtkS18EMUegkUj8jw0IMEcbyHKFC/rTCaYOt93CxGBXM +IChiMPAsFeYzGa/D6xzAkfcRaJRQ+Ek3CDLXPnXfo7xpABXezYcPXAJrgsgBfWrw +HdxzAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEASCKbqEX5ysC549mq90ydk4jyDW3m +PUyet01fKpcRqVs+OJxdExFBTra3gho6WzzpTSPsuX2ZKOLF5k6KkCvdCGvhC1Kv +HHPIExurfzvdlSRzj6HbKyPuSfxyOloH0bBp7/Gg5RIuBPKlbmfbnTLtwEjhhbMU +SoYI8HZd3HfY87c= -----END CERTIFICATE----- diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index 7912063bc8..4035dfbf5f 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -29,6 +29,7 @@ #include <QtCore/qglobal.h> #include <QtCore/qthread.h> +#include <QtCore/qelapsedtimer.h> #include <QtNetwork/qhostaddress.h> #include <QtNetwork/qhostinfo.h> #include <QtNetwork/qnetworkproxy.h> @@ -710,7 +711,7 @@ void tst_QSslSocket::sslErrors() const auto socketSslErrors = socket->sslErrors(); for (const QSslError &err : socketSslErrors) sslErrors << err.error(); - qSort(sslErrors); + std::sort(sslErrors.begin(), sslErrors.end()); QVERIFY(sslErrors.contains(QSslError::HostNameMismatch)); QVERIFY(sslErrors.contains(FLUKE_CERTIFICATE_ERROR)); @@ -720,7 +721,7 @@ void tst_QSslSocket::sslErrors() const auto sslErrorsSpyErrors = qvariant_cast<QList<QSslError> >(qAsConst(sslErrorsSpy).first().first()); for (const QSslError &err : sslErrorsSpyErrors) emittedErrors << err.error(); - qSort(emittedErrors); + std::sort(emittedErrors.begin(), emittedErrors.end()); QCOMPARE(sslErrors, emittedErrors); // check the same errors were emitted by peerVerifyError @@ -729,7 +730,7 @@ void tst_QSslSocket::sslErrors() const QList<QVariantList> &peerVerifyList = peerVerifyErrorSpy; for (const QVariantList &args : peerVerifyList) peerErrors << qvariant_cast<QSslError>(args.first()).error(); - qSort(peerErrors); + std::sort(peerErrors.begin(), peerErrors.end()); QCOMPARE(sslErrors, peerErrors); } @@ -1989,7 +1990,7 @@ public slots: QTestEventLoop::instance().exitLoop(); } void waitSomeMore(QSslSocket *socket) { - QTime t; + QElapsedTimer t; t.start(); while (!socket->encryptedBytesAvailable()) { QCoreApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents, 250); @@ -2754,6 +2755,7 @@ void tst_QSslSocket::encryptWithoutConnecting() void tst_QSslSocket::resume_data() { + QSKIP("Temporary skip while updating certificates"); QTest::addColumn<bool>("ignoreErrorsAfterPause"); QTest::addColumn<QList<QSslError> >("errorsToIgnore"); QTest::addColumn<bool>("expectSuccess"); @@ -3591,12 +3593,7 @@ protected: socket = new QSslSocket(this); socket->setSslConfiguration(config); socket->setPeerVerifyMode(peerVerifyMode); - if (QSslSocket::sslLibraryVersionNumber() > 0x10101000L) { - // FIXME. With OpenSSL 1.1.1 and TLS 1.3 PSK auto-test is broken. - socket->setProtocol(QSsl::TlsV1_2); - } else { - socket->setProtocol(protocol); - } + socket->setProtocol(protocol); if (ignoreSslErrors) connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(ignoreErrorSlot())); @@ -3940,11 +3937,6 @@ void tst_QSslSocket::pskServer() return; QSslSocket socket; -#ifdef TLS1_3_VERSION - // FIXME: with OpenSSL 1.1.1 (thus TLS 1.3) test is known to fail - // due to the different PSK mechanism (?) - to be investigated ASAP. - socket.setProtocol(QSsl::TlsV1_2); -#endif this->socket = &socket; QSignalSpy connectedSpy(&socket, SIGNAL(connected())); diff --git a/tests/auto/opengl/qglthreads/tst_qglthreads.cpp b/tests/auto/opengl/qglthreads/tst_qglthreads.cpp index b7b5b505a0..8a38d0f517 100644 --- a/tests/auto/opengl/qglthreads/tst_qglthreads.cpp +++ b/tests/auto/opengl/qglthreads/tst_qglthreads.cpp @@ -33,6 +33,7 @@ #include <qpa/qplatformintegration.h> #include <QtWidgets/QApplication> #include <QtOpenGL/QtOpenGL> +#include <qelapsedtimer.h> #include "tst_qglthreads.h" #ifndef QT_OPENGL_ES_2 @@ -74,9 +75,9 @@ public: } void run() { - QTime time; - time.start(); - while (time.elapsed() < RUNNING_TIME) { + QElapsedTimer timer; + timer.start(); + while (timer.elapsed() < RUNNING_TIME) { lock(); waitForReadyToSwap(); @@ -291,11 +292,11 @@ public: } void run() { - QTime time; - time.start(); + QElapsedTimer timer; + timer.start(); failure = false; - while (time.elapsed() < RUNNING_TIME && !failure) { + while (timer.elapsed() < RUNNING_TIME && !failure) { m_widget->makeCurrent(); @@ -466,13 +467,13 @@ public: public slots: void draw() { bool beginFailed = false; - QTime time; - time.start(); + QElapsedTimer timer; + timer.start(); int rotAngle = 10; device->prepareDevice(); QPaintDevice *paintDevice = device->realPaintDevice(); QSize s(paintDevice->width(), paintDevice->height()); - while (time.elapsed() < RUNNING_TIME) { + while (timer.elapsed() < RUNNING_TIME) { QPainter p; if (!p.begin(paintDevice)) { beginFailed = true; diff --git a/tests/auto/other/compiler/tst_compiler.cpp b/tests/auto/other/compiler/tst_compiler.cpp index b2b45bb237..de15f4c62d 100644 --- a/tests/auto/other/compiler/tst_compiler.cpp +++ b/tests/auto/other/compiler/tst_compiler.cpp @@ -842,7 +842,7 @@ void tst_Compiler::cxx11_constexpr() static constexpr QBasicAtomicInt atomic = Q_BASIC_ATOMIC_INITIALIZER(1); static constexpr int i = constexprValue(); QCOMPARE(i, constexprValue()); - QCOMPARE(atomic.load(), 1); + QCOMPARE(atomic.loadRelaxed(), 1); #endif } diff --git a/tests/auto/other/lancelot/paintcommands.h b/tests/auto/other/lancelot/paintcommands.h index 2923502e68..79bdab634a 100644 --- a/tests/auto/other/lancelot/paintcommands.h +++ b/tests/auto/other/lancelot/paintcommands.h @@ -37,7 +37,6 @@ #include <qpixmap.h> #include <qbrush.h> #include <qhash.h> -#include <qregexp.h> QT_FORWARD_DECLARE_CLASS(QPainter) #ifndef QT_NO_OPENGL diff --git a/tests/auto/other/lancelot/scripts/degeneratebeziers.qps b/tests/auto/other/lancelot/scripts/degeneratebeziers.qps index 6c069fd82f..948968b0cd 100644 --- a/tests/auto/other/lancelot/scripts/degeneratebeziers.qps +++ b/tests/auto/other/lancelot/scripts/degeneratebeziers.qps @@ -34,3 +34,14 @@ setPen blue 40 solidline roundcap drawPath revbez setPen red 0 drawPath revbez + +resetMatrix +path_lineTo tightJoin 60 10 +path_cubicTo tightJoin 50 0 100 0 100 50 + +translate 50 500 + +setPen green 40 solidline roundcap roundjoin +drawPath tightJoin +setPen red 0 +drawPath tightJoin diff --git a/tests/auto/other/networkselftest/tst_networkselftest.cpp b/tests/auto/other/networkselftest/tst_networkselftest.cpp index dc353d2090..1b125d8825 100644 --- a/tests/auto/other/networkselftest/tst_networkselftest.cpp +++ b/tests/auto/other/networkselftest/tst_networkselftest.cpp @@ -29,6 +29,7 @@ #include <QtTest/QtTest> #include <QtNetwork/QtNetwork> #include <QtCore/QDateTime> +#include <QtCore/QElapsedTimer> #include <QtCore/QTextStream> #include <QtCore/QRandomGenerator> #include <QtCore/QStandardPaths> @@ -195,7 +196,7 @@ static bool doSocketFlush(QTcpSocket *socket, int timeout = 4000) #ifndef QT_NO_SSL QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket); #endif - QTime timer; + QElapsedTimer timer; timer.start(); int t = timeout; forever { @@ -421,7 +422,7 @@ void tst_NetworkSelfTest::serverReachability() QTcpSocket socket; socket.connectToHost(QtNetworkSettings::serverName(), 12346); - QTime timer; + QElapsedTimer timer; timer.start(); socket.waitForConnected(10000); QVERIFY2(timer.elapsed() < 9900, "Connection to closed port timed out instead of refusing, something is wrong"); diff --git a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp index fc979bce2d..c8698242d5 100644 --- a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp +++ b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.cpp @@ -80,13 +80,9 @@ qint64 DynamicTreeModel::findParentId(qint64 searchId) const if (searchId <= 0) return -1; - QHashIterator<qint64, QList<QList<qint64> > > i(m_childItems); - while (i.hasNext()) { - i.next(); - QListIterator<QList<qint64> > j(i.value()); - while (j.hasNext()) { - QList<qint64> l = j.next(); - if (l.contains(searchId)) + for (auto i = m_childItems.cbegin(), end = m_childItems.cend(); i != end; ++i) { + for (const auto &list : i.value()) { + if (list.contains(searchId)) return i.key(); } } @@ -163,13 +159,12 @@ ModelChangeCommand::ModelChangeCommand(DynamicTreeModel *model, QObject *parent) { } -QModelIndex ModelChangeCommand::findIndex(QList<int> rows) +QModelIndex ModelChangeCommand::findIndex(const QList<int> &rows) const { const int col = 0; QModelIndex parent = QModelIndex(); - QListIterator<int> i(rows); - while (i.hasNext()) { - parent = m_model->index(i.next(), col, parent); + for (int row : rows) { + parent = m_model->index(row, col, parent); if (!parent.isValid()) qFatal("%s: parent must be valid", Q_FUNC_INFO); } diff --git a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h index 709751dd27..0807ffbe94 100644 --- a/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h +++ b/tests/auto/other/qabstractitemmodelutils/dynamictreemodel.h @@ -97,7 +97,7 @@ public: m_rowNumbers = rowNumbers; } - QModelIndex findIndex(QList<int> rows); + QModelIndex findIndex(const QList<int> &rows) const; void setStartRow(int row) { diff --git a/tests/auto/other/qobjectrace/tst_qobjectrace.cpp b/tests/auto/other/qobjectrace/tst_qobjectrace.cpp index 22782f6b09..e09d304ff3 100644 --- a/tests/auto/other/qobjectrace/tst_qobjectrace.cpp +++ b/tests/auto/other/qobjectrace/tst_qobjectrace.cpp @@ -85,7 +85,7 @@ class RaceThread : public QThread { Q_OBJECT RaceObject *object; - QTime stopWatch; + QElapsedTimer stopWatch; public: RaceThread() @@ -414,7 +414,7 @@ void tst_QObjectRace::disconnectRace() { enum { ThreadCount = 20, TimeLimit = 3000 }; - QCOMPARE(countedStructObjectsCount.load(), 0u); + QCOMPARE(countedStructObjectsCount.loadRelaxed(), 0u); { QScopedPointer<DisconnectRaceSenderObject> sender(new DisconnectRaceSenderObject()); @@ -440,7 +440,7 @@ void tst_QObjectRace::disconnectRace() QVERIFY(senderThread->wait()); } - QCOMPARE(countedStructObjectsCount.load(), 0u); + QCOMPARE(countedStructObjectsCount.loadRelaxed(), 0u); { QScopedPointer<DisconnectRaceSenderObject> sender(new DisconnectRaceSenderObject()); @@ -466,7 +466,7 @@ void tst_QObjectRace::disconnectRace() } } - QCOMPARE(countedStructObjectsCount.load(), 0u); + QCOMPARE(countedStructObjectsCount.loadRelaxed(), 0u); } QTEST_MAIN(tst_QObjectRace) diff --git a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp index 99083242be..d1b4ed8bcd 100644 --- a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp +++ b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp @@ -94,17 +94,16 @@ QString tst_QPrinterInfo::getDefaultPrinterFromSystem() command << "lpstat" << "-d"; QString output = getOutputFromCommand(command); - QRegExp noDefaultReg("[^:]*no .*default"); - int pos = noDefaultReg.indexIn(output); - if (pos >= 0) { + QRegularExpression noDefaultReg("[^:]*no .*default"); + QRegularExpressionMatch match; + match = noDefaultReg.match(output); + if (match.hasMatch()) return QString(); - } - QRegExp defaultReg("default.*: *([a-zA-Z0-9_-]+)"); - defaultReg.indexIn(output); - printer = defaultReg.cap(1); + QRegularExpression defaultReg("default.*: *([a-zA-Z0-9_-]+)"); + match = defaultReg.match(output); + printer = match.captured(1); #endif // Q_OS_UNIX - return printer; } @@ -121,10 +120,12 @@ QStringList tst_QPrinterInfo::getPrintersFromSystem() QString output = getOutputFromCommand(command); QStringList list = output.split(QChar::fromLatin1('\n')); - QRegExp reg("^[Pp]rinter ([.a-zA-Z0-9-_@]+)"); + QRegularExpression reg("^[Pp]rinter ([.a-zA-Z0-9-_@]+)"); + QRegularExpressionMatch match; for (int c = 0; c < list.size(); ++c) { - if (reg.indexIn(list[c]) >= 0) { - QString printer = reg.cap(1); + match = reg.match(list[c]); + if (match.hasMatch()) { + QString printer = match.captured(1); ans << printer; } } diff --git a/tests/auto/shared/highdpi.h b/tests/auto/shared/highdpi.h new file mode 100644 index 0000000000..f0c34bea25 --- /dev/null +++ b/tests/auto/shared/highdpi.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef HIGHDPI_H +#define HIGHDPI_H + +#include <QtCore/qbytearray.h> +#include <QtCore/qpoint.h> +#include <QtCore/qrect.h> +#include <QtCore/qsize.h> + +// Helpers for comparing geometries a that may go through scaling in the +// platform plugin with fuzz (pass rounded-down device pixel ratios or +// scaling factors). Error message for use with QVERIFY2() are also provided. + +class HighDpi +{ +public: + HighDpi() = delete; + HighDpi(const HighDpi &) = delete; + HighDpi &operator=(const HighDpi &) = delete; + HighDpi(HighDpi &&) = delete; + HighDpi &operator=(HighDpi &&) = delete; + ~HighDpi() = delete; + + static int manhattanDelta(const QPoint &p1, const QPoint p2) + { + return (p1 - p2).manhattanLength(); + } + + static bool fuzzyCompare(const QPoint &p1, const QPoint p2, int fuzz) + { + return manhattanDelta(p1, p2) <= fuzz; + } + + static QByteArray msgPointMismatch(const QPoint &p1, const QPoint p2) + { + return QByteArray::number(p1.x()) + ',' + QByteArray::number(p1.y()) + + " != " + QByteArray::number(p2.x()) + ',' + QByteArray::number(p2.y()) + + ", manhattanLength=" + QByteArray::number(manhattanDelta(p1, p2)); + } + + // Compare a size that may go through scaling in the platform plugin with fuzz. + + static inline int manhattanDelta(const QSize &s1, const QSize &s2) + { + return qAbs(s1.width() - s2.width()) + qAbs(s1.height() - s2.height()); + } + + static inline bool fuzzyCompare(const QSize &s1, const QSize &s2, int fuzz) + { + return manhattanDelta(s1, s2) <= fuzz; + } + + static QByteArray msgSizeMismatch(const QSize &s1, const QSize &s2) + { + return QByteArray::number(s1.width()) + 'x' + QByteArray::number(s1.height()) + + " != " + QByteArray::number(s2.width()) + 'x' + QByteArray::number(s2.height()) + + ", manhattanLength=" + QByteArray::number(manhattanDelta(s1, s2)); + } + + // Compare a geometry that may go through scaling in the platform plugin with fuzz. + + static inline bool fuzzyCompare(const QRect &r1, const QRect &r2, int fuzz) + { + return manhattanDelta(r1.topLeft(), r2.topLeft()) <= fuzz + && manhattanDelta(r1.size(), r2.size()) <= fuzz; + } + + static QByteArray msgRectMismatch(const QRect &r1, const QRect &r2) + { + return formatRect(r1) + " != " + formatRect(r2); + } + +private: + static QByteArray formatRect(const QRect &r) + { + return QByteArray::number(r.width()) + 'x' + QByteArray::number(r.height()) + + (r.left() < 0 ? '-' : '+') + QByteArray::number(r.left()) + + (r.top() < 0 ? '-' : '+') + QByteArray::number(r.top()); + } +}; + +#endif // HIGHDPI_H diff --git a/tests/auto/sql/kernel/qsqlthread/tst_qsqlthread.cpp b/tests/auto/sql/kernel/qsqlthread/tst_qsqlthread.cpp index 09a842eb83..aa2cc05b56 100644 --- a/tests/auto/sql/kernel/qsqlthread/tst_qsqlthread.cpp +++ b/tests/auto/sql/kernel/qsqlthread/tst_qsqlthread.cpp @@ -345,7 +345,7 @@ void tst_QSqlThread::cleanupTestCase() void tst_QSqlThread::init() { threadFinishedCount = 0; - counter.store(4); + counter.storeRelaxed(4); } void tst_QSqlThread::cleanup() diff --git a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp index b617151a36..44dd4a74cf 100644 --- a/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp @@ -32,6 +32,7 @@ #include <QtSql> #include <QtSql/private/qsqltablemodel_p.h> #include <QThread> +#include <QElapsedTimer> const QString test(qTableName("test", __FILE__, QSqlDatabase())), test2(qTableName("test2", __FILE__, QSqlDatabase())), @@ -1804,12 +1805,12 @@ void tst_QSqlTableModel::sqlite_bigTable() QSqlQuery q(db); QVERIFY_SQL( q, exec("create table "+bigtable+"(id int primary key, name varchar)")); QVERIFY_SQL( q, prepare("insert into "+bigtable+"(id, name) values (?, ?)")); - QTime startTime; - startTime.start(); + QElapsedTimer timing; + timing.start(); for (int i = 0; i < 10000; ++i) { q.addBindValue(i); q.addBindValue(QString::number(i)); - if(i%1000 == 0 && startTime.elapsed() > 5000) + if (i % 1000 == 0 && timing.elapsed() > 5000) qDebug() << i << "records written"; QVERIFY_SQL( q, exec()); } diff --git a/tests/auto/testlib/qabstractitemmodeltester/tst_qabstractitemmodeltester.cpp b/tests/auto/testlib/qabstractitemmodeltester/tst_qabstractitemmodeltester.cpp index 60aa350145..b305eee0ec 100644 --- a/tests/auto/testlib/qabstractitemmodeltester/tst_qabstractitemmodeltester.cpp +++ b/tests/auto/testlib/qabstractitemmodeltester/tst_qabstractitemmodeltester.cpp @@ -63,7 +63,7 @@ void tst_QAbstractItemModelTester::stringListModel() model.setStringList(QStringList() << "a" << "e" << "plop" << "b" << "c"); proxy.setDynamicSortFilter(true); - proxy.setFilterRegExp(QRegExp("[^b]")); + proxy.setFilterRegularExpression(QRegularExpression("[^b]")); } void tst_QAbstractItemModelTester::treeWidgetModel() diff --git a/tests/auto/testlib/selftests/sleep/tst_sleep.cpp b/tests/auto/testlib/selftests/sleep/tst_sleep.cpp index b7b141afd0..95cb68521d 100644 --- a/tests/auto/testlib/selftests/sleep/tst_sleep.cpp +++ b/tests/auto/testlib/selftests/sleep/tst_sleep.cpp @@ -28,6 +28,7 @@ #include <QtCore/QCoreApplication> +#include <QtCore/QElapsedTimer> #include <QtTest/QtTest> class tst_Sleep: public QObject @@ -41,7 +42,7 @@ private slots: void tst_Sleep::sleep() { - QTime t; + QElapsedTimer t; t.start(); QTest::qSleep(100); diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index ec4a44e672..b88d929ca9 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -149,6 +149,17 @@ namespace TestQNamespace { Q_FLAG_NS(TestFlag2) } + +#define TESTEXPORTMACRO Q_DECL_EXPORT + +namespace TestExportNamespace { + Q_NAMESPACE_EXPORT(TESTEXPORTMACRO) + enum class MyEnum { + Key1, Key2 + }; + Q_ENUM_NS(MyEnum) +} + QT_USE_NAMESPACE template <bool b> struct QTBUG_31218 {}; @@ -3893,6 +3904,10 @@ void tst_Moc::testQNamespace() QCOMPARE(meta.enclosingMetaObject(), &TestQNamespace::staticMetaObject); QCOMPARE(meta.keyCount(), 2); + QCOMPARE(TestExportNamespace::staticMetaObject.enumeratorCount(), 1); + checkEnum(TestExportNamespace::staticMetaObject.enumerator(0), "MyEnum", + {{"Key1", 0}, {"Key2", 1}}); + QCOMPARE(FooNamespace::staticMetaObject.enumeratorCount(), 1); QCOMPARE(FooNamespace::FooNestedNamespace::staticMetaObject.enumeratorCount(), 2); QCOMPARE(FooNamespace::FooNestedNamespace::FooMoreNestedNamespace::staticMetaObject.enumeratorCount(), 1); diff --git a/tests/auto/tools/qmake/tst_qmake.cpp b/tests/auto/tools/qmake/tst_qmake.cpp index cacee30c86..1df31904d6 100644 --- a/tests/auto/tools/qmake/tst_qmake.cpp +++ b/tests/auto/tools/qmake/tst_qmake.cpp @@ -422,7 +422,7 @@ void tst_qmake::prompt() { #if 0 QProcess qmake; - qmake.setReadChannelMode(QProcess::MergedChannels); + qmake.setProcessChannelMode(QProcess::MergedChannels); qmake.setWorkingDirectory(QLatin1String("testdata/prompt")); qmake.start(QLatin1String("qmake CONFIG-=debug_and_release CONFIG-=debug CONFIG+=release"), QIODevice::Text | QIODevice::ReadWrite); diff --git a/tests/auto/tools/rcc/data/depfile/simple.d.expected b/tests/auto/tools/rcc/data/depfile/simple.d.expected new file mode 100644 index 0000000000..a89b61bdc7 --- /dev/null +++ b/tests/auto/tools/rcc/data/depfile/simple.d.expected @@ -0,0 +1 @@ +simple.qrc.cpp: ../images/images/circle.png ../images/images/square.png diff --git a/tests/auto/tools/rcc/data/depfile/simple.qrc b/tests/auto/tools/rcc/data/depfile/simple.qrc new file mode 100644 index 0000000000..521dc4d4a0 --- /dev/null +++ b/tests/auto/tools/rcc/data/depfile/simple.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>../images/images/circle.png</file> + <file>../images/images/square.png</file> +</qresource> +</RCC> diff --git a/tests/auto/tools/rcc/data/depfile/specialchar$file.txt b/tests/auto/tools/rcc/data/depfile/specialchar$file.txt new file mode 100644 index 0000000000..5da849b5c6 --- /dev/null +++ b/tests/auto/tools/rcc/data/depfile/specialchar$file.txt @@ -0,0 +1 @@ +ABC diff --git a/tests/auto/tools/rcc/data/depfile/specialchar.d.expected b/tests/auto/tools/rcc/data/depfile/specialchar.d.expected new file mode 100644 index 0000000000..9dd1af0958 --- /dev/null +++ b/tests/auto/tools/rcc/data/depfile/specialchar.d.expected @@ -0,0 +1 @@ +specialchar.qrc.cpp: specialchar$$file.txt ../images/images/subdir/triangle.png diff --git a/tests/auto/tools/rcc/data/depfile/specialchar.qrc b/tests/auto/tools/rcc/data/depfile/specialchar.qrc new file mode 100644 index 0000000000..133cbc7655 --- /dev/null +++ b/tests/auto/tools/rcc/data/depfile/specialchar.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>../images/images/subdir/triangle.png</file> + <file>specialchar$file.txt</file> +</qresource> +</RCC> diff --git a/tests/auto/tools/rcc/tst_rcc.cpp b/tests/auto/tools/rcc/tst_rcc.cpp index 24fd79cf19..42a4134e5f 100644 --- a/tests/auto/tools/rcc/tst_rcc.cpp +++ b/tests/auto/tools/rcc/tst_rcc.cpp @@ -89,6 +89,9 @@ private slots: void readback_data(); void readback(); + void depFileGeneration_data(); + void depFileGeneration(); + void python(); void cleanupTestCase(); @@ -416,6 +419,49 @@ void tst_rcc::readback() QCOMPARE(resourceData, fileSystemData); } +void tst_rcc::depFileGeneration_data() +{ + QTest::addColumn<QString>("qrcfile"); + QTest::addColumn<QString>("depfile"); + QTest::addColumn<QString>("expected"); + + QTest::newRow("simple") << "simple.qrc" << "simple.d" << "simple.d.expected"; + QTest::newRow("specialchar") << "specialchar.qrc" << "specialchar.d" << "specialchar.d.expected"; +} + +void tst_rcc::depFileGeneration() +{ + QFETCH(QString, qrcfile); + QFETCH(QString, depfile); + QFETCH(QString, expected); + const QString directory = m_dataPath + QLatin1String("/depfile"); + + QProcess process; + process.setWorkingDirectory(directory); + process.start(m_rcc, { "-d", depfile, "-o", qrcfile + ".cpp", qrcfile }); + QVERIFY2(process.waitForStarted(), msgProcessStartFailed(process).constData()); + if (!process.waitForFinished()) { + process.kill(); + QFAIL(msgProcessTimeout(process).constData()); + } + QVERIFY2(process.exitStatus() == QProcess::NormalExit, + msgProcessCrashed(process).constData()); + QVERIFY2(process.exitCode() == 0, + msgProcessFailed(process).constData()); + + QFile depFileOutput(directory + QLatin1String("/") + depfile); + QVERIFY(depFileOutput.open(QIODevice::ReadOnly | QIODevice::Text)); + QByteArray depFileData = depFileOutput.readAll(); + depFileOutput.close(); + + QFile depFileExpected(directory + QLatin1String("/") + expected); + QVERIFY(depFileExpected.open(QIODevice::ReadOnly | QIODevice::Text)); + QByteArray expectedData = depFileExpected.readAll(); + depFileExpected.close(); + + QCOMPARE(depFileData, expectedData); +} + void tst_rcc::python() { const QString path = m_dataPath + QLatin1String("/sizes"); @@ -450,6 +496,8 @@ void tst_rcc::cleanupTestCase() { QDir dataDir(m_dataPath + QLatin1String("/binary")); QFileInfoList entries = dataDir.entryInfoList(QStringList() << QLatin1String("*.rcc")); + QDir dataDepDir(m_dataPath + QLatin1String("/depfile")); + entries += dataDepDir.entryInfoList({QLatin1String("*.d"), QLatin1String("*.qrc.cpp")}); foreach (const QFileInfo &entry, entries) QFile::remove(entry.absoluteFilePath()); } diff --git a/tests/auto/tools/uic/baseline/dialog.ui b/tests/auto/tools/uic/baseline/dialog.ui index e99d6fb3c4..936cc2eee8 100644 --- a/tests/auto/tools/uic/baseline/dialog.ui +++ b/tests/auto/tools/uic/baseline/dialog.ui @@ -1,4 +1,4 @@ -<ui version="4.0" > +<ui version="4.0" connectslotsbyname="false"> <class>Dialog</class> <widget class="QDialog" name="Dialog" > <property name="geometry" > diff --git a/tests/auto/tools/uic/baseline/dialog.ui.h b/tests/auto/tools/uic/baseline/dialog.ui.h index aeed71d058..cd6449873e 100644 --- a/tests/auto/tools/uic/baseline/dialog.ui.h +++ b/tests/auto/tools/uic/baseline/dialog.ui.h @@ -52,8 +52,6 @@ public: retranslateUi(Dialog); - - QMetaObject::connectSlotsByName(Dialog); } // setupUi void retranslateUi(QDialog *Dialog) diff --git a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp index afe49368ae..c840dabc1a 100644 --- a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp +++ b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp @@ -26,6 +26,7 @@ ** ****************************************************************************/ +#include "../../../shared/highdpi.h" #include <QtTest/QtTest> @@ -388,8 +389,10 @@ void tst_QDialog::toolDialogPosition() dialog.move(QPoint(100,100)); const QPoint beforeShowPosition = dialog.pos(); dialog.show(); + const int fuzz = int(dialog.devicePixelRatioF()); const QPoint afterShowPosition = dialog.pos(); - QCOMPARE(afterShowPosition, beforeShowPosition); + QVERIFY2(HighDpi::fuzzyCompare(afterShowPosition, beforeShowPosition, fuzz), + HighDpi::msgPointMismatch(afterShowPosition, beforeShowPosition).constData()); } class Dialog : public QDialog diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp index a5b8646d40..63f6e67a3e 100644 --- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp +++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp @@ -2551,7 +2551,7 @@ void tst_QWizard::task183550_stretchFactor() page2->enableVerticalExpansion(); wizard.next(); QCOMPARE(wizard.currentPage(), static_cast<QWizardPage*>(page2)); - QVERIFY(page2->treeWidgetHeight() > page2->treeWidgetSizeHintHeight()); + QVERIFY(page2->treeWidgetHeight() >= page2->treeWidgetSizeHintHeight()); wizard.back(); QCOMPARE(wizard.currentPage(), static_cast<QWizardPage*>(page1)); diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 0cfdecbcab..4f3ff15ae0 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -5055,6 +5055,12 @@ public: void tst_QGraphicsItem::paint() { +#if defined(Q_OS_MACOS) + if (QSysInfo::productVersion() == QLatin1String("10.12")) { + QSKIP("Test is very flaky on MacOS_10_12, see QTBUG-76566"); + } +#endif + QGraphicsScene scene; PaintTester paintTester; diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 4a301337ef..530c3bb464 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -330,7 +330,7 @@ public: { // Make sure QGraphicsProxyWidget::paint does not modify the render hints set on the painter. painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform - | QPainter::NonCosmeticDefaultPen | QPainter::TextAntialiasing); + | QPainter::TextAntialiasing); const QPainter::RenderHints oldRenderHints = painter->renderHints(); QGraphicsProxyWidget::paint(painter, option, widget); QCOMPARE(painter->renderHints(), oldRenderHints); diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST index e3d968b4f2..ee13a37212 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST @@ -4,6 +4,7 @@ xcb xcb [cursor2] xcb +windows [rubberBandExtendSelection] xcb [rotated_rubberBand] diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index efee901227..52cc7ed128 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -352,8 +352,8 @@ void tst_QGraphicsView::renderHints() view.setScene(&scene); - view.setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); - QCOMPARE(view.renderHints(), QPainter::TextAntialiasing | QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); + view.setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing); + QCOMPARE(view.renderHints(), QPainter::TextAntialiasing | QPainter::Antialiasing); QCOMPARE(item->hints, 0); view.show(); @@ -361,8 +361,8 @@ void tst_QGraphicsView::renderHints() view.repaint(); QTRY_COMPARE(item->hints, view.renderHints()); - view.setRenderHints(QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); - QCOMPARE(view.renderHints(), QPainter::Antialiasing | QPainter::NonCosmeticDefaultPen); + view.setRenderHints(QPainter::Antialiasing); + QCOMPARE(view.renderHints(), QPainter::Antialiasing); view.repaint(); QTRY_COMPARE(item->hints, view.renderHints()); @@ -2280,53 +2280,53 @@ void tst_QGraphicsView::cursor2() QVERIFY(QTest::qWaitForWindowExposed(&view)); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-15, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); view.setDragMode(QGraphicsView::ScrollHandDrag); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); view.setDragMode(QGraphicsView::NoDrag); - QCOMPARE(view.viewport()->cursor().shape(), Qt::ArrowCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::ArrowCursor); view.viewport()->setCursor(Qt::PointingHandCursor); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); item2->setCursor(Qt::SizeAllCursor); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::PointingHandCursor); view.setDragMode(QGraphicsView::ScrollHandDrag); sendMouseMove(view.viewport(), view.mapFromScene(-30, -30)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::OpenHandCursor); sendMouseMove(view.viewport(), view.mapFromScene(0, 0)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::IBeamCursor); sendMouseMove(view.viewport(), view.mapFromScene(-15, -15)); - QCOMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); + QTRY_COMPARE(view.viewport()->cursor().shape(), Qt::SizeAllCursor); } #endif diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index 7fd1822295..dc246c0ebf 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -26,6 +26,7 @@ ** ****************************************************************************/ +#include "../../../shared/highdpi.h" #include <QtTest/QtTest> @@ -51,6 +52,8 @@ #include <QPlainTextEdit> #include <QDialog> +#include <qscreen.h> + #include <QtWidgets/private/qabstractitemdelegate_p.h> Q_DECLARE_METATYPE(QAbstractItemDelegate::EndEditHint) @@ -223,8 +226,8 @@ private slots: void dateTextForRole_data(); void dateTextForRole(); -#ifdef QT_BUILD_INTERNAL private: +#ifdef QT_BUILD_INTERNAL struct RoleDelegate : public QItemDelegate { QString textForRole(Qt::ItemDataRole role, const QVariant &value, const QLocale &locale) @@ -234,6 +237,8 @@ private: } }; #endif + + const int m_fuzz = int(QGuiApplication::primaryScreen()->devicePixelRatio()); }; @@ -286,8 +291,8 @@ void tst_QItemDelegate::textRectangle() QFont font; TestItemDelegate delegate; QRect result = delegate.textRectangle(0, rect, font, text); - - QCOMPARE(result, expected); + QVERIFY2(HighDpi::fuzzyCompare(result, expected, m_fuzz), + HighDpi::msgRectMismatch(result, expected).constData()); } void tst_QItemDelegate::sizeHint_data() diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp index 3d68e42baf..0d62c2cd4b 100644 --- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp +++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp @@ -70,7 +70,7 @@ private slots: void shortcutFromKeyEvent(); // QTBUG-48325 private: - int m_lastEventType; + QEvent::Type m_lastEventType; const int m_keyboardScheme; QAction *m_lastAction; }; @@ -82,7 +82,7 @@ tst_QAction::tst_QAction() void tst_QAction::init() { - m_lastEventType = 0; + m_lastEventType = QEvent::None; m_lastAction = nullptr; } @@ -94,23 +94,23 @@ void tst_QAction::cleanup() // Testing get/set functions void tst_QAction::getSetCheck() { - QAction obj1(0); + QAction obj1(nullptr); // QActionGroup * QAction::actionGroup() // void QAction::setActionGroup(QActionGroup *) - QActionGroup *var1 = new QActionGroup(0); + QActionGroup *var1 = new QActionGroup(nullptr); obj1.setActionGroup(var1); QCOMPARE(var1, obj1.actionGroup()); - obj1.setActionGroup((QActionGroup *)0); - QCOMPARE((QActionGroup *)0, obj1.actionGroup()); + obj1.setActionGroup(nullptr); + QCOMPARE(obj1.actionGroup(), nullptr); delete var1; // QMenu * QAction::menu() // void QAction::setMenu(QMenu *) - QMenu *var2 = new QMenu(0); + QMenu *var2 = new QMenu(nullptr); obj1.setMenu(var2); QCOMPARE(var2, obj1.menu()); - obj1.setMenu((QMenu *)0); - QCOMPARE((QMenu *)0, obj1.menu()); + obj1.setMenu(nullptr); + QCOMPARE(obj1.menu(), nullptr); delete var2; QCOMPARE(obj1.priority(), QAction::NormalPriority); @@ -148,7 +148,7 @@ void tst_QAction::setText() { QFETCH(QString, text); - QAction action(0); + QAction action(nullptr); action.setText(text); QCOMPARE(action.text(), text); @@ -161,7 +161,7 @@ void tst_QAction::setIconText() { QFETCH(QString, iconText); - QAction action(0); + QAction action(nullptr); action.setIconText(iconText); QCOMPARE(action.iconText(), iconText); @@ -171,7 +171,7 @@ void tst_QAction::setIconText() void tst_QAction::setUnknownFont() // QTBUG-42728 { - QAction action(0); + QAction action(nullptr); QFont font("DoesNotExist", 11); action.setFont(font); @@ -182,17 +182,17 @@ void tst_QAction::setUnknownFont() // QTBUG-42728 void tst_QAction::updateState(QActionEvent *e) { if (!e) { - m_lastEventType = 0; - m_lastAction = 0; + m_lastEventType = QEvent::None; + m_lastAction = nullptr; } else { - m_lastEventType = (int)e->type(); + m_lastEventType = e->type(); m_lastAction = e->action(); } } void tst_QAction::actionEvent() { - QAction a(0); + QAction a(nullptr); a.setText("action text"); // add action @@ -202,33 +202,33 @@ void tst_QAction::actionEvent() testWidget.addAction(&a); qApp->processEvents(); - QCOMPARE(m_lastEventType, (int)QEvent::ActionAdded); + QCOMPARE(m_lastEventType, QEvent::ActionAdded); QCOMPARE(m_lastAction, &a); // change action a.setText("new action text"); qApp->processEvents(); - QCOMPARE(m_lastEventType, (int)QEvent::ActionChanged); + QCOMPARE(m_lastEventType, QEvent::ActionChanged); QCOMPARE(m_lastAction, &a); // remove action testWidget.removeAction(&a); qApp->processEvents(); - QCOMPARE(m_lastEventType, (int)QEvent::ActionRemoved); + QCOMPARE(m_lastEventType, QEvent::ActionRemoved); QCOMPARE(m_lastAction, &a); } //basic testing of standard keys void tst_QAction::setStandardKeys() { - QAction act(0); + QAction act(nullptr); act.setShortcut(QKeySequence("CTRL+L")); QList<QKeySequence> list; act.setShortcuts(list); act.setShortcuts(QKeySequence::Copy); - QCOMPARE(act.shortcut(), act.shortcuts().first()); + QCOMPARE(act.shortcut(), act.shortcuts().constFirst()); QList<QKeySequence> expected; const QKeySequence ctrlC = QKeySequence(QStringLiteral("CTRL+C")); @@ -263,7 +263,7 @@ void tst_QAction::alternateShortcuts() QList<QKeySequence> shlist = QList<QKeySequence>() << QKeySequence("CTRL+P") << QKeySequence("CTRL+A"); act.setShortcuts(shlist); - QSignalSpy spy(&act, SIGNAL(triggered())); + QSignalSpy spy(&act, &QAction::triggered); act.setAutoRepeat(true); QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier); @@ -322,7 +322,7 @@ void tst_QAction::enabledVisibleInteraction() testWidget.show(); QApplication::setActiveWindow(&testWidget); - QAction act(0); + QAction act(nullptr); // check defaults QVERIFY(act.isEnabled()); QVERIFY(act.isVisible()); @@ -370,7 +370,7 @@ void tst_QAction::task229128TriggeredSignalWithoutActiongroup() { // test without a group const QScopedPointer<QAction> actionWithoutGroup(new QAction("Test", nullptr)); - QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), SIGNAL(triggered(bool))); + QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), QOverload<bool>::of(&QAction::triggered)); QCOMPARE(spyWithoutGroup.count(), 0); actionWithoutGroup->trigger(); // signal should be emitted @@ -388,7 +388,7 @@ void tst_QAction::task229128TriggeredSignalWithoutActiongroup() void tst_QAction::task229128TriggeredSignalWhenInActiongroup() { - QActionGroup ag(0); + QActionGroup ag(nullptr); QAction *action = new QAction("Test", &ag); QAction *checkedAction = new QAction("Test 2", &ag); ag.addAction(action); @@ -397,8 +397,8 @@ void tst_QAction::task229128TriggeredSignalWhenInActiongroup() checkedAction->setCheckable(true); checkedAction->setChecked(true); - QSignalSpy actionSpy(checkedAction, SIGNAL(triggered(bool))); - QSignalSpy actionGroupSpy(&ag, SIGNAL(triggered(QAction*))); + QSignalSpy actionSpy(checkedAction, QOverload<bool>::of(&QAction::triggered)); + QSignalSpy actionGroupSpy(&ag, QOverload<QAction*>::of(&QActionGroup::triggered)); QCOMPARE(actionGroupSpy.count(), 0); QCOMPARE(actionSpy.count(), 0); checkedAction->trigger(); @@ -513,10 +513,10 @@ void tst_QAction::disableShortcutsWithBlockedWidgets() class ShortcutOverrideWidget : public QWidget { public: - ShortcutOverrideWidget(QWidget *parent = 0) : QWidget(parent), shortcutOverrideCount(0) {} - int shortcutOverrideCount; + using QWidget::QWidget; + int shortcutOverrideCount = 0; protected: - bool event(QEvent *e) + bool event(QEvent *e) override { if (e->type() == QEvent::ShortcutOverride) ++shortcutOverrideCount; diff --git a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp index 0ba3cedf16..524040d003 100644 --- a/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp +++ b/tests/auto/widgets/kernel/qactiongroup/tst_qactiongroup.cpp @@ -41,6 +41,7 @@ private slots: void enabledPropagation(); void visiblePropagation(); void exclusive(); + void exclusiveOptional(); void separators(); void testActionInTwoQActionGroup(); void unCheckCurrentAction(); @@ -48,11 +49,11 @@ private slots: void tst_QActionGroup::enabledPropagation() { - QActionGroup testActionGroup( 0 ); + QActionGroup testActionGroup(nullptr); QAction* childAction = new QAction( &testActionGroup ); QAction* anotherChildAction = new QAction( &testActionGroup ); - QAction* freeAction = new QAction(0); + QAction* freeAction = new QAction(nullptr); QVERIFY( testActionGroup.isEnabled() ); QVERIFY( childAction->isEnabled() ); @@ -87,11 +88,11 @@ void tst_QActionGroup::enabledPropagation() void tst_QActionGroup::visiblePropagation() { - QActionGroup testActionGroup( 0 ); + QActionGroup testActionGroup(nullptr); QAction* childAction = new QAction( &testActionGroup ); QAction* anotherChildAction = new QAction( &testActionGroup ); - QAction* freeAction = new QAction(0); + QAction* freeAction = new QAction(nullptr); QVERIFY( testActionGroup.isVisible() ); QVERIFY( childAction->isVisible() ); @@ -124,7 +125,7 @@ void tst_QActionGroup::visiblePropagation() void tst_QActionGroup::exclusive() { - QActionGroup group(0); + QActionGroup group(nullptr); group.setExclusive(false); QVERIFY( !group.isExclusive() ); @@ -151,6 +152,52 @@ void tst_QActionGroup::exclusive() QVERIFY( !actThree->isChecked() ); } +void tst_QActionGroup::exclusiveOptional() +{ + QActionGroup group(0); + group.setExclusive(true); + QVERIFY( group.isExclusive() ); + + QAction* actOne = new QAction( &group ); + actOne->setCheckable( true ); + QAction* actTwo = new QAction( &group ); + actTwo->setCheckable( true ); + QAction* actThree = new QAction( &group ); + actThree->setCheckable( true ); + + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->trigger(); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->trigger(); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + group.setExclusionPolicy( QActionGroup::ExclusionPolicy::ExclusiveOptional ); + QVERIFY( group.isExclusive() ); + + actOne->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); +} + void tst_QActionGroup::separators() { QMainWindow mw; @@ -168,7 +215,7 @@ void tst_QActionGroup::separators() menu.addActions(actGroup.actions()); - QCOMPARE((int)menu.actions().size(), 2); + QCOMPARE(menu.actions().size(), 2); const auto removeActions = [&menu](const QList<QAction *> &actions) { for (QAction *action : actions) @@ -176,14 +223,14 @@ void tst_QActionGroup::separators() }; removeActions(actGroup.actions()); - QCOMPARE((int)menu.actions().size(), 0); + QCOMPARE(menu.actions().size(), 0); action = new QAction(&actGroup); action->setText("test two"); menu.addActions(actGroup.actions()); - QCOMPARE((int)menu.actions().size(), 3); + QCOMPARE(menu.actions().size(), 3); } void tst_QActionGroup::testActionInTwoQActionGroup() @@ -203,7 +250,7 @@ void tst_QActionGroup::testActionInTwoQActionGroup() void tst_QActionGroup::unCheckCurrentAction() { - QActionGroup group(0); + QActionGroup group(nullptr); QAction action1(&group) ,action2(&group); action1.setCheckable(true); action2.setCheckable(true); diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp index b78287f84b..8c262ff3a5 100644 --- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp +++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp @@ -30,6 +30,8 @@ #include <QtTest/QtTest> #include <qapplication.h> #include <qtextedit.h> +#include <qlineedit.h> +#include <qcompleter.h> #include <qpushbutton.h> #include <qmainwindow.h> #include <qstatusbar.h> @@ -39,7 +41,6 @@ #include <qshortcut.h> #include <qscreen.h> -class AccelForm; QT_BEGIN_NAMESPACE class QMainWindow; class QTextEdit; @@ -49,15 +50,14 @@ class tst_QShortcut : public QObject { Q_OBJECT public: - tst_QShortcut(); - virtual ~tst_QShortcut(); - enum Action { SetupAccel, TestAccel, - ClearAll - } currentAction; + ClearAll, + TestEnd + }; + Q_ENUM(Action) enum Widget { NoWidget, @@ -68,8 +68,8 @@ public: TriggerSlot5, TriggerSlot6, TriggerSlot7, - SendKeyEvent }; + Q_ENUM(Widget) enum Result { NoResult, @@ -82,7 +82,8 @@ public: Slot7Triggered, SentKeyEvent, Ambiguous - } currentResult; + } currentResult = NoResult; + Q_ENUM(Result) public slots: void slotTrig1() { currentResult = Slot1Triggered; } @@ -99,16 +100,9 @@ public slots: void ambigSlot5() { currentResult = Ambiguous; ambigResult = Slot5Triggered; } void ambigSlot6() { currentResult = Ambiguous; ambigResult = Slot6Triggered; } void ambigSlot7() { currentResult = Ambiguous; ambigResult = Slot7Triggered; } - void statusMessage( const QString& message ) { sbText = message; } - void shortcutDestroyed(QObject* obj); - void sendKeyEvent() { sendKeyEvents(edit, Qt::CTRL + Qt::Key_B, 0); currentResult = SentKeyEvent; } - -public slots: - void initTestCase(); - void cleanupTestCase(); - void cleanup() { QCOMPARE(QApplication::topLevelWidgets().size(), 1); } private slots: + void cleanup(); void number_data(); void number(); void text_data(); @@ -120,34 +114,25 @@ private slots: void unicodeCompare(); void context(); void duplicatedShortcutOverride(); + void shortcutToFocusProxy(); protected: static Qt::KeyboardModifiers toButtons( int key ); void defElements(); - void clearAllShortcuts(); - QShortcut *setupShortcut(int testWidget, const QKeySequence &ks); - QShortcut *setupShortcut(int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0); - - QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1 = 0, int k2 = 0, int k3 = 0, int k4 = 0); - QShortcut *setupShortcut(QWidget *parent, const char *name, int testWidget, const QKeySequence &ks, Qt::ShortcutContext context = Qt::WindowShortcut); + QShortcut *setupShortcut(QWidget *parent, const QString &name, const QKeySequence &ks, + Qt::ShortcutContext context = Qt::WindowShortcut); + QShortcut *setupShortcut(QWidget *parent, const QString &name, Widget testWidget, + const QKeySequence &ks, Qt::ShortcutContext context = Qt::WindowShortcut); - void sendKeyEvents(QWidget *w, int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); - void sendKeyEvents(int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); + static void sendKeyEvents(QWidget *w, int k1, QChar c1 = 0, int k2 = 0, QChar c2 = 0, + int k3 = 0, QChar c3 = 0, int k4 = 0, QChar c4 = 0); void testElement(); - QMainWindow *mainW; - QList<QShortcut*> shortcuts; - QTextEdit *edit; - QString sbText; Result ambigResult; }; -Q_DECLARE_METATYPE(tst_QShortcut::Widget); -Q_DECLARE_METATYPE(tst_QShortcut::Result); -Q_DECLARE_METATYPE(tst_QShortcut::Action); - class TestEdit : public QTextEdit { Q_OBJECT @@ -159,7 +144,8 @@ public: } protected: - bool event(QEvent *e) { + bool event(QEvent *e) override + { // Make testedit allow any Ctrl+Key as shortcut if (e->type() == QEvent::ShortcutOverride) { QKeyEvent *ke = static_cast<QKeyEvent*>(e); @@ -192,33 +178,28 @@ protected: } }; -tst_QShortcut::tst_QShortcut(): mainW( 0 ) +class MainWindow : public QMainWindow { -} +public: + MainWindow(); -tst_QShortcut::~tst_QShortcut() -{ - clearAllShortcuts(); -} + TestEdit *testEdit() const { return m_testEdit; } + +private: + TestEdit *m_testEdit; +}; -void tst_QShortcut::initTestCase() +MainWindow::MainWindow() { - currentResult = NoResult; - mainW = new QMainWindow(0); - mainW->setWindowFlags(Qt::X11BypassWindowManagerHint); - edit = new TestEdit(mainW, "test_edit"); - mainW->setFixedSize( 200, 200 ); - mainW->setCentralWidget( edit ); - mainW->show(); - mainW->activateWindow(); - QVERIFY(QTest::qWaitForWindowActive(mainW)); - connect( mainW->statusBar(), SIGNAL(messageChanged(QString)), - this, SLOT(statusMessage(QString)) ); + setWindowFlags(Qt::X11BypassWindowManagerHint); + m_testEdit = new TestEdit(this, "test_edit"); + setCentralWidget(m_testEdit); + setFixedSize(200, 200); } -void tst_QShortcut::cleanupTestCase() +void tst_QShortcut::cleanup() { - delete mainW; + QVERIFY(QApplication::topLevelWidgets().size() <= 1); // The data driven tests keep a widget around } Qt::KeyboardModifiers tst_QShortcut::toButtons( int key ) @@ -273,7 +254,7 @@ void tst_QShortcut::number_data() defElements(); // Clear all - QTest::newRow("N00 - clear") << ClearAll << NoWidget <<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<<NoResult; + QTest::newRow("N00 - clear") << ClearAll << NoWidget <<QString()<<0<<0<<0<<0<<0<<0<<0<<0<<NoResult; //=========================================== // [Shift + key] on non-shift shortcuts testing @@ -285,15 +266,15 @@ void tst_QShortcut::number_data() Shift + Qt::Key_Plus on Qt::Key_Pluss Qt::Key_Plus on Qt::Key_Pluss */ - QTest::newRow("N001 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N001 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("N001:Shift + M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N001:M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N001 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + //QTest::newRow("N001:Shift + M - [M]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N001:M - [M]") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N001 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("N001:Shift++ [+]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N001:+ [+]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N001 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("N001:Shift++ [+]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N001:+ [+]") << TestAccel << NoWidget << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N001 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_M on Shift + Qt::Key_M @@ -301,32 +282,32 @@ void tst_QShortcut::number_data() Shift + Qt::Key_Plus on Shift + Qt::Key_Pluss Qt::Key_Plus on Shift + Qt::Key_Pluss */ - QTest::newRow("N002 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N002:Shift+M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N002:M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N002 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N002:Shift++ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N002:+ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N002 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N002 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::SHIFT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N002:Shift+M - [Shift+M]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N002:M - [Shift+M]") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N002 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::SHIFT + Qt::Key_Plus) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N002:Shift++ [Shift++]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N002:+ [Shift++]") << TestAccel << NoWidget << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N002 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Qt::Key_F1 Qt::Key_F1 on Qt::Key_F1 */ - QTest::newRow("N003 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N003 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("N003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N003:F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N003 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("N003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N003:F1 - [F1]") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N003 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Shift + Qt::Key_F1 Qt::Key_F1 on Shift + Qt::Key_F1 */ - QTest::newRow("N004 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N004:Shift+F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N004 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N004 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N004:Shift+F1 - [Shift+F1]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N004 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Qt::Key_Tab @@ -334,14 +315,14 @@ void tst_QShortcut::number_data() Qt::Key_Backtab on Qt::Key_Tab Shift + Qt::Key_Backtab on Qt::Key_Tab */ - QTest::newRow("N005a - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005a:Tab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N005a - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005a:Tab - [Tab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("N005a:Shift+Tab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + //QTest::newRow("N005a:Shift+Tab - [Tab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; // (Shift+)BackTab != Tab, but Shift+BackTab == Shift+Tab - QTest::newRow("N005a:Backtab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005a:Shift+Backtab - [Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005a - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N005a:Backtab - [Tab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005a:Shift+Backtab - [Tab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005a - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Shift + Qt::Key_Tab @@ -349,12 +330,12 @@ void tst_QShortcut::number_data() Qt::Key_Backtab on Shift + Qt::Key_Tab Shift + Qt::Key_Backtab on Shift + Qt::Key_Tab */ - QTest::newRow("N005b - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005b:Tab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005b:Shift+Tab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N005b:BackTab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N005b:Shift+BackTab - [Shift+Tab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N005b - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N005b - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005b:Tab - [Shift+Tab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005b:Shift+Tab - [Shift+Tab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N005b:BackTab - [Shift+Tab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N005b:Shift+BackTab - [Shift+Tab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N005b - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Qt::Key_Backtab @@ -362,15 +343,15 @@ void tst_QShortcut::number_data() Qt::Key_Backtab on Qt::Key_Backtab Shift + Qt::Key_Backtab on Qt::Key_Backtab */ - QTest::newRow("N006a - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N006a:Tab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N006a - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N006a:Tab - [BackTab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // This should work, since platform dependent code will transform the // Shift+Tab into a Shift+BackTab, which should trigger the shortcut - QTest::newRow("N006a:Shift+Tab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL - QTest::newRow("N006a:BackTab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N006a:Shift+Tab - [BackTab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL + QTest::newRow("N006a:BackTab - [BackTab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("N006a:Shift+BackTab - [BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N006a - clear") << ClearAll << NoWidget<< QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("N006a:Shift+BackTab - [BackTab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N006a - clear") << ClearAll << NoWidget<< QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_Tab on Shift + Qt::Key_Backtab @@ -378,12 +359,12 @@ void tst_QShortcut::number_data() Qt::Key_Backtab on Shift + Qt::Key_Backtab Shift + Qt::Key_Backtab on Shift + Qt::Key_Backtab */ - QTest::newRow("N006b - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N006b:Tab - [Shift+BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N006b:Shift+Tab - [Shift+BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N006b:BackTab - [Shift+BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N006b:Shift+BackTab - [Shift+BackTab]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL - QTest::newRow("N006b - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N006b - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N006b:Tab - [Shift+BackTab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N006b:Shift+Tab - [Shift+BackTab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Tab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N006b:BackTab - [Shift+BackTab]") << TestAccel << NoWidget << QString() << int(Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N006b:Shift+BackTab - [Shift+BackTab]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Backtab) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; //XFAIL + QTest::newRow("N006b - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all //=========================================== // [Shift + key] and [key] on shortcuts with @@ -394,11 +375,11 @@ void tst_QShortcut::number_data() Qt::Key_F1 Shift + Qt::Key_F1 */ - QTest::newRow("N007 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N007 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N007:F1") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N007:Shift + F1") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N007 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N007 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N007 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N007:F1") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N007:Shift + F1") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N007 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_M @@ -406,51 +387,51 @@ void tst_QShortcut::number_data() Ctrl + Qt::Key_M Alt + Qt::Key_M */ - QTest::newRow("N01 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N02 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N03 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N04 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N:Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N:Shift+Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N:Ctrl+Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N:Alt+Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N01 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N02 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N03 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N04 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N:Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:Shift+Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N:Ctrl+Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:Alt+Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; /* Testing Single Sequence Ambiguity Qt::Key_M on shortcut2 */ - QTest::newRow("N05 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N:Qt::Key_M on slot") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous; - QTest::newRow("N05 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N05 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N:Qt::Key_M on slot") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous; + QTest::newRow("N05 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Specialkeys Qt::Key_aring Qt::Key_Aring Qt::UNICODE_ACCEL + Qt::Key_K */ - QTest::newRow("N06 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N07 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N08 - slot2") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::UNICODE_ACCEL + Qt::Key_K) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N06 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N07 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N08 - slot2") << SetupAccel << TriggerSlot1 << QString() << int(Qt::UNICODE_ACCEL + Qt::Key_K) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N:Qt::Key_aring") << TestAccel << NoWidget << QString("") << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N:Qt::Key_Aring") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString("") << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N:Qt::UNICODE_ACCEL + Qt::Key_K")<< TestAccel << NoWidget << QString("") << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N09 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N:Qt::Key_aring") << TestAccel << NoWidget << QString() << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:Qt::Key_Aring") << TestAccel << NoWidget << QString() << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString() << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString() << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N:Qt::UNICODE_ACCEL + Qt::Key_K")<< TestAccel << NoWidget << QString() << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N09 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Multiple Sequences Qt::Key_M Qt::Key_I, Qt::Key_M Shift+Qt::Key_I, Qt::Key_M */ - QTest::newRow("N10 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N11 - slot2") << SetupAccel << TriggerSlot2 << QString("") << int(Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("N12 - slot1") << SetupAccel << TriggerSlot1 << QString("") << int(Qt::SHIFT + Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult; - - QTest::newRow("N:Qt::Key_M (2)") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("N:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("N13 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("N10 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N11 - slot2") << SetupAccel << TriggerSlot2 << QString() << int(Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("N12 - slot1") << SetupAccel << TriggerSlot1 << QString() << int(Qt::SHIFT + Qt::Key_I) << 0 << int(Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << NoResult; + + QTest::newRow("N:Qt::Key_M (2)") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("N:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("N:end") << TestEnd << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; } // ------------------------------------------------------------------ @@ -460,7 +441,7 @@ void tst_QShortcut::text_data() { defElements(); // Clear all - QTest::newRow("T00 - clear") << ClearAll << NoWidget <<QString("")<<0<<0<<0<<0<<0<<0<<0<<0<< NoResult; + QTest::newRow("T00 - clear") << ClearAll << NoWidget <<QString()<<0<<0<<0<<0<<0<<0<<0<<0<< NoResult; //=========================================== // [Shift + key] on non-shift shortcuts testing @@ -474,13 +455,13 @@ void tst_QShortcut::text_data() */ QTest::newRow("T001 - slot1") << SetupAccel << TriggerSlot1 << QString("M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("T001:Shift+M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T001:M - [M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + //QTest::newRow("T001:Shift+M - [M]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T001:M - [M]") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; QTest::newRow("T001 - slot2") << SetupAccel << TriggerSlot2 << QString("+") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("T001:Shift++ [+]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T001:+ [+]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T001 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("T001:Shift++ [+]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T001:+ [+]") << TestAccel << NoWidget << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T001 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_M on Shift + Qt::Key_M @@ -491,12 +472,12 @@ void tst_QShortcut::text_data() Ctrl + Qt::Key_Plus on Ctrl + Qt::Key_Pluss */ QTest::newRow("T002 - slot1") << SetupAccel << TriggerSlot1 << QString("Shift+M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T002:Shift+M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T002:M - [Shift+M]") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("T002:Shift+M - [Shift+M]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T002:M - [Shift+M]") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T002 - slot2") << SetupAccel << TriggerSlot2 << QString("Shift++") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T002:Shift++ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T002:+ [Shift++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T002 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T002:Shift++ [Shift++]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T002:+ [Shift++]") << TestAccel << NoWidget << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("T002 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Ctrl + Qt::Key_Plus on Ctrl + Qt::Key_Plus @@ -505,10 +486,10 @@ void tst_QShortcut::text_data() */ QTest::newRow("T002b - slot1") << SetupAccel << TriggerSlot1 << QString("Ctrl++") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("T002b:Shift+Ctrl++ [Ctrl++]")<< TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T002b:Ctrl++ [Ctrl++]") << TestAccel << NoWidget << QString("") << int(Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T002b:+ [Ctrl++]") << TestAccel << NoWidget << QString("") << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T002b - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("T002b:Shift+Ctrl++ [Ctrl++]")<< TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T002b:Ctrl++ [Ctrl++]") << TestAccel << NoWidget << QString() << int(Qt::CTRL + Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T002b:+ [Ctrl++]") << TestAccel << NoWidget << QString() << int(Qt::Key_Plus) << int('+') << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("T002b - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Qt::Key_F1 @@ -516,18 +497,18 @@ void tst_QShortcut::text_data() */ QTest::newRow("T003 - slot1") << SetupAccel << TriggerSlot1 << QString("F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; //commented out because the behaviour changed, those tests should be updated - //QTest::newRow("T003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T003:F1 - [F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T003 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + //QTest::newRow("T003:Shift+F1 - [F1]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T003:F1 - [F1]") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T003 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Shift + Qt::Key_F1 on Shift + Qt::Key_F1 Qt::Key_F1 on Shift + Qt::Key_F1 */ QTest::newRow("T004 - slot1") << SetupAccel << TriggerSlot1 << QString("Shift+F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T004:Shift+F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T004 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T004:Shift+F1 - [Shift+F1]") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T004:F1 - [Shift+F1]") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; + QTest::newRow("T004 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all //=========================================== // [Shift + key] and [key] on shortcuts with @@ -540,9 +521,9 @@ void tst_QShortcut::text_data() */ QTest::newRow("T007 - slot1") << SetupAccel << TriggerSlot1 << QString("F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T007 - slot2") << SetupAccel << TriggerSlot2 << QString("Shift+F1") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T007:F1") << TestAccel << NoWidget << QString("") << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T007:Shift + F1") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T007 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T007:F1") << TestAccel << NoWidget << QString() << int(Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T007:Shift + F1") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_F1) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T007 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Sequences Qt::Key_M @@ -555,17 +536,17 @@ void tst_QShortcut::text_data() QTest::newRow("T03 - slot1") << SetupAccel << TriggerSlot1 << QString("Ctrl+M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T04 - slot2") << SetupAccel << TriggerSlot2 << QString("Alt+M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T:Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T:Shift + Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T:Ctrl + Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T:Alt + Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T:Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:Shift + Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_M) << int('M') << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T:Ctrl + Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::CTRL + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:Alt + Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::ALT + Qt::Key_M) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; /* Testing Single Sequence Ambiguity Qt::Key_M on shortcut2 */ QTest::newRow("T05 - slot2") << SetupAccel << TriggerSlot2 << QString("M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T:Qt::Key_M on TriggerSlot2") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous; - QTest::newRow("T06 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T:Qt::Key_M on TriggerSlot2") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Ambiguous; + QTest::newRow("T06 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Single Specialkeys Qt::Key_aring @@ -576,12 +557,12 @@ void tst_QShortcut::text_data() QTest::newRow("T06 - slot1") << SetupAccel << TriggerSlot1 << QString::fromLatin1("\x0C5")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T07 - slot2") << SetupAccel << TriggerSlot2 << QString::fromLatin1("Shift+\x0C5")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T08 - slot2") << SetupAccel << TriggerSlot1 << QString("K") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T:Qt::Key_aring") << TestAccel << NoWidget << QString("") << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T:Qt::Key_Aring") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString("") << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T:Qt::UNICODE_ACCEL + Qt::Key_K")<< TestAccel << NoWidget << QString("") << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T09 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T:Qt::Key_aring") << TestAccel << NoWidget << QString() << int(Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:Qt::Key_Aring") << TestAccel << NoWidget << QString() << int(Qt::SHIFT+Qt::Key_Aring) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T:Qt::Key_aring - Text Form") << TestAccel << NoWidget << QString() << 0 << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:Qt::Key_Aring - Text Form") << TestAccel << NoWidget << QString() << int(Qt::SHIFT+0) << 0xC5 << 0 << 0 << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T:Qt::UNICODE_ACCEL + Qt::Key_K")<< TestAccel << NoWidget << QString() << int(Qt::UNICODE_ACCEL + Qt::Key_K) << int('k') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T09 - clear") << ClearAll << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all /* Testing Multiple Sequences Qt::Key_M @@ -591,10 +572,38 @@ void tst_QShortcut::text_data() QTest::newRow("T10 - slot1") << SetupAccel << TriggerSlot1 << QString("M") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T11 - slot2") << SetupAccel << TriggerSlot2 << QString("I, M")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; QTest::newRow("T12 - slot1") << SetupAccel << TriggerSlot1 << QString("Shift+I, M")<< 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; - QTest::newRow("T:Qt::Key_M (2)") << TestAccel << NoWidget << QString("") << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered; - QTest::newRow("T:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString("") << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered; - QTest::newRow("T13 - clear") << ClearAll << NoWidget << QString("") << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; // Clear all + QTest::newRow("T:Qt::Key_M (2)") << TestAccel << NoWidget << QString() << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::Key_I) << int('i') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot2Triggered; + QTest::newRow("T:Shift+Qt::Key_I, Qt::Key_M") << TestAccel << NoWidget << QString() << int(Qt::SHIFT + Qt::Key_I) << int('I') << int(Qt::Key_M) << int('m') << 0 << 0 << 0 << 0 << Slot1Triggered; + QTest::newRow("T:end") << TestEnd << NoWidget << QString() << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << NoResult; +} + +class ButtonWidget : public QWidget +{ +public: + ButtonWidget(); + + QPushButton *pushButton1() const { return m_pb1; } + QPushButton *pushButton2() const { return m_pb2; } + +private: + QPushButton *m_pb1; + QPushButton *m_pb2; +}; + +ButtonWidget::ButtonWidget() +{ + // Setup two identical shortcuts on different pushbuttons + QString name = QLatin1String("pushbutton-1"); + m_pb1 = new QPushButton(name, this); + m_pb1->setObjectName(name); + name = QLatin1String("pushbutton-2"); + m_pb2 = new QPushButton(name, this); + m_pb2->setObjectName(name); + auto hLayout = new QHBoxLayout(this); + hLayout->addWidget(m_pb1); + hLayout->addWidget(m_pb2); + hLayout->addStretch(); } // ------------------------------------------------------------------ @@ -602,9 +611,11 @@ void tst_QShortcut::text_data() // ------------------------------------------------------------------ void tst_QShortcut::disabledItems() { - clearAllShortcuts(); - mainW->activateWindow(); - QVERIFY(QTest::qWaitForWindowActive(mainW)); + ButtonWidget mainW; + mainW.setWindowTitle(QTest::currentTestFunction()); + mainW.show(); + mainW.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&mainW)); /* Testing Disabled Shortcuts Qt::Key_M on slot1 @@ -614,27 +625,27 @@ void tst_QShortcut::disabledItems() */ // Setup two identical shortcuts on different pushbuttons - QPushButton pb1(mainW); - QPushButton pb2(mainW); - pb1.setObjectName("pushbutton-1"); - pb2.setObjectName("pushbutton-2"); - pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger - pb2.show(); - - QShortcut *cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M"); - QShortcut *cut2 = setupShortcut(&pb1, "shortcut2-pb1", TriggerSlot1, "Shift+M"); - QShortcut *cut3 = setupShortcut(&pb2, "shortcut3-pb2", TriggerSlot2, "M"); - QShortcut *cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+M"); + auto pb1 = mainW.pushButton1(); + auto pb2 = mainW.pushButton2(); + const int shiftM = Qt::SHIFT + Qt::Key_M; + QShortcut *cut1 = setupShortcut(pb1, "shortcut1-pb1", TriggerSlot1, + QKeySequence(Qt::Key_M)); + QShortcut *cut2 = setupShortcut(pb1, "shortcut2-pb1", TriggerSlot1, + QKeySequence(shiftM)); + QShortcut *cut3 = setupShortcut(pb2, "shortcut3-pb2", TriggerSlot2, + QKeySequence(Qt::Key_M)); + QShortcut *cut4 = setupShortcut(pb2, "shortcut4-pb2", TriggerSlot2, + QKeySequence(shiftM)); cut3->setEnabled(false); cut4->setEnabled(false); currentResult = NoResult; - sendKeyEvents(Qt::Key_M, 'm'); + sendKeyEvents(&mainW, Qt::Key_M, 'm'); QCOMPARE(currentResult, Slot1Triggered); currentResult = NoResult; - sendKeyEvents(Qt::SHIFT+Qt::Key_M, 'M'); + sendKeyEvents(&mainW, shiftM, 'M'); QCOMPARE(currentResult, Slot1Triggered); cut2->setEnabled(false); @@ -647,11 +658,11 @@ void tst_QShortcut::disabledItems() Shift + Qt::Key_M on slot2 */ currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); + sendKeyEvents(&mainW, Qt::Key_M, 'm' ); QCOMPARE( currentResult, Slot1Triggered ); currentResult = NoResult; - sendKeyEvents( Qt::SHIFT+Qt::Key_M, 'M' ); + sendKeyEvents(&mainW, shiftM, 'M' ); QCOMPARE( currentResult, Slot2Triggered ); @@ -659,67 +670,34 @@ void tst_QShortcut::disabledItems() Qt::Key_F5 on slot1 Shift + Qt::Key_F5 on slot2 (disabled) */ - clearAllShortcuts(); - cut1 = setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "F5"); - cut4 = setupShortcut(&pb2, "shortcut4-pb2", TriggerSlot2, "Shift+F5"); - - cut1->setKey(QKeySequence("F5")); - cut4->setKey(QKeySequence("Shift+F5")); + qDeleteAll(mainW.findChildren<QShortcut *>()); + const int shiftF5 = Qt::SHIFT + Qt::Key_F5; + cut1 = setupShortcut(pb1, "shortcut1-pb1", TriggerSlot1, QKeySequence(Qt::Key_F5)); + cut4 = setupShortcut(pb2, "shortcut4-pb2", TriggerSlot2, QKeySequence(shiftF5)); cut1->setEnabled(true); cut4->setEnabled(false); currentResult = NoResult; - sendKeyEvents( Qt::Key_F5, 0 ); + sendKeyEvents(&mainW, Qt::Key_F5, 0 ); QCOMPARE( currentResult, Slot1Triggered ); currentResult = NoResult; - sendKeyEvents( Qt::SHIFT+Qt::Key_F5, 0 ); + sendKeyEvents(&mainW, shiftF5, 0 ); QCOMPARE( currentResult, NoResult ); - -#if 0 - qFatal("Not testing statusbar text feedback yet, since not implemented"); - /* Testing Disabled Accel, and the corresponding statusbar feedback - Ctrl + Qt::Key_K, Ctrl + Qt::Key_L on slot1 - Ctrl + Qt::Key_K, Ctrl + Qt::Key_M on slot2 (disabled) - */ - cut1->setKey(QKeySequence("Ctrl+K, Ctrl+L")); - cut4->setKey(QKeySequence("Ctrl+K, Ctrl+M")); - - cut1->setEnabled(true); - cut4->setEnabled(false); - - currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); - sendKeyEvents( Qt::CTRL+Qt::Key_Q, 0 ); - QCOMPARE( currentResult, NoResult ); - if (over_330) - QCOMPARE( sbText, QString("Ctrl+K, Ctrl+Q not defined") ); - - currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); - sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 ); - QCOMPARE( currentResult, NoResult ); - if (over_330) - QCOMPARE( sbText, QString() ); - - currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_K, 0 ); - sendKeyEvents( Qt::CTRL+Qt::Key_L, 0 ); - QCOMPARE( currentResult, Slot1Triggered ); - if (over_330) - QCOMPARE( sbText, QString() ); -#endif - clearAllShortcuts(); - cut1 = 0; - cut4 = 0; } // ------------------------------------------------------------------ // Ambiguous Elements ----------------------------------------------- // ------------------------------------------------------------------ void tst_QShortcut::ambiguousRotation() { - clearAllShortcuts(); + MainWindow mainW; + const QString name = QLatin1String(QTest::currentTestFunction()); + mainW.setWindowTitle(name); + mainW.show(); + mainW.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&mainW)); + /* Testing Shortcut rotation scheme Ctrl + Qt::Key_A on slot1 (disabled) Ctrl + Qt::Key_A on slot2 (disabled) @@ -729,13 +707,15 @@ void tst_QShortcut::ambiguousRotation() Ctrl + Qt::Key_A on slot6 Ctrl + Qt::Key_A on slot7 (disabled) */ - QShortcut *cut1 = setupShortcut(TriggerSlot1, "Ctrl+A"); - QShortcut *cut2 = setupShortcut(TriggerSlot2, "Ctrl+A"); - QShortcut *cut3 = setupShortcut(TriggerSlot3, "Ctrl+A"); - QShortcut *cut4 = setupShortcut(TriggerSlot4, "Ctrl+A"); - QShortcut *cut5 = setupShortcut(TriggerSlot5, "Ctrl+A"); - QShortcut *cut6 = setupShortcut(TriggerSlot6, "Ctrl+A"); - QShortcut *cut7 = setupShortcut(TriggerSlot7, "Ctrl+A"); + const int ctrlA = Qt::CTRL + Qt::Key_A; + QKeySequence ctrlA_Sequence(ctrlA); + QShortcut *cut1 = setupShortcut(&mainW, name, TriggerSlot1, ctrlA_Sequence); + QShortcut *cut2 = setupShortcut(&mainW, name, TriggerSlot2, ctrlA_Sequence); + QShortcut *cut3 = setupShortcut(&mainW, name, TriggerSlot3, ctrlA_Sequence); + QShortcut *cut4 = setupShortcut(&mainW, name, TriggerSlot4, ctrlA_Sequence); + QShortcut *cut5 = setupShortcut(&mainW, name, TriggerSlot5, ctrlA_Sequence); + QShortcut *cut6 = setupShortcut(&mainW, name, TriggerSlot6, ctrlA_Sequence); + QShortcut *cut7 = setupShortcut(&mainW, name, TriggerSlot7, ctrlA_Sequence); cut1->setEnabled(false); cut2->setEnabled(false); @@ -749,37 +729,37 @@ void tst_QShortcut::ambiguousRotation() // Continue... currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot3Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot4Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot6Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot3Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot4Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot6Triggered); @@ -804,94 +784,87 @@ void tst_QShortcut::ambiguousRotation() currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot1Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot2Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot5Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot7Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot1Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot2Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot5Triggered); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(Qt::CTRL+Qt::Key_A); + sendKeyEvents(&mainW, ctrlA); QCOMPARE(currentResult, Ambiguous); QCOMPARE(ambigResult, Slot7Triggered); - - clearAllShortcuts(); - cut1 = 0; cut2 = 0; - cut3 = 0; cut4 = 0; - cut5 = 0; cut6 = 0; - cut7 = 0; } void tst_QShortcut::ambiguousItems() { - clearAllShortcuts(); + ButtonWidget mainW; + mainW.setWindowTitle(QTest::currentTestFunction()); + mainW.show(); + mainW.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&mainW)); + /* Testing Ambiguous Shortcuts Qt::Key_M on Pushbutton 1 Qt::Key_M on Pushbutton 2 */ // Setup two identical shortcuts on different pushbuttons - QPushButton pb1(mainW); - QPushButton pb2(mainW); - pb1.setObjectName("pushbutton-1"); - pb2.setObjectName("pushbutton-2"); - pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger - pb2.show(); + auto pb1 = mainW.pushButton1(); + auto pb2 = mainW.pushButton2(); - setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, "M"); - setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, "M"); + setupShortcut(pb1, "shortcut1-pb1", TriggerSlot1, QKeySequence(Qt::Key_M)); + setupShortcut(pb2, "shortcut2-pb2", TriggerSlot2, QKeySequence(Qt::Key_M)); currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); + sendKeyEvents(&mainW, Qt::Key_M, 'm' ); QCOMPARE( currentResult, Ambiguous ); QCOMPARE( ambigResult, Slot1Triggered ); currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); + sendKeyEvents(&mainW, Qt::Key_M, 'm' ); QCOMPARE( currentResult, Ambiguous ); QCOMPARE( ambigResult, Slot2Triggered ); currentResult = NoResult; - sendKeyEvents( Qt::Key_M, 'm' ); + sendKeyEvents(&mainW, Qt::Key_M, 'm' ); QCOMPARE( currentResult, Ambiguous ); QCOMPARE( ambigResult, Slot1Triggered ); - - clearAllShortcuts(); } @@ -900,32 +873,31 @@ void tst_QShortcut::ambiguousItems() // ------------------------------------------------------------------ void tst_QShortcut::unicodeCompare() { - clearAllShortcuts(); + ButtonWidget mainW; + mainW.setWindowTitle(QTest::currentTestFunction()); + mainW.show(); + mainW.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&mainW)); + /* Testing Unicode/non-Unicode Shortcuts Qt::Key_M on Pushbutton 1 Qt::Key_M on Pushbutton 2 */ - QPushButton pb1(mainW); - QPushButton pb2(mainW); - pb1.setObjectName("pushbutton-1"); - pb2.setObjectName("pushbutton-2"); - pb1.show(); // Must be show for QShortcutMap::correctSubWindow to trigger - pb2.show(); + auto pb1 = mainW.pushButton1(); + auto pb2 = mainW.pushButton2(); QKeySequence ks1("Ctrl+M"); // Unicode QKeySequence ks2(Qt::CTRL+Qt::Key_M); // non-Unicode - setupShortcut(&pb1, "shortcut1-pb1", TriggerSlot1, ks1); - setupShortcut(&pb1, "shortcut2-pb2", TriggerSlot2, ks2); + setupShortcut(pb1, "shortcut1-pb1", TriggerSlot1, ks1); + setupShortcut(pb2, "shortcut2-pb2", TriggerSlot2, ks2); currentResult = NoResult; - sendKeyEvents( Qt::CTRL+Qt::Key_M, 0 ); + sendKeyEvents(&mainW, Qt::CTRL + Qt::Key_M, 0); QCOMPARE( currentResult, Ambiguous ); // They _are_ ambiguous, so the QKeySequence operator== // should indicate the same QVERIFY( ks1 == ks2 ); QVERIFY( !(ks1 != ks2) ); - - clearAllShortcuts(); } // ------------------------------------------------------------------ @@ -933,25 +905,29 @@ void tst_QShortcut::unicodeCompare() // ------------------------------------------------------------------ void tst_QShortcut::keypressConsumption() { - clearAllShortcuts(); - edit->clear(); - QCOMPARE(edit->toPlainText().size(), 0); + MainWindow mainW; + mainW.setWindowTitle(QTest::currentTestFunction()); + mainW.show(); + mainW.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&mainW)); + auto edit = mainW.testEdit(); - QShortcut *cut1 = setupShortcut(edit, "shortcut1-line", TriggerSlot1, "Ctrl+I, A"); - QShortcut *cut2 = setupShortcut(edit, "shortcut1-line", TriggerSlot2, "Ctrl+I, B"); + const int ctrlI = Qt::CTRL + Qt::Key_I; + QShortcut *cut1 = setupShortcut(edit, "shortcut1-line", TriggerSlot1, QKeySequence(ctrlI, Qt::Key_A)); + QShortcut *cut2 = setupShortcut(edit, "shortcut1-line", TriggerSlot2, QKeySequence(ctrlI, Qt::Key_B)); currentResult = NoResult; ambigResult = NoResult; - sendKeyEvents(edit, Qt::CTRL + Qt::Key_I, 0); // Send key to edit + sendKeyEvents(edit, ctrlI, 0); // Send key to edit QCOMPARE( currentResult, NoResult ); QCOMPARE( ambigResult, NoResult ); - QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(edit->toPlainText(), QString()); // Make sure next keypress is eaten (failing multiple keysequence) sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit QCOMPARE( currentResult, NoResult ); QCOMPARE( ambigResult, NoResult ); - QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(edit->toPlainText(), QString()); // Next keypress should be normal sendKeyEvents(edit, Qt::Key_C, 'c'); // Send key to edit @@ -979,11 +955,15 @@ void tst_QShortcut::keypressConsumption() QCOMPARE( ambigResult, NoResult ); QVERIFY(edit->toPlainText().endsWith("<Ctrl+I>a")); - clearAllShortcuts(); + qDeleteAll(mainW.findChildren<QShortcut *>()); edit->clear(); QCOMPARE(edit->toPlainText().size(), 0); - setupShortcut(edit, "first", SendKeyEvent, "Ctrl+A"); + auto cut = setupShortcut(edit, QLatin1String("first"), QKeySequence(Qt::CTRL + Qt::Key_A)); + connect(cut, &QShortcut::activated, edit, [this, edit] () { + this->sendKeyEvents(edit, Qt::CTRL + Qt::Key_B, 0); + this->currentResult = tst_QShortcut::SentKeyEvent; + }); // Verify reentrancy when a non-shortcut is triggered as part // of shortcut processing. @@ -992,7 +972,7 @@ void tst_QShortcut::keypressConsumption() sendKeyEvents(edit, Qt::CTRL + Qt::Key_A, 0); QCOMPARE(currentResult, SentKeyEvent); QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString(QString("<Ctrl+B>"))); + QCOMPARE(edit->toPlainText(), QLatin1String("<Ctrl+B>")); } // ------------------------------------------------------------------ @@ -1000,12 +980,17 @@ void tst_QShortcut::keypressConsumption() // ------------------------------------------------------------------ void tst_QShortcut::context() { - clearAllShortcuts(); + const QString name = QLatin1String(QTest::currentTestFunction()); + MainWindow mainW; + mainW.setWindowTitle(name + QLatin1String("_Helper")); + mainW.show(); + auto edit = mainW.testEdit(); QWidget myBox; - TestEdit *other1 = new TestEdit(&myBox, "test_edit_other1"); - TestEdit *other2 = new TestEdit(&myBox, "test_edit_other2"); - QHBoxLayout *layout = new QHBoxLayout(&myBox); + myBox.setWindowTitle(name); + auto other1 = new TestEdit(&myBox, "test_edit_other1"); + auto other2 = new TestEdit(&myBox, "test_edit_other2"); + auto layout = new QHBoxLayout(&myBox); layout->addWidget(other1); layout->addWidget(other2); myBox.show(); @@ -1030,8 +1015,8 @@ void tst_QShortcut::context() // Focus on 'other1' edit, so Active Window context should trigger other1->activateWindow(); // <--- QApplication::setActiveWindow(other1); - QCOMPARE(qApp->activeWindow(), other1->window()); - QCOMPARE(qApp->focusWidget(), (QWidget *)other1); + QCOMPARE(QApplication::activeWindow(), other1->window()); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(other1)); currentResult = NoResult; ambigResult = NoResult; @@ -1039,13 +1024,13 @@ void tst_QShortcut::context() other1->clear(); other2->clear(); - QCOMPARE(qApp->focusWidget(), (QWidget *)other1); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(other1)); sendKeyEvents(other1, Qt::ALT+Qt::Key_1); QCOMPARE(currentResult, Slot1Triggered); QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); - QCOMPARE(other1->toPlainText(), QString("")); - QCOMPARE(other2->toPlainText(), QString("")); + QCOMPARE(edit->toPlainText(), QString()); + QCOMPARE(other1->toPlainText(), QString()); + QCOMPARE(other2->toPlainText(), QString()); // ..but not Focus context on 'other2'.. currentResult = NoResult; @@ -1057,9 +1042,9 @@ void tst_QShortcut::context() sendKeyEvents(other1, Qt::ALT+Qt::Key_2); QCOMPARE(currentResult, NoResult); QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); + QCOMPARE(edit->toPlainText(), QString()); QCOMPARE(other1->toPlainText(), QString("<Alt+2>")); - QCOMPARE(other2->toPlainText(), QString("")); + QCOMPARE(other2->toPlainText(), QString()); // ..however, application global context on 'edit' should.. currentResult = NoResult; @@ -1071,15 +1056,15 @@ void tst_QShortcut::context() sendKeyEvents(other1, Qt::ALT+Qt::Key_3); QCOMPARE(currentResult, Slot3Triggered); QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); - QCOMPARE(other1->toPlainText(), QString("")); - QCOMPARE(other2->toPlainText(), QString("")); + QCOMPARE(edit->toPlainText(), QString()); + QCOMPARE(other1->toPlainText(), QString()); + QCOMPARE(other2->toPlainText(), QString()); // Changing focus to 'other2' should make the Focus context there work other2->activateWindow(); other2->setFocus(); // ### - QTRY_COMPARE(qApp->activeWindow(), other2->window()); - QCOMPARE(qApp->focusWidget(), (QWidget *)other2); + QTRY_COMPARE(QApplication::activeWindow(), other2->window()); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget *>(other2)); currentResult = NoResult; ambigResult = NoResult; @@ -1090,20 +1075,18 @@ void tst_QShortcut::context() sendKeyEvents(other2, Qt::ALT+Qt::Key_2); QCOMPARE(currentResult, Slot2Triggered); QCOMPARE(ambigResult, NoResult); - QCOMPARE(edit->toPlainText(), QString("")); - QCOMPARE(other1->toPlainText(), QString("")); - QCOMPARE(other2->toPlainText(), QString("")); - - clearAllShortcuts(); + QCOMPARE(edit->toPlainText(), QString()); + QCOMPARE(other1->toPlainText(), QString()); + QCOMPARE(other2->toPlainText(), QString()); } // QTBUG-38986, do not generate duplicated QEvent::ShortcutOverride in event processing. class OverrideCountingWidget : public QWidget { public: - OverrideCountingWidget(QWidget *parent = 0) : QWidget(parent), overrideCount(0) {} + using QWidget::QWidget; - int overrideCount; + int overrideCount = 0; bool event(QEvent *e) override { @@ -1127,95 +1110,55 @@ void tst_QShortcut::duplicatedShortcutOverride() QCOMPARE(w.overrideCount, 1); } -// ------------------------------------------------------------------ -// Element Testing helper functions --------------------------------- -// ------------------------------------------------------------------ -void tst_QShortcut::clearAllShortcuts() +QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const QString &name, const QKeySequence &ks, Qt::ShortcutContext context) { - QList<QShortcut *> shortcutsCpy = shortcuts; - qDeleteAll(shortcutsCpy); - shortcuts.clear(); -} - -QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QKeySequence &ks) -{ - return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, ks); -} - -QShortcut *tst_QShortcut::setupShortcut(int testWidget, const QString &txt, int k1, int k2, int k3, int k4) -{ - return setupShortcut(mainW, QTest::currentDataTag() ? QTest::currentDataTag() : "", testWidget, - (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt))); -} - -QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, const QString &txt, int k1, int k2, int k3, int k4) -{ - return setupShortcut(parent, name, testWidget, - (txt.isEmpty() ? QKeySequence(k1, k2, k3, k4) : QKeySequence(txt))); + // Set up shortcut for next test + auto cut = new QShortcut(ks, parent, nullptr, nullptr, context); + cut->setObjectName(name); + return cut; } -QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int testWidget, +QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const QString &name, Widget testWidget, const QKeySequence &ks, Qt::ShortcutContext context) { // Set up shortcut for next test - QShortcut *cut = new QShortcut(QKeySequence(), parent, 0, 0, context); - cut->setObjectName(name); - cut->setKey(ks); + auto cut = setupShortcut(parent, name, ks, context); - const char *normal = 0; - const char *ambig = 0; - switch(testWidget) - { + switch (testWidget) { case TriggerSlot1: - normal = SLOT(slotTrig1()); - ambig = SLOT(ambigSlot1()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig1); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot1); break; case TriggerSlot2: - normal = SLOT(slotTrig2()); - ambig = SLOT(ambigSlot2()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig2); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot2); break; case TriggerSlot3: - normal = SLOT(slotTrig3()); - ambig = SLOT(ambigSlot3()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig3); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot3); break; case TriggerSlot4: - normal = SLOT(slotTrig4()); - ambig = SLOT(ambigSlot4()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig4); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot4); break; case TriggerSlot5: - normal = SLOT(slotTrig5()); - ambig = SLOT(ambigSlot5()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig5); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot5); break; case TriggerSlot6: - normal = SLOT(slotTrig6()); - ambig = SLOT(ambigSlot6()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig6); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot6); break; case TriggerSlot7: - normal = SLOT(slotTrig7()); - ambig = SLOT(ambigSlot7()); + connect(cut, &QShortcut::activated, this, &tst_QShortcut::slotTrig7); + connect(cut, &QShortcut::activatedAmbiguously, this, &tst_QShortcut::ambigSlot7); + break; + case NoWidget: break; - case SendKeyEvent: - normal = SLOT(sendKeyEvent()); } - connect(cut, SIGNAL(activated()), this, normal); - if (ambig) - connect(cut, SIGNAL(activatedAmbiguously()), this, ambig); - connect(cut, SIGNAL(destroyed(QObject*)), this, SLOT(shortcutDestroyed(QObject*))); - shortcuts.append(cut); return cut; } -void tst_QShortcut::shortcutDestroyed(QObject* obj) -{ - shortcuts.erase(std::remove(shortcuts.begin(), shortcuts.end(), obj), - shortcuts.end()); -} - -void tst_QShortcut::sendKeyEvents(int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4) -{ - sendKeyEvents(mainW, k1, c1, k2, c2, k3, c3, k4, c4); -} - void tst_QShortcut::sendKeyEvents(QWidget *w, int k1, QChar c1, int k2, QChar c2, int k3, QChar c3, int k4, QChar c4) { Qt::KeyboardModifiers b1 = toButtons( k1 ); @@ -1255,6 +1198,8 @@ void tst_QShortcut::sendKeyEvents(QWidget *w, int k1, QChar c1, int k2, QChar c2 void tst_QShortcut::testElement() { + static QScopedPointer<MainWindow> mainW; + currentResult = NoResult; QFETCH(tst_QShortcut::Action, action); QFETCH(tst_QShortcut::Widget, testWidget); @@ -1269,15 +1214,54 @@ void tst_QShortcut::testElement() QFETCH(int, c4); QFETCH(tst_QShortcut::Result, result); - if (action == ClearAll) { - clearAllShortcuts(); - } else if (action == SetupAccel) { - setupShortcut(testWidget, txt, k1, k2, k3, k4); - } else { - sendKeyEvents(k1, c1, k2, c2, k3, c3, k4, c4); - QCOMPARE((int)currentResult, (int)result); + if (mainW.isNull()) { + mainW.reset(new MainWindow); + mainW->setWindowTitle(QTest::currentTestFunction()); + mainW->show(); + mainW->activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(mainW.data())); + } + + switch (action) { + case ClearAll: + qDeleteAll(mainW->findChildren<QShortcut *>()); + break; + case SetupAccel: + setupShortcut(mainW.data(), txt, testWidget, txt.isEmpty() + ? QKeySequence(k1, k2, k3, k4) : QKeySequence::fromString(txt)); + break; + case TestAccel: + sendKeyEvents(mainW.data(), k1, c1, k2, c2, k3, c3, k4, c4); + QCOMPARE(currentResult, result); + break; + case TestEnd: + mainW.reset(); + break; } } +void tst_QShortcut::shortcutToFocusProxy() +{ + QLineEdit le; + QCompleter completer; + QStringListModel *slm = new QStringListModel(QStringList() << "a0" << "a1" << "a2", &completer); + completer.setModel(slm); + completer.setCompletionMode(QCompleter::PopupCompletion); + le.setCompleter(&completer); + QShortcut *shortcut = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_S), &le); + QObject::connect(shortcut, &QShortcut::activated, &le, &QLineEdit::clear); + le.setFocus(); + le.show(); + + QVERIFY(QTest::qWaitForWindowActive(&le)); + QCOMPARE(QApplication::focusWidget(), &le); + QTest::keyEvent(QTest::Press, QApplication::focusWidget(), Qt::Key_A); + + QCOMPARE(le.text(), QString::fromLocal8Bit("a")); + QTest::keyEvent(QTest::Press, QApplication::focusWidget(), Qt::Key_Alt); + QTest::keyEvent(QTest::Press, QApplication::focusWidget(), Qt::Key_S, Qt::AltModifier); + QCOMPARE(le.text(), QString()); +} + QTEST_MAIN(tst_QShortcut) #include "tst_qshortcut.moc" diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 7203e7b170..103be88f86 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -26,6 +26,7 @@ ** ****************************************************************************/ +#include "../../../shared/highdpi.h" #include <qboxlayout.h> #include <qapplication.h> @@ -53,6 +54,7 @@ #include <qrandom.h> #include <qtoolbar.h> #include <qtoolbutton.h> +#include <QtCore/qoperatingsystemversion.h> #include <QtGui/qpaintengine.h> #include <QtGui/qbackingstore.h> #include <QtGui/qguiapplication.h> @@ -140,19 +142,6 @@ static QByteArray msgComparisonFailed(T v1, const char *op, T v2) return s.toLocal8Bit(); } -// Compare a window position that may go through scaling in the platform plugin with fuzz. -static inline bool qFuzzyCompareWindowPosition(const QPoint &p1, const QPoint p2, int fuzz) -{ - return (p1 - p2).manhattanLength() <= fuzz; -} - -static QString msgPointMismatch(const QPoint &p1, const QPoint p2) -{ - QString result; - QDebug(&result) << p1 << "!=" << p2 << ", manhattanLength=" << (p1 - p2).manhattanLength(); - return result; -} - class tst_QWidget : public QObject { Q_OBJECT @@ -192,6 +181,7 @@ private slots: void tabOrderWithProxy(); void tabOrderWithCompoundWidgets(); void tabOrderNoChange(); + void tabOrderNoChange2(); #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) void activation(); #endif @@ -418,6 +408,7 @@ private: QPoint m_safeCursorPos; const bool m_windowsAnimationsEnabled; QTouchDevice *m_touchScreen; + const int m_fuzz; }; bool tst_QWidget::ensureScreenSize(int width, int height) @@ -576,6 +567,7 @@ tst_QWidget::tst_QWidget() , m_safeCursorPos(0, 0) , m_windowsAnimationsEnabled(windowsAnimationsEnabled()) , m_touchScreen(QTest::createTouchDevice()) + , m_fuzz(int(QGuiApplication::primaryScreen()->devicePixelRatio())) { if (m_windowsAnimationsEnabled) // Disable animations which can interfere with screen grabbing in moveChild(), showAndMoveChild() setWindowsAnimationsEnabled(false); @@ -1952,6 +1944,24 @@ static QVector<QWidget*> getFocusChain(QWidget *start, bool bForward) return ret; } +//#define DEBUG_FOCUS_CHAIN +static void dumpFocusChain(QWidget *start, bool bForward, const char *desc = nullptr) +{ +#ifdef DEBUG_FOCUS_CHAIN + qDebug() << "Dump focus chain, start:" << start << "isForward:" << bForward << desc; + QWidget *cur = start; + do { + qDebug() << cur; + auto widgetPrivate = static_cast<QWidgetPrivate *>(qt_widget_private(cur)); + cur = bForward ? widgetPrivate->focus_next : widgetPrivate->focus_prev; + } while (cur != start); +#else + Q_UNUSED(start) + Q_UNUSED(bForward) + Q_UNUSED(desc) +#endif +} + void tst_QWidget::tabOrderNoChange() { QWidget w; @@ -1963,7 +1973,61 @@ void tst_QWidget::tabOrderNoChange() const auto focusChainForward = getFocusChain(&w, true); const auto focusChainBackward = getFocusChain(&w, false); + dumpFocusChain(&w, true); QWidget::setTabOrder(tabWidget, tv); + dumpFocusChain(&w, true); + QCOMPARE(focusChainForward, getFocusChain(&w, true)); + QCOMPARE(focusChainBackward, getFocusChain(&w, false)); +} + +void tst_QWidget::tabOrderNoChange2() +{ + QWidget w; + auto *verticalLayout = new QVBoxLayout(&w); + auto *tabWidget = new QTabWidget(&w); + tabWidget->setObjectName("tabWidget"); + verticalLayout->addWidget(tabWidget); + + auto *tab1 = new QWidget(tabWidget); + tab1->setObjectName("tab1"); + auto *vLay1 = new QVBoxLayout(tab1); + auto *le1 = new QLineEdit(tab1); + le1->setObjectName("le1"); + auto *le2 = new QLineEdit(tab1); + le2->setObjectName("le2"); + vLay1->addWidget(le1); + vLay1->addWidget(le2); + tabWidget->addTab(tab1, QStringLiteral("Tab 1")); + + auto *tab2 = new QWidget(tabWidget); + tab2->setObjectName("tab2"); + auto *vLay2 = new QVBoxLayout(tab2); + auto *le3 = new QLineEdit(tab2); + le3->setObjectName("le3"); + auto *le4 = new QLineEdit(tab2); + le4->setObjectName("le4"); + vLay2->addWidget(le3); + vLay2->addWidget(le4); + tabWidget->addTab(tab2, QStringLiteral("Tab 2")); + + const auto focusChainForward = getFocusChain(&w, true); + const auto focusChainBackward = getFocusChain(&w, false); + dumpFocusChain(&w, true); + dumpFocusChain(&w, false); + // this will screw up the focus chain order without visible changes, + // so don't call it here for the simplicity of the test + //QWidget::setTabOrder(tabWidget, le1); + + QWidget::setTabOrder(le1, le2); + dumpFocusChain(&w, true, "QWidget::setTabOrder(le1, le2)"); + QWidget::setTabOrder(le2, le3); + dumpFocusChain(&w, true, "QWidget::setTabOrder(le2, le3)"); + QWidget::setTabOrder(le3, le4); + dumpFocusChain(&w, true, "QWidget::setTabOrder(le3, le4)"); + QWidget::setTabOrder(le4, tabWidget); + dumpFocusChain(&w, true, "QWidget::setTabOrder(le4, tabWidget)"); + dumpFocusChain(&w, false); + QCOMPARE(focusChainForward, getFocusChain(&w, true)); QCOMPARE(focusChainBackward, getFocusChain(&w, false)); } @@ -2049,10 +2113,9 @@ void tst_QWidget::windowState() widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); QTest::qWait(100); - const int fuzz = int(QHighDpiScaling::factor(widget1.windowHandle())); QVERIFY(!(widget1.windowState() & Qt::WindowMaximized)); - QTRY_VERIFY2(qFuzzyCompareWindowPosition(widget1.pos(), pos, fuzz), - qPrintable(msgPointMismatch(widget1.pos(), pos))); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget1.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget1.pos(), pos))); QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState); widget1.setWindowState(Qt::WindowMinimized); @@ -2073,8 +2136,8 @@ void tst_QWidget::windowState() widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized); QTest::qWait(100); QVERIFY(!(widget1.windowState() & (Qt::WindowMinimized|Qt::WindowMaximized))); - QTRY_VERIFY2(qFuzzyCompareWindowPosition(widget1.pos(), pos, fuzz), - qPrintable(msgPointMismatch(widget1.pos(), pos))); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget1.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget1.pos(), pos))); QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState); widget1.setWindowState(Qt::WindowFullScreen); @@ -2095,8 +2158,8 @@ void tst_QWidget::windowState() widget1.setWindowState(Qt::WindowNoState); QTest::qWait(100); VERIFY_STATE(Qt::WindowNoState); - QTRY_VERIFY2(qFuzzyCompareWindowPosition(widget1.pos(), pos, fuzz), - qPrintable(msgPointMismatch(widget1.pos(), pos))); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget1.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget1.pos(), pos))); QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState); widget1.setWindowState(Qt::WindowFullScreen); @@ -2129,8 +2192,8 @@ void tst_QWidget::windowState() QVERIFY(!(widget1.windowState() & stateMask)); QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState); - QTRY_VERIFY2(qFuzzyCompareWindowPosition(widget1.pos(), pos, fuzz), - qPrintable(msgPointMismatch(widget1.pos(), pos))); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget1.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget1.pos(), pos))); QTRY_COMPARE(widget1.size(), size); } @@ -2323,7 +2386,7 @@ void tst_QWidget::resizeEvent() { QWidget wParent; wParent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - wParent.resize(200, 200); + wParent.resize(m_testWidgetSize); ResizeWidget wChild(&wParent); wParent.show(); QVERIFY(QTest::qWaitForWindowExposed(&wParent)); @@ -2341,7 +2404,7 @@ void tst_QWidget::resizeEvent() { ResizeWidget wTopLevel; wTopLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - wTopLevel.resize(200, 200); + wTopLevel.resize(m_testWidgetSize); wTopLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&wTopLevel)); if (m_platform == QStringLiteral("winrt")) @@ -2379,17 +2442,20 @@ void tst_QWidget::showMinimized() #ifdef Q_OS_WINRT QEXPECT_FAIL("", "Winrt does not support move and resize", Abort); #endif - QCOMPARE(plain.pos(), pos); + QVERIFY2(HighDpi::fuzzyCompare(plain.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(plain.pos(), pos))); plain.showNormal(); QVERIFY(!plain.isMinimized()); QVERIFY(plain.isVisible()); - QCOMPARE(plain.pos(), pos); + QVERIFY2(HighDpi::fuzzyCompare(plain.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(plain.pos(), pos))); plain.showMinimized(); QVERIFY(plain.isMinimized()); QVERIFY(plain.isVisible()); - QCOMPARE(plain.pos(), pos); + QVERIFY2(HighDpi::fuzzyCompare(plain.pos(), pos, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(plain.pos(), pos))); plain.hide(); QVERIFY(plain.isMinimized()); @@ -2781,7 +2847,9 @@ void tst_QWidget::setGeometry() tlw.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget child(&tlw); - QRect tr(100,100,200,200); + const QPoint topLeft = QGuiApplication::primaryScreen()->availableGeometry().topLeft(); + const QSize initialSize = 2 * m_testWidgetSize; + QRect tr(topLeft + QPoint(100,100), initialSize); QRect cr(50,50,50,50); tlw.setGeometry(tr); child.setGeometry(cr); @@ -2792,8 +2860,7 @@ void tst_QWidget::setGeometry() QCOMPARE(child.geometry(), cr); tlw.setParent(nullptr, Qt::Window|Qt::FramelessWindowHint); - tr = QRect(0,0,100,100); - tr.moveTopLeft(QGuiApplication::primaryScreen()->availableGeometry().topLeft()); + tr = QRect(topLeft, initialSize / 2); tlw.setGeometry(tr); QCOMPARE(tlw.geometry(), tr); tlw.showNormal(); @@ -3265,7 +3332,8 @@ void tst_QWidget::saveRestoreGeometry() if (m_platform == QStringLiteral("winrt")) QEXPECT_FAIL("", "WinRT does not support move/resize", Abort); - QTRY_COMPARE(widget.pos(), position); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget.pos(), position, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget.pos(), position))); QCOMPARE(widget.size(), size); savedGeometry = widget.saveGeometry(); } @@ -3293,10 +3361,12 @@ void tst_QWidget::saveRestoreGeometry() QVERIFY(QTest::qWaitForWindowExposed(&widget)); QApplication::processEvents(); - QTRY_COMPARE(widget.pos(), position); + QVERIFY2(HighDpi::fuzzyCompare(widget.pos(), position, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget.pos(), position))); QCOMPARE(widget.size(), size); widget.show(); - QCOMPARE(widget.pos(), position); + QVERIFY2(HighDpi::fuzzyCompare(widget.pos(), position, m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget.pos(), position))); QCOMPARE(widget.size(), size); } @@ -3410,6 +3480,9 @@ void tst_QWidget::restoreVersion1Geometry() QFETCH(QSize, expectedSize); QFETCH(QRect, expectedNormalGeometry); + if (m_platform == QLatin1String("windows") && QGuiApplication::primaryScreen()->geometry().width() > 2000) + QSKIP("Skipping due to minimum decorated window size on Windows"); + // WindowActive is uninteresting for this test const Qt::WindowStates WindowStateMask = Qt::WindowFullScreen | Qt::WindowMaximized | Qt::WindowMinimized; @@ -4990,7 +5063,8 @@ void tst_QWidget::windowMoveResize() widget.showNormal(); QTest::qWait(10); - QTRY_COMPARE(widget.pos(), rect.topLeft()); + QTRY_VERIFY2(HighDpi::fuzzyCompare(widget.pos(), rect.topLeft(), m_fuzz), + qPrintable(HighDpi::msgPointMismatch(widget.pos(), rect.topLeft()))); // Windows: Minimum size of decorated windows. const bool expectResizeFail = (!windowFlags && (rect.width() < 160 || rect.height() < 40)) && m_platform == QStringLiteral("windows"); @@ -6983,7 +7057,7 @@ void tst_QWidget::renderWithPainter() // Make sure QWidget::render does not modify the render hints set on the painter. painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform - | QPainter::NonCosmeticDefaultPen | QPainter::TextAntialiasing); + | QPainter::TextAntialiasing); QPainter::RenderHints oldRenderHints = painter.renderHints(); widget.render(&painter); QCOMPARE(painter.renderHints(), oldRenderHints); @@ -7581,7 +7655,7 @@ void tst_QWidget::moveWindowInShowEvent() void tst_QWidget::repaintWhenChildDeleted() { #ifdef Q_OS_WIN - if (QSysInfo::WindowsVersion & QSysInfo::WV_VISTA) { + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista) { QTest::qWait(1000); } #endif @@ -8780,7 +8854,7 @@ void tst_QWidget::translucentWidget() #ifdef Q_OS_WIN QWidget *desktopWidget = QApplication::desktop()->screen(0); - if (QSysInfo::windowsVersion() >= QSysInfo::WV_VISTA) + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista) widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height()); else #endif @@ -8791,6 +8865,12 @@ void tst_QWidget::translucentWidget() QEXPECT_FAIL("", "WinRT: This fails. QTBUG-68297.", Abort); QCOMPARE(actual.size(),expected.size()); QCOMPARE(actual,expected); + + const QWindow *window = label.windowHandle(); + const QSurfaceFormat translucentFormat = window->requestedFormat(); + label.setAttribute(Qt::WA_TranslucentBackground, false); + const QSurfaceFormat opaqueFormat = window->requestedFormat(); + QVERIFY(translucentFormat != opaqueFormat); } class MaskResizeTestWidget : public QWidget diff --git a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp index a552c91928..68e672e16d 100644 --- a/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp +++ b/tests/auto/widgets/styles/qstyle/tst_qstyle.cpp @@ -353,7 +353,10 @@ void tst_QStyle::testWindowsVistaStyle() QStyle *vistastyle = QStyleFactory::create("WindowsVista"); QVERIFY(testAllFunctions(vistastyle)); - if (QSysInfo::WindowsVersion == QSysInfo::WV_VISTA) + if (QOperatingSystemVersion::current().majorVersion() + == QOperatingSystemVersion::WindowsVista.majorVersion() + && QOperatingSystemVersion::current().minorVersion() + == QOperatingSystemVersion::WindowsVista.minorVersion()) testPainting(vistastyle, "vista"); delete vistastyle; } diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp index 8bb16cc9d1..5a51f15008 100644 --- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp @@ -38,47 +38,50 @@ #include "../../../../shared/filesystem.h" +#include <memory> + +Q_DECLARE_METATYPE(QCompleter::CompletionMode) + using namespace QTestPrivate; class CsvCompleter : public QCompleter { Q_OBJECT public: - CsvCompleter(QObject *parent = 0) : QCompleter(parent), csv(true) { } + using QCompleter::QCompleter; - QString pathFromIndex(const QModelIndex& sourceIndex) const; + QString pathFromIndex(const QModelIndex& sourceIndex) const override; void setCsvCompletion(bool set) { csv = set; } protected: - QStringList splitPath(const QString &path) const { + QStringList splitPath(const QString &path) const override + { return csv ? path.split(QLatin1Char(',')) : QCompleter::splitPath(path); } private: - bool csv; + bool csv = true; }; -QString CsvCompleter::pathFromIndex(const QModelIndex& si) const +QString CsvCompleter::pathFromIndex(const QModelIndex &sourceIndex) const { if (!csv) - return QCompleter::pathFromIndex(si); + return QCompleter::pathFromIndex(sourceIndex); - if (!si.isValid()) + if (!sourceIndex.isValid()) return QString(); - QModelIndex idx = si; + QModelIndex idx = sourceIndex; QStringList list; do { QString t = model()->data(idx, completionRole()).toString(); list.prepend(t); QModelIndex parent = idx.parent(); - idx = parent.sibling(parent.row(), si.column()); + idx = parent.sibling(parent.row(), sourceIndex.column()); } while (idx.isValid()); - if (list.count() == 1) - return list[0]; - return list.join(','); + return list.count() == 1 ? list.constFirst() : list.join(QLatin1Char(',')); } class tst_QCompleter : public QObject @@ -154,15 +157,14 @@ private: }; void setSourceModel(ModelType); - CsvCompleter *completer; + CsvCompleter *completer = nullptr; QTreeWidget *treeWidget; - const int completionColumn; - const int columnCount; + const int completionColumn = 0; + const int columnCount = 3; }; -tst_QCompleter::tst_QCompleter() : completer(0), completionColumn(0), columnCount(3) +tst_QCompleter::tst_QCompleter() : treeWidget(new QTreeWidget) { - treeWidget = new QTreeWidget; treeWidget->move(100, 100); treeWidget->setColumnCount(columnCount); } @@ -184,11 +186,11 @@ void tst_QCompleter::setSourceModel(ModelType type) for (int i = 0; i < 2; i++) { for (int j = 0; j < 5; j++) { parent = new QTreeWidgetItem(treeWidget); - const QString text = QString::asprintf("%c%i", i == 0 ? 'P' : 'p', j); + const QString text = QLatin1Char(i == 0 ? 'P' : 'p') + QString::number(j); parent->setText(completionColumn, text); for (int k = 0; k < 5; k++) { child = new QTreeWidgetItem(parent); - QString t = QString::asprintf("c%i", k) + text; + QString t = QLatin1Char('c') + QString::number(k) + text; child->setText(completionColumn, t); } } @@ -203,11 +205,11 @@ void tst_QCompleter::setSourceModel(ModelType type) for (int i = 0; i < 5; i++) { for (int j = 0; j < 2; j++) { parent = new QTreeWidgetItem(treeWidget); - const QString text = QString::asprintf("%c%i", j == 0 ? 'P' : 'p', i); + const QString text = QLatin1Char(j == 0 ? 'P' : 'p') + QString::number(i); parent->setText(completionColumn, text); for (int k = 0; k < 5; k++) { child = new QTreeWidgetItem(parent); - QString t = QString::asprintf("c%i", k) + text; + QString t = QLatin1Char('c') + QString::number(k) + text; child->setText(completionColumn, t); } } @@ -229,7 +231,7 @@ void tst_QCompleter::setSourceModel(ModelType type) case FILESYSTEM_MODEL: completer->setCsvCompletion(false); { - QFileSystemModel *m = new QFileSystemModel(completer); + auto m = new QFileSystemModel(completer); m->setRootPath("/"); completer->setModel(m); } @@ -237,13 +239,14 @@ void tst_QCompleter::setSourceModel(ModelType type) break; default: qDebug() << "Invalid type"; + break; } } void tst_QCompleter::filter(bool assync) { QFETCH(QString, filterText); - QFETCH(QString, step); + QFETCH(const QString, step); QFETCH(QString, completion); QFETCH(QString, completionText); @@ -252,33 +255,43 @@ void tst_QCompleter::filter(bool assync) return; } - int times = 0; -retry: - - completer->setCompletionPrefix(filterText); - - for (int i = 0; i < step.length(); i++) { - int row = completer->currentRow(); - switch (step[i].toUpper().toLatin1()) { - case 'P': --row; break; - case 'N': ++row; break; - case 'L': row = completer->completionCount() - 1; break; - case 'F': row = 0; break; - default: - QFAIL(qPrintable(QString( - "Problem with 'step' value in test data: %1 (only P, N, L and F are allowed)." - ).arg(step[i]))); + int result = -1; + const int attempts = assync ? 10 : 1; + for (int times = 0; times < attempts; ++times) { + completer->setCompletionPrefix(filterText); + + for (QChar s : step) { + int row = completer->currentRow(); + switch (s.toUpper().toLatin1()) { + case 'P': + --row; + break; + case 'N': + ++row; + break; + case 'L': + row = completer->completionCount() - 1; + break; + case 'F': + row = 0; + break; + default: + QFAIL(qPrintable(QString( + "Problem with 'step' value in test data: %1 (only P, N, L and F are allowed)." + ).arg(s))); + } + completer->setCurrentRow(row); } - completer->setCurrentRow(row); - } - int r = QString::compare(completer->currentCompletion(), completionText, completer->caseSensitivity()); - if (assync && r && times < 10) { - times++; - QTest::qWait(50*times); - goto retry; + result = QString::compare(completer->currentCompletion(), completionText, + completer->caseSensitivity()); + if (result == 0) + break; + if (assync) + QTest::qWait(50 * times); } - QVERIFY(!r); + + QCOMPARE(result, 0); } // Testing get/set functions @@ -844,8 +857,7 @@ void tst_QCompleter::sortedEngineMapFromSource() QModelIndex si1, si2, pi; QAbstractItemModel *sourceModel = completer->model(); - const QAbstractProxyModel *completionModel = - qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); + auto completionModel = qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); // Fitering ON // empty @@ -915,8 +927,7 @@ void tst_QCompleter::unsortedEngineMapFromSource() QModelIndex si, si2, si3, pi; QAbstractItemModel *sourceModel = completer->model(); - const QAbstractProxyModel *completionModel = - qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); + auto completionModel = qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); si = sourceModel->index(6, completionColumn); // "P3" QCOMPARE(si.data().toString(), QLatin1String("P3")); @@ -997,8 +1008,7 @@ void tst_QCompleter::historySearch() completer->setCaseSensitivity(Qt::CaseSensitive); setSourceModel(HISTORY_MODEL); - const QAbstractProxyModel *completionModel = - qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); + auto completionModel = qobject_cast<const QAbstractProxyModel *>(completer->completionModel()); // "p3,c3p3" and "p2,c4p2" are added in the tree root @@ -1046,7 +1056,7 @@ void tst_QCompleter::setters() { delete completer; completer = new CsvCompleter; - QVERIFY(completer->popup() != 0); + QVERIFY(completer->popup() != nullptr); QPointer<QDirModel> dirModel = new QDirModel(completer); QAbstractItemModel *oldModel = completer->model(); completer->setModel(dirModel); @@ -1055,28 +1065,28 @@ void tst_QCompleter::setters() completer->setPopup(new QListView); QCOMPARE(completer->popup()->model(), completer->completionModel()); completer->setModel(new QStringListModel(completer)); - QVERIFY(dirModel == 0); // must have been deleted + QVERIFY(dirModel == nullptr); // must have been deleted - completer->setModel(0); - completer->setWidget(0); + completer->setModel(nullptr); + completer->setWidget(nullptr); } void tst_QCompleter::modelDeletion() { delete completer; completer = new CsvCompleter; - QStringList list; - list << "item1" << "item2" << "item3"; - QStringListModel *listModel = new QStringListModel(list); + const QStringList list = {"item1", "item2", "item3"}; + std::unique_ptr<QStringListModel> listModel(new QStringListModel(list)); completer->setCompletionPrefix("i"); - completer->setModel(listModel); + completer->setModel(listModel.get()); QCOMPARE(completer->completionCount(), 3); - QScopedPointer<QListView> view(new QListView); + std::unique_ptr<QListView> view(new QListView); + view->setWindowTitle(QLatin1String(QTest::currentTestFunction())); view->setModel(completer->completionModel()); - delete listModel; + listModel.reset(); view->move(200, 200); view->show(); - qApp->processEvents(); + QCoreApplication::processEvents(); view.reset(); QCOMPARE(completer->completionCount(), 0); QCOMPARE(completer->currentRow(), -1); @@ -1090,6 +1100,7 @@ void tst_QCompleter::multipleWidgets() completer.setCompletionMode(QCompleter::InlineCompletion); QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.move(200, 200); window.show(); QApplication::setActiveWindow(&window); @@ -1098,7 +1109,7 @@ void tst_QCompleter::multipleWidgets() QFocusEvent focusIn(QEvent::FocusIn); QFocusEvent focusOut(QEvent::FocusOut); - QComboBox *comboBox = new QComboBox(&window); + auto comboBox = new QComboBox(&window); comboBox->setEditable(true); comboBox->setCompleter(&completer); comboBox->setFocus(); @@ -1114,7 +1125,7 @@ void tst_QCompleter::multipleWidgets() comboBox->clearEditText(); QCOMPARE(comboBox->currentText(), QString("")); // combo box text must not change! - QLineEdit *lineEdit = new QLineEdit(&window); + auto lineEdit = new QLineEdit(&window); lineEdit->setCompleter(&completer); lineEdit->show(); lineEdit->setFocus(); @@ -1129,29 +1140,28 @@ void tst_QCompleter::multipleWidgets() void tst_QCompleter::focusIn() { - QStringList list; - list << "item1" << "item2" << "item2"; - QCompleter completer(list); + QCompleter completer({"item1", "item2", "item2"}); QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.move(200, 200); window.show(); window.activateWindow(); QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); - QComboBox *comboBox = new QComboBox(&window); + auto comboBox = new QComboBox(&window); comboBox->setEditable(true); comboBox->setCompleter(&completer); comboBox->show(); comboBox->lineEdit()->setText("it"); - QLineEdit *lineEdit = new QLineEdit(&window); + auto lineEdit = new QLineEdit(&window); lineEdit->setCompleter(&completer); lineEdit->setText("it"); lineEdit->show(); - QLineEdit *lineEdit2 = new QLineEdit(&window); // has no completer! + auto lineEdit2 = new QLineEdit(&window); // has no completer! lineEdit2->show(); comboBox->setFocus(); @@ -1190,12 +1200,13 @@ void tst_QCompleter::dynamicSortOrder() void tst_QCompleter::disabledItems() { QLineEdit lineEdit; - QStandardItemModel *model = new QStandardItemModel(&lineEdit); + lineEdit.setWindowTitle(QLatin1String(QTest::currentTestFunction())); + auto model = new QStandardItemModel(&lineEdit); QStandardItem *suggestions = new QStandardItem("suggestions"); suggestions->setEnabled(false); model->appendRow(suggestions); model->appendRow(new QStandardItem("suggestions Enabled")); - QCompleter *completer = new QCompleter(model, &lineEdit); + auto completer = new QCompleter(model, &lineEdit); QSignalSpy spy(completer, QOverload<const QString &>::of(&QCompleter::activated)); lineEdit.setCompleter(completer); lineEdit.move(200, 200); @@ -1206,42 +1217,40 @@ void tst_QCompleter::disabledItems() QTest::keyPress(&lineEdit, Qt::Key_U); QAbstractItemView *view = lineEdit.completer()->popup(); QVERIFY(view->isVisible()); - QTest::mouseClick(view->viewport(), Qt::LeftButton, 0, view->visualRect(view->model()->index(0, 0)).center()); + QTest::mouseClick(view->viewport(), Qt::LeftButton, {}, view->visualRect(view->model()->index(0, 0)).center()); QCOMPARE(spy.count(), 0); QVERIFY(view->isVisible()); - QTest::mouseClick(view->viewport(), Qt::LeftButton, 0, view->visualRect(view->model()->index(1, 0)).center()); + QTest::mouseClick(view->viewport(), Qt::LeftButton, {}, view->visualRect(view->model()->index(1, 0)).center()); QCOMPARE(spy.count(), 1); QVERIFY(!view->isVisible()); } void tst_QCompleter::task178797_activatedOnReturn() { - QStringList words; - words << "foobar1" << "foobar2"; QLineEdit ledit; setFrameless(&ledit); - QCompleter *completer = new QCompleter(words, &ledit); + auto completer = new QCompleter({"foobar1", "foobar2"}, &ledit); ledit.setCompleter(completer); QSignalSpy spy(completer, QOverload<const QString &>::of(&QCompleter::activated)); QCOMPARE(spy.count(), 0); ledit.move(200, 200); ledit.show(); - qApp->setActiveWindow(&ledit); + QApplication::setActiveWindow(&ledit); QVERIFY(QTest::qWaitForWindowActive(&ledit)); QTest::keyClick(&ledit, Qt::Key_F); - qApp->processEvents(); - QTRY_VERIFY(qApp->activePopupWidget()); - QTest::keyClick(qApp->activePopupWidget(), Qt::Key_Down); - qApp->processEvents(); - QTest::keyClick(qApp->activePopupWidget(), Qt::Key_Return); - qApp->processEvents(); + QCoreApplication::processEvents(); + QTRY_VERIFY(QApplication::activePopupWidget()); + QTest::keyClick(QApplication::activePopupWidget(), Qt::Key_Down); + QCoreApplication::processEvents(); + QTest::keyClick(QApplication::activePopupWidget(), Qt::Key_Return); + QCoreApplication::processEvents(); QCOMPARE(spy.count(), 1); } class task189564_StringListModel : public QStringListModel { const QString omitString; - Qt::ItemFlags flags(const QModelIndex &index) const + Qt::ItemFlags flags(const QModelIndex &index) const override { Qt::ItemFlags flags = Qt::ItemIsEnabled; if (data(index, Qt::DisplayRole).toString() != omitString) @@ -1249,7 +1258,7 @@ class task189564_StringListModel : public QStringListModel return flags; } public: - task189564_StringListModel(const QString &omitString, QObject *parent = 0) + explicit task189564_StringListModel(const QString &omitString, QObject *parent = nullptr) : QStringListModel(parent) , omitString(omitString) { @@ -1315,8 +1324,7 @@ void tst_QCompleter::task246056_setCompletionPrefix() QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Down); QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Enter); // don't crash! QCOMPARE(spy.count(), 1); - QList<QVariant> arguments = spy.at(0); - QModelIndex index = arguments.at(0).value<QModelIndex>(); + const auto index = spy.at(0).constFirst().toModelIndex(); QVERIFY(!index.isValid()); } @@ -1331,7 +1339,7 @@ public: completer->setWidget(this); } - void keyPressEvent (QKeyEvent *e) + void keyPressEvent (QKeyEvent *e) override { completer->popup(); QTextEdit::keyPressEvent(e); @@ -1344,11 +1352,11 @@ class task250064_Widget : public QWidget public: task250064_Widget() : m_textEdit(new task250064_TextEdit) { - QTabWidget *tabWidget = new QTabWidget; + auto tabWidget = new QTabWidget; tabWidget->setFocusPolicy(Qt::ClickFocus); tabWidget->addTab(m_textEdit, "untitled"); - QVBoxLayout *layout = new QVBoxLayout(this); + auto layout = new QVBoxLayout(this); layout->addWidget(tabWidget); m_textEdit->setPlainText("bla bla bla"); @@ -1357,7 +1365,7 @@ public: void setCompletionModel() { - m_textEdit->completer->setModel(0); + m_textEdit->completer->setModel(nullptr); } QTextEdit *textEdit() const { return m_textEdit; } @@ -1369,6 +1377,7 @@ private: void tst_QCompleter::task250064_lostFocus() { task250064_Widget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.show(); QApplication::setActiveWindow(&widget); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -1382,33 +1391,33 @@ void tst_QCompleter::task250064_lostFocus() void tst_QCompleter::task253125_lineEditCompletion_data() { QTest::addColumn<QStringList>("list"); - QTest::addColumn<int>("completionMode"); + QTest::addColumn<QCompleter::CompletionMode>("completionMode"); - QStringList list = QStringList() - << "alpha" << "beta" << "gamma" << "delta" << "epsilon" << "zeta" - << "eta" << "theta" << "iota" << "kappa" << "lambda" << "mu" - << "nu" << "xi" << "omicron" << "pi" << "rho" << "sigma" - << "tau" << "upsilon" << "phi" << "chi" << "psi" << "omega"; + QStringList list = {"alpha", "beta", "gamma", "delta", "epsilon", "zeta", + "eta", "theta", "iota", "kappa", "lambda", "mu", + "nu", "xi", "omicron", "pi", "rho", "sigma", + "tau", "upsilon", "phi", "chi", "psi", "omega"}; - QTest::newRow("Inline") << list << (int)QCompleter::InlineCompletion; - QTest::newRow("Filtered") << list << (int)QCompleter::PopupCompletion; - QTest::newRow("Unfiltered") << list << (int)QCompleter::UnfilteredPopupCompletion; + QTest::newRow("Inline") << list << QCompleter::InlineCompletion; + QTest::newRow("Filtered") << list << QCompleter::PopupCompletion; + QTest::newRow("Unfiltered") << list << QCompleter::UnfilteredPopupCompletion; } void tst_QCompleter::task253125_lineEditCompletion() { QFETCH(QStringList, list); - QFETCH(int, completionMode); + QFETCH(QCompleter::CompletionMode, completionMode); - QStringListModel *model = new QStringListModel; - model->setStringList(list); + std::unique_ptr<QStringListModel> model(new QStringListModel(list)); - QCompleter *completer = new QCompleter(list); - completer->setModel(model); - completer->setCompletionMode((QCompleter::CompletionMode)completionMode); + std::unique_ptr<QCompleter> completer(new QCompleter(list)); + completer->setModel(model.get()); + completer->setCompletionMode(completionMode); QLineEdit edit; - edit.setCompleter(completer); + edit.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("::") + + QLatin1String(QTest::currentDataTag())); + edit.setCompleter(completer.get()); edit.move(200, 200); edit.show(); edit.setFocus(); @@ -1550,9 +1559,6 @@ void tst_QCompleter::task253125_lineEditCompletion() QTest::keyClick(edit.completer()->popup(), Qt::Key_Enter); QCOMPARE(edit.text(), QString("zz")); - - delete completer; - delete model; } void tst_QCompleter::task247560_keyboardNavigation() @@ -1570,6 +1576,7 @@ void tst_QCompleter::task247560_keyboardNavigation() completer.setCompletionColumn(1); QLineEdit edit; + edit.setWindowTitle(QLatin1String(QTest::currentTestFunction())); edit.setCompleter(&completer); edit.move(200, 200); edit.show(); @@ -1677,6 +1684,7 @@ void tst_QCompleter::QTBUG_14292_filesystem() QVERIFY(fs.createDirectory(QLatin1String(testDir2))); QLineEdit edit; + edit.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QCompleter comp; comp.setModel(&model); edit.setCompleter(&comp); @@ -1739,16 +1747,14 @@ void tst_QCompleter::QTBUG_14292_filesystem() void tst_QCompleter::QTBUG_52028_tabAutoCompletes() { - QStringList words; - words << "foobar1" << "foobar2" << "hux"; - QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setLayout(new QVBoxLayout); QComboBox cbox; cbox.setEditable(true); cbox.setInsertPolicy(QComboBox::NoInsert); - cbox.addItems(words); + cbox.addItems({"foobar1", "foobar2", "hux"}); cbox.completer()->setCaseSensitivity(Qt::CaseInsensitive); cbox.completer()->setCompletionMode(QCompleter::PopupCompletion); @@ -1756,8 +1762,8 @@ void tst_QCompleter::QTBUG_52028_tabAutoCompletes() w.layout()->addWidget(&cbox); // Adding a line edit is a good reason for tab to do something unrelated - QLineEdit le; - w.layout()->addWidget(&le); + auto le = new QLineEdit; + w.layout()->addWidget(le); const auto pos = QApplication::desktop()->availableGeometry(&w).topLeft() + QPoint(200,200); w.move(pos); @@ -1778,30 +1784,27 @@ void tst_QCompleter::QTBUG_52028_tabAutoCompletes() QEXPECT_FAIL("", "QTBUG-52028 will not be fixed today.", Abort); QCOMPARE(cbox.currentText(), QLatin1String("hux")); QCOMPARE(activatedSpy.count(), 0); - QVERIFY(!le.hasFocus()); + QVERIFY(!le->hasFocus()); } void tst_QCompleter::QTBUG_51889_activatedSentTwice() { - QStringList words; - words << "foobar1" << "foobar2" << "bar" <<"hux"; - QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setLayout(new QVBoxLayout); QComboBox cbox; setFrameless(&cbox); cbox.setEditable(true); cbox.setInsertPolicy(QComboBox::NoInsert); - cbox.addItems(words); + cbox.addItems({"foobar1", "foobar2", "bar", "hux"}); cbox.completer()->setCaseSensitivity(Qt::CaseInsensitive); cbox.completer()->setCompletionMode(QCompleter::PopupCompletion); w.layout()->addWidget(&cbox); - QLineEdit le; - w.layout()->addWidget(&le); + w.layout()->addWidget(new QLineEdit); const auto pos = QApplication::desktop()->availableGeometry(&w).topLeft() + QPoint(200,200); w.move(pos); diff --git a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp index 1a0d7a9289..d8fbb8e041 100644 --- a/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp +++ b/tests/auto/widgets/widgets/qabstractslider/tst_qabstractslider.cpp @@ -33,7 +33,7 @@ #include <QSlider> #include <QStyle> #include <QStyleOption> -#include <QTime> +#include <QElapsedTimer> #include <QDebug> #include <QtTest/private/qtesthelpers_p.h> @@ -91,7 +91,7 @@ private slots: void connectedSliders(); private: - void waitUntilTimeElapsed(const QTime& t, int ms); + void waitUntilTimeElapsed(const QElapsedTimer &t, int ms); QWidget *topLevel; Slider *slider; @@ -2053,11 +2053,11 @@ void tst_QAbstractSlider::setValue() QVERIFY(sliderMovedTimeStamp < valueChangedTimeStamp); } -void tst_QAbstractSlider::waitUntilTimeElapsed(const QTime& t, int ms) +void tst_QAbstractSlider::waitUntilTimeElapsed(const QElapsedTimer &t, int ms) { const int eps = 80; while (t.elapsed() < ms + eps) - QTest::qWait(qMax(ms - t.elapsed() + eps, 25)); + QTest::qWait(qMax(int(ms - t.elapsed() + eps), 25)); } void tst_QAbstractSlider::setRepeatAction() @@ -2073,7 +2073,7 @@ void tst_QAbstractSlider::setRepeatAction() QCOMPARE(spy.count(), 0); QCOMPARE(slider->value(), 55); - QTime t; + QElapsedTimer t; t.start(); QTest::qWait(300); QCOMPARE(spy.count(), 0); diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 5b4761ba87..a576770811 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -852,8 +852,8 @@ void tst_QComboBox::autoCompletionCaseSensitivity() // case insensitive testWidget->clearEditText(); QSignalSpy spyReturn(testWidget, SIGNAL(activated(int))); - testWidget->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive); - QCOMPARE(testWidget->autoCompletionCaseSensitivity(), Qt::CaseInsensitive); + testWidget->completer()->setCaseSensitivity(Qt::CaseInsensitive); + QCOMPARE(testWidget->completer()->caseSensitivity(), Qt::CaseInsensitive); QTest::keyClick(testWidget->lineEdit(), Qt::Key_A); qApp->processEvents(); @@ -886,8 +886,8 @@ void tst_QComboBox::autoCompletionCaseSensitivity() // case sensitive testWidget->clearEditText(); - testWidget->setAutoCompletionCaseSensitivity(Qt::CaseSensitive); - QCOMPARE(testWidget->autoCompletionCaseSensitivity(), Qt::CaseSensitive); + testWidget->completer()->setCaseSensitivity(Qt::CaseSensitive); + QCOMPARE(testWidget->completer()->caseSensitivity(), Qt::CaseSensitive); QTest::keyClick(testWidget->lineEdit(), Qt::Key_A); qApp->processEvents(); QCOMPARE(testWidget->currentText(), QString("aww")); diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp index c6f6900def..cd045e476c 100644 --- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp @@ -3454,7 +3454,7 @@ void tst_QDateTimeEdit::timeSpec() } QVERIFY(edit.minimumTime() != min.time()); QVERIFY(edit.minimumDateTime().timeSpec() != min.timeSpec()); - QCOMPARE(edit.minimumDateTime().toTime_t(), min.toTime_t()); + QCOMPARE(edit.minimumDateTime().toSecsSinceEpoch(), min.toSecsSinceEpoch()); } else { QSKIP("Not tested in the GMT timezone"); } diff --git a/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp b/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp index 1813e5ad5f..5392d36ae0 100644 --- a/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp +++ b/tests/auto/widgets/widgets/qfontcombobox/tst_qfontcombobox.cpp @@ -108,7 +108,7 @@ void tst_QFontComboBox::currentFont() QFont oldCurrentFont = box.currentFont(); box.setCurrentFont(currentFont); - QRegExp foundry(" \\[.*\\]"); + QRegularExpression foundry(" \\[.*\\]"); if (!box.currentFont().family().contains(foundry)) { QCOMPARE(box.currentFont(), currentFont); } diff --git a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp index df5ff9d448..3408fc0946 100644 --- a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp +++ b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp @@ -174,7 +174,7 @@ void tst_QProgressBar::format() #ifndef Q_OS_MAC // Animated scroll bars get paint events all the time #ifdef Q_OS_WIN - if (QSysInfo::WindowsVersion < QSysInfo::WV_VISTA) + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::WindowsVista) #endif QVERIFY(!bar.repainted); #endif diff --git a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp index d744cece9c..8b45ac20b7 100644 --- a/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp +++ b/tests/auto/widgets/widgets/qsplitter/tst_qsplitter.cpp @@ -735,6 +735,7 @@ void tst_QSplitter::replaceWidget() // Configure splitter QWidget *oldWidget = sp.widget(index); + QTest::qWait(100); // Make sure we record the right original size (after the window manager adds the frame) const QRect oldGeom = oldWidget ? oldWidget->geometry() : QRect(); if (oldWidget) { // Collapse first, then hide, if necessary diff --git a/tests/auto/widgets/widgets/qtextbrowser/heading.html b/tests/auto/widgets/widgets/qtextbrowser/heading.html new file mode 100644 index 0000000000..8b23807f65 --- /dev/null +++ b/tests/auto/widgets/widgets/qtextbrowser/heading.html @@ -0,0 +1,2 @@ +<h3>this is a heading</h3> +<p>this is a paragraph</p> diff --git a/tests/auto/widgets/widgets/qtextbrowser/markdown.really b/tests/auto/widgets/widgets/qtextbrowser/markdown.really new file mode 100644 index 0000000000..be56aef234 --- /dev/null +++ b/tests/auto/widgets/widgets/qtextbrowser/markdown.really @@ -0,0 +1,2 @@ +### this is a heading +this is a paragraph diff --git a/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro b/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro index 05c156bf59..dfdcf26497 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro +++ b/tests/auto/widgets/widgets/qtextbrowser/qtextbrowser.pro @@ -4,6 +4,6 @@ SOURCES += tst_qtextbrowser.cpp QT += widgets testlib -TESTDATA += *.html *.md subdir/* +TESTDATA += *.html *.md markdown.really subdir/* builtin_testdata: DEFINES += BUILTIN_TESTDATA diff --git a/tests/auto/widgets/widgets/qtextbrowser/quotesAndFractions.md b/tests/auto/widgets/widgets/qtextbrowser/quotesAndFractions.md new file mode 100644 index 0000000000..6bad9cb95b --- /dev/null +++ b/tests/auto/widgets/widgets/qtextbrowser/quotesAndFractions.md @@ -0,0 +1 @@ +you’ll hope to see ❝quotes❞ ﹠1½ ⅔ ¼ ⅗ ⅚ ⅝ some “vulgar” fractions (pardon my «French») diff --git a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp index 22cd3b46c6..27bf0ce7be 100644 --- a/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp +++ b/tests/auto/widgets/widgets/qtextbrowser/tst_qtextbrowser.cpp @@ -92,7 +92,10 @@ private slots: void focusIndicator(); void focusHistory(); void urlEncoding(); - void markdown(); + void sourceType_data(); + void sourceType(); + void unicode_data(); + void unicode(); private: TestBrowser *browser; @@ -679,20 +682,72 @@ void tst_QTextBrowser::urlEncoding() delete browser; } -void tst_QTextBrowser::markdown() +void tst_QTextBrowser::sourceType_data() { - browser->setSource(QUrl::fromLocalFile(QFINDTESTDATA("markdown.md"))); + QTest::addColumn<QString>("sourceFile"); + QTest::addColumn<QTextDocument::ResourceType>("sourceType"); + QTest::addColumn<int>("expectedMaxHeadingLevel"); + QTest::addColumn<QTextDocument::ResourceType>("expectedSourceType"); + +#if QT_CONFIG(textmarkdownreader) + const int maxMdHeadingLevel = 3; + const QTextDocument::ResourceType mdExpectedType = QTextDocument::MarkdownResource; +#else + // If Qt doesn't support markdown, and we read a MD document anyway, it won't have any H3's. + const int maxMdHeadingLevel = 0; + const QTextDocument::ResourceType mdExpectedType = QTextDocument::HtmlResource; +#endif + QTest::newRow("markdown detected") << "markdown.md" << QTextDocument::UnknownResource << maxMdHeadingLevel << mdExpectedType; + QTest::newRow("markdown specified") << "markdown.really" << QTextDocument::MarkdownResource << maxMdHeadingLevel << mdExpectedType; + QTest::newRow("markdown not identified") << "markdown.really" << QTextDocument::UnknownResource << 0 << QTextDocument::HtmlResource; + QTest::newRow("html detected") << "heading.html" << QTextDocument::UnknownResource << 3 << QTextDocument::HtmlResource; + QTest::newRow("html specified") << "heading.html" << QTextDocument::HtmlResource << 3 << QTextDocument::HtmlResource; +} + +void tst_QTextBrowser::sourceType() +{ + QFETCH(QString, sourceFile); + QFETCH(QTextDocument::ResourceType, sourceType); + QFETCH(int, expectedMaxHeadingLevel); + QFETCH(QTextDocument::ResourceType, expectedSourceType); + if (sourceType == QTextDocument::UnknownResource) + // verify that the property setter works, with its default parameter for sourceType + browser->setProperty("source", QUrl::fromLocalFile(QFINDTESTDATA(sourceFile))); + else + browser->setSource(QUrl::fromLocalFile(QFINDTESTDATA(sourceFile)), sourceType); + QCOMPARE(browser->sourceType(), expectedSourceType); QTextFrame::iterator iterator = browser->document()->rootFrame()->begin(); int maxHeadingLevel = -1; while (!iterator.atEnd()) maxHeadingLevel = qMax(iterator++.currentBlock().blockFormat().intProperty(QTextFormat::HeadingLevel), maxHeadingLevel); + QCOMPARE(maxHeadingLevel, expectedMaxHeadingLevel); +} + +void tst_QTextBrowser::unicode_data() +{ + QTest::addColumn<QString>("sourceFile"); + QTest::addColumn<QTextDocument::ResourceType>("sourceType"); + QTest::addColumn<QString>("expectedText"); + #if QT_CONFIG(textmarkdownreader) - QCOMPARE(maxHeadingLevel, 3); -#else - // If Qt doesn't support markdown, this document will be misidentified as HTML, so it won't have any H3's. - QCOMPARE(maxHeadingLevel, 0); + QTest::newRow("markdown with quotes and fractions") << "quotesAndFractions.md" << QTextDocument::MarkdownResource << + "you\u2019ll hope to see \u275Dquotes\u275E \uFE601\u00BD \u2154 \u00BC \u2157 \u215A \u215D some \u201Cvulgar\u201D fractions (pardon my \u00ABFrench\u00BB)"; #endif } +void tst_QTextBrowser::unicode() +{ + QFETCH(QString, sourceFile); + QFETCH(QTextDocument::ResourceType, sourceType); + QFETCH(QString, expectedText); + browser->setSource(QUrl::fromLocalFile(QFINDTESTDATA(sourceFile)), sourceType); + QTextFrame::iterator iterator = browser->document()->rootFrame()->begin(); + while (!iterator.atEnd()) { + QString blockText = iterator++.currentBlock().text(); + if (!blockText.isEmpty()) + QCOMPARE(blockText, expectedText); + } +} + QTEST_MAIN(tst_QTextBrowser) #include "tst_qtextbrowser.moc" diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp index 3669935823..81682dc027 100644 --- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp @@ -160,6 +160,7 @@ private slots: void selectionChanged(); #ifndef QT_NO_CLIPBOARD void copyPasteBackgroundImage(); + void copyPasteForegroundImage(); #endif void setText(); void cursorRect(); @@ -1904,6 +1905,36 @@ void tst_QTextEdit::copyPasteBackgroundImage() ba.texture().cacheKey() == bb.texture().cacheKey()); QFile::remove(QLatin1String("foo.png")); } + +void tst_QTextEdit::copyPasteForegroundImage() +{ + ed->clear(); + + QPixmap pix(20, 20); + pix.fill(Qt::blue); + + QTextCharFormat fmt; + { + QBrush textureBrush; + { + textureBrush.setTexture(pix); + } + textureBrush.setStyle(Qt::TexturePattern); + fmt.setForeground(textureBrush); + } + ed->textCursor().insertText("Foobar", fmt); + + ed->moveCursor(QTextCursor::Start); + ed->moveCursor(QTextCursor::End, QTextCursor::KeepAnchor); + + ed->copy(); + ed->clear(); + ed->paste(); + + QBrush brush = ed->textCursor().charFormat().foreground(); + QCOMPARE(brush.style(), Qt::TexturePattern); + QCOMPARE(brush.texture().cacheKey(), pix.cacheKey()); +} #endif void tst_QTextEdit::setText() diff --git a/tests/auto/xml/sax/qxmlinputsource/tst_qxmlinputsource.cpp b/tests/auto/xml/sax/qxmlinputsource/tst_qxmlinputsource.cpp index 752e39c23f..d40c8c2fd6 100644 --- a/tests/auto/xml/sax/qxmlinputsource/tst_qxmlinputsource.cpp +++ b/tests/auto/xml/sax/qxmlinputsource/tst_qxmlinputsource.cpp @@ -34,6 +34,7 @@ #include <QTcpServer> #include <QTcpSocket> #include <QTimer> +#include <QElapsedTimer> #include <QtDebug> #include <QtTest/QtTest> #include <QXmlDefaultHandler> @@ -259,7 +260,7 @@ public: // Delibrately wait a maximum of 10 seconds for the sake // of the test, so it doesn't unduly hang const int waitTime = qMax(10000, msecs); - QTime t; + QElapsedTimer t; t.start(); while (t.elapsed() < waitTime) { QCoreApplication::processEvents(); diff --git a/tests/auto/xml/sax/qxmlsimplereader/parser/parser.cpp b/tests/auto/xml/sax/qxmlsimplereader/parser/parser.cpp index 17351883c3..556603a681 100644 --- a/tests/auto/xml/sax/qxmlsimplereader/parser/parser.cpp +++ b/tests/auto/xml/sax/qxmlsimplereader/parser/parser.cpp @@ -28,7 +28,7 @@ #include <qxml.h> -#include <qregexp.h> +#include <qregularexpression.h> #include "parser.h" @@ -139,11 +139,11 @@ bool ContentHandler::startElement(const QString &namespaceURI, QString ContentHandler::escapeStr(const QString &s) { QString result = s; - result.replace(QRegExp("\""), "\\\""); - result.replace(QRegExp("\\"), "\\\\"); - result.replace(QRegExp("\n"), "\\n"); - result.replace(QRegExp("\r"), "\\r"); - result.replace(QRegExp("\t"), "\\t"); + result.replace(QRegularExpression("\""), "\\\""); + result.replace(QRegularExpression("\\"), "\\\\"); + result.replace(QRegularExpression("\n"), "\\n"); + result.replace(QRegularExpression("\r"), "\\r"); + result.replace(QRegularExpression("\t"), "\\t"); return result; } |