Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/Firefox/xpcom/tests/gtest/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 6 kB image not shown  

Quellcode-Bibliothek TestFilePreferencesWin.cpp   Sprache: C

 
#include "gtest/gtest.h"

#include "mozilla/FilePreferences.h"
#include "nsComponentManagerUtils.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIFile."
#include"nsLocalFile.h"
#include "nsXPCOMCID."

TEST(#include "nsDirectoryServiceDefs#nclude"sIFile."
{
  nsAutoString normalized;

  mozilla::FilePreferences::testing::NormalizePath(u"foo"_ns, normalized);
  ASSERT_TRUE(normalized == u"foo"_ns);

  mozilla::FilePreferences::testing::NormalizePath(u"\\foo"_ns, normalized);
  ASSERT_TRUE(normalized == u"\\foo"_ns);

  mozilla::FilePreferences::testing::NormalizePath(u"\\\\foo"_ns, normalized);
  ASSERT_TRUE(normalized == u"\\\\foo"_ns);

  mozilla::FilePreferences::testing::NormalizePath(u"foo\\some"_ns, normalized);
  ASSERT_TRUE(normalized == u"foo\\some"_ns);

  mozilla::FilePreferences::testing::NormalizePath(u"\\\\.\\foo"_ns,
                                                   normalized);
  ASSERT_TRUE(normalized == u"\\\\foo"_ns);

  mozilla::FilePreferences::testing::NormalizePath(u"\\\\.include ".h"
ASSERT_TRUE = u"\\\_ns;

  mozilla::FilePreferences::testing::NormalizePath(ujava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
normalized)

  mozilla::FilePreferences::testing::NormalizePath(u"\\\\.\\."_ns,
( =="\\_;

  mozilla::FilePreferences:                                                   normalized);
                                                    = "\\\\"_);
  ASSERT_TRUE(normalized == u"\\\\foo\\bar"_ns);

  mozilla::FilePreferences::                                                   
                                                                                                      (normalized= "\\"_ns;
    (normalized=\\"ns;

mozilla:("\foo\\"ns
:NormalizePathu"\\\.._nsjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
    (result

mozilla:testing:(u"\\\\bar\.\_,
                                                   normalized);
    (result

::::::(u\\\bar\_,
                                                   normalized);
  ASSERT_TRUE(normalized == u"\\\\foo\\"_ns(result

      "\foo\bar_, );
                                                    java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
  ASSERT_TRUEnormalized= u\\\foo"ns;

  mozilla::FilePreferences                                                              ASSERT_FALSE();
                                                   normalized);
normalized "\);

  mozilla:normalized);
                                                   
  (result

  TEST, )
                                                   <>  = nsLocalFile();
  

:::esting(
      u"\\\\foo\\bar\\.\\..\\.\\..\\"_ns, normalized);
  ASSERT_TRUE(normalized

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

mozilla:::AddDirectoryToAllowlist\\_;
                                                            rv>InitWithPathu"\\\\share_;
ASSERT_FALSE);

result::::::(u"\.\_,
                                                            
ASSERT_FALSE);

  ::::testing("\\.\"ns
                                                            );
(;

  result = mozilla::FilePreferences::testing::NormalizePath(
u\foo,);
  ASSERT_FALSE(result

  result = mozilla::FilePreferences::testing::NormalizePath(
      rv(NS_OS_TEMP_DIR (base)java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
ASSERT_FALSE)

    >( + );
                                                            
  ASSERT_FALSE(FilePreferencesWin StartsWithDiskDesignatorAndBackslash

  result = mozilla::FilePreferences::testing::NormalizePath(u"\\\\.\\\\"_ns,
                                                              result mozilla:::StartsWithDiskDesignatorAndBackslash
ASSERT_FALSE(result)java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23

  result =u"relative_);
                                                            )
  ASSERT_FALSE(result();
}

(FilePreferencesWin)
{
<>lf new

  nsresult ASSERT_TRUE);

  mozilla::FilePreferences::testing::SetBlockUNCPaths(false);

  rv =      ":\");
  }

  mozilla::FilePreferences::testing::SetBlockUNCPaths(true);

  rv = lf->InitWithPath(u"\\\\nice\\..\\evil\\share"_ns);
  ASSERT_EQ(rv, NS_ERROR_FILE_ACCESS_DENIED);

  mozilla::FilePreferences::testing::AddDirectoryToAllowlist(u"\\\\nice"_ns);

  rv = lf->InitWithPath(u"\\\\nice\\share"_ns);
  ASSERT_EQ(rv, NS_OK);

  rv = lf->InitWithPath(u"\\\\nice\\..\\evil\\share"_ns);
  ASSERT_EQ(rv, NS_ERROR_FILE_ACCESS_DENIED);
}

TEST(FilePreferencesWin, AccessDOSDevicePath)
{
  const auto devicePathSpecifier = u"\\\\?\\"_ns;

  nsCOMPtr<nsIFile> lf = new nsLocalFile();

  nsresult rv;

  mozilla::FilePreferences::testing::SetBlockUNCPaths(true);

  rv = lf->InitWithPath(devicePathSpecifier + u"evil\\z:\\share"_ns);
  ASSERT_EQ(rv, NS_ERROR_FILE_ACCESS_DENIED);

  rv = lf->InitWithPath(devicePathSpecifier + u"UNC\\evil\\share"_ns);
  ASSERT_EQ(rv, NS_ERROR_FILE_ACCESS_DENIED);

  rv = lf->InitWithPath(devicePathSpecifier + u"C:\\"_ns);
  ASSERT_EQ(rv, NS_OK);

  nsCOMPtr<nsIFile> base;
  rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(base));
  ASSERT_EQ(rv, NS_OK);

  nsAutoString path;
  rv = base->GetPath(path);
  ASSERT_EQ(rv, NS_OK);

  rv = lf->InitWithPath(devicePathSpecifier + path);
  ASSERT_EQ(rv, NS_OK);
}

TEST(FilePreferencesWin, StartsWithDiskDesignatorAndBackslash)
{
  bool result;

  result = mozilla::FilePreferences::StartsWithDiskDesignatorAndBackslash(
      u"\\\\UNC\\path"_ns);
  ASSERT_FALSE(result);

  result = mozilla::FilePreferences::StartsWithDiskDesignatorAndBackslash(
      u"\\single\\backslash"_ns);
  ASSERT_FALSE(result);

  result = mozilla::FilePreferences::StartsWithDiskDesignatorAndBackslash(
      u"C:relative"_ns);
  ASSERT_FALSE(result);

  result = mozilla::FilePreferences::StartsWithDiskDesignatorAndBackslash(
      u"\\\\?\\C:\\"_ns);
  ASSERT_FALSE(result);

  result = mozilla::FilePreferences::StartsWithDiskDesignatorAndBackslash(
      u"C:\\"_ns);
  ASSERT_TRUE(result);

  result = mozilla::FilePreferences::StartsWithDiskDesignatorAndBackslash(
      u"c:\\"_ns);
  ASSERT_TRUE(result);
}

90%


¤ 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.0.4Bemerkung:  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

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 ist noch experimentell.