| 89 | } |
| 90 | |
| 91 | static bool run_message_test(const char *label, internal_socket_t *left, internal_socket_t *right) |
| 92 | { |
| 93 | internal_callbacks_t events; |
| 94 | |
| 95 | memset(&events, 0, sizeof(events)); |
| 96 | |
| 97 | events.on_data = on_data; |
| 98 | |
| 99 | internal_set_callbacks(left, &events ); |
| 100 | internal_set_callbacks(right, &events ); |
| 101 | |
| 102 | const char* binary_message; |
| 103 | int received_message_count = 0; |
| 104 | int expected_message_count = 2; |
| 105 | |
| 106 | std::vector<std::string> msg_queue; |
| 107 | |
| 108 | printf("[%s] starting\n", label); |
| 109 | |
| 110 | // g_signal_connect(left, "on-data", G_CALLBACK(on_data), msg_queue); |
| 111 | // g_signal_connect(right, "on-data", G_CALLBACK(on_data), msg_queue); |
| 112 | // g_signal_connect(left, "on-binary-data", G_CALLBACK(on_binary_data), msg_queue); |
| 113 | // g_signal_connect(right, "on-binary-data", G_CALLBACK(on_binary_data), msg_queue); |
| 114 | |
| 115 | internal_set_data( left, &msg_queue ); |
| 116 | internal_set_data( right, &msg_queue ); |
| 117 | |
| 118 | printf("[%s] sending messages\n", label); |
| 119 | |
| 120 | binary_message = "binary: left->right"; |
| 121 | internal_write_socket(left, binary_message, strlen(binary_message)); |
| 122 | binary_message = "binary: right->left"; |
| 123 | internal_write_socket(right, binary_message, strlen(binary_message)); |
| 124 | |
| 125 | printf("[%s] expecting messages\n", label); |
| 126 | |
| 127 | int timeout = 5000; |
| 128 | for (received_message_count = 0; received_message_count < expected_message_count; ) { |
| 129 | wait(&timeout); |
| 130 | |
| 131 | // detect time has run out... |
| 132 | if( timeout <= 0 ) |
| 133 | { |
| 134 | printf("[%s] *** timeout while waiting for message\n", label); |
| 135 | break; |
| 136 | } |
| 137 | |
| 138 | for( auto it = msg_queue.begin(); it != msg_queue.end(); ) { |
| 139 | const char* received_message = it->c_str(); |
| 140 | |
| 141 | printf("[%s] received message: %s\n", label, received_message); |
| 142 | |
| 143 | received_message_count++; |
| 144 | |
| 145 | msg_queue.erase(it); |
| 146 | |
| 147 | it = msg_queue.begin(); |
| 148 | } |
no test coverage detected