Server IP : 172.67.216.182 / Your IP : 108.162.226.10 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/server/mysql/src/unittest/gunit/ |
Upload File : |
/* Copyright (c) 2022, 2023, Oracle and/or its affiliates. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ // First include (the generated) my_config.h, to get correct platform defines, // then gtest.h (before any other MySQL headers), to avoid min() macros etc ... #ifdef _WIN32_WINNT #if (_WIN32_WINNT < 0x0602) #undef _WIN32_WINNT // We need at least _WIN32_WINNT_WIN8 i.e. 0x0602 for // EnumDynamicTimeZoneInformation #define _WIN32_WINNT 0x0602 #endif // (_WIN32_WINNT < 0x0602) #endif // _WIN32_WINNT #include "my_config.h" #include "test_utils.h" #include <gtest/gtest.h> #include <stdlib.h> #include "../sql/log.h" // CET: 32 bytes // date (10), 'T', time (8), '.', microseconds (6), timezone offset (6) #define LEN_MS_CET 32 // UTC: 27 bytes // date (10), 'T', time (8), '.', microseconds (6), 'Z' #define LEN_MS_UTC 27 // we use micro-seconds since the epoch #define MICRO_FAC ((ulonglong)1000000L) namespace log_timestamp_unittest { using my_testing::Server_initializer; class LogTimestampTest : public ::testing::Test { protected: virtual void SetUp() { initializer.SetUp(); } virtual void TearDown() { initializer.TearDown(); } THD *thd() { return initializer.thd(); } Server_initializer initializer; }; /* Test basic functionality - throttling, eligibility, printing of summary of Slow_log_throttle. */ TEST_F(LogTimestampTest, iso8601) { char time_buff[iso8601_size]; #ifdef WIN32 DYNAMIC_TIME_ZONE_INFORMATION original_dti = {}; DWORD original_dti_result = GetDynamicTimeZoneInformation(&original_dti); EXPECT_NE(original_dti_result, TIME_ZONE_ID_INVALID); if (original_dti.DaylightDate.wMonth == 0) { /* Current system time zone does not support Daylight savings. If the Windows system time zone has no daylight saving, then attempting to set TZ to a timezone that does have daylight saving will result in localtime_r producing inaccurate results. Skipping the test. Bug#34380460 will be tracking this issue. */ return; } char tz[] = "TZ=CET-1CES"; #else char tz[] = "TZ=CET"; #endif int time_buff_len; EXPECT_EQ(((iso8601_size)-1), LEN_MS_CET); EXPECT_EQ(((LEN_MS_CET)-5), LEN_MS_UTC); // set up timezone (central european time) putenv(tz); EXPECT_STREQ(&(tz[3]), getenv("TZ")); tzset(); /// 1970/01/01 .000001 (1) // UTC (winter) opt_log_timestamps = 0; // UTC Timestamp time_buff_len = make_iso8601_timestamp(time_buff, 1); EXPECT_EQ(LEN_MS_UTC, time_buff_len); EXPECT_STREQ("1970-01-01T00:00:00.000001Z", time_buff); // CET (winter) +1h opt_log_timestamps = 1; // System Timestamp time_buff_len = make_iso8601_timestamp(time_buff, 1); EXPECT_EQ(LEN_MS_CET, time_buff_len); EXPECT_STREQ("1970-01-01T01:00:00.000001+01:00", time_buff); /// 2011-07-07 (1309996800) // UTC (summer) opt_log_timestamps = 0; time_buff_len = make_iso8601_timestamp(time_buff, MICRO_FAC * 1309996800); EXPECT_EQ(LEN_MS_UTC, time_buff_len); EXPECT_STREQ("2011-07-07T00:00:00.000000Z", time_buff); // CET (summer) +2h opt_log_timestamps = 1; time_buff_len = make_iso8601_timestamp(time_buff, MICRO_FAC * 1309996800); EXPECT_EQ(LEN_MS_CET, time_buff_len); EXPECT_STREQ("2011-07-07T02:00:00.000000+02:00", time_buff); /// 1987-06-05 04:03:02.123456 // UTC opt_log_timestamps = 0; time_buff_len = make_iso8601_timestamp( time_buff, (MICRO_FAC * 549864182) + 123456); EXPECT_EQ(LEN_MS_UTC, time_buff_len); EXPECT_STREQ("1987-06-05T04:03:02.123456Z", time_buff); } // End of Error_log_timestamp test cases. } // namespace log_timestamp_unittest