Eine aufbereitete Darstellung der Quelle

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

Benutzer

Quelle  TestAppDateTimeFormat.cpp

  Sprache: C
 

#include "gtest/gtest.h"
#include "mozilla/gtest/MozAssertions.h"
#include "mozilla/intl/AppDateTimeFormat.h"
#include "mozilla/intl/DateTimeFormat.h"

namespace mozilla::intl {
using Style = DateTimeFormat::Style;
using StyleBag = DateTimeFormat::StyleBag;
using ComponentsBag = DateTimeFormat::ComponentsBag;

static DateTimeFormat::StyleBag ToStyleBag(Maybe<DateTimeFormat::Style> date,
                                           Maybe<DateTimeFormat::Style> time) {
  DateTimeFormat::StyleBag style;
  style.date = date;
  style.time = time;
  return style;
}

TEST(AppDateTimeFormat, FormatPRExplodedTime)
{
  PRTime prTime = 0;
  PRExplodedTime prExplodedTime;
  PR_ExplodeTime(prTime, PR_GMTParameters, &prExplodedTime);

  AppDateTimeFormat::sLocale = new nsCString("en-US");
  AppDateTimeFormat::DeleteCache();
  StyleBag style = ToStyleBag(Some(Style::Long), Some(Style::Long));

  nsAutoString formattedTime;
  nsresult rv =
      AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"January") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"12:00:00 AM") != kNotFound ||
              formattedTime.Find(u"12:00:00\u202FAM") != kNotFound ||
              formattedTime.Find(u"00:00:00") != kNotFound);

  prExplodedTime = {0019010197040, {(19 * 60), 0}};

  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);

  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"January") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"12:19:00 AM") != kNotFound ||
              formattedTime.Find(u"12:19:00\u202FAM") != kNotFound ||
              formattedTime.Find(u"00:19:00") != kNotFound);

  prExplodedTime = {00,    071,
                    0197040, {(6 * 60 * 60), (1 * 60 * 60)}};
  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"January") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"7:00:00 AM") != kNotFound ||
              formattedTime.Find(u"7:00:00\u202FAM") != kNotFound ||
              formattedTime.Find(u"07:00:00") != kNotFound);

  prExplodedTime = {
      00,    29111,
      019704,  0,  {(10 * 60 * 60) + (29 * 60), (1 * 60 * 60)}};
  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"January") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"11:29:00 AM") != kNotFound ||
              formattedTime.Find(u"11:29:00\u202FAM") != kNotFound ||
              formattedTime.Find(u"11:29:00") != kNotFound);

  prExplodedTime = {003723311119693364, {-(23 * 60), 0}};
  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"December") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"31") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"11:37:00 PM") != kNotFound ||
              formattedTime.Find(u"11:37:00\u202FPM") != kNotFound ||
              formattedTime.Find(u"23:37:00") != kNotFound);

  prExplodedTime = {00017311119693364, {-(7 * 60 * 60), 0}};
  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"December") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"31") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"5:00:00 PM") != kNotFound ||
              formattedTime.Find(u"5:00:00\u202FPM") != kNotFound ||
              formattedTime.Find(u"17:00:00") != kNotFound);

  prExplodedTime = {
      0,  0,    4714,  31,
      1119693,  364, {-((10 * 60 * 60) + (13 * 60)), (1 * 60 * 60)}};
  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"December") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"31") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"2:47:00 PM") != kNotFound ||
              formattedTime.Find(u"2:47:00\u202FPM") != kNotFound ||
              formattedTime.Find(u"14:47:00") != kNotFound);
}

