Eine aufbereitete Darstellung der Quelle

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

Benutzer

SSL TestShortRead.cpp

  Interaktion und
PortierbarkeitC
 

/* 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/ErrorNames.h"
#include "nsCOMPtr.h"
#include "nsConverterInputStream.h"
#include "nsIInputStream.h"
#include "nsISupports.h"
#include "nsStringStream.h"

namespace {

class ShortReadWrapper final : public nsIInputStream {
 public:
  NS_DECL_THREADSAFE_ISUPPORTS
  NS_DECL_NSIINPUTSTREAM

  template <size_t N>
  ShortReadWrapper(const uint32_t (&aShortReads)[N],
                   nsIInputStream* aBaseStream)
      : mShortReadIter(std::begin(aShortReads)),
        mShortReadEnd(std::end(aShortReads)),
        mBaseStream(aBaseStream) {}

  ShortReadWrapper(const ShortReadWrapper&) = delete;
  ShortReadWrapper& operator=(const ShortReadWrapper&) = delete;

 private:
  ~ShortReadWrapper() = default;

  const uint32_t* mShortReadIter;
  const uint32_t* mShortReadEnd;
  nsCOMPtr<nsIInputStream> mBaseStream;
};

NS_IMPL_ISUPPORTS(ShortReadWrapper, nsIInputStream)

NS_IMETHODIMP
ShortReadWrapper::Close() { return mBaseStream->Close(); }

NS_IMETHODIMP
ShortReadWrapper::Available(uint64_t* aAvailable) {
  nsresult rv = mBaseStream->Available(aAvailable);
  NS_ENSURE_SUCCESS(rv, rv);

  if (mShortReadIter != mShortReadEnd) {
    *aAvailable = std::min(uint64_t(*mShortReadIter), *aAvailable);
  }
  return NS_OK;
}

NS_IMETHODIMP
ShortReadWrapper::StreamStatus() { return mBaseStream->StreamStatus(); }

NS_IMETHODIMP
ShortReadWrapper::Read(char* aBuf, uint32_t aCount, uint32_t* _retval) {
  if (mShortReadIter != mShortReadEnd) {
    aCount = std::min(*mShortReadIter, aCount);
  }

  nsresult rv = mBaseStream->Read(aBuf, aCount, _retval);
  if (NS_SUCCEEDED(rv) && mShortReadIter != mShortReadEnd) {
    ++mShortReadIter;
  }
  return rv;
}

NS_IMETHODIMP
ShortReadWrapper::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure,
                               uint32_t aCount, uint32_t* _retval) {
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
ShortReadWrapper::IsNonBlocking(bool* _retval) {
  return mBaseStream->IsNonBlocking(_retval);
}

}  // namespace

TEST(ConverterStreamShortRead, ShortRead)
{
  uint8_t bytes[] = {0xd8, 0x35, 0xdc, 0x20};
  nsCOMPtr<nsIInputStream> baseStream;
  ASSERT_TRUE(NS_SUCCEEDED(NS_NewByteInputStream(getter_AddRefs(baseStream),
                                                 AsChars(mozilla::Span(bytes)),
                                                 NS_ASSIGNMENT_COPY)));

  static const uint32_t kShortReads[] = {121};
  nsCOMPtr<nsIInputStream> shortStream =
      new ShortReadWrapper(kShortReads, baseStream);

  RefPtr<nsConverterInputStream> unicharStream = new nsConverterInputStream();
  ASSERT_TRUE(NS_SUCCEEDED(
      unicharStream->Init(shortStream, "UTF-16BE"4096,
                          nsIConverterInputStream::ERRORS_ARE_FATAL)));

  uint32_t read;
  nsAutoString result;
  ASSERT_TRUE(
      NS_SUCCEEDED(unicharStream->ReadString(UINT32_MAX, result, &read)));

  ASSERT_EQ(read, 2u);
  ASSERT_TRUE(result == u"\U0001d420");
}

Messung V0.5 in Prozent
C=99 H=100 G=99

¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.12Angebot  (Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-26) ¤

*Eine klare Vorstellung vom Zielzustand






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=434850
#Domains=655579