TEST(tuple_gen_2,template2) { CTupleGeneratorSmart gen; gen.Create(1, 1); gen.add_client_pool(cdSEQ_DIST,0x10000001,0x1000000f,64000,4,NULL,0,0); gen.add_server_pool(cdSEQ_DIST,0x30000001,0x40000001,64000,4,false); CTupleTemplateGeneratorSmart template_1; template_1.Create(&gen,0,0); template_1.SetW(10); CTupleBase result; int i; for (i=0; i<20; i++) { template_1.GenerateTuple(result); uint32_t result_src = result.getClient(); uint32_t result_dest = result.getServer(); uint16_t result_port = result.getClientPort(); //printf(" %x %x %x \n",result_src,result_dest,result_port); EXPECT_EQ(result_src, (uint32_t)(0x10000001+(i/10))); EXPECT_EQ(result_dest, (uint32_t)(((0x30000001+ (i/10) )) )); EXPECT_EQ(result_port, 1024+(i%10)); } template_1.Delete(); gen.Delete(); }
/* tuple generator using CClientInfoL*/ TEST(tuple_gen_2,GenerateTuple) { CTupleGeneratorSmart gen; gen.Create(1, 1); gen.add_client_pool(cdSEQ_DIST,0x10000001,0x10000f01,64000,4,NULL,0,0); gen.add_server_pool(cdSEQ_DIST,0x30000001,0x40000001,64000,4,false); CTupleTemplateGeneratorSmart template_1; template_1.Create(&gen,0,0); CTupleBase result; uint32_t result_src; uint32_t result_dest; uint16_t result_port; for(int i=0;i<10;i++) { template_1.GenerateTuple(result); printf(" C:%x S:%x P:%d \n",result.getClient(),result.getServer(),result.getClientPort()); result_src = result.getClient(); result_dest = result.getServer(); result_port = result.getClientPort(); EXPECT_EQ(result_src, (uint32_t)(0x10000001+i)); EXPECT_EQ(result_dest, (uint32_t) (((0x30000001+i)) ) ); EXPECT_EQ(result_port, 1024); } gen.Delete(); // EXPECT_EQ((size_t)0, gen.m_clients.size()); }
TEST(tuple_gen,try_to_free) { CTupleGeneratorSmart gen; gen.Create(1, 1); gen.add_client_pool(cdSEQ_DIST,0x10000001,0x10000001,64000,4,NULL,0,0); gen.add_server_pool(cdSEQ_DIST,0x30000001,0x400000ff,64000,4,false); CTupleTemplateGeneratorSmart template_1; template_1.Create(&gen,0,0); CTupleBase result; int i; for (i=0; i<65557; i++) { template_1.GenerateTuple(result); uint32_t result_src = result.getClient(); uint32_t result_dest = result.getServer(); uint16_t result_port = result.getClientPort(); gen.FreePort(0,result.getClientId(),result_port); } // should have error EXPECT_FALSE((gen.getErrorAllocationCounter()>0)?true:false); template_1.Delete(); gen.Delete(); }
TEST(tuple_gen,template1) { CTupleGeneratorSmart gen; gen.Create(1, 1); gen.add_client_pool(cdSEQ_DIST,0x10000001,0x1000000f,64000,4, g_dummy, 0, 0); gen.add_server_pool(cdSEQ_DIST,0x30000001,0x40000001,64000,4,false); CTupleTemplateGeneratorSmart template_1; template_1.Create(&gen,0,0); template_1.SetSingleServer(true,0x12121212,0,0); CTupleBase result; int i; for (i=0; i<10; i++) { template_1.GenerateTuple(result); uint32_t result_src = result.getClient(); uint32_t result_dest = result.getServer(); //printf(" %x %x %x \n",result_src,result_dest,result_port); EXPECT_EQ(result_src, (uint32_t)(0x10000001+i)); EXPECT_EQ(result_dest, (uint32_t)(((0x12121212)) )); } template_1.Delete(); gen.Delete(); }
TEST(tuple_gen_2,GenerateTuple2) { CTupleGeneratorSmart gen; gen.Create(1, 1); gen.add_client_pool(cdSEQ_DIST,0x10000001,0x1000000f,64000,4,g_dummy,0,0); gen.add_server_pool(cdSEQ_DIST,0x30000001,0x40000001,64000,4,false); CTupleTemplateGeneratorSmart template_1; template_1.Create(&gen,0,0); CTupleBase result; uint32_t result_src; uint32_t result_dest; uint16_t result_port; for(int i=0;i<200;i++) { template_1.GenerateTuple(result); // gen.Dump(stdout); // fprintf(stdout, "i:%d\n",i); result_src = result.getClient(); result_dest = result.getServer(); result_port = result.getClientPort(); EXPECT_EQ(result_src, (uint32_t)(0x10000001+i%15)); EXPECT_EQ(result_dest, (uint32_t)((0x30000001+i) ) ); EXPECT_EQ(result_port, 1024+i/15); } gen.Delete(); // EXPECT_EQ((size_t)0, gen.m_clients.size()); gen.Create(1, 1); gen.add_client_pool(cdSEQ_DIST,0x10000001,0x1000000f,64000,4,g_dummy,0,0); gen.add_server_pool(cdSEQ_DIST,0x30000001,0x40000001,64000,4,false); template_1.Create(&gen,0,0); for(int i=0;i<200;i++) { template_1.GenerateTuple(result); // gen.Dump(stdout); // fprintf(stdout, "i:%d\n",i); result_src = result.getClient(); result_dest = result.getServer(); result_port = result.getClientPort(); EXPECT_EQ(result_src, (uint32_t)(0x10000001+i%15)); EXPECT_EQ(result_dest, (uint32_t) (((0x30000001+i)) ) ); EXPECT_EQ(result_port, 1024+i/15); } }
TEST(tuple_gen,no_free) { CTupleGeneratorSmart gen; gen.Create(1, 1); gen.add_client_pool(cdSEQ_DIST,0x10000001,0x10000001,64000,4,g_dummy,0,0); gen.add_server_pool(cdSEQ_DIST,0x30000001,0x400000ff,64000,4,false); CTupleTemplateGeneratorSmart template_1; template_1.Create(&gen,0,0); CTupleBase result; int i; for (i=0; i<65557; i++) { template_1.GenerateTuple(result); } // should have error EXPECT_TRUE((gen.getErrorAllocationCounter()>0)?true:false); template_1.Delete(); gen.Delete(); }