Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/modules/libpref/test/unit/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 2 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=78 H=92 G=84

¤ 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.