main_test.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include "db_api/CDBSingletonDefine.h"
  3. #include"module_service/module_mgr.h"
  4. void test_find_path(const point&p1,const point&p2)
  5. {
  6. printf("\nfind-path: from=(%.3lf,%.3lf),to=(%.3lf,%.3lf)\n",p1.x,p1.y,p2.x,p2.y);
  7. std::vector<point> rc=card_path::inst().find_path(p1,p2);
  8. for(uint32_t i=0;i<rc.size();i++)
  9. printf("x=%.3lf,y=%.3lf\n",rc[i].x,rc[i].y);
  10. }
  11. struct test_Sa{
  12. static void test_savedata2db(void * p)
  13. {
  14. while(true)
  15. {
  16. std::string sql = "CALL add_att_staff(0010000002323, 2323, '2018-12-14 14:00:14', '2018-12-14 14:00:14', 0, 0, 0.000);";
  17. sDBConnPool.PushAsync(sql.c_str());
  18. //boost::this_thread::sleep( boost::posix_time::microseconds( 10000 ) );
  19. usleep(1000*1000);
  20. }
  21. }
  22. static void test_query(void *p)
  23. {
  24. std::string sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
  25. ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
  26. vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
  27. vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed \
  28. FROM dat_vehicle_extend ve \
  29. LEFT JOIN dat_vehicle v ON ve.vehicle_id = v.vehicle_id \
  30. LEFT JOIN dat_card c ON ve.card_id = c.card_id \
  31. LEFT JOIN dat_dept d ON ve.dept_id = d.dept_id \
  32. LEFT JOIN dat_group g ON ve.group_id = g.group_id \
  33. LEFT JOIN dat_vehicle_type vt ON v.vehicle_type_id = vt.vehicle_type_id \
  34. LEFT JOIN dat_vehicle_category vc ON vc.vehicle_category_id = vt.vehicle_category_id \
  35. WHERE c.state_id = 0";
  36. std::string Error;
  37. YADB::CDBResultSet DBRes;
  38. while(true)
  39. {
  40. if (!sDBConnPool.Query(sql.c_str(),DBRes,Error))
  41. {
  42. printf(" Error = %s \n",Error.c_str());
  43. }
  44. usleep(10);
  45. }
  46. }
  47. static void Test_JsonDataSend(void * p)
  48. {
  49. std::string text = "";
  50. FILE * pfile = fopen("message_error.json","r");
  51. if ( NULL != pfile)
  52. {
  53. char p[10240] = {0};
  54. while(!feof(pfile))
  55. {
  56. memset(p,0,sizeof(p));
  57. fread(p,1,sizeof(p) - 1,pfile);
  58. text += std::string(p);
  59. }
  60. fclose(pfile);
  61. }
  62. int count = 0;
  63. while(true)
  64. {
  65. swsClientMgr.send(JSON_CMD_VALUE_PUSH,text);
  66. usleep(1000*1000*2);
  67. printf("WSClient Send DataLen=%d count=%d \n",(int)text.length(),count++);
  68. }
  69. }
  70. };
  71. void test_createthread()
  72. {
  73. for (int i = 1 ; i < 1 ; i++)
  74. {
  75. new std::thread( std::bind( &test_Sa::Test_JsonDataSend, &i ) );
  76. }
  77. }