-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_tester_c.cpp
More file actions
76 lines (61 loc) · 2.32 KB
/
load_tester_c.cpp
File metadata and controls
76 lines (61 loc) · 2.32 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
/// @file load_tester_c.cpp
/// @brief Реализация C-интерфейса для нагрузочного тестирования
#include "load_tester_c.h"
#include "load_tester.hpp"
#include <cstring>
#ifdef __cplusplus
extern "C" {
#endif
// === Реализация функций ===
LoadTesterPtr create_tester() {
return new LoadTester();
}
LoadTesterPtr create_tester_with_url(const char* url) {
return new LoadTester(std::string(url));
}
void destroy_tester(LoadTesterPtr tester) {
delete static_cast<LoadTester*>(tester);
}
TestDataConfigPtr create_test_data_config() {
return new TestDataConfig();
}
void destroy_test_data_config(TestDataConfigPtr config) {
delete static_cast<TestDataConfig*>(config);
}
void set_target_url(LoadTesterPtr tester, const char* url) {
LoadTester* t = static_cast<LoadTester*>(tester);
t->setTargetUrl(std::string(url));
}
void set_test_data_config(LoadTesterPtr tester, TestDataConfigPtr config) {
LoadTester* t = static_cast<LoadTester*>(tester);
TestDataConfig* c = static_cast<TestDataConfig*>(config);
t->setTestDataConfig(*c);
}
void add_field_to_config(TestDataConfigPtr config, const char* field_name,
const char* value, int is_random, int min_val, int max_val) {
TestDataConfig* c = static_cast<TestDataConfig*>(config);
FieldConfig field_config;
field_config.value = value ? std::string(value) : "";
field_config.is_random = (is_random != 0);
field_config.min_val = min_val;
field_config.max_val = max_val;
(*c)[std::string(field_name)] = field_config;
}
void add_response_check(LoadTesterPtr tester, const char* field_path,
const char* expected_value, int check_exists) {
LoadTester* t = static_cast<LoadTester*>(tester);
t->addResponseCheck(std::string(field_path),
expected_value ? std::string(expected_value) : "",
check_exists != 0);
}
void clear_response_checks(LoadTesterPtr tester) {
LoadTester* t = static_cast<LoadTester*>(tester);
t->clearResponseChecks();
}
void run_test(LoadTesterPtr tester, int num_threads, int duration_seconds, int requests_per_second) {
LoadTester* t = static_cast<LoadTester*>(tester);
t->runTest(num_threads, duration_seconds, requests_per_second);
}
#ifdef __cplusplus
}
#endif