TEST(AppDateTimeFormat, DateFormatSelectors)
{
  PRTime prTime = 0;
  PRExplodedTime prExplodedTime;
  PR_ExplodeTime(prTime, PR_GMTParameters, &prExplodedTime);

  AppDateTimeFormat::sLocale = new nsCString("en-US");
  AppDateTimeFormat::DeleteCache();

  nsAutoString formattedTime;

  {
    ComponentsBag components{};
    components.year = Some(DateTimeFormat::Numeric::Numeric);
    components.month = Some(DateTimeFormat::Month::TwoDigit);

    nsresult rv =
        AppDateTimeFormat::Format(components, &prExplodedTime, formattedTime);
    ASSERT_NS_SUCCEEDED(rv);
    ASSERT_STREQ("01/1970", NS_ConvertUTF16toUTF8(formattedTime).get());
  }
  {
    ComponentsBag components{};
    components.year = Some(DateTimeFormat::Numeric::Numeric);
    components.month = Some(DateTimeFormat::Month::Long);

    nsresult rv =
        AppDateTimeFormat::Format(components, &prExplodedTime, formattedTime);
    ASSERT_NS_SUCCEEDED(rv);
    ASSERT_STREQ("January 1970", NS_ConvertUTF16toUTF8(formattedTime).get());
  }
  {
    ComponentsBag components{};
    components.month = Some(DateTimeFormat::Month::Long);

    nsresult rv =
        AppDateTimeFormat::Format(components, &prExplodedTime, formattedTime);
    ASSERT_NS_SUCCEEDED(rv);
    ASSERT_STREQ("January", NS_ConvertUTF16toUTF8(formattedTime).get());
  }
  {
    ComponentsBag components{};
    components.weekday = Some(DateTimeFormat::Text::Short);

    nsresult rv =
        AppDateTimeFormat::Format(components, &prExplodedTime, formattedTime);
    ASSERT_NS_SUCCEEDED(rv);
    ASSERT_STREQ("Thu", NS_ConvertUTF16toUTF8(formattedTime).get());
  }
}

TEST(AppDateTimeFormat, FormatPRExplodedTimeForeign)
{
  PRTime prTime = 0;
  PRExplodedTime prExplodedTime;
  PR_ExplodeTime(prTime, PR_GMTParameters, &prExplodedTime);

  AppDateTimeFormat::sLocale = new nsCString("de-DE");
  AppDateTimeFormat::DeleteCache();
  StyleBag style = ToStyleBag(Some(Style::Long), Some(Style::Long));

  nsAutoString formattedTime;
  nsresult rv =
      AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"1.") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"Januar") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"12:00:00 AM") != kNotFound ||
              formattedTime.Find(u"12:00:00\u202FAM") != kNotFound ||
              formattedTime.Find(u"00:00:00") != kNotFound);

  prExplodedTime = {0019010197040, {(19 * 60), 0}};
  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"1.") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"Januar") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"12:19:00 AM") != kNotFound ||
              formattedTime.Find(u"12:19:00\u202FAM") != kNotFound ||
              formattedTime.Find(u"00:19:00") != kNotFound);

  prExplodedTime = {00,    071,
                    0197040, {(6 * 60 * 60), (1 * 60 * 60)}};
  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"1.") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"Januar") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"7:00:00 AM") != kNotFound ||
              formattedTime.Find(u"7:00:00\u202FAM") != kNotFound ||
              formattedTime.Find(u"07:00:00") != kNotFound);

  prExplodedTime = {
      00,    29111,
      019704,  0,  {(10 * 60 * 60) + (29 * 60), (1 * 60 * 60)}};
  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"1.") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"Januar") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1970") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"11:29:00 AM") != kNotFound ||
              formattedTime.Find(u"11:29:00\u202FAM") != kNotFound ||
              formattedTime.Find(u"11:29:00") != kNotFound);

  prExplodedTime = {003723311119693364, {-(23 * 60), 0}};
  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"31.") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"Dezember") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"11:37:00 PM") != kNotFound ||
              formattedTime.Find(u"11:37:00\u202FPM") != kNotFound ||
              formattedTime.Find(u"23:37:00") != kNotFound);

  prExplodedTime = {00017311119693364, {-(7 * 60 * 60), 0}};
  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"31.") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"Dezember") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"5:00:00 PM") != kNotFound ||
              formattedTime.Find(u"5:00:00\u202FPM") != kNotFound ||
              formattedTime.Find(u"17:00:00") != kNotFound);

  prExplodedTime = {
      0,  0,    4714,  31,
      1119693,  364, {-((10 * 60 * 60) + (13 * 60)), (1 * 60 * 60)}};
  rv = AppDateTimeFormat::Format(style, &prExplodedTime, formattedTime);
  ASSERT_NS_SUCCEEDED(rv);
  ASSERT_TRUE(formattedTime.Find(u"31.") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"Dezember") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"1969") != kNotFound);
  ASSERT_TRUE(formattedTime.Find(u"2:47:00 PM") != kNotFound ||
              formattedTime.Find(u"2:47:00\u202FPM") != kNotFound ||
              formattedTime.Find(u"14:47:00") != kNotFound);
}

