package com.android.dialer.helpdesk.util; import java.io.BufferedReader; import java.io.InputStreamReader; /** * Standalone off-device test for {@link CzE164}. Two modes: * - default: assertion suite. * - "xcheck": read raw numbers from stdin, print normalized output per line — used by the harness * to diff against the real backend Helpdesk::Phone.e164. */ public class CzE164Test { static int pass = 0, fail = 0; static void eq(String got, String want, String d) { if (got == null ? want == null : got.equals(want)) { pass++; System.out.println(" ok " + d); } else { fail++; System.out.println(" FAIL " + d + " (got: " + got + ", want: " + want + ")"); } } public static void main(String[] args) throws Exception { if (args.length > 0 && args[0].equals("xcheck")) { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); String line; while ((line = r.readLine()) != null) { String out = CzE164.normalize(line); System.out.println(out == null ? "" : out); } return; } eq(CzE164.normalize("601 234 567"), "+420601234567", "bare CZ national -> +420"); eq(CzE164.normalize("00420601234567"), "+420601234567", "00420 -> +420"); eq(CzE164.normalize("+420601234567"), "+420601234567", "already E.164 passthrough"); eq(CzE164.normalize("+420 601-234-567"), "+420601234567", "strips spaces/dashes"); eq(CzE164.normalize("(602) 000 000"), "+420602000000", "strips parens"); eq(CzE164.normalize("hidden"), null, "non-numeric -> nil"); eq(CzE164.normalize(""), null, "empty -> nil"); eq(CzE164.normalize(null), null, "null -> nil"); eq(CzE164.normalize("12345"), null, "too short -> nil"); eq(CzE164.normalize("+441632960000"), "+441632960000", "foreign E.164 passthrough"); System.out.println("\n" + pass + " passed, " + fail + " failed"); System.exit(fail == 0 ? 0 : 1); } }