-- Copyright (C) 1982  by Xerox Corporation. All rights reserved. 
-- TestNetworkAddressConversion.mesa, HGM, 20-Dec-82 21:37:29

DIRECTORY
  Exec USING [AddCommand, ExecProc, OutputProc],
  Format USING [
    CR, HostNumber, NetFormat, NetworkAddress, NetworkNumber, SocketNumber, StringProc, Text],
  SpecialSystem USING [HostNumber, NetworkAddress, NetworkNumber, SocketNumber],
  String USING [AppendString],
  System USING [],
  Unformat USING [HostNumber, NetworkAddress, NetworkNumber, SocketNumber];

TestNetworkAddressConversion: PROGRAM IMPORTS Exec, Format, String, Unformat EXPORTS System =
  BEGIN

  HostNumber: PUBLIC TYPE = SpecialSystem.HostNumber;
  NetworkAddress: PUBLIC TYPE = SpecialSystem.NetworkAddress;
  NetworkNumber: PUBLIC TYPE = SpecialSystem.NetworkNumber;
  SocketNumber: PUBLIC TYPE = SpecialSystem.SocketNumber;

  s0: SocketNumber = [0];
  s1: SocketNumber = [1];
  s123: SocketNumber = [123B];
  s123000: SocketNumber = [123000B];
  s123456: SocketNumber = [123456B];
  sOnes: SocketNumber = [177777B];
  s10: SocketNumber = [10];
  s100: SocketNumber = [100];
  s1000: SocketNumber = [1000];
  s10000: SocketNumber = [10000];

  SocketNumbers: PROCEDURE [out: Format.StringProc] =
    BEGIN
    TestSocket: PROCEDURE [name: STRING, s: SocketNumber] =
      BEGIN
      Complain: PROCEDURE =
        BEGIN
        Format.Text[out, "   **"L];
        Format.SocketNumber[out, temp, octal];
        Format.Text[out, "**  "L];
	END;
      temp: SocketNumber;
      Format.Text[out, name];
      Format.Text[out, " = "L];
      Format.SocketNumber[out, s, octal];
      Format.SocketNumber[StuffIntoTemp, s, octal];
      temp ← Unformat.SocketNumber[string, octal];
      IF s # temp THEN Complain[];
      Format.Text[out, " = "L];
      Format.SocketNumber[out, s, hex];
      Format.SocketNumber[StuffIntoTemp, s, hex];
      temp ← Unformat.SocketNumber[string, octal];
      IF s # temp THEN Complain[];
      temp ← Unformat.SocketNumber[string, hex];
      IF s # temp THEN Complain[];
      temp ← Unformat.SocketNumber[string, productSoftware];
      IF s # temp THEN Complain[];
      Format.Text[out, " = "L];
      Format.SocketNumber[out, s, productSoftware];
      Format.SocketNumber[StuffIntoTemp, s, productSoftware];
      temp ← Unformat.SocketNumber[string, octal];
      IF s # temp THEN Complain[];
      temp ← Unformat.SocketNumber[string, hex];
      IF s # temp THEN Complain[];
      temp ← Unformat.SocketNumber[string, productSoftware];
      IF s # temp THEN Complain[];
      Format.CR[out];
      END;
    TestSocket["s0", s0];
    TestSocket["s1", s1];
    TestSocket["s123", s123];
    TestSocket["s123000", s123000];
    TestSocket["s123456", s123456];
    TestSocket["sOnes", sOnes];
    TestSocket["s10", s10];
    TestSocket["s100", s100];
    TestSocket["s1000", s1000];
    TestSocket["s10000", s10000];
    END;


  n0: NetworkNumber = [0, 0];
  n1: NetworkNumber = [0, 1];
  n123: NetworkNumber = [0, 123B];
  n123000: NetworkNumber = [123B, 0];
  n123456: NetworkNumber = [123B, 456B];
  nOnes: NetworkNumber = [177777B, 177777B];

  NetworkNumbers: PROCEDURE [out: Format.StringProc] =
    BEGIN
    TestNetwork: PROCEDURE [name: STRING, n: NetworkNumber] =
      BEGIN
      Complain: PROCEDURE =
        BEGIN
        Format.Text[out, "   **"L];
        Format.NetworkNumber[out, temp, octal];
        Format.Text[out, "**  "L];
	END;
      temp: NetworkNumber;
      Format.Text[out, name];
      Format.Text[out, " = "L];
      Format.NetworkNumber[out, n, octal];
      Format.NetworkNumber[StuffIntoTemp, n, octal];
      temp ← Unformat.NetworkNumber[string, octal];
      IF n # temp THEN Complain[];
      Format.Text[out, " = "L];
      Format.NetworkNumber[out, n, hex];
      Format.NetworkNumber[StuffIntoTemp, n, hex];
      temp ← Unformat.NetworkNumber[string, octal];
      IF n # temp THEN Complain[];
      temp ← Unformat.NetworkNumber[string, hex];
      IF n # temp THEN Complain[];
      temp ← Unformat.NetworkNumber[string, productSoftware];
      IF n # temp THEN Complain[];
      Format.Text[out, " = "L];
      Format.NetworkNumber[out, n, productSoftware];
      Format.NetworkNumber[StuffIntoTemp, n, productSoftware];
      temp ← Unformat.NetworkNumber[string, octal];
      IF n # temp THEN Complain[];
      temp ← Unformat.NetworkNumber[string, hex];
      IF n # temp THEN Complain[];
      temp ← Unformat.NetworkNumber[string, productSoftware];
      IF n # temp THEN Complain[];
      Format.CR[out];
      END;
    TestNetwork["n0", n0];
    TestNetwork["n1", n1];
    TestNetwork["n123", n123];
    TestNetwork["n123000", n123000];
    TestNetwork["n123456", n123456];
    TestNetwork["nOnes", nOnes];
    END;


  h0: HostNumber = [0, 0, 0, 0, 0, 0];
  h1: HostNumber = [0, 0, 0, 0, 0, 1];
  h123: HostNumber = [0, 0, 0, 1, 2, 3];
  h123000: HostNumber = [1, 2, 3, 0, 0, 0];
  h123456: HostNumber = [1, 2, 3, 4, 5, 6];
  hOnes: HostNumber = [377B, 377B, 377B, 377B, 377B, 377B];
  hAlmostOnes: HostNumber = [377B, 377B, 377B, 377B, 377B, 376B];
  -- Test all hex digits
  hAllLeft: HostNumber = [376B, 334B, 272B, 230B, 166B, 124B];
  hAllRight: HostNumber = [272B, 230B, 166B, 124B, 062B, 020B];
  hHanuman: HostNumber = [0, 0, 0, 0, 50B, 43B];
  hTulare: HostNumber = [0, 0, 252B, 0, 0, 6];

  HostNumbers: PROCEDURE [out: Format.StringProc] =
    BEGIN
    TestHost: PROCEDURE [name: STRING, h: HostNumber] =
      BEGIN
      Complain: PROCEDURE =
        BEGIN
        Format.Text[out, "   **"L];
        Format.HostNumber[out, temp, octal];
        Format.Text[out, "**  "L];
	END;
      temp: HostNumber;
      Format.Text[out, name];
      Format.Text[out, " = "L];
      Format.HostNumber[out, h, octal];
      Format.HostNumber[StuffIntoTemp, h, octal];
      temp ← Unformat.HostNumber[string, octal];
      IF h # temp THEN Complain[];
      Format.Text[out, " = "L];
      Format.HostNumber[out, h, hex];
      Format.HostNumber[StuffIntoTemp, h, hex];
      temp ← Unformat.HostNumber[string, octal];
      IF h # temp THEN Complain[];
      temp ← Unformat.HostNumber[string, hex];
      IF h # temp THEN Complain[];
      temp ← Unformat.HostNumber[string, productSoftware];
      IF h # temp THEN Complain[];
      Format.Text[out, " = "L];
      Format.HostNumber[out, h, productSoftware];
      Format.HostNumber[StuffIntoTemp, h, productSoftware];
      temp ← Unformat.HostNumber[string, octal];
      IF h # temp THEN Complain[];
      temp ← Unformat.HostNumber[string, hex];
      IF h # temp THEN Complain[];
      temp ← Unformat.HostNumber[string, productSoftware];
      IF h # temp THEN Complain[];
      Format.CR[out];
      END;
    TestHost["h0", h0];
    TestHost["h1", h1];
    TestHost["h123", h123];
    TestHost["h123000", h123000];
    TestHost["h123456", h123456];
    TestHost["hOnes", hOnes];
    TestHost["hAlmostOnes", hAlmostOnes];
    TestHost["hAllLeft", hAllLeft];
    TestHost["hAllRight", hAllRight];
    TestHost["Hanuman(24043B=10-275)", hHanuman];
    TestHost["Tulare(2-852-126-726)", hTulare];
    END;


  a0: NetworkAddress = [n0, h0, s0];
  a1: NetworkAddress = [n1, h1, s1];
  a123: NetworkAddress = [n123, h123, s123];
  a123000: NetworkAddress = [n123000, h123000, s123000];
  a123456: NetworkAddress = [n123456, h123456, s123456];
  aOnes: NetworkAddress = [nOnes, hOnes, sOnes];
  aAlmostOnes: NetworkAddress = [nOnes, hAlmostOnes, sOnes];

  NetworkAddresses: PROCEDURE [out: Format.StringProc] =
    BEGIN
    TestNetworkAddress: PROCEDURE [name: STRING, a: NetworkAddress] =
      BEGIN
      Complain: PROCEDURE =
        BEGIN
        Format.Text[out, "   **"L];
        Format.NetworkAddress[out, temp, octal];
        Format.Text[out, "**  "L];
	END;
      temp: NetworkAddress;
      Format.Text[out, name];
      Format.Text[out, " = "L];
      Format.NetworkAddress[out, a, octal];
      Format.NetworkAddress[StuffIntoTemp, a, octal];
      temp ← Unformat.NetworkAddress[string, octal];
      IF a # temp THEN Complain[];
      Format.Text[out, " = "L];
      Format.NetworkAddress[out, a, hex];
      Format.NetworkAddress[StuffIntoTemp, a, hex];
      temp ← Unformat.NetworkAddress[string, octal];
      IF a # temp THEN Complain[];
      temp ← Unformat.NetworkAddress[string, octal];
      IF a # temp THEN Complain[];
      temp ← Unformat.NetworkAddress[string, hex];
      IF a # temp THEN Complain[];
      temp ← Unformat.NetworkAddress[string, productSoftware];
      IF a # temp THEN Complain[];
      Format.Text[out, " = "L];
      Format.NetworkAddress[out, a, productSoftware];
      Format.NetworkAddress[StuffIntoTemp, a, productSoftware];
      temp ← Unformat.NetworkAddress[string, octal];
      IF a # temp THEN Complain[];
      temp ← Unformat.NetworkAddress[string, octal];
      IF a # temp THEN Complain[];
      temp ← Unformat.NetworkAddress[string, hex];
      IF a # temp THEN Complain[];
      Format.CR[out];
      END;
    TestNetworkAddress["a0", a0];
    TestNetworkAddress["a1", a1];
    TestNetworkAddress["a123", a123];
    TestNetworkAddress["a123000", a123000];
    TestNetworkAddress["a123456", a123456];
    TestNetworkAddress["aOnes", aOnes];
    TestNetworkAddress["aAlmostOnes", aAlmostOnes];
    END;


  string: LONG STRING = [100];
  StuffIntoTemp: PROCEDURE [s: LONG STRING, clientData: LONG POINTER] =
    BEGIN
    string.length ← 0;
    String.AppendString[string, s];
    END;
 
  TestSocket: Exec.ExecProc =
    BEGIN
    out: Format.StringProc = Exec.OutputProc[h];
    SocketNumbers[out];
    END;

  TestHost: Exec.ExecProc =
    BEGIN
    out: Format.StringProc = Exec.OutputProc[h];
    HostNumbers[out];
    END;

  TestNet: Exec.ExecProc =
    BEGIN
    out: Format.StringProc = Exec.OutputProc[h];
    NetworkNumbers[out];
    END;

  TestAddress: Exec.ExecProc =
    BEGIN
    out: Format.StringProc = Exec.OutputProc[h];
    NetworkAddresses[out];
    END;

  TestThings: Exec.ExecProc =
    BEGIN
    out: Format.StringProc = Exec.OutputProc[h];
    SocketNumbers[out];
    NetworkNumbers[out];
    HostNumbers[out];
    NetworkAddresses[out];
    END;

  Exec.AddCommand["TestSocketNumberConversion.~"L, TestSocket];
  Exec.AddCommand["TestHostNumberConversion.~"L, TestHost];
  Exec.AddCommand["TestNetworkNumberConversion.~"L, TestNet];
  Exec.AddCommand["TestNetworkAddressConversion.~"L, TestAddress];
  Exec.AddCommand["TestNetworkThingsConversion.~"L, TestThings];
  END.