The f_socket_connect() should return F_file_descriptor when socket.id is in use.
Add appropriate unit tests.
* @param path
* The path file name.
* @param mode
- * The file mode to open in.
+ * The file mode permission to open in (such as F_file_mode_all_rwx_d).
* @param file
* The data related to the file being opened.
* This will be updated with the file descriptor.
#ifndef _di_f_socket_connect_
f_status_t f_socket_connect(const f_socket_t socket) {
+ if (socket.id != -1) return F_file_descriptor;
+
if (connect(socket.id, (struct sockaddr *) &socket.address, socket.length) == -1) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EADDRINUSE) return F_status_set_error(F_busy_address);
*
* @return
* F_okay on success.
+ * F_file_descriptor if socket file descriptor is already connected (socket.id != -1).
*
* F_access_denied (with error bit) on access denied.
* F_available_not_address (with error bit) if address is unavailable (is non-existent or not local).
} // for
}
+void test__f_socket_connect__returns_file_descriptor(void **state) {
+
+ {
+ f_socket_t socket = f_socket_t_initialize;
+ socket.id = 1;
+
+ const f_status_t status = f_socket_connect(socket);
+
+ assert_int_equal(status, F_file_descriptor);
+ }
+}
+
void test__f_socket_connect__works(void **state) {
f_socket_t socket = f_socket_t_initialize;
extern void test__f_socket_connect__fails(void **state);
/**
+ * Test that the function returns F_file_descriptor_not.
+ *
+ * @see f_socket_connect()
+ */
+extern void test__f_socket_connect__returns_file_descriptor(void **state);
+
+/**
* Test that function works.
*
* @see f_socket_connect()
cmocka_unit_test(test__f_socket_bind_local__works),
cmocka_unit_test(test__f_socket_connect__fails),
+ cmocka_unit_test(test__f_socket_connect__returns_file_descriptor),
cmocka_unit_test(test__f_socket_connect__works),
cmocka_unit_test(test__f_socket_create__fails),