test.cpp
19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include "sharelib.h"
#include <io.h>
#include <string/StringBuilder.hpp>
#ifdef _DEBUG
#ifdef WIN64
#pragma comment(lib, "../lib/x64/sharelib_Debug.lib")
#else
#pragma comment(lib, "../lib/sharelib_Debug.lib")
#endif
#else
#ifdef WIN64
#pragma comment(lib, "../lib/x64/sharelib.lib")
#else
#pragma comment(lib, "../lib/sharelib.lib")
#endif
#endif
using namespace std;
using namespace Common;
void test_sharelib(void)
{
if (1)
{
// test StrUtil::IsNumber()
/*
string str = "";
str = "-1";
cout << str << " " << StrUtil::IsNumber(str) << endl;
cout << str << " " << StrUtil::IsDigit(str) << endl;
str = "";
cout << str << " " << StrUtil::IsNumber(str) << endl;
cout << str << " " << StrUtil::IsDigit(str) << endl;
str = "1";
cout << str << " " << StrUtil::IsNumber(str) << endl;
cout << str << " " << StrUtil::IsDigit(str) << endl;
str = "1-";
cout << str << " " << StrUtil::IsNumber(str) << endl;
cout << str << " " << StrUtil::IsDigit(str) << endl;
//*/
// test File::is_avi_format()
/*
str = "F:\\case_video\\common\\1-big.avi";
cout << str << " " << File::is_avi_format(str) << endl;
str = "F:\\case_video\\common\\1工商银行-140929.avi";
cout << str << " " << File::is_avi_format(str) << endl;
str = "F:\\case_video\\common\\avi_ng.avi";
cout << str << " " << File::is_avi_format(str) << endl;
str = "F:\\case_video\\common\\test.264";
cout << str << " " << File::is_avi_format(str) << endl;
str = "F:\\case_video\\common\\none.avi";
cout << str << " " << File::is_avi_format(str) << endl;
//*/
// test File::get_file_list()
STRINGLIST file_list;
//File::get_file_list("F:\\case_video\\common\\", "264*.avi", file_list);
File::get_file_list("E:", "*.*", file_list);
std::sort(file_list.begin(), file_list.end());
for (size_t i=0; i<file_list.size(); ++i)
{
cout << file_list[i] << endl;
}
return;
}
// Test MD5 function
cout << "Test MD5\n";
STRING test_str = "sample";
//cout << Common::Utility::generate_md5(test_str) << endl;
cout << endl;
// Test NetInfo
cout << "Test NetInfo\n";
ip_list_t ip_list;
mac_list_t mac_list;
Common::NetInfo::get_local_ip_list(ip_list);
Common::NetInfo::get_local_mac_list(mac_list);
cout << endl;
// Test smart ptr
cout << "Test smart ptr\n";
Common::smart_ptr<INT> p1(new INT(4));
Common::smart_ptr<INT> p2(new INT(5));
Common::smart_ptr<INT> p3(new INT(6));
vector< Common::smart_ptr<INT> > index_list;
index_list.push_back(p1);
index_list.push_back(p2);
index_list.push_back(p3);
for(size_t i=0; i<index_list.size(); ++i)
{
cout << *index_list.at(i) << " ";
}
cout << endl;
// Test file function
//string test_file = "test.avi.config";
//cout << "File ext: " << Common::File::get_file_ext(test_file) << endl;
// Test get file time
//cout << "get file time: " << Common::File::get_file_time("e:\\video_snap.jpg") << endl;
// Test generate_guid
//cout << "guid " << Common::Utility::generate_guid() << endl;
// Test get_file_data
scoped_buffer buffer(4);
BYTE thakral_header[4] = {0x00, 0x00, 0x01, 0xb2};
if (Common::File::get_file_data("E:\\DeviceRecord\\thakral\\djl_sample.h264", buffer.get(), buffer.size()))
{
BYTE * tmp_ptr = buffer.get();
if ((tmp_ptr[0] == thakral_header[0])
&& (tmp_ptr[1] == thakral_header[1])
&& (tmp_ptr[2] == thakral_header[2])
&& (tmp_ptr[3] == thakral_header[3]))
{
cout << "leagal thakral record file!" << endl;
}
else
{
cout << "illeagal thakral record file!" << endl;
}
cout << "read file data ok!" << endl;
}
else
{
cout << "read file data fail!" << endl;
}
}
void test_net_info(void)
{
string server_ip = "";
cout << "local ip list:" << endl;
ip_list_t ip_list;
Common::NetInfo::get_local_ip_list(ip_list);
for (int i=0; i<ip_list.size(); i++)
{
cout << ip_list[i] << endl;
}
cout << "local ip=" << NetInfo::get_default_local_ip() << endl;
cout << "local mac list:" << endl;
mac_list_t mac_list;
Common::NetInfo::get_local_mac_list(mac_list);
for (int i=0; i<mac_list.size(); i++)
{
cout << mac_list[i].mac << endl;
}
cout << "local mac=" << NetInfo::get_default_local_mac() << endl;
// 已连接服务器测试
/*
server_ip = "192.168.101.191";
cout << "server ip=" << server_ip << " online=" << NetInfo::is_server_online(server_ip) << endl;
// 未连接服务器测试
server_ip = "192.168.101.192";
cout << "server ip=" << server_ip << " online=" << NetInfo::is_server_online(server_ip) << endl;
// 本机测试
server_ip = "192.168.101.148";
cout << "server ip=" << server_ip << " online=" << NetInfo::is_server_online(server_ip) << endl;
// 本机测试
server_ip = "localhost";
cout << "server ip=" << server_ip << " online=" << NetInfo::is_server_online(server_ip) << endl;
// 本机测试
server_ip = "127.0.0.1";
cout << "server ip=" << server_ip << " online=" << NetInfo::is_server_online(server_ip) << endl;
//*/
}
void test_file_func(void)
{
// 从共享文件路径中解析共享服务器IP地址
if (0)
{
STRING sample_file = EMPTY_STRING;
sample_file = "\\\\192.168.101.191\\upload\\sample.avi";
cout << sample_file << " ip=" << File::get_ip_from_file(sample_file) << endl;
sample_file = "\\\\192.168.101.191\\sample.avi";
cout << sample_file << " ip=" << File::get_ip_from_file(sample_file) << endl;
sample_file = "\\\\192.168.101.191\\";
cout << sample_file << " ip=" << File::get_ip_from_file(sample_file) << endl;
sample_file = "\\\\192.168.101.191";
cout << sample_file << " ip=" << File::get_ip_from_file(sample_file) << endl;
sample_file = "c:\\upload\\sample.avi";
cout << sample_file << " ip=" << File::get_ip_from_file(sample_file) << endl;
sample_file = "";
cout << sample_file << " ip=" << File::get_ip_from_file(sample_file) << endl;
}
// 根据文件前缀和扩展名批量删除指定目录文件
if (0)
{
STRING dir = "d:\\temp";
STRING file_prefix = "video";
STRING file_ext = "bmp";
File::batch_delete_file(dir);
}
// 读取文件数据
if (0)
{
BYTE dh_header[5];
if (File::get_file_data("E:\\DeviceRecord\\dh\\dh_sample_1.dav", dh_header, sizeof(dh_header)))
{
cout << STRING((char *)dh_header, (char *)dh_header + sizeof(dh_header)) << endl;
}
}
}
void test_time_func()
{
// test double to int
double d1 = 200.5670;
long i1 = 0;
lua_number2int(i1, d1);
cout << d1 << " " << i1 << endl;
// test time to string;
UINT64 cur_time = DateTime::get_current_time();
STRING time_str = DateTime::time_to_string(cur_time);
cout << time_str << endl;
// test string to time
UINT64 new_time = DateTime::string_to_time("2010-12-01 12:53:49");
cout << DateTime::time_to_string(new_time) << endl;
}
void test_str(const string& str)
{
cout << str << "\t";
if (StrUtil::IsNumber(str.c_str(), str.length()))
{
//cout << "Is number! " << StrUtil::StrToInt(str) << endl;
}
else
{
//cout << "Is not number! " << endl;
}
}
void test_str_func()
{
cout << "Test IsNumber() & StrToInt()\n";
test_str("");
test_str("-");
test_str("+");
test_str("--");
test_str("++");
test_str("1234");
test_str("-1234");
test_str("+1234");
test_str("1234.");
test_str("1234+");
}
void test_add_func()
{
// quote_path
//STRING path = "c:\\test\\";
//cout << path << " " << Utility::quote_path(Utility::quote_path(path)) << endl;
// is_path_writable
//cout << Utility::is_path_writable(path) << endl;
//cout << Utility::is_path_writable("D:\\") << endl;
// format_time
//cout << DateTime::format_time(0) << endl;
//cout << DateTime::format_time(59) << endl;
//cout << DateTime::format_time(60) << endl;
//cout << DateTime::format_time(3600) << endl;
//cout << DateTime::format_time(3601) << endl;
// is_file_writable
//cout << File::is_file_writable("c:\\test.dat") << endl;
//cout << File::is_file_writable("d:\\test.dat") << endl;
}
void test_string_builder()
{
int time_val = 3670;
int hour = time_val / 3600;
int minute = (time_val % 3600) / 60;
int second = (time_val % 3600) % 60;
std::string info = String_Builder<100>()
<< setfill('0')
<< setw(2)
<< hour
<< ":"
<< setw(2)
<< minute
<< ":"
<< setw(2)
<< second;
cout << info;
}
void test_configbox(void)
{
///*
STRING info_file = STRING("D:\\中文目录 测试\\test.avi") + ".info";
//Common::File::create_file(info_file);
CConfigBox configbox;
configbox.load(info_file);
std::vector<std::string> ip_list;
configbox.get_properties("dispatch_ip", ip_list);
cout << ip_list.size() << endl;
ip_list.push_back("");
configbox.set_properties("dispatch_ip", ip_list);
configbox.save();
//*/
/*
// 保存
configbox.set_property("str", "中文测试");
configbox.set_property_as_int("type", 1234);
configbox.set_property_as_double("reset", 1234.56789);
configbox.save();
cout << configbox.get_property("str") << endl;
cout << configbox.get_property_as_int("type") << endl;
double db_val = configbox.get_property_as_double("reset");
cout << db_val << endl;
//*/
//long num = 123456789;
//ostringstream oss;
//oss << num;
//cout << "中文输出 " << oss.str() << endl;
cin.get();
}
void test_module_manager(const std::string& dll_file)
{
#ifndef _DEBUG
return;
#endif
CModuleManager module_manager;
IModuleInfoPtr miptr = module_manager.load(dll_file);
if (miptr)
{
if (module_manager.unload(miptr))
{
cout << "test_module_manager() ok! \n\tfile=" << dll_file << endl;
return;
}
}
cout << "test_module_manager() fail! \n\tfile=" << dll_file << endl;
}
void test_get_file_size(const std::string& test_file)
{
cout << "test_file=" << test_file << endl;
UINT64 file_size = File::get_file_size(test_file);
cout << "\tfile_size=" << file_size << endl;
}
void test_profile(void)
{
string job_file = "\\\\10.10.10.171\\viecas_media@10.10.10.171\\13\\common\\user_2\\analyse\\{954462A6-72F1-4520-86CA-0FE6BB2E7CE2}\\1.job";
cout << "job_file=" << job_file << endl;
string context_file = Profile::get_profile_str_val("job", "context_file", EMPTY_STRING, job_file.c_str());
cout << "context_file=" << context_file << endl;
string input_file = Profile::get_profile_str_val("job", "input_file", EMPTY_STRING, job_file.c_str());
cout << "input_file=" << input_file.size() << endl;
string record_file = Profile::get_profile_str_val("input", "record_file", EMPTY_STRING, input_file.c_str());
cout << "record_file=" << record_file << endl;
}
void test_utility_20140224(void)
{
cout << "Utility::is_windows_2003_or_later() " << Utility::is_windows_2003_or_later() << endl;
cout << Utility::path_remove_backslash(EMPTY_STRING) << endl;
cout << Utility::path_remove_backslash("C") << endl;
cout << Utility::path_remove_backslash("C:") << endl;
cout << Utility::path_remove_backslash("C:\\test") << endl;
cout << Utility::path_remove_backslash("C:\\test\\") << endl;
cout << Utility::is_local_path(EMPTY_STRING) << endl;
cout << Utility::is_local_path("C:") << endl;
cout << Utility::is_local_path("C:\\test") << endl;
cout << Utility::is_local_path("C:\\test\\") << endl;
cout << Utility::is_local_path("\\\\10.10.10.171\\test") << endl;
cout << NFS::is_local_client(DEFAULT_LOCAL_IP, DEFAULT_LOCAL_IP) << endl;
cout << NFS::is_local_client("10.10.10.171", "10.10.10.171") << endl;
cout << NFS::is_local_client("10.10.10.171", "10.10.10.172") << endl;
NFS::disconnect("\\\\10.10.10.172\\viecas_media@10.10.10.172");
}
int _tmain(int argc, _TCHAR* argv[])
{
#ifdef _WIN64
cout << "_WIN64 is defined as " << _WIN64 << endl;
#endif
#ifdef _WIN32
cout << "_WIN32 is defined as " << _WIN32 << endl;
#endif
//string uuid = Utility::generate_guid();
//cout << uuid << " " << uuid.length() << endl;
//uuid 长度为38字节
//cout << StrUtil::IntToStr(0) << endl;
//cout << StrUtil::IntToStr(1) << endl;
//cout << StrUtil::IntToStr(-1) << endl;
// 测试新增接口20140224
if (0)
{
test_utility_20140224();
}
// 测试获取配置参数
if (0)
{
test_profile();
}
// 测试数值转换
if (0)
{
int i_val = 0;
string i_str = StrUtil::IntToStr(i_val);
cout << i_val << "\t" << i_str << endl;
float f_val = 1.0 / 3;
string f_str = StrUtil::FloatToStr(f_val);
cout << f_val << "\t" << f_str << endl;
double d_val = 10000.0 / 7;
string d_str = StrUtil::DoubleToStr(d_val);
cout << d_val << "\t" << d_str << endl;
}
// 测试获取IP/MAC地址
if (0)
{
cout << "\ndefault ip=" << Common::NetInfo::get_default_local_ip() << endl;
ip_list_t ip_list;
Common::NetInfo::get_local_ip_list(ip_list);
for (size_t i=0; i<ip_list.size(); i++)
{
cout << "ip=" << ip_list[i] << endl;
}
cout << "\ndefault mac=" << Common::NetInfo::get_default_local_mac() << endl;
mac_list_t mac_list;
Common::NetInfo::get_local_mac_list(mac_list);
for (size_t i=0; i<mac_list.size(); i++)
{
cout << "mac=" << mac_list[i].mac << " type=" << mac_list[i].mac_type << endl;
for (size_t j=0; j<mac_list[i].ip_list.size(); j++)
{
cout << "\tip=" << mac_list[i].ip_list[j] << endl;
}
}
}
// 测试获取文件长度
if (0)
{
test_get_file_size("E:\\error\\杭州\\002秋涛北路与解放东路西南角-1-20120903000000-20120903025954-364286280.ts.uvf");
test_get_file_size("E:\\error\\杭州\\002秋涛北路与解放东路西南角-1-20120903000000-20120903025954-364286280.ts");
test_get_file_size("E:\\error\\杭州\\002秋涛北路与解放东路西南角-1-20120903000000-20120903025954-364286280.ts.uvf.info");
}
// 插件管理器测试 [20120801 ok]
if (0)
{
string dll_file1 = "E:\\viecas\\src\\vs2008sp1\\client\\bin\\RecordProcess\\fenghuo\\FHMediaPlayerD.dll";
//string dll_file1 = "E:\\viecas\\src\\vs2008sp1\\server\\RecordProcess\\bin\\thakral\\ThakralPluginD.dll";
test_module_manager(dll_file1);
//string dll_file2 = "E:\\viecas\\src\\vs2008sp1\\server\\RecordProcess\\bin\\samsung\\SNSPluginD.dll";
//test_module_manager(dll_file2);
//string dll_file3 = "E:\\viecas\\src\\vs2008sp1\\server\\RecordProcess\\bin\\tiandy\\TDPluginD.dll";
//test_module_manager(dll_file3);
return 0;
}
// test check_file_data [20120409 ok]
if (0)
{
BYTE HK_FILE_HEADER[] = {0x34, 0x48, 0x4B, 0x48, 0xFE, 0xB3, 0xD0, 0xD6};
const BYTE HK_HD_FILE_HEADER[] = {0x49, 0x4D, 0x4B, 0x48, 0x01, 0x01, 0x00, 0x00};
STRING sample_file = "D:\\hk_sample.mp4";
cout << sample_file << " " << File::check_file_data(sample_file, HK_FILE_HEADER, sizeof(HK_FILE_HEADER)) << endl;
STRING hd_sample_file = "F:\\设备录像测试文件\\海康\\hk_p720P_1.mp4";
cout << hd_sample_file << " " << File::check_file_data(hd_sample_file, HK_HD_FILE_HEADER, sizeof(HK_HD_FILE_HEADER)) << endl;
}
// test delete_file [20120309 ok]
if (0)
{
STRING file_path = "D:\\test - 副本.avi";
File::delete_file(file_path);
cout << File::file_exist(file_path) << endl;
}
// Test run_and_wait [20120228 ok]
if (0)
{
STRING app_file = "E:\\viecas\\src\\vs2008sp1\\server\\RecordProcess\\bin\\RecordIdentify.exe";
STRINGLIST param_list;
param_list.push_back("D:\\DeviceRecord\\dh\\2_CH01TIME20100517230000.DAV");
DWORD exit_code = 0;
BOOL result = Utility::run_and_wait(app_file, param_list, TRUE, exit_code);
cout << "result=" << result
<< " exit code=" << exit_code
<< endl;
}
if (0)
{
STRING input_file = "D:\\DeviceRecord\\hik\\error\\hk_sample.mp4";
BYTE buffer[1024] = {0};
if (File::get_file_data(input_file, buffer, sizeof(buffer)))
{
cout << "get file data ok!" << endl;
}
return 0;
}
if (1)
{
test_configbox();
return 0;
}
if (0)
{
STRING input_file = "D:\\DeviceRecord\\hik\\error\\ch00000000000001-110506-133522-140750-01p10002000000400.264";
STRING file_time = File::get_file_time(input_file);
cout << file_time << endl;
return 0;
}
//test_string_builder();
// Test create file
if (0)
{
STRING test_file = "d:\\test_video\\测试中文 目录\\sample.info";
File::create_file(test_file);
CConfigBox configbox;
configbox.load(test_file);
configbox.set_property("test_str", "测试中文");
configbox.set_property_as_int("test_int", 123);
double val = 123.0 / 13;
configbox.set_property_as_double("test_double", val);
configbox.save();
cout.setf(ios::fixed);
cout.precision(16);
cout << "input test_double=" << val << endl;
val = configbox.get_property_as_double("test_double");
cout << "read test_double=" << val << endl;
cin.get();
return 0;
}
//test_sharelib();
//test_net_info();
//test_file_func();
//test_time_func();
//test_str_func();
if (0)
{
STRING app = "E:\\svn_t110\\viecas\\src\\branch\\vs2008sp1\\client\\bin\\RecordConvertor.exe";
STRINGLIST param_list;
Utility::run(app, param_list);
}
/*
cout << StrUtil::StrToFloat("") << endl;
cout << StrUtil::StrToFloat("1") << endl;
cout << StrUtil::StrToFloat("1.0") << endl;
cout << StrUtil::StrToFloat("1.234") << endl;
cout << StrUtil::StrToFloat("1.23456789") << endl;
STRING AppPath = Utility::get_app_path();
STRING AppDataPath = Utility::get_app_data_path() + "Victory\\";
//AppDataPath = "\\\\192.168.101.191\\viecas_media\\temp";
BOOL flag = Utility::path_exists(AppDataPath);
if (flag)
{
cout << "path " << AppDataPath << " exists!\n";
}
else
{
cout << "path " << AppDataPath << " not exists!\n";
//CreateDirectory(AppDataPath.c_str(), NULL);
}
//*/
//test_add_func();
cin.get();
return 0;
}