tests/auto/qfile/tst_qfile.cpp
changeset 30 5dc02b23752f
parent 22 79de32ba3296
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   194     void renameMultiple();
   194     void renameMultiple();
   195     void appendAndRead();
   195     void appendAndRead();
   196     void miscWithUncPathAsCurrentDir();
   196     void miscWithUncPathAsCurrentDir();
   197     void standarderror();
   197     void standarderror();
   198     void handle();
   198     void handle();
       
   199     void nativeHandleLeaks();
   199 
   200 
   200     void readEof_data();
   201     void readEof_data();
   201     void readEof();
   202     void readEof();
   202 
   203 
   203     void map_data();
   204     void map_data();
   390     QFile::remove("nullinline.txt");
   391     QFile::remove("nullinline.txt");
   391     QFile::remove("myLink2.lnk");
   392     QFile::remove("myLink2.lnk");
   392     QFile::remove("resources");
   393     QFile::remove("resources");
   393     QFile::remove("qfile_map_testfile");
   394     QFile::remove("qfile_map_testfile");
   394     QFile::remove("readAllBuffer.txt");
   395     QFile::remove("readAllBuffer.txt");
       
   396     QFile::remove("qt_file.tmp");
   395 }
   397 }
   396 
   398 
   397 //------------------------------------------
   399 //------------------------------------------
   398 // The 'testfile' is currently just a
   400 // The 'testfile' is currently just a
   399 // testfile. The path of this file, the
   401 // testfile. The path of this file, the
  2536     QCOMPARE(int(file3.handle()), fd);
  2538     QCOMPARE(int(file3.handle()), fd);
  2537     QT_CLOSE(fd);
  2539     QT_CLOSE(fd);
  2538 #endif
  2540 #endif
  2539 }
  2541 }
  2540 
  2542 
       
  2543 void tst_QFile::nativeHandleLeaks()
       
  2544 {
       
  2545     int fd1, fd2;
       
  2546 
       
  2547 #ifdef Q_OS_WIN
       
  2548     HANDLE handle1, handle2;
       
  2549 #endif
       
  2550 
       
  2551     {
       
  2552         QFile file("qt_file.tmp");
       
  2553         QVERIFY( file.open(QIODevice::ReadWrite) );
       
  2554 
       
  2555         fd1 = file.handle();
       
  2556         QVERIFY( -1 != fd1 );
       
  2557     }
       
  2558 
       
  2559 #ifdef Q_OS_WIN
       
  2560     handle1 = ::CreateFileA("qt_file.tmp", GENERIC_READ, 0, NULL,
       
  2561             OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
       
  2562     QVERIFY( INVALID_HANDLE_VALUE != handle1 );
       
  2563     QVERIFY( ::CloseHandle(handle1) );
       
  2564 #endif
       
  2565 
       
  2566     {
       
  2567         QFile file("qt_file.tmp");
       
  2568         QVERIFY( file.open(QIODevice::ReadOnly) );
       
  2569 
       
  2570         fd2 = file.handle();
       
  2571         QVERIFY( -1 != fd2 );
       
  2572     }
       
  2573 
       
  2574 #ifdef Q_OS_WIN
       
  2575     handle2 = ::CreateFileA("qt_file.tmp", GENERIC_READ, 0, NULL,
       
  2576             OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
       
  2577     QVERIFY( INVALID_HANDLE_VALUE != handle2 );
       
  2578     QVERIFY( ::CloseHandle(handle2) );
       
  2579 #endif
       
  2580 
       
  2581     QCOMPARE( fd2, fd1 );
       
  2582 
       
  2583 #ifdef Q_OS_WIN
       
  2584     QCOMPARE( handle2, handle1 );
       
  2585 #endif
       
  2586 }
       
  2587 
  2541 void tst_QFile::readEof_data()
  2588 void tst_QFile::readEof_data()
  2542 {
  2589 {
  2543     QTest::addColumn<QString>("filename");
  2590     QTest::addColumn<QString>("filename");
  2544     QTest::addColumn<int>("imode");
  2591     QTest::addColumn<int>("imode");
  2545 
  2592