Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  TestUniquePtrExtensions.cpp

  Sprache: C
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "gtest/gtest.h"

#include "mozilla/UniquePtrExtensions.h"
#ifdef XP_UNIX
#  include "fcntl.h"
#  include "unistd.h"
#endif
#ifdef XP_WIN
#  include "namedpipeapi.h"
#endif

using namespace mozilla;

static UniqueFileHandle CreateArbitraryFileHandle() {
#ifdef XP_UNIX
  return UniqueFileHandle(dup(0));
#endif
#ifdef XP_WIN
  UniqueFileHandle hnd0, hnd1;
  if (::CreatePipe(getter_Transfers(hnd0), getter_Transfers(hnd1),
                   /* lpPipeAttributes = */ nullptr,
                   /* nSize = */ 0)) {
    return hnd0;
  }
  return nullptr;
#endif
}

// Test duplicating a null UniqueFileHandle
TEST(MFBT_UniquePtrExtensions, UFH_DupNull)
{
  UniqueFileHandle fd0;
  ASSERT_FALSE(fd0);
  UniqueFileHandle fd1 = DuplicateFileHandle(fd0);
  EXPECT_FALSE(fd1);
}

// Test that DuplicateFileHandle returns a valid fd/handle which isn't
// the same as the input.
TEST(MFBT_UniquePtrExtensions, UFH_DupBasic)
{
  UniqueFileHandle fd0 = CreateArbitraryFileHandle();
  ASSERT_TRUE(fd0);
  UniqueFileHandle fd1 = DuplicateFileHandle(fd0);
  EXPECT_TRUE(fd1);
  EXPECT_NE(fd0.get(), fd1.get());
}

#ifdef XP_UNIX

// Test that SetCloseOnExec works
TEST(MFBT_UniquePtrExtensions, UFH_SetCloExec)
{
  UniqueFileHandle fd0(dup(0));
  ASSERT_TRUE(fd0);
  int rv0 = fcntl(fd0.get(), F_GETFD);
  ASSERT_GE(rv0, 0);
  EXPECT_FALSE(rv0 & FD_CLOEXEC);

  SetCloseOnExec(fd0);
  ASSERT_TRUE(fd0);
  int rv1 = fcntl(fd0.get(), F_GETFD);
  ASSERT_GE(rv1, 0);
  EXPECT_TRUE(rv1 & FD_CLOEXEC);
}

// Test that DuplicateFileHandle sets close-on-exec
TEST(MFBT_UniquePtrExtensions, UFH_DupCloExec)
{
  UniqueFileHandle fd0(dup(0));
  ASSERT_TRUE(fd0);
  int rv0 = fcntl(fd0.get(), F_GETFD);
  ASSERT_GE(rv0, 0);
  EXPECT_FALSE(rv0 & FD_CLOEXEC);

  UniqueFileHandle fd1 = DuplicateFileHandle(fd0);
  ASSERT_TRUE(fd1);
  int rv1 = fcntl(fd1.get(), F_GETFD);
  ASSERT_GE(rv1, 0);
  EXPECT_TRUE(rv1 & FD_CLOEXEC);
}

#endif  // XP_UNIX

Messung V0.5 in Prozent
C=93 H=97 G=94

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002