-- .../asn1specs/err_test.asn1
--
-- This module exercises snacc's semantic error checking of ASN.1 types.
-- Every line that has the "error" comment should cause snacc to produce
-- at least one error message
--
-- Mike Sample 92/07
--
-- $Header: /cvs/Darwin/src/live/Security/SecuritySNACCRuntime/asn1specs/err-test.asn1,v 1.1.1.1 2001/05/18 23:14:05 mb Exp $
-- $Log: err-test.asn1,v $
-- Revision 1.1.1.1  2001/05/18 23:14:05  mb
-- Move from private repository to open source repository
--
-- Revision 1.1.1.1  1999/03/16 18:05:55  aram
-- Originals from SMIME Free Library.
--
-- Revision 1.3  1995/07/25 19:53:16  rj
-- changed `_' to `-' in file names.
--
-- Revision 1.2  1994/08/28  09:54:17  rj
-- comment leader fixed.
--
-- Revision 1.1  1994/08/28  09:51:13  rj
-- first check-in.

ERROR-TEST DEFINITIONS ::=
BEGIN


-- first check that CHOICEs and SETs  without distinct tags
-- cause error msgs

AChoice ::= CHOICE -- error
{
    f1 [0] INTEGER,  -- these two have the same
    f2 [0] INTEGER,  -- tags
    f3 INTEGER,      -- the tag of f3
    f4 AChoice3      -- conflicts with one of AChoice3's elmt tags
}

ASet ::= SET  -- error
{
    f1 [0] INTEGER, -- same [0] tags
    f2 [0] INTEGER
}


T1 ::= INTEGER
T2 ::= BOOLEAN

AChoice2 ::= CHOICE  -- error
{
   T1,
   INTEGER
}

ASet2 ::= SET  -- error
{
   T2,
   BOOLEAN
}

AChoice3 ::= CHOICE
{
   T1,
   T2
}


--
-- now check that Sequence have distinct tags
-- on one or consective optional elmts and following (if any)
-- non-optional elmt
--

ASequence ::= SEQUENCE  -- no errors
{
    f1 [0] INTEGER,
    f2 [0] BOOLEAN
}

ASequence1 ::= SEQUENCE
{
    INTEGER OPTIONAL,
    INTEGER OPTIONAL, -- error,  ambiguous values possible
    INTEGER,          -- error
    INTEGER
}

ASequence3 ::= SEQUENCE
{
    f1 [0] OBJECT IDENTIFIER OPTIONAL,
    f2 [1] INTEGER OPTIONAL,
    f3 [0] BOOLEAN,            -- error
    f4 [2] OCTET STRING OPTIONAL,
    f5 [2] BIT STRING OPTIONAL, -- error
    f6 [3] ASequence OPTIONAL,
    f7 [3] INTEGER,  -- error
    f8 [4] BOOLEAN OPTIONAL,
    f9 [4] INTEGER OPTIONAL  -- error
}



--
-- now check that duplicate APPLICATION tag errors are reported
--
Foo1 ::= [APPLICATION 0] INTEGER
Foo2 ::= [APPLICATION 1] INTEGER

Bar1 ::= [APPLICATION 0] IMPLICIT INTEGER  -- error
Bar2 ::= [APPLICATION 1] IMPLICIT INTEGER  -- error

--
-- check that field name errors are reported
--

AChoice4 ::= CHOICE
{
   f1 INTEGER,
   f2 BOOLEAN,
    [0] AChoice4
}

ASet3 ::= SET
{
   f1 [0] INTEGER,
   f2 [1] INTEGER,
   f3 [2] BOOLEAN,
   f3 [3] BOOLEAN,  -- error, field name conflict
      [4] AChoice4  -- error, field name conflict too
}


--
-- now check some recursive type related errors
--

A2 ::= A2  -- error

A1 ::= B1  -- error
B1 ::= A1  -- error

C1 ::= D1  -- error
D1 ::= E1  -- error
E1 ::= F1  -- error
F1 ::= C1  -- error

RecSeq ::= SEQUENCE
{
     INTEGER,
     BOOLEAN,
     RecSeq,  -- warning, infinitely large values?
     RecSeq OPTIONAL -- this should be ok 'cause it's optional
}


--
-- now check some named bit and named number related errors
--
aVal  INTEGER ::= -4

Enum1 ::= ENUMERATED { zero(0), one(1), two(2), one(0) } -- 2 errors

Int1 ::= INTEGER { zero(0), one(1), two(2), yoyo(2), one(7), foo(aVal) } -- 2 errors

Bits1 ::= BIT STRING { zero(0), one(1), two(2), one(4), foo(-2), pogo(0),
                       gogo(aVal) }  -- 4 errors



--
-- now check that implicitly tagged CHOICE, ANY and ANY DEFINED BY
-- cause error msgs
--
BChoice1 ::= [APPLICATION 5] IMPLICIT CHOICE  -- error
{
    INTEGER,
    BOOLEAN
}

BChoice2 ::= CHOICE -- no error
{
    INTEGER,
    BOOLEAN
}

BChoice3 ::= [APPLICATION 6] CHOICE -- no error
{
    INTEGER,
    BOOLEAN
}

BSeq ::= SEQUENCE
{
    INTEGER,
    BOOLEAN,
    [0] IMPLICIT BChoice2, -- error
    [1] IMPLICIT BChoice3, -- no error
    [2] IMPLICIT CHOICE {INTEGER, BOOLEAN} -- error
}


--
-- now test that errors are reported for multiply defined
-- types and valus
--

TypeCopy1 ::= INTEGER
TypeCopy1 ::= BOOLEAN
TypeCopy1 ::= INTEGER

valCopy1 INTEGER ::= 1
valCopy1 BOOLEAN ::= TRUE
valCopy1 INTEGER ::= 1


--
--  test some OBJECT IDENTIFER value errors
--

oid1 OBJECT IDENTIFIER ::= { oid1 ms(1) 1 } -- error: recursive value
oid2 OBJECT IDENTIFIER ::= { oid1 ms(1) 2 }

 -- error: can only ref other oid values from first arc
oid3 OBJECT IDENTIFIER ::= { ms(1) oid2 2 }

boolVal BOOLEAN ::= TRUE
intVal1 INTEGER ::= 1
intVal2 INTEGER ::= -1
oid4 OBJECT IDENTIFIER ::= { oid2 intVal1 intVal2 boolVal 1}

oid5 OBJECT IDENTIFIER ::= { 1 2 -4}

oid6 OBJECT IDENTIFIER ::= { oid7 1}
oid7 OBJECT IDENTIFIER ::= { oid6 1 }
END
