hnbgw: Add test to check for duplicate hnb registrations

Change-Id: Ib20d07ffabb91dfa82c212aaa363cafc7496bba8
Related: OS#6084
diff --git a/hnbgw/HNBGW_Tests.ttcn b/hnbgw/HNBGW_Tests.ttcn
index 7429c38..d3d3a36 100644
--- a/hnbgw/HNBGW_Tests.ttcn
+++ b/hnbgw/HNBGW_Tests.ttcn
@@ -208,7 +208,7 @@
 }
 
 
-const integer NUM_HNB := 1;
+const integer NUM_HNB := 2;
 
 type record HnbConfig {
 	LocationAreaIdentification lai,
@@ -320,13 +320,6 @@
 /* global initialization function */
 function f_init(charstring id := "HNBGW", float guard_timeout := 30.0) runs on test_CT {
 
-	g_hnb_cfg[0] := {
-		lai := {
-			mcc_mnc := '00101'H,
-			lac := 2342
-		},
-		sac := 55
-	}
 	T_guard.start(guard_timeout);
 	activate(as_Tguard());
 
@@ -336,6 +329,13 @@
 		unitdata_cb := refers(IuhRanapUnitdataCallback)
 	};
 	for (var integer i := 0; i < NUM_HNB; i := i+1) {
+		g_hnb_cfg[i] := {
+			lai := {
+				mcc_mnc := '00101'H,
+				lac := 2342 + i
+			},
+			sac := 55
+		};
 		f_init_hnodeb(testcasename(), i, rua_ops);
 	}
 
@@ -374,7 +374,7 @@
 /* helper function to start all of the simulated hNodeBs */
 function f_start_hnbs() runs on test_CT {
 	for (var integer i:= 0; i < NUM_HNB; i := i+1) {
-		f_hnbap_register(i);
+		f_hnbap_register(i, i);
 	}
 }
 
@@ -634,13 +634,13 @@
  ***********************************************************************/
 
 
-function f_hnbap_register(integer hnb_idx := 0) runs on test_CT
+function f_hnbap_register(integer hnb_idx := 0, integer cell_id := 0, boolean expect_reject := false) runs on test_CT
 {
 	timer T := 2.0;
 
 	HNBAP[hnb_idx].send(tr_HNBAP_HNBRegisterRequest(char2oct("TTCN3 HNodeB"),
 					'00F110'O,
-					int2bit(1 + hnb_idx, 28),
+					int2bit(1 + cell_id, 28),
 					int2oct(2, 2),
 					int2oct(3, 1),
 					int2oct(4, 2)));
@@ -648,13 +648,24 @@
 	T.start;
 	alt {
 	[] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterAccept(?)) {
-		setverdict(pass);
+		if (expect_reject) {
+			setverdict(fail, "Rx HNB Register Accept while expecting reject");
+		} else {
+			setverdict(pass);
+		}
+	}
+	[] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterReject(?)) {
+		if (expect_reject) {
+			setverdict(pass);
+		} else {
+			setverdict(fail, "Rx HNB Register Reject while expecting accept");
+		}
 	}
 	[] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
 		repeat;
 	}
 	[] T.timeout {
-		setverdict(fail, "Timeout waiting for HNB Register Accept");
+		setverdict(fail, "Timeout waiting for HNB Register response");
 	}
 	}
 }
@@ -665,6 +676,14 @@
 	f_shutdown_helper();
 }
 
+testcase TC_hnb_register_duplicate() runs on test_CT {
+	f_init();
+	f_hnbap_register(0);
+	f_hnbap_register(1, 0, expect_reject := true);
+	f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
+	f_shutdown_helper();
+}
+
 /***********************************************************************
  * RUA / RANAP Testing
  ***********************************************************************/
@@ -1322,6 +1341,7 @@
 
 control {
 	execute(TC_hnb_register());
+	execute(TC_hnb_register_duplicate());
 	execute(TC_ranap_cs_initial_ue());
 	execute(TC_ranap_ps_initial_ue());
 	execute(TC_ranap_cs_initial_ue_empty_cr());