5
5
static ta_core_t ta_core ;
6
6
struct timespec start_time , end_time ;
7
7
8
+ char driver_tag_msg [NUM_TRYTES_TAG ];
9
+ send_mam_res_t * res ;
10
+
8
11
#if defined(ENABLE_STAT )
9
12
#define TEST_COUNT 100
10
13
#else
11
14
#define TEST_COUNT 1
12
15
#endif
13
16
17
+ static void gen_rand_tag (char * tag ) {
18
+ const char tryte_alpahbet [] = "NOPQRSTUVWXYZ9ABCDEFGHIJKLM" ;
19
+
20
+ for (int i = 0 ; i < NUM_TRYTES_TAG ; i ++ ) {
21
+ tag [i ] = tryte_alpahbet [rand () % 27 ];
22
+ }
23
+ }
24
+
14
25
double diff_time (struct timespec start , struct timespec end ) {
15
26
struct timespec diff ;
16
27
if (end .tv_nsec - start .tv_nsec < 0 ) {
@@ -81,14 +92,19 @@ void test_get_tips(void) {
81
92
}
82
93
83
94
void test_send_transfer (void ) {
84
- const char * json =
95
+ const char * pre_json =
85
96
"{\"value\":100,"
86
- "\"message\":\"" TAG_MSG "\",\"tag\":\"" TAG_MSG
87
- "\","
97
+ "\"message\":\"" TAG_MSG
98
+ "\",\"tag\":\"%s\", "
88
99
"\"address\":\"" TRYTES_81_1 "\"}" ;
89
100
char * json_result ;
90
101
double sum = 0 ;
91
102
103
+ gen_rand_tag (driver_tag_msg );
104
+ int json_len = strlen (pre_json );
105
+ char json [json_len + NUM_TRYTES_TAG ];
106
+ sprintf (json , pre_json , driver_tag_msg );
107
+
92
108
for (size_t count = 0 ; count < TEST_COUNT ; count ++ ) {
93
109
test_time_start (& start_time );
94
110
TEST_ASSERT_EQUAL_INT32 (
@@ -123,7 +139,7 @@ void test_find_transactions_by_tag(void) {
123
139
test_time_start (& start_time );
124
140
125
141
TEST_ASSERT_EQUAL_INT32 (
126
- SC_OK , api_find_transactions_by_tag (& ta_core .service , FIND_TAG_MSG ,
142
+ SC_OK , api_find_transactions_by_tag (& ta_core .service , driver_tag_msg ,
127
143
& json_result ));
128
144
test_time_end (& start_time , & end_time , & sum );
129
145
free (json_result );
@@ -139,8 +155,8 @@ void test_find_transactions_obj_by_tag(void) {
139
155
test_time_start (& start_time );
140
156
141
157
TEST_ASSERT_EQUAL_INT32 (
142
- SC_OK , api_find_transactions_obj_by_tag (& ta_core .service , FIND_TAG_MSG ,
143
- & json_result ));
158
+ SC_OK , api_find_transactions_obj_by_tag (& ta_core .service ,
159
+ driver_tag_msg , & json_result ));
144
160
test_time_end (& start_time , & end_time , & sum );
145
161
free (json_result );
146
162
}
@@ -151,12 +167,15 @@ void test_send_mam_message(void) {
151
167
double sum = 0 ;
152
168
const char * json = "{\"message\":\"" TEST_PAYLOAD "\"}" ;
153
169
char * json_result ;
170
+ res = send_mam_res_new ();
154
171
155
172
for (size_t count = 0 ; count < TEST_COUNT ; count ++ ) {
156
173
test_time_start (& start_time );
157
174
TEST_ASSERT_EQUAL_INT32 (
158
175
SC_OK , api_mam_send_message (& ta_core .tangle , & ta_core .service , json ,
159
176
& json_result ));
177
+ send_mam_res_deserialize (json_result , res );
178
+
160
179
test_time_end (& start_time , & end_time , & sum );
161
180
free (json_result );
162
181
}
@@ -171,15 +190,17 @@ void test_receive_mam_message(void) {
171
190
test_time_start (& start_time );
172
191
173
192
TEST_ASSERT_EQUAL_INT32 (
174
- SC_OK , api_receive_mam_message (& ta_core .service , TEST_BUNDLE_HASH ,
175
- & json_result ));
193
+ SC_OK , api_receive_mam_message (& ta_core .service ,
194
+ ( char * ) res -> bundle_hash , & json_result ));
176
195
test_time_end (& start_time , & end_time , & sum );
177
196
free (json_result );
178
197
}
179
198
printf ("Average time of receive_mam_message: %lf\n" , sum / TEST_COUNT );
180
199
}
181
200
182
201
int main (void ) {
202
+ srand (time (NULL ));
203
+
183
204
UNITY_BEGIN ();
184
205
185
206
ta_config_default_init (& ta_core .info , & ta_core .tangle , & ta_core .cache ,
@@ -194,8 +215,8 @@ int main(void) {
194
215
RUN_TEST (test_get_transaction_object );
195
216
RUN_TEST (test_find_transactions_by_tag );
196
217
RUN_TEST (test_find_transactions_obj_by_tag );
197
- RUN_TEST (test_receive_mam_message );
198
218
RUN_TEST (test_send_mam_message );
219
+ RUN_TEST (test_receive_mam_message );
199
220
ta_config_destroy (& ta_core .service );
200
221
return UNITY_END ();
201
222
}
0 commit comments