TEST(AppDateTimeFormat, DateFormatSelectorsForeign)
{
  PRTime prTime = 0;
  PRExplodedTime prExplodedTime;
  PR_ExplodeTime(prTime, PR_GMTParameters, &prExplodedTime);

  AppDateTimeFormat::sLocale = new nsCString("de-DE");
  AppDateTimeFormat::DeleteCache();

  nsAutoString formattedTime;
  {
    ComponentsBag components{};
    components.year = Some(DateTimeFormat::Numeric::Numeric);
    components.month = Some(DateTimeFormat::Month::TwoDigit);

    nsresult rv =
        AppDateTimeFormat::Format(components, &prExplodedTime, formattedTime);
    ASSERT_NS_SUCCEEDED(rv);
    ASSERT_STREQ("01.1970", NS_ConvertUTF16toUTF8(formattedTime).get());
  }
  {
    ComponentsBag components{};
    components.year = Some(DateTimeFormat::Numeric::Numeric);
    components.month = Some(DateTimeFormat::Month::Long);

    nsresult rv =
        AppDateTimeFormat::Format(components, &prExplodedTime, formattedTime);
    ASSERT_NS_SUCCEEDED(rv);
    ASSERT_STREQ("Januar 1970", NS_ConvertUTF16toUTF8(formattedTime).get());
  }
  {
    ComponentsBag components{};
    components.weekday = Some(DateTimeFormat::Text::Short);

    nsresult rv =
        AppDateTimeFormat::Format(components, &prExplodedTime, formattedTime);
    ASSERT_NS_SUCCEEDED(rv);
    ASSERT_STREQ("Do", NS_ConvertUTF16toUTF8(formattedTime).get());
  }
  {
    ComponentsBag components{};
    components.weekday = Some(DateTimeFormat::Text::Long);

    nsresult rv =
        AppDateTimeFormat::Format(components, &prExplodedTime, formattedTime);
    ASSERT_NS_SUCCEEDED(rv);
    ASSERT_STREQ("Donnerstag", NS_ConvertUTF16toUTF8(formattedTime).get());
  }
  {
    ComponentsBag components{};
    components.month = Some(DateTimeFormat::Month::Long);

    nsresult rv =
        AppDateTimeFormat::Format(components, &prExplodedTime, formattedTime);
    ASSERT_NS_SUCCEEDED(rv);
    ASSERT_STREQ("Januar", NS_ConvertUTF16toUTF8(formattedTime).get());
  }
  {
    ComponentsBag components{};
    components.weekday = Some(DateTimeFormat::Text::Short);

    nsresult rv =
        AppDateTimeFormat::Format(components, &prExplodedTime, formattedTime);
    ASSERT_NS_SUCCEEDED(rv);
    ASSERT_STREQ("Do", NS_ConvertUTF16toUTF8(formattedTime).get());
  }
}

}  // namespace mozilla::intl

Messung V0.5 in Prozent
C=91 H=93 G=91

¤ Dauer der Verarbeitung: 0.9 Sekunden  (vorverarbeitet am  2026-06-07) ¤

*© 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

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik