|  | /////////////////////////////////////////////////////////////////////////////// | 
|  | //                                                                           // | 
|  | // Copyright (c) 2000-2017 Ericsson Telecom AB                               // | 
|  | //                                                                           // | 
|  | // All rights reserved. This program and the accompanying materials          // | 
|  | // are made available under the terms of the Eclipse Public License v1.0     // | 
|  | // which accompanies this distribution, and is available at                  // | 
|  | // http://www.eclipse.org/legal/epl-v10.html                                 // | 
|  | /////////////////////////////////////////////////////////////////////////////// | 
|  |  | 
|  | /////////////////////////////////////////////////////////// | 
|  | //  Module: HashMap_int2int_test | 
|  | // | 
|  | //  Purpose: | 
|  | //    Test file for HashMap. | 
|  | // | 
|  | ////////////////////////////////////////////////////////// | 
|  |  | 
|  | module HashMap_int2int_test | 
|  |  | 
|  | { | 
|  |  | 
|  | //========================================================================= | 
|  | // Import Part | 
|  | //========================================================================= | 
|  |  | 
|  | import from EPTF_CLL_Base_Functions all; | 
|  | import from EPTF_CLL_Common_Definitions all; | 
|  | import from EPTF_CLL_HashMapInt2Int_Functions all; | 
|  | import from TCCEnv_Functions all; | 
|  | import from EPTF_CLL_HashMap_Functions all; | 
|  | import from EPTF_CLL_HashMap_Definitions all; | 
|  |  | 
|  | //========================================================================= | 
|  | //Component Types | 
|  | //========================================================================= | 
|  |  | 
|  | type component MyMTC_CT extends EPTF_HashMap_CT { | 
|  | } | 
|  |  | 
|  |  | 
|  | //========================================================================= | 
|  | // Testcases | 
|  | //========================================================================= | 
|  |  | 
|  |  | 
|  | //========================================================================= | 
|  | // Testcase: tc_int2int_HashMap_baseFunctions() | 
|  | //========================================================================= | 
|  | testcase tc_int2int_HashMap_baseFunctions() | 
|  | runs on MyMTC_CT | 
|  | { | 
|  |  | 
|  | f_EPTF_HashMap_init_CT ("HashMapTest"); | 
|  |  | 
|  | var integer wrong_name_check; | 
|  | if(not f_EPTF_int2int_HashMap_GetID("badname",wrong_name_check) ) | 
|  | { | 
|  | log("Wrong name, ID: ",wrong_name_check); | 
|  | setverdict(pass); | 
|  | } | 
|  |  | 
|  | //create first hashmap | 
|  | var charstring first := "my_first_hashmap"; | 
|  | var integer first_int; | 
|  | var integer first_check; | 
|  |  | 
|  | first_int := f_EPTF_int2int_HashMap_New (first); | 
|  | log("Creating first hashmap called: ", first, " ", first_int); | 
|  |  | 
|  | // getting the ID of first hashmap | 
|  | log("Getting the ID of first hashmap"); | 
|  | if( f_EPTF_int2int_HashMap_GetID(first,first_check) ) | 
|  | { | 
|  | if ( first_int == first_check ){ setverdict(pass) } else { setverdict (fail) } | 
|  | } | 
|  |  | 
|  | //create second hashmap | 
|  | var charstring second := "my_second_hashmap"; | 
|  | var integer second_int; | 
|  | var integer second_check; | 
|  |  | 
|  | second_int := f_EPTF_int2int_HashMap_New (second); | 
|  | log("Creating second hashmap called: ", second, " ", second_int); | 
|  |  | 
|  | // getting the ID of second hashmap | 
|  | log("Getting the ID of second hashmap"); | 
|  | if( f_EPTF_int2int_HashMap_GetID(second,second_check) ) | 
|  | { | 
|  | if ( second_int == second_check ){ setverdict(pass) } else { setverdict (fail) } | 
|  | } | 
|  |  | 
|  | //maximum size | 
|  | var float hm_max_size; | 
|  | hm_max_size := f_EPTF_int2int_HashMap_MaxSize (first_int); | 
|  | log( "Maximum size of hashmap first: ",hm_max_size ); | 
|  |  | 
|  | //getting the number of buckets | 
|  | var integer hm_bucketCount; | 
|  | hm_bucketCount := f_EPTF_int2int_HashMap_BucketCount (first_int); | 
|  | log( "Size of the hashmap first before resizing: ",hm_bucketCount ); | 
|  |  | 
|  | //setting the number of buckets to minimum 500 | 
|  | f_EPTF_int2int_HashMap_Resize (first_int,500); | 
|  | hm_bucketCount := f_EPTF_int2int_HashMap_BucketCount (first_int); | 
|  | log( "Size of the hashmap first after resizing: ",hm_bucketCount ); | 
|  | //if ( hm_bucketCount >= 200){ setverdict(pass) } else { setverdict (fail) } | 
|  |  | 
|  | //insert to first hashmap | 
|  | log( "Inserting data to hashmap first" ); | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int, 123, 11 ); | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int, 234, 22 ); | 
|  |  | 
|  | //print number of key/value pairs of first hashmap | 
|  | var integer hm_size; | 
|  | hm_size := f_EPTF_int2int_HashMap_Size (first_int); | 
|  | log( "Number of elements in hashmap first: \n", hm_size ); | 
|  | if ( hm_size == 2 ){ setverdict(pass) }else{ setverdict( fail ) } | 
|  |  | 
|  | // read an element from first hashmap | 
|  | var integer hm_data; | 
|  | if ( f_EPTF_int2int_HashMap_Find ( first_int,123 , hm_data ) ) | 
|  | { | 
|  | log("Reading data from hashmap first, key = 123 data: \n", hm_data ); | 
|  | if ( hm_data == 11 ){ setverdict(pass) }else{ setverdict(fail) } | 
|  | } | 
|  | else | 
|  | { | 
|  | setverdict(fail); | 
|  | } | 
|  |  | 
|  | //insert to second hashmap | 
|  | log( "Inserting data to hashmap second" ); | 
|  | f_EPTF_int2int_HashMap_Insert ( second_int,123 , 11 ); | 
|  | f_EPTF_int2int_HashMap_Insert ( second_int,234 , 33 ); | 
|  | f_EPTF_int2int_HashMap_Insert ( second_int,345 , 44 ); | 
|  |  | 
|  | //print number of key/value pairs of second hashmap | 
|  | var integer hm_size2; | 
|  | hm_size2 := f_EPTF_int2int_HashMap_Size (second_int); | 
|  | log( "Number of elements in hashmap second: \n", hm_size2 ); | 
|  | if ( hm_size2 == 3 ){ setverdict(pass) }else{ setverdict(fail) } | 
|  |  | 
|  | // read an element from second hashmap | 
|  | var integer hm_data2; | 
|  | if ( f_EPTF_int2int_HashMap_Find ( second_int,123, hm_data2 ) ) | 
|  | { | 
|  | log("Reading data from hashmap second, key = 123 data: \n", hm_data2 ); | 
|  | if ( hm_data2 == 11 ){ setverdict(pass) }else{ setverdict(fail) } | 
|  | } | 
|  | else | 
|  | { | 
|  | setverdict(fail); | 
|  | } | 
|  |  | 
|  |  | 
|  | // read a not valid element from first hashmap | 
|  | var integer hm_data3; | 
|  | if ( f_EPTF_int2int_HashMap_Find ( first_int,666 , hm_data3 ) ) | 
|  | { | 
|  | setverdict(fail); | 
|  | } | 
|  | else | 
|  | { | 
|  | log("Reading data from hashmap first, key = badkey data: \n", hm_data3 ); | 
|  | setverdict(pass); | 
|  | } | 
|  |  | 
|  |  | 
|  | //erase an element from first | 
|  | f_EPTF_int2int_HashMap_Erase ( first_int, 123 ); | 
|  | hm_size := f_EPTF_int2int_HashMap_Size (first_int); | 
|  | log( "Number of elements in hashmap first: \n", hm_size ); | 
|  | if ( hm_size == 1 ){ setverdict(pass) }else{ setverdict(fail) } | 
|  |  | 
|  |  | 
|  | //calculate hash value of a key | 
|  | var integer hm_hashValue; | 
|  | hm_hashValue := f_EPTF_int2int_HashMap_CallHashFunc ( first_int,123 ); | 
|  | log( "The hash value of key=hello is:", hm_hashValue ); | 
|  | hm_hashValue := f_EPTF_int2int_HashMap_CallHashFunc ( first_int,234 ); | 
|  | log( "The hash value of key=world is:", hm_hashValue ); | 
|  |  | 
|  |  | 
|  | //create third hashmap | 
|  | var charstring third := "my_third_hashmap"; | 
|  | var integer third_int; | 
|  | var integer third_check; | 
|  |  | 
|  | third_int := f_EPTF_int2int_HashMap_New (third); | 
|  | log("Creating third hashmap called: ", third, " ", third_int); | 
|  |  | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Assign( third_int, first_int ); | 
|  | log("Assigning third hashmap to first"); | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int, 854, 99 ); | 
|  | //erasing a key | 
|  | f_EPTF_int2int_HashMap_Erase ( first_int, 234 ); | 
|  |  | 
|  | //erasing a non existent key | 
|  | f_EPTF_int2int_HashMap_Erase ( first_int, 999 ); | 
|  |  | 
|  | // Dumping all hashmap | 
|  | f_EPTF_int2int_HashMap_DumpAll(); | 
|  |  | 
|  | //The contents of all hashmap: | 
|  | //----Dumping all begin---- | 
|  | //----Dumping HashMap called: "my_first_hashmap" begin---- | 
|  | // (key,data): 854 99 | 
|  | // (key,data): 123 11 | 
|  | // (key,data): 345 44 | 
|  | //----Dumping HashMap called: "my_first_hashmap" end---- | 
|  | //----Dumping HashMap called: "my_second_hashmap" begin---- | 
|  | //(key,data): 234 22 | 
|  | //----Dumping HashMap called: "my_second_hashmap" end---- | 
|  | //----Dumping HashMap called: "my_third_hashmap" begin---- | 
|  | // (key,data): 234 33 | 
|  | // (key,data): 123 11 | 
|  | // (key,data): 345 44 | 
|  | //----Dumping HashMap called: "my_third_hashmap" end---- | 
|  | //----Dumping all end---- | 
|  |  | 
|  | //clear the hashmap first | 
|  | log( "Clearing hashmap and checking whether it`s empty: \n"); | 
|  | f_EPTF_int2int_HashMap_Clear(first_int); | 
|  |  | 
|  |  | 
|  | //check if hashmap is empty | 
|  | if( f_EPTF_int2int_HashMap_Empty(first_int) ){setverdict(pass) } else { setverdict (fail) } | 
|  |  | 
|  |  | 
|  | //deleting hashmaps | 
|  | f_EPTF_int2int_HashMap_Delete (first); | 
|  | log("Deleting first hashmap called: ",first); | 
|  | f_EPTF_int2int_HashMap_Delete (second); | 
|  | log("Deleting second hashmap called: ",second); | 
|  | f_EPTF_int2int_HashMap_Delete (third); | 
|  | log("Deleting third hashmap called: ",third); | 
|  |  | 
|  | //create a fourth hashmap | 
|  | var charstring fourth := "my_fourth_hashmap"; | 
|  | var integer fourth_int; | 
|  | var integer fourth_check; | 
|  |  | 
|  | fourth_int := f_EPTF_int2int_HashMap_New (fourth); | 
|  | log("Creating fourth hashmap called: ", fourth, " ", fourth_int); | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Delete (fourth); | 
|  | log("Deleting fourth hashmap called: ",fourth); | 
|  |  | 
|  | // DeleteByID test: | 
|  | var charstring hashMap_1 := "my_hashMap_1_hashmap" | 
|  | var integer hashMap_1_Id := f_EPTF_int2int_HashMap_New (hashMap_1); | 
|  | var charstring hashMap_2 := "my_hashMap_2_hashmap" | 
|  | var integer hashMap_2_Id := f_EPTF_int2int_HashMap_New (hashMap_2); | 
|  | var charstring hashMap_3 := "my_hashMap_3_hashmap" | 
|  | var integer hashMap_3_Id := f_EPTF_int2int_HashMap_New (hashMap_3); | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Insert ( hashMap_1_Id,123 , 11 ) | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Insert ( hashMap_2_Id,221 , 21 ) | 
|  | f_EPTF_int2int_HashMap_Insert ( hashMap_2_Id,222 , 22 ) | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Insert ( hashMap_3_Id,321 , 31 ) | 
|  | f_EPTF_int2int_HashMap_Insert ( hashMap_3_Id,322 , 32 ) | 
|  | f_EPTF_int2int_HashMap_Insert ( hashMap_3_Id,323 , 33 ) | 
|  |  | 
|  | if (not f_EPTF_int2int_HashMap_Find ( hashMap_1_Id,123 , hm_data ) and hm_data != 11) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  |  | 
|  | if (not f_EPTF_int2int_HashMap_Find ( hashMap_2_Id,221 , hm_data ) and hm_data != 21) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  | if (not f_EPTF_int2int_HashMap_Find ( hashMap_2_Id,222 , hm_data ) and hm_data != 22) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  |  | 
|  | if (not f_EPTF_int2int_HashMap_Find ( hashMap_3_Id,321 , hm_data ) and hm_data != 31) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  | if (not f_EPTF_int2int_HashMap_Find ( hashMap_3_Id,322 , hm_data ) and hm_data != 32) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  | if (not f_EPTF_int2int_HashMap_Find ( hashMap_3_Id,323 , hm_data ) and hm_data != 33) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  |  | 
|  | if (f_EPTF_int2int_HashMap_Find ( hashMap_2_Id,323 , hm_data )) { | 
|  | setverdict(fail, "Nonexistent element found") | 
|  | }; | 
|  | f_EPTF_int2int_HashMap_DumpAll(); | 
|  | f_EPTF_int2int_HashMap_DeleteById (hashMap_2_Id); | 
|  |  | 
|  | f_EPTF_int2int_HashMap_DumpAll(); | 
|  |  | 
|  | if (not f_EPTF_int2int_HashMap_Find ( hashMap_1_Id,123 , hm_data ) and hm_data != 11) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  |  | 
|  | if (not f_EPTF_int2int_HashMap_Find ( hashMap_3_Id,321 , hm_data ) and hm_data != 31) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  | if (not f_EPTF_int2int_HashMap_Find ( hashMap_3_Id,322 , hm_data ) and hm_data != 32) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  | if (not f_EPTF_int2int_HashMap_Find ( hashMap_3_Id,323 , hm_data ) and hm_data != 33) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  |  | 
|  | var integer id; | 
|  | if( f_EPTF_int2int_HashMap_GetID(hashMap_2,id) ) { | 
|  | setverdict(fail, "Nonexistent hashmap found"); | 
|  | } | 
|  | if(not f_EPTF_int2int_HashMap_GetID(hashMap_1,id) and id != hashMap_1_Id ) { | 
|  | setverdict(fail, "Existent hashmap not found"); | 
|  | } | 
|  | if(not f_EPTF_int2int_HashMap_GetID(hashMap_3,id) and id != hashMap_3_Id ) { | 
|  | setverdict(fail, "Existent hashmap not found"); | 
|  | } | 
|  |  | 
|  |  | 
|  | //   if (f_EPTF_int2int_HashMap_Find ( hashMap_2_Id,221 , hm_data )) { | 
|  | //     setverdict(fail, "Nonexistent element found") | 
|  | //   }; | 
|  | // | 
|  | f_EPTF_int2int_HashMap_Delete (hashMap_2); | 
|  | f_EPTF_int2int_HashMap_DeleteById (hashMap_2_Id); | 
|  | f_EPTF_int2int_HashMap_DeleteById (hashMap_1_Id); | 
|  | f_EPTF_int2int_HashMap_DeleteById (hashMap_1_Id); | 
|  | f_EPTF_int2int_HashMap_Delete (hashMap_1); | 
|  | f_EPTF_int2int_HashMap_DeleteById (hashMap_3_Id); | 
|  | f_EPTF_int2int_HashMap_DeleteById (hashMap_3_Id); | 
|  |  | 
|  | f_EPTF_int2int_HashMap_DumpAll(); | 
|  |  | 
|  | // DeleteByID test END | 
|  |  | 
|  | f_EPTF_Base_stop(none); | 
|  | } | 
|  |  | 
|  |  | 
|  | //========================================================================= | 
|  | // Testcase: tc_int2int_HashMap_test_bigInt() | 
|  | //========================================================================= | 
|  |  | 
|  | testcase tc_int2int_HashMap_test_bigInt() | 
|  | runs on MyMTC_CT | 
|  | { | 
|  | f_EPTF_HashMap_init_CT ("tc_int2int_HashMap_test_bigInt"); | 
|  |  | 
|  | var integer vl_hashMapId := f_EPTF_int2int_HashMap_New ("HM1"); | 
|  | f_EPTF_int2int_HashMap_Insert ( vl_hashMapId,12345678901234567890 , 22 ); | 
|  |  | 
|  | var integer vl_data; | 
|  | if (not f_EPTF_int2int_HashMap_Find ( vl_hashMapId,12345678901234567890 , vl_data ) and vl_data != 22) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  |  | 
|  | f_EPTF_Base_stop(pass); | 
|  |  | 
|  | } | 
|  |  | 
|  | //========================================================================= | 
|  | // Testcase: tc_int2int_HashMap_test_bigIntData() | 
|  | //========================================================================= | 
|  |  | 
|  | testcase tc_int2int_HashMap_test_bigIntData() | 
|  | runs on MyMTC_CT | 
|  | { | 
|  | f_EPTF_HashMap_init_CT ("tc_int2int_HashMap_test_bigInt"); | 
|  |  | 
|  | var integer vl_hashMapId := f_EPTF_int2int_HashMap_New ("HM1"); | 
|  | f_EPTF_int2int_HashMap_Insert ( vl_hashMapId,1 , 12345678901234567890 ); | 
|  |  | 
|  | var integer vl_data; | 
|  | if (not f_EPTF_int2int_HashMap_Find ( vl_hashMapId,1 , vl_data ) and vl_data != 12345678901234567890) { | 
|  | setverdict(fail, "Existing element not found") | 
|  | }; | 
|  |  | 
|  | f_EPTF_Base_stop(pass); | 
|  |  | 
|  | } | 
|  |  | 
|  | //========================================================================= | 
|  | // Testcase: tc_int2int_HashMap_otherFunctions() | 
|  | //========================================================================= | 
|  |  | 
|  | testcase tc_int2int_HashMap_otherFunctions() | 
|  | runs on MyMTC_CT | 
|  | { | 
|  |  | 
|  | f_EPTF_HashMap_init_CT ("HashMapTest_otherFunctions"); | 
|  |  | 
|  | //create first hashmap | 
|  | var charstring first := "my_first_hashmap"; | 
|  | var integer first_int; | 
|  | var integer first_check; | 
|  | first_int := f_EPTF_int2int_HashMap_New (first); | 
|  |  | 
|  | // getting the ID of hashmap | 
|  | log("Getting the ID of hashmap"); | 
|  | if( f_EPTF_int2int_HashMap_GetID(first,first_check) ) | 
|  | { | 
|  | if ( first_int == first_check ){ setverdict(pass) } else { setverdict (fail) } | 
|  | } | 
|  |  | 
|  | // 1. While cycle, no elements in hashmap | 
|  | var integer readkey:=0; | 
|  |  | 
|  | log("1. WHILE cycle, no elements in hashmap "); | 
|  | var boolean cycleIsOver:= f_EPTF_int2int_HashMap_Begin(first_int, readkey); | 
|  | if( not cycleIsOver ) | 
|  | { | 
|  | log("No elements in hashmap" ); | 
|  | setverdict(pass); | 
|  | }; | 
|  |  | 
|  | while (cycleIsOver) | 
|  | { | 
|  | var integer hm_data; | 
|  | if ( f_EPTF_int2int_HashMap_Find ( first_int, readkey, hm_data ) ) | 
|  | { | 
|  | log("1. WHILE cycle: \n", readkey," ", hm_data ); | 
|  | } | 
|  | cycleIsOver := f_EPTF_int2int_HashMap_Next(first_int,readkey); | 
|  | setverdict(fail); | 
|  | } | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int,123 , 11 ); | 
|  |  | 
|  |  | 
|  | // 2. While cycle, one element in hashmap | 
|  | readkey:=0; | 
|  |  | 
|  | log("2. WHILE cycle, 1 element in hashmap "); | 
|  | cycleIsOver:= f_EPTF_int2int_HashMap_Begin(first_int, readkey); | 
|  | if( not cycleIsOver ) | 
|  | { | 
|  | log("No elements in hashmap" ); | 
|  | setverdict(fail); | 
|  | }; | 
|  |  | 
|  | while (cycleIsOver) | 
|  | { | 
|  | var integer hm_data; | 
|  | if ( f_EPTF_int2int_HashMap_Find ( first_int, readkey, hm_data ) ) | 
|  | { | 
|  | log("2. WHILE cycle: \n", readkey," ", hm_data ); | 
|  | } | 
|  | cycleIsOver := f_EPTF_int2int_HashMap_Next(first_int,readkey); | 
|  | setverdict(pass); | 
|  | } | 
|  |  | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int,234 , 22 ); | 
|  |  | 
|  |  | 
|  | // 3. While cycle, two element in hashmap | 
|  | log("3. WHILE cycle, 2 element in hashmap "); | 
|  | readkey:=0; | 
|  | cycleIsOver:= f_EPTF_int2int_HashMap_Begin(first_int, readkey); | 
|  | if( not cycleIsOver ) | 
|  | { | 
|  | log("No elements in hashmap" ); | 
|  | setverdict(fail); | 
|  | }; | 
|  |  | 
|  | while (cycleIsOver) | 
|  | { | 
|  | var integer hm_data; | 
|  | if ( f_EPTF_int2int_HashMap_Find ( first_int, readkey, hm_data ) ) | 
|  | { | 
|  | log("3. WHILE cycle: \n", readkey," ", hm_data ); | 
|  | } | 
|  | cycleIsOver := f_EPTF_int2int_HashMap_Next(first_int,readkey); | 
|  | setverdict(pass); | 
|  | } | 
|  |  | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int,345 , 33 ); | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int,456 , 44 ); | 
|  |  | 
|  |  | 
|  | // 4. While cycle, four element in hashmap | 
|  | log("4. WHILE cycle, 4 element in hashmap "); | 
|  | readkey:=0; | 
|  | cycleIsOver:= f_EPTF_int2int_HashMap_Begin(first_int, readkey); | 
|  | if( not cycleIsOver ) | 
|  | { | 
|  | log("No elements in hashmap" ); | 
|  | setverdict(fail); | 
|  | }; | 
|  |  | 
|  | while (cycleIsOver) | 
|  | { | 
|  | var integer hm_data; | 
|  | if ( f_EPTF_int2int_HashMap_Find ( first_int, readkey, hm_data ) ) | 
|  | { | 
|  | log("4. WHILE cycle: \n", readkey," ", hm_data ); | 
|  | } | 
|  | cycleIsOver := f_EPTF_int2int_HashMap_Next(first_int,readkey); | 
|  | setverdict(pass); | 
|  | } | 
|  |  | 
|  |  | 
|  | // FOR cycle, four elements in hashmap | 
|  | log("FOR cycle, 4 element in hashmap "); | 
|  | readkey:=0; | 
|  | for (var boolean cycle:=f_EPTF_int2int_HashMap_Begin(first_int, readkey); | 
|  | cycle; cycle:=f_EPTF_int2int_HashMap_Next(first_int,readkey)) | 
|  | { | 
|  | var integer hm_data; | 
|  | if ( f_EPTF_int2int_HashMap_Find ( first_int, readkey, hm_data ) ) | 
|  | { | 
|  | log("FOR cycle: \n", readkey, " ", hm_data ); | 
|  | } | 
|  | setverdict(pass); | 
|  | } | 
|  |  | 
|  |  | 
|  | // Dumping hashmap | 
|  | log("Dumping hashmap by name"); | 
|  | f_EPTF_int2int_HashMap_Dump(first); | 
|  |  | 
|  |  | 
|  | // Dumping hashmap by id | 
|  | log("Dumping hashmap by ID"); | 
|  | f_EPTF_int2int_HashMap_DumpByID(first_int); | 
|  |  | 
|  |  | 
|  | //deleting hashmap | 
|  | f_EPTF_int2int_HashMap_Delete (first); | 
|  | log("Deleting hashmap called: ",first); | 
|  |  | 
|  | } | 
|  |  | 
|  | //========================================================================= | 
|  | // Testcase: tc_int2int_HashMap_testUpdateFunction() | 
|  | //========================================================================= | 
|  |  | 
|  | testcase tc_int2int_HashMap_testUpdateFunction() | 
|  | runs on MyMTC_CT | 
|  | { | 
|  |  | 
|  | f_EPTF_HashMap_init_CT ("HashMapTest"); | 
|  |  | 
|  | //create hashmap | 
|  | var charstring first := "my_hashmap"; | 
|  | var integer first_int; | 
|  | var integer first_check; | 
|  |  | 
|  | first_int := f_EPTF_int2int_HashMap_New (first); | 
|  | log("Creating hashmap called: ", first, " ", first_int); | 
|  |  | 
|  | //insert to hashmap | 
|  | log( "Inserting data to hashmap" ); | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int,123 , 11 ); | 
|  |  | 
|  | // | 
|  | f_EPTF_int2int_HashMap_Update ( first_int,123 , 22 ); | 
|  | f_EPTF_int2int_HashMap_Update ( first_int,234 , 33 ); | 
|  | f_EPTF_int2int_HashMap_Update ( first_int,345 , 44 ); | 
|  |  | 
|  | // read an element from hashmap | 
|  | var integer hm_data; | 
|  | if ( f_EPTF_int2int_HashMap_Find ( first_int,123 , hm_data ) ) | 
|  | { | 
|  | log("Reading data from hashmap, key = 123 data: \n", hm_data ); | 
|  | if ( hm_data == 22 ){ setverdict(pass) }else{ setverdict(fail) } | 
|  | } | 
|  | else | 
|  | { | 
|  | setverdict(fail); | 
|  | } | 
|  |  | 
|  | // Dumping hashmap | 
|  | log("Dumping hashmap "); | 
|  | f_EPTF_int2int_HashMap_Dump(first); | 
|  |  | 
|  |  | 
|  | //deleting hashmaps | 
|  | f_EPTF_int2int_HashMap_Delete (first); | 
|  | log("Deleting hashmap called: ",first); | 
|  | } | 
|  |  | 
|  | function f_int2int_HashMap_createOfSize( | 
|  | in integer pl_size) | 
|  | runs on MyMTC_CT | 
|  | { | 
|  | var integer i := 0; | 
|  | var charstring name := "my_hashmap"; | 
|  | var integer id := f_EPTF_int2int_HashMap_New(name); | 
|  | for(i := 0; i < pl_size; i := i + 1) { | 
|  | f_EPTF_int2int_HashMap_Insert(id, i, i); | 
|  | } | 
|  | f_EPTF_int2int_HashMap_Delete(name); | 
|  | } | 
|  |  | 
|  | //========================================================================= | 
|  | // Testcase: tc_int2int_HashMap_testGrowage() | 
|  | //========================================================================= | 
|  |  | 
|  | testcase tc_int2int_HashMap_testGrowage() | 
|  | runs on MyMTC_CT | 
|  | { | 
|  | f_EPTF_HashMap_init_CT ("HashMapTest"); | 
|  |  | 
|  | if(tsp_CLL_debug_acceptableMaxSizeOfGrowingVariables < 0) { | 
|  | log(%definitionId&": tsp_CLL_debug_acceptableMaxSizeOfGrowingVariables is less than 0."); | 
|  | stop; | 
|  | } | 
|  |  | 
|  | log(%definitionId&": Creating a hashmap with ", tsp_CLL_debug_acceptableMaxSizeOfGrowingVariables, " elements"); | 
|  | log(%definitionId&":   This should cause NO logs about exceeding the max size."); | 
|  | f_int2int_HashMap_createOfSize(tsp_CLL_debug_acceptableMaxSizeOfGrowingVariables); | 
|  |  | 
|  | log(%definitionId&": Creating a hashmap with ", tsp_CLL_debug_acceptableMaxSizeOfGrowingVariables + 1, " elements"); | 
|  | log(%definitionId&":   This should cause a single log about exceeding the max size."); | 
|  | f_int2int_HashMap_createOfSize(tsp_CLL_debug_acceptableMaxSizeOfGrowingVariables + 1); | 
|  |  | 
|  | if(tsp_CLL_debug_acceptableMaxSizeOfGrowingVariables > 0) { | 
|  | log(%definitionId&": Creating a hashmap with ", 2*tsp_CLL_debug_acceptableMaxSizeOfGrowingVariables, " elements"); | 
|  | log(%definitionId&":   This should cause a few logs about exceeding the max size.") | 
|  | f_int2int_HashMap_createOfSize(2 * tsp_CLL_debug_acceptableMaxSizeOfGrowingVariables); | 
|  |  | 
|  | log(%definitionId&": Creating a hashmap with ", 100*tsp_CLL_debug_acceptableMaxSizeOfGrowingVariables, " elements"); | 
|  | log(%definitionId&":   This should cause more logs about exceeding the max size.") | 
|  | f_int2int_HashMap_createOfSize(100 * tsp_CLL_debug_acceptableMaxSizeOfGrowingVariables); | 
|  | } | 
|  | } | 
|  |  | 
|  | //========================================================================= | 
|  | // Testcase: tc_int2int_HashMap_FindTest() | 
|  | //========================================================================= | 
|  |  | 
|  | testcase tc_int2int_HashMap_FindTest() | 
|  | runs on MyMTC_CT | 
|  | { | 
|  | f_EPTF_HashMap_init_CT ("HashMapTest"); | 
|  | var integer vl_i := -3; | 
|  | var integer vl_h := f_EPTF_int2int_HashMap_New("bubuhash"); | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Insert(vl_h, 34, 1); | 
|  | f_EPTF_int2int_HashMap_Insert(vl_h, 48, 2); | 
|  |  | 
|  | var boolean vl_ret := f_EPTF_int2int_HashMap_Find(vl_h, 52, vl_i); | 
|  |  | 
|  | if(vl_i == -1 and not vl_ret){ | 
|  | setverdict(pass) | 
|  | }else{ | 
|  | setverdict ( fail ); | 
|  | } | 
|  |  | 
|  | vl_ret := f_EPTF_int2int_HashMap_Find(vl_h, 48, vl_i); | 
|  |  | 
|  | if(vl_i != 2 or not vl_ret){ | 
|  | setverdict ( fail ); | 
|  | } | 
|  |  | 
|  | vl_ret := f_EPTF_int2int_HashMap_Find(vl_h, 34, vl_i); | 
|  |  | 
|  | if(vl_i != 1 or not vl_ret){ | 
|  | setverdict ( fail ); | 
|  | } | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Delete("bubuhash"); | 
|  | } | 
|  |  | 
|  |  | 
|  | /////////////////////////////////////////////////////////// | 
|  | //  Testcase: tc_int2int_HashMap_NoCleanUp1 and 2 | 
|  | // | 
|  | //  Purpose: | 
|  | //	  To test the Hashmap init function : the first test case inits a hashmap | 
|  | //    and exists without calling the cleanup. | 
|  | //    The second one is the one to watch. If it passes, then the feature is ok. | 
|  | //    It tries to create a hashmap and insert a data just like the first | 
|  | //    traffic case. If the init and cleanup works fine, it will succeed. | 
|  | //    If error, then the cleanup does not erase the hashmaps created in | 
|  | //    the previous testcases if no cleanup is called (if e.g. a DTE happens). | 
|  | // | 
|  | /////////////////////////////////////////////////////////// | 
|  | testcase tc_int2int_HashMap_NoCleanUp1() runs on MyMTC_CT | 
|  | { | 
|  | f_EPTF_HashMap_init_CT ("HashMapTest"); | 
|  | var integer vl_h := f_EPTF_int2int_HashMap_New("bubuhash"); | 
|  | f_EPTF_int2int_HashMap_Insert(vl_h, 34, 1); | 
|  | setverdict(pass); | 
|  | } | 
|  |  | 
|  | testcase tc_int2int_HashMap_NoCleanUp2() runs on MyMTC_CT | 
|  | { | 
|  | f_EPTF_HashMap_init_CT ("HashMapTest"); | 
|  | var integer vl_h := f_EPTF_int2int_HashMap_New("bubuhash"); | 
|  | f_EPTF_int2int_HashMap_Insert(vl_h, 34, 1); | 
|  | setverdict(pass); | 
|  | f_EPTF_Base_cleanup_CT(); | 
|  | f_EPTF_Base_stop(none); | 
|  | } | 
|  |  | 
|  | //========================================================================= | 
|  | // Testcase: tc_int2int_HashMapTest_dumpByID_manual() | 
|  | //========================================================================= | 
|  |  | 
|  | testcase tc_int2int_HashMapTest_dumpByID_manual() | 
|  | runs on MyMTC_CT | 
|  | { | 
|  |  | 
|  | f_EPTF_HashMap_init_CT ("HashMapTest_dump"); | 
|  |  | 
|  | //create first hashmap | 
|  | var charstring first := "my_first_hashmap"; | 
|  | var integer first_int; | 
|  | first_int := f_EPTF_int2int_HashMap_New (first); | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int,1123 , 111 ); | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int,1234 , 122 ); | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int,1345 , 133 ); | 
|  | f_EPTF_int2int_HashMap_Insert ( first_int,1456 , 144 ); | 
|  |  | 
|  | //create second hashmap | 
|  | var charstring second := "my_second_hashmap"; | 
|  | var integer second_int; | 
|  | second_int := f_EPTF_int2int_HashMap_New (second); | 
|  |  | 
|  | f_EPTF_int2int_HashMap_Insert ( second_int,2123 , 211 ); | 
|  | f_EPTF_int2int_HashMap_Insert ( second_int,2234 , 222 ); | 
|  | f_EPTF_int2int_HashMap_Insert ( second_int,2345 , 233 ); | 
|  | f_EPTF_int2int_HashMap_Insert ( second_int,2456 , 244 ); | 
|  |  | 
|  | // Dumping hashmap | 
|  | log("Dumping hashmap by name"); | 
|  | f_EPTF_int2int_HashMap_Dump(first); | 
|  |  | 
|  |  | 
|  | // Dumping hashmap by id | 
|  | log("Dumping hashmap by ID"); | 
|  | f_EPTF_int2int_HashMap_DumpByID(first_int); | 
|  |  | 
|  |  | 
|  | // Dumping hashmap | 
|  | log("Dumping hashmap by name"); | 
|  | f_EPTF_int2int_HashMap_Dump(second); | 
|  |  | 
|  | // Dumping hashmap by id | 
|  | log("Dumping hashmap by ID"); | 
|  | f_EPTF_int2int_HashMap_DumpByID(second_int); | 
|  |  | 
|  | // Dumping all hashmap | 
|  | f_EPTF_int2int_HashMap_DumpAll(); | 
|  |  | 
|  | //deleting hashmap | 
|  | f_EPTF_int2int_HashMap_Delete (first); | 
|  | log("Deleting hashmap called: ",first); | 
|  |  | 
|  | //deleting hashmap | 
|  | f_EPTF_int2int_HashMap_Delete (second); | 
|  | log("Deleting hashmap called: ",second); | 
|  |  | 
|  | f_EPTF_Base_stop(pass); | 
|  | } | 
|  |  | 
|  | //========================================================================= | 
|  | // Control | 
|  | //========================================================================= | 
|  |  | 
|  | control | 
|  | { | 
|  | select (f_GetEnv("TTCN_TEST_TYPE")) { | 
|  | case ("SMOKE") { | 
|  | execute( tc_int2int_HashMap_baseFunctions() ); | 
|  | execute(tc_int2int_HashMap_test_bigInt()); | 
|  | execute(tc_int2int_HashMap_test_bigIntData()); | 
|  | execute( tc_int2int_HashMap_otherFunctions() ); | 
|  | execute( tc_int2int_HashMap_testUpdateFunction() ); | 
|  | //execute( tc_int2int_HashMap_testGrowage() ); | 
|  | execute( tc_int2int_HashMap_FindTest() ); | 
|  | } | 
|  | case else { | 
|  | execute( tc_int2int_HashMap_baseFunctions() ); | 
|  | execute(tc_int2int_HashMap_test_bigInt()); | 
|  | execute(tc_int2int_HashMap_test_bigIntData()); | 
|  | execute( tc_int2int_HashMap_otherFunctions() ); | 
|  | execute( tc_int2int_HashMap_testUpdateFunction() ); | 
|  | //execute( tc_int2int_HashMap_testGrowage() ); | 
|  | execute( tc_int2int_HashMap_FindTest() ); | 
|  | execute( tc_int2int_HashMap_NoCleanUp1() ); | 
|  | execute( tc_int2int_HashMap_NoCleanUp2() ); | 
|  | execute( tc_int2int_HashMapTest_dumpByID_manual() ); | 
|  | } | 
|  | } | 
|  |  | 
|  | } | 
|  | }  // end of module |