Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Apache/docs/manual/   (Apache Web Server Version 2.4.65©)  Datei vom 11.0.2025 mit Größe 38 kB image not shown  

Quelle  test_nsPrefOverrideMap.js   Sprache: JAVA

 

/* 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/. */


const BOOL_TEST_PREF = "test.nsPrefOverrideMap.bool";
const INT_TEST_PREF = "test.nsPrefOverrideMap.int";
const STRING_TEST_PREF = "test.nsPrefOverrideMap.string";

add_task(async function test_map() {
  let map = Cc["@mozilla.org/pref-override-map;1"].createInstance(
    Ci.nsIPrefOverrideMap
  );

  // Set types of prefs.  Map operations must respect them.
  Services.prefs.setBoolPref(BOOL_TEST_PREF, false);
  Services.prefs.setIntPref(INT_TEST_PREF, -1);
  Services.prefs.setStringPref(STRING_TEST_PREF, "string");

  Assert.throws(
    () => map.addEntry("not.a.real.pref", 0),
    /NS_ERROR_DOM_NOT_FOUND_ERR/
  );
  Assert.throws(
    () => map.getEntry("not.a.real.pref"),
    /NS_ERROR_DOM_NOT_FOUND_ERR/
  );

  // Entry must be added to map before getEntry
  Assert.throws(() => map.getEntry(BOOL_TEST_PREF), /NS_ERROR_ILLEGAL_VALUE/);

  // Entry value can be changed.
  map.addEntry(BOOL_TEST_PREF, false);
  Assert.equal(map.getEntry(BOOL_TEST_PREF), false);
  map.addEntry(BOOL_TEST_PREF, true);
  Assert.equal(map.getEntry(BOOL_TEST_PREF), true);

  // Cannot change pref value type
  Assert.throws(
    () => map.addEntry(BOOL_TEST_PREF, "wrong type"),
    /TypeMismatchError/
  );
  Assert.throws(
    () => map.addEntry(INT_TEST_PREF, "wrong type"),
    /TypeMismatchError/
  );
  Assert.throws(
    () => map.addEntry(STRING_TEST_PREF, true),
    /TypeMismatchError/
  );

  // null value is allowed for any type
  Assert.equal(map.getEntry(BOOL_TEST_PREF), true);
  map.addEntry(BOOL_TEST_PREF, null);
  Assert.equal(map.getEntry(BOOL_TEST_PREF), null);
  map.addEntry(INT_TEST_PREF, null);
  Assert.equal(map.getEntry(INT_TEST_PREF), null);
  map.addEntry(STRING_TEST_PREF, null);
  Assert.equal(map.getEntry(STRING_TEST_PREF), null);

  // Type must be bool, number, string or null
  Assert.throws(() => map.addEntry(BOOL_TEST_PREF, {}), /TypeMismatchError/);
  Assert.equal(map.getEntry(BOOL_TEST_PREF), null);

  // Cleanup
  Services.prefs.clearUserPref(BOOL_TEST_PREF);
  Services.prefs.clearUserPref(INT_TEST_PREF);
  Services.prefs.clearUserPref(STRING_TEST_PREF);
});

Messung V0.5 in Prozent
C=97 H=95 G=95

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-09-28) ¤

*© Formatika GbR, Deutschland






über den Urheber dieser Seite

Die Firma ist wie angegeben erreichbar.

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.