@@ -409,7 +409,13 @@ TEST(coroutine_hook, timeout) {
409
409
size_t length = text.length ();
410
410
411
411
// unregister fd
412
+ errno = 0 ;
412
413
ASSERT_EQ (swoole_coroutine_socket_set_timeout (pairs[0 ], SO_SNDTIMEO, 0.05 ), -1 );
414
+ ASSERT_EQ (errno, EINVAL);
415
+
416
+ errno = 0 ;
417
+ ASSERT_EQ (swoole_coroutine_socket_set_connect_timeout (pairs[0 ], 0.05 ), -1 );
418
+ ASSERT_EQ (errno, EINVAL);
413
419
414
420
swoole::Coroutine::create ([&](void *) {
415
421
ASSERT_EQ (swoole_coroutine_socket_create (pairs[0 ]), 0 );
@@ -694,3 +700,31 @@ TEST(coroutine_hook, unwrap) {
694
700
ASSERT_EQ (swoole_coroutine_socket_unwrap (_sock0->get_fd ()), -1 );
695
701
});
696
702
}
703
+
704
+ static void test_freopen () {
705
+ auto output_file = " /tmp/output.txt" ;
706
+ auto fp = swoole_coroutine_fopen (TEST_LOG_FILE, " w" );
707
+ ASSERT_NE (fp, nullptr );
708
+ swoole_coroutine_fputs (" hello\n " , fp);
709
+
710
+ ASSERT_NE (swoole_coroutine_freopen (output_file, " w" , fp), nullptr );
711
+ swoole_coroutine_fputs (" world\n " , fp);
712
+
713
+ swoole_coroutine_fclose (fp);
714
+
715
+ auto rs1 = swoole::file_get_contents (output_file);
716
+ ASSERT_FALSE (rs1->contains (" hello\n " ));
717
+ ASSERT_TRUE (rs1->contains (" world\n " ));
718
+
719
+ auto rs2 = swoole::file_get_contents (TEST_LOG_FILE);
720
+ ASSERT_TRUE (rs2->contains (" hello\n " ));
721
+ ASSERT_FALSE (rs2->contains (" world\n " ));
722
+
723
+ unlink (TEST_LOG_FILE);
724
+ unlink (output_file);
725
+ }
726
+
727
+ TEST (coroutine_hook, freopen) {
728
+ coroutine::run ([&](void *arg) { test_freopen (); });
729
+ test_freopen ();
730
+ }
0 commit comments