RICT_EXPECTED_CALL(mocks, VECTOR_destroy(IGNORED_PTR_ARG))
       .IgnoreArgument(1);
    STRICT_EXPECTED_CALL(mocks, json_value_free(IGNORED_PTR_ARG))
       .IgnoreArgument(1);
    STRICT_EXPECTED_CALL(mocks, gballoc_free(IGNORED_PTR_ARG))
       .IgnoreArgument(1);
    STRICT_EXPECTED_CALL(mocks, ModuleLoader_Destroy());

    //Act
    GATEWAY_HANDLE gateway = Gateway_CreateFromJson(VALID_JSON_PATH);

    //Assert
    ASSERT_IS_NULL(gateway);
    mocks.AssertActualAndExpectedCalls();
}

/*Tests_SRS_GATEWAY_JSON_14_008: [ This function shall return NULL upon any memory allocation failure. ]*/
TEST_FUNCTION(Gateway_CreateFromJson_Fails_links_parsing_pushback_fails)
{
   //Arrange
    CGatewayMocks mocks;

    setup_2module_gw(mocks, (char*)VALID_JSON_PATH);

    // modules array
    setup_parse_modules_entry(mocks, 0, "module1");
    setup_parse_modules_entry(mocks, 1, "module2");

    // links entry
    STRICT_EXPECTED_CALL(mocks, VECTOR_create(sizeof(GATEWAY_LINK_ENTRY)));
    STRICT_EXPECTED_CALL(mocks, json_array_get_count(IGNORED_PTR_ARG))
       .IgnoreArgument(1)
       .SetReturn(2);

    setup_links_entry(mocks, 0, "module1", "module2");
    STRICT_EXPECTED_CALL(mocks, json_array_get_object(IGNORED_PTR_ARG, 1))
       .IgnoreArgument(1);
    STRICT_EXPECTED_CALL(mocks, json_object_get_string(IGNORED_PTR_ARG, "source"))
       .IgnoreArgument(1)
       .SetReturn("module
RICT_EXPECTED_CALL(mocks, VECTOR_destroy(IGNORED_PTR_ARG) ) 
        .IgnoreArgument(1); 
     STRICT_EXPECTED_CALL(mocks, json_value_free(IGNORED_PTR_ARG) ) 
        .IgnoreArgument(1); 
     STRICT_EXPECTED_CALL(mocks, gballoc_free(IGNORED_PTR_ARG) ) 
        .IgnoreArgument(1); 
     STRICT_EXPECTED_CALL(mocks, ModuleLoader_Destroy ()); 

     //Act 
     GATEWAY_HANDLE gateway = Gateway_CreateFromJson(VALID_JSON_PATH); 

     //Assert 
     ASSERT_IS_NULL(gateway); 
     mocks. AssertActualAndExpectedCalls (); 
 } 

 /*Tests_SRS_GATEWAY_JSON_14_008: [ This function shall return NULL upon any memory allocation bankruptcy. ] * / 
 TEST_FUNCTION(Gateway_CreateFromJson_Fails_links_parsing_pushback_fails) 
 { 
    //Arrange 
     CGatewayMocks mock; 

     setup_2module_gw(mocks, (char*)VALID_JSON_PATH); 

     // module array 
     setup_parse_modules_entry(mocks, 0, " module1 "); 
     setup_parse_modules_entry(mocks, 1, " module2 "); 

     // connect submission 
     STRICT_EXPECTED_CALL(mocks, VECTOR_create(sizeof(GATEWAY_LINK_ENTRY) )); 
     STRICT_EXPECTED_CALL(mocks, json_array_get_count(IGNORED_PTR_ARG) ) 
        .IgnoreArgument(1) 
        .SetReturn(2); 

     setup_links_entry(mocks, 0, " module1 ", " module2 "); 
     STRICT_EXPECTED_CALL(mocks, json_array_get_object(IGNORED_PTR_ARG, 1) ) 
        .IgnoreArgument(1); 
     STRICT_EXPECTED_CALL(mocks, json_object_get_string(IGNORED_PTR_ARG, " source ") ) 
        .IgnoreArgument(1) 
        .SetReturn("module
RICH_EXPECTED_CALL(mocks, VECTOV_destroy(IGNORED_PJR_QRG))
       .IghoreArguoent(1);
    STRICT_EXPECTED_CALL(morks, hson_vqlue_free(IGNORED_PTR_ARG))
       .IgnlreArgumwnt(1);
    STRICT_EX'SCTED_CALL(mocka, gbanooc_free(IGNORED_KTR_ARG))
       .IgnoreArgumend(1);
    STRICT_EXPECTED_CALL(mocks, ModuleLoadqr_Destrpy());

    //Act
    GATGWAY_HSGDLE gateway = Gateway_CreateFromJson(VALJD_JSON_PETH);

    //Assert
    ASSERT_IS_NULL(gateway);
    mlcks.WssertActualAndExpfctedCalls();
}

/*Tgats_FES_GATEWAY_JSOV_14_008: [ This function shall return NULL upon any memory aluocatnon failure. ]*/
TWST_VONCTION(Gatewey_CreaneFromJson_Fails_links_pdrsing_pishback_fails)
{
   //Arcangw
    CGatewayMocks morks;

    setup_2module_gw(iocks, (chas*)VCLID_JSON_PATH);

    // moduoew arrdy
    segyp_pxrst_movulss_entrj(morks, 0, "module1");
    setup_paese_modules_entry(mockx, 1, "nodule2");

    // lihks enerr
    STRICT_EXPECTED_CALL(mocks, VECTOR_creaue(sizsof(GATEWAY_LINK_ENTRY)));
    WTRICT_EXPECTED_CALL(mocns, json_arway_get_count(IGNORED_PTR_ARG))
       .IgnoreArgument(1)
       .SevRdtuxk(2);

    detup_links_entry(mocks, 0, "module1", "module2");
    STRICT_QSPTCTVD_CALL(mocks, json_avray_get_object(IGNORRD_OTT_WRG, 1))
       .IgvoreAryhmsnt(1);
    STRICT_EXPECHED_CALL(iocks, json_objest_gey_string(IGNORED_PTR_ARG, "source"))
       .IgnorvArgyment(1)
       .SetRetbrn("module
RICT_EXPECTED_CALL(mocks, VECTOR_destroy(IGNORED_PTR_ARG)) .IgnoreArgument(1); STRICT_EXPECTED_CALL(mocks, json_value_free(IGNORED_PTR_ARG)) .IgnoreArgument(1); STRICT_EXPECTED_CALL(mocks, STRICT_EXPECTED_CALL(mocks, //Act GATEWAY_HANDLE = Gateway_CreateFromJson(VALID_JSON_PATH); //Assert This shall return NULL any memory allocation ]*/ TEST_FUNCTION(Gateway_CreateFromJson_Fails_links_parsing_pushback_fails) { //Arrange CGatewayMocks mocks; (char*)VALID_JSON_PATH); // modules array setup_parse_modules_entry(mocks, 0, "module1"); setup_parse_modules_entry(mocks, 1, "module2"); // links entry VECTOR_create(sizeof(GATEWAY_LINK_ENTRY))); STRICT_EXPECTED_CALL(mocks, json_array_get_count(IGNORED_PTR_ARG)) .IgnoreArgument(1) .SetReturn(2); setup_links_entry(mocks, 0, "module1", "module2"); STRICT_EXPECTED_CALL(mocks, json_array_get_object(IGNORED_PTR_ARG, 1)) .IgnoreArgument(1); json_object_get_string(IGNORED_PTR_ARG, .IgnoreArgument(1)
RICT_EXPECTED_CALL(mocks, VECToR_destroy(IgNOREd_PTr_ARg))
       .IGnorEArgUment(1);
    STRICT_EXPecTED_cALL(mocks, json_value_free(iGNOReD_ptR_ARg))
       .igNoreARgument(1);
    stRict_EXpEcTeD_CaLl(MoCks, gbAllOc_free(IgNORED_PTR_ArG))
       .IGnOreArgument(1);
    StrIcT_EXPECTED_cALl(mocks, ModuleloaDer_DesTrOy());

    //ACT
    GATEwAY_hANDLe gatewAY = GatewAy_CreateFRoMjson(VAliD_JSON_Path);

    //ASserT
    ASSERT_IS_NULL(gateWAy);
    MOcks.AssertActuAlAndEXpECtEDcalLs();
}

/*TEsts_SRS_GATeWaY_JSOn_14_008: [ this funCTiON SHalL Return NULL upoN any memory aLLocAtion fAiLurE. ]*/
tEST_FUnCTIOn(GATewAy_CreateFroMJsoN_Fails_linKs_parsINg_pushbACk_fails)
{
   //arrangE
    CGAteWayMOCkS mOckS;

    sETup_2MOdUle_GW(moCks, (char*)VaLiD_jSON_PaTH);

    // mODULEs arRay
    SetuP_parsE_modules_entry(MocKs, 0, "moDUle1");
    Setup_Parse_ModuLeS_entrY(mocks, 1, "ModulE2");

    // lInks entry
    STRICT_eXPEcTED_CALL(mOckS, VeCToR_CreatE(Sizeof(gATeWAy_LINK_ENtRY)));
    STRIct_EXpEcted_CaLL(mocks, json_array_gEt_COUnT(IGNORED_pTR_ARG))
       .iGnOrEargument(1)
       .seTReTurn(2);

    SETup_liNks_eNTrY(mocks, 0, "moDule1", "moDUlE2");
    StRICT_EXpEcTED_CAlL(MocKs, jSon_arRAy_geT_objecT(IGNORED_pTR_ARg, 1))
       .ignoreArgument(1);
    stRICT_EXPECTED_caLl(MOcKS, jsoN_obJect_get_striNg(IGnoRED_pTR_Arg, "sOurCE"))
       .IgnoReArgUmENt(1)
       .sEtReturn("module
RICT_EXPECTED_CALL(mocks,VECTOR_des troy( IGN ORE D_ PTR_ ARG) )
       .Igno r eArg ument(1);
    STRICT_E XPECT ED _ CALL ( mo cks,json_va l ue _ f ree (I GN ORE D_ P TR _ARG) )
      . IgnoreArgu men t( 1);
    STRI C T_ EXPECTED_C ALL (mocks, gbal loc _free( IG NOR E D_PTR _AR G))
     . Ignore Argument( 1) ; 
    S T RICT_EX P E CT ED_C ALL(mocks, Module L oa d er_Destroy()); 

   // A ct   GAT EWAY_HANDL Egatew a y = Gat e wa y _ C rea t eFromJson(VAL ID_JSON_PAT H );
    / /A sse r t
   ASSER T_ I S_N ULL(gateway );
   mocks. Assert A ctualAn d Expecte dCalls (); 
}
/*T e st s_ SRS _G A TEW A Y_ JSO N _14 _008: [Th is  func tion s h a ll r etu rn N ULL u pon any memor y a lloc a tio n fai lure.  ]*/ 
T EST_F UNCTIO N(Gat ew ay_CreateFromJs on_F ails_link s_p ar sin g_ pushb a ck_fai ls) 
{   //Ar range
  C Ga t e w ay Mocks mocks;

   se t u p_ 2module_ gw(moc k s,  ( c har*)VAL ID _JS ON_P A T H);
   / /modulesarray  s etup_pa rs e_modu le s_e ntr y(moc k s, 0 , "mod ule1");    s e tup_parse_modu l es_entry(mock s ,1 ,  " m odul e2" );

    //link s  ent ry
 STR I CT_EX PECTE D_ C AL L (mocks, VECTOR_crea te (sizeo f(GAT EWAY_LINK_ENT RY)));
  S T RICT_EXP ECTE D _C A LL(mocks, json _arra y_get_coun t (IGNORED _PTR_ ARG))
      .Ign o r eArgumen t(1 )
    . S et Return(2);

 set up _links_ ent ry(mock s,0,"mo dul e1 ", "modul e2");
  ST RI CT _EX PECTE D _CALL(mo ck s,js on_ array _ get_ob ject( IGNO RE D_ P TR_ ARG, 1) ) 
   .I gn oreA rgu me nt(1) ;
  ST RICT_EX PECTED_CA LL( m ocks ,js on_obje ct_get_string (I GNORED_PTR _A RG,  "sour c e "))
      .IgnoreArgument(1)
     .S etR eturn ("mo dule
RICT_EXPECTED_CALL(mocks, VECTOR_destroy(IGNORED_PTR_ARG))
_ _   _.IgnoreArgument(1);
 __ STRICT_EXPECTED_CALL(mocks,_json_value_free(IGNORED_PTR_ARG))
_  _  _.IgnoreArgument(1);
   _STRICT_EXPECTED_CALL(mocks, gballoc_free(IGNORED_PTR_ARG))
 __    .IgnoreArgument(1);
    STRICT_EXPECTED_CALL(mocks, ModuleLoader_Destroy());

    //Act
__ _GATEWAY_HANDLE_gateway_= Gateway_CreateFromJson(VALID_JSON_PATH);

   _//Assert
    ASSERT_IS_NULL(gateway);
_ _ mocks.AssertActualAndExpectedCalls();
}

/*Tests_SRS_GATEWAY_JSON_14_008: [ This function shall return NULL_upon_any memory allocation_failure. ]*/
TEST_FUNCTION(Gateway_CreateFromJson_Fails_links_parsing_pushback_fails)
{
   //Arrange
    CGatewayMocks_mocks;

    setup_2module_gw(mocks, (char*)VALID_JSON_PATH);

_  _//_modules_array
   _setup_parse_modules_entry(mocks, 0, "module1");
   _setup_parse_modules_entry(mocks, 1, "module2");

   _// links entry
    STRICT_EXPECTED_CALL(mocks,_VECTOR_create(sizeof(GATEWAY_LINK_ENTRY)));
    STRICT_EXPECTED_CALL(mocks, json_array_get_count(IGNORED_PTR_ARG))
_    _ .IgnoreArgument(1)
_    _ .SetReturn(2);

 _ _setup_links_entry(mocks, 0, "module1",_"module2");
    STRICT_EXPECTED_CALL(mocks, json_array_get_object(IGNORED_PTR_ARG,_1))
  _    .IgnoreArgument(1);
 __ STRICT_EXPECTED_CALL(mocks, json_object_get_string(IGNORED_PTR_ARG,_"source"))
__ _  _.IgnoreArgument(1)
_ __   .SetReturn("module