/******************************************************************************
 * Copyright (c) 2000-2021 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 ******************************************************************************/

// This module tests that the compiler allows both uppercase and lowercase
// first letters for the name of an open type alternative
module Open_type_use {

import from IO_based_message language "ASN.1:2002" all;

// Constants (lowercase first letter)
const MyMessage c_message_id1_lower := {
  id := 1,
  content := { mySeq := { field1 := 42, field2 := omit }}
}

const MyMessage c_message_id2_lower := {
  id := 2,
  content := { myEnum := first}
}

const MyMessage c_message_id3_lower := {
  id := 3,
  content := { iNTEGER := 42 }
}

const MyMessage c_message_id4_lower := {
  id := 4,
  content := { nULL := NULL }
}

// Constants (uppercase first letter)
const MyMessage c_message_id1_upper := {
  id := 1,
  content := { MySeq := { field1 := 42, field2 := omit }}
}

const MyMessage c_message_id2_upper := {
  id := 2,
  content := { MyEnum := first}
}

const MyMessage c_message_id3_upper := {
  id := 3,
  content := { INTEGER := 42 }
}

const MyMessage c_message_id4_upper := {
  id := 4,
  content := { NULL := NULL }
}

// Templates (lowercase first letter)
template MyMessage t_message_id1_lower := {
  id := 1,
  content := { mySeq := { field1 := 42, field2 := omit }}
}

template MyMessage t_message_id2_lower := {
  id := 2,
  content := { myEnum := first}
}

template MyMessage t_message_id3_lower := {
  id := 3,
  content := { iNTEGER := 42 }
}

template MyMessage t_message_id4_lower := {
  id := 4,
  content := { nULL := NULL }
}

// Templates (uppercase first letter)
template MyMessage t_message_id1_upper := {
  id := 1,
  content := { MySeq := { field1 := 42, field2 := omit }}
}

template MyMessage t_message_id2_upper := {
  id := 2,
  content := { MyEnum := first}
}

template MyMessage t_message_id3_upper := {
  id := 3,
  content := { INTEGER := 42 }
}

template MyMessage t_message_id4_upper := {
  id := 4,
  content := { NULL := NULL }
}

// Value list template (contains both lowercase and uppercase examples)
template MyMessage t_message_value_list := (
  { id := 1, content := { mySeq := { field1 := 42, field2 := omit }} },
  { id := 2, content := { myEnum := first} },
  { id := 3, content := { iNTEGER := 42 } },
  { id := 4, content := { nULL := NULL } },
  { id := 1, content := { MySeq := { field1 := -42, field2 := omit }} },
  { id := 2, content := { MyEnum := second} },
  { id := 3, content := { INTEGER := -42 } },
  { id := 4, content := { NULL := NULL } }
);

// Dummy function to declare variables in
function f_dummy() {
  // Variables (lowercase first letter)
  var MyMessage v_message_id1_lower := {
    id := 1,
    content := { mySeq := { field1 := 42, field2 := omit }}
  }

  var MyMessage v_message_id2_lower := {
    id := 2,
    content := { myEnum := first}
  }
  
  var MyMessage v_message_id3_lower := {
    id := 3,
    content := { iNTEGER := 42 }
  }
  
  var MyMessage v_message_id4_lower := {
    id := 4,
    content := { nULL := NULL }
  }

  // Variables (uppercase first letter)
  var MyMessage v_message_id1_upper := {
    id := 1,
    content := { MySeq := { field1 := 42, field2 := omit }}
  }

  var MyMessage v_message_id2_upper := {
    id := 2,
    content := { MyEnum := first}
  }
  
  var MyMessage v_message_id3_upper := {
    id := 3,
    content := { INTEGER := 42 }
  }
  
  var MyMessage v_message_id4_upper := {
    id := 4,
    content := { NULL := NULL }
  }

  // Template variables (lowercase first letter)
  var template MyMessage vt_message_id1_lower := {
    id := 1,
    content := { mySeq := { field1 := 42, field2 := omit }}
  }

  var template MyMessage vt_message_id2_lower := {
    id := 2,
    content := { myEnum := first}
  }
  
  var template MyMessage vt_message_id3_lower := {
    id := 3,
    content := { iNTEGER := 42 }
  }
  
  var template MyMessage vt_message_id4_lower := {
    id := 4,
    content := { nULL := NULL }
  }

  // Template variables (uppercase first letter)
  var template MyMessage vt_message_id1_upper := {
    id := 1,
    content := { MySeq := { field1 := 42, field2 := omit }}
  }

  var template MyMessage vt_message_id2_upper := {
    id := 2,
    content := { MyEnum := first}
  }
  
  var template MyMessage vt_message_id3_upper := {
    id := 3,
    content := { INTEGER := 42 }
  }
  
  var template MyMessage vt_message_id4_upper := {
    id := 4,
    content := { NULL := NULL }
  }
  
  // Value list template variable (contains both lowercase and uppercase examples)
  var template MyMessage vt_message_value_list := (
    { id := 1, content := { mySeq := { field1 := 42, field2 := omit }} },
    { id := 2, content := { myEnum := first} },
    { id := 3, content := { iNTEGER := 42 } },
    { id := 4, content := { nULL := NULL } },
    { id := 1, content := { MySeq := { field1 := -42, field2 := omit }} },
    { id := 2, content := { MyEnum := second} },
    { id := 3, content := { INTEGER := -42 } },
    { id := 4, content := { NULL := NULL } }
  );
  
  // Referencing fields of open types (contains both lowercase and uppercase examples)
  v_message_id1_lower.content.mySeq := { field1 := 41, field2 := omit };
  v_message_id1_upper.content.MySeq := { field1 := 41, field2 := omit };
  v_message_id2_lower.content.myEnum := second;
  v_message_id2_upper.content.MyEnum := second;
  v_message_id3_lower.content.iNTEGER := 15;
  v_message_id3_upper.content.INTEGER := 15;
  v_message_id4_lower.content.nULL := NULL;
  v_message_id4_upper.content.NULL := NULL;
  vt_message_id1_lower.content.mySeq := { field1 := 41, field2 := omit };
  vt_message_id1_upper.content.MySeq := { field1 := 41, field2 := omit };
  vt_message_id2_lower.content.myEnum := second;
  vt_message_id2_upper.content.MyEnum := second;
  vt_message_id3_lower.content.iNTEGER := 15;
  vt_message_id3_upper.content.INTEGER := 15;
  vt_message_id4_lower.content.nULL := NULL;
  vt_message_id4_upper.content.NULL := NULL;
  if (c_message_id1_lower.content.mySeq == { field1 := 41, field2 := omit } and
      c_message_id1_upper.content.MySeq == { field1 := 41, field2 := omit } and
      c_message_id2_lower.content.myEnum == second and
      c_message_id2_upper.content.MyEnum == second and
      c_message_id3_lower.content.iNTEGER == 15 and
      c_message_id3_upper.content.INTEGER == 15 and
      c_message_id4_lower.content.nULL == NULL and // NULL != NULL !?
      c_message_id4_upper.content.NULL == NULL) {
    log("a");
  }
  if (v_message_id1_lower.content.mySeq == { field1 := 41, field2 := omit } and
      v_message_id1_upper.content.MySeq == { field1 := 41, field2 := omit } and
      v_message_id2_lower.content.myEnum == second and
      v_message_id2_upper.content.MyEnum == second and
      v_message_id3_lower.content.iNTEGER == 15 and
      v_message_id3_upper.content.INTEGER == 15 and
      v_message_id4_lower.content.nULL == NULL and
      v_message_id4_upper.content.NULL == NULL) {
    log("b");
  }
  if (match({ field1 := 41, field2 := omit }, t_message_id1_lower.content.mySeq) and
      match({ field1 := 41, field2 := omit }, t_message_id1_lower.content.MySeq) and
      match(second, t_message_id2_lower.content.myEnum) and
      match(second, t_message_id2_lower.content.MyEnum) and
      match(15, t_message_id3_lower.content.iNTEGER) and
      match(15, t_message_id3_lower.content.INTEGER) and
      match(NULL, t_message_id4_lower.content.nULL) and
      match(NULL, t_message_id4_lower.content.NULL)) {
    log("c");
  }
  if (match({ field1 := 41, field2 := omit }, vt_message_id1_upper.content.mySeq) and
      match({ field1 := 41, field2 := omit }, vt_message_id1_upper.content.MySeq) and
      match(second, vt_message_id2_upper.content.myEnum) and
      match(second, vt_message_id2_upper.content.MyEnum) and
      match(15, vt_message_id3_upper.content.iNTEGER) and
      match(15, vt_message_id3_upper.content.INTEGER) and
      match(NULL, vt_message_id4_upper.content.nULL) and
      match(NULL, vt_message_id4_upper.content.NULL)) {
    log("d");
  }
}

}
