403Webshell
Server IP : 172.67.216.182  /  Your IP : 172.70.147.173
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /www/server/mysql/src/unittest/gunit/sql_table-t.cc
/* Copyright (c) 2011, 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, version 2.0,
   as published by the Free Software Foundation.

   This program is also distributed with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have included with MySQL.

   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, version 2.0, 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,
   51 Franklin Street, Suite 500, Boston, MA 02110-1335 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 ...
#include "my_config.h"
#include <gtest/gtest.h>

#include "mock_create_field.h"
#include "test_utils.h"
#include "mock_field_timestamp.h"
#include "item.h"
#include "sql_class.h"
#include "rpl_handler.h"                        // delegates_init()
#include "sql_table.h"

namespace sql_table_unittest {

using my_testing::Server_initializer;
using my_testing::Mock_error_handler;

/*
  Test of functionality in the file sql_table.cc
 */
class SqlTableTest : public ::testing::Test
{
protected:
  virtual void SetUp() { initializer.SetUp(); }
  virtual void TearDown() { initializer.TearDown(); }

  THD *get_thd() { return initializer.thd(); }

  Server_initializer initializer;
};


/*
  Test of promote_first_timestamp_column(). We pass it a list of two TIMESTAMP
  NOT NULL columns, the first of which should be promoted to DEFAULT
  CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP. The second column should not
  be promoted.
 */
TEST_F(SqlTableTest, PromoteFirstTimestampColumn1)
{
  Mock_create_field column_1_definition(MYSQL_TYPE_TIMESTAMP, NULL, NULL);
  Mock_create_field column_2_definition(MYSQL_TYPE_TIMESTAMP, NULL, NULL);
  column_1_definition.flags|= NOT_NULL_FLAG;
  column_2_definition.flags|= NOT_NULL_FLAG;
  List<Create_field> definitions;
  definitions.push_front(&column_1_definition);
  definitions.push_back(&column_2_definition);
  promote_first_timestamp_column(&definitions);
  EXPECT_EQ(Field::TIMESTAMP_DNUN_FIELD, column_1_definition.unireg_check);
  EXPECT_EQ(Field::NONE, column_2_definition.unireg_check);
}



/*
  Test of promote_first_timestamp_column(). We pass it a list of two TIMESTAMP
  NOT NULL columns, the first of which should be promoted to DEFAULT
  CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP. The second column should not
  be promoted.
 */
TEST_F(SqlTableTest, PromoteFirstTimestampColumn2)
{
  Mock_create_field column_1_definition(MYSQL_TYPE_TIMESTAMP2, NULL, NULL);
  Mock_create_field column_2_definition(MYSQL_TYPE_TIMESTAMP2, NULL, NULL);
  column_1_definition.flags|= NOT_NULL_FLAG;
  column_2_definition.flags|= NOT_NULL_FLAG;
  List<Create_field> definitions;
  definitions.push_front(&column_1_definition);
  definitions.push_back(&column_2_definition);
  promote_first_timestamp_column(&definitions);
  EXPECT_EQ(Field::TIMESTAMP_DNUN_FIELD, column_1_definition.unireg_check);
  EXPECT_EQ(Field::NONE, column_2_definition.unireg_check);
}


/*
  Test of promote_first_timestamp_column(). We pass it a list of two columns,
  one TIMESTAMP NULL DEFAULT 1, and one TIMESTAMP NOT NULL. No promotion
  should take place.
 */
TEST_F(SqlTableTest, PromoteFirstTimestampColumn3)
{
  Item_string  *item_str= new Item_string("1", 1, &my_charset_latin1);
  Mock_create_field column_1_definition(MYSQL_TYPE_TIMESTAMP, item_str, NULL);
  Mock_create_field column_2_definition(MYSQL_TYPE_TIMESTAMP, NULL, NULL);
  column_2_definition.flags|= NOT_NULL_FLAG;
  List<Create_field> definitions;
  definitions.push_front(&column_1_definition);
  definitions.push_back(&column_2_definition);
  promote_first_timestamp_column(&definitions);
  EXPECT_EQ(Field::NONE, column_1_definition.unireg_check);
  EXPECT_EQ(Field::NONE, column_2_definition.unireg_check);
}


/*
  This is a test case based on innobase_init()
  There was an out-of-bounds read when converting "-@" to a table name.
 */
TEST_F(SqlTableTest, FileNameToTableName)
{
  struct PackStuff
  {
    char foo1;
    char str[3];
    char foo2;
  };
  PackStuff foo;
  memcpy(foo.str, "-@", 3);
  MEM_NOACCESS(&foo.foo1, 1);
  MEM_NOACCESS(&foo.foo2, 1);

  const char test_filename[] = "-@";
  char       test_tablename[sizeof test_filename
                            + sizeof("#mysql50#") - 1];
  //#mysql50# is prefix used by MySQL to indicate pre-5.1 table name encoding.


  // This one used to fail with AddressSanitizer
  size_t name_length;
  name_length= filename_to_tablename(test_filename,
                                     test_tablename,
                                     sizeof(test_tablename)
#ifndef NDEBUG
                                     , true
#endif
                                     );
  EXPECT_EQ((sizeof(test_tablename)) - 1, name_length);

  // This one used to fail if compiled with -DHAVE_VALGRIND
  name_length= filename_to_tablename(foo.str,
                                     test_tablename,
                                     sizeof(test_tablename)
#ifndef NDEBUG
                                     , true
#endif
                                     );
  EXPECT_EQ((sizeof(test_tablename)) - 1, name_length);

}

}

Youez - 2016 - github.com/yon3zu
LinuXploit