summaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-07-18 16:46:57 +0200
committerSergei Golubchik <sergii@pisem.net>2013-07-18 16:46:57 +0200
commit5f6380adde2dac3f32b40339b9b702c0135eb7d6 (patch)
tree31068acc0b39c208d35d524688a5985831af0447 /unittest
parent8a23ae088dc38f591efeab9eccdef5eb9094add9 (diff)
parent97e640b9ae83e07b444fceede6b0524256c7a3cc (diff)
downloadmariadb-git-5f6380adde2dac3f32b40339b9b702c0135eb7d6.tar.gz
10.0-base merge
Diffstat (limited to 'unittest')
-rw-r--r--unittest/mysys/CMakeLists.txt16
-rw-r--r--unittest/mysys/explain_filename-t.cc165
-rw-r--r--unittest/mysys/my_delete-t.c57
-rw-r--r--unittest/mytap/tap.c2
-rw-r--r--unittest/mytap/tap.h2
5 files changed, 239 insertions, 3 deletions
diff --git a/unittest/mysys/CMakeLists.txt b/unittest/mysys/CMakeLists.txt
index 1de1bd19143..fb6154748ac 100644
--- a/unittest/mysys/CMakeLists.txt
+++ b/unittest/mysys/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
#
# 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
@@ -19,3 +19,17 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql
MY_ADD_TESTS(bitmap base64 my_vsnprintf my_atomic my_rdtsc lf my_malloc
LINK_LIBRARIES mysys)
+
+IF(WIN32)
+ MY_ADD_TESTS(my_delete LINK_LIBRARIES mysys)
+ENDIF()
+
+IF(WIN32)
+ ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc
+ ../../sql/nt_servc.cc)
+ELSE()
+ ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc)
+ENDIF()
+
+TARGET_LINK_LIBRARIES(explain_filename-t sql mytap)
+ADD_TEST(explain_filename explain_filename-t)
diff --git a/unittest/mysys/explain_filename-t.cc b/unittest/mysys/explain_filename-t.cc
new file mode 100644
index 00000000000..096fdf3b168
--- /dev/null
+++ b/unittest/mysys/explain_filename-t.cc
@@ -0,0 +1,165 @@
+/*
+ Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+
+ 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
+*/
+
+/** Unit test case for the function explain_filename(). */
+
+#include <tap.h>
+#include <mysqld_error.h>
+#include <sql_class.h>
+#include <sql_table.h>
+
+#define BUFLEN 1000
+char to[BUFLEN];
+char from[BUFLEN];
+
+const char *error_messages[1000];
+
+int setup()
+{
+ system_charset_info = &my_charset_utf8_bin;
+ my_default_lc_messages = &my_locale_en_US;
+
+ /* Populate the necessary error messages */
+ error_messages[ER_DATABASE_NAME - ER_ERROR_FIRST] = "Database";
+ error_messages[ER_TABLE_NAME - ER_ERROR_FIRST] = "Table";
+ error_messages[ER_PARTITION_NAME - ER_ERROR_FIRST] = "Partition";
+ error_messages[ER_SUBPARTITION_NAME - ER_ERROR_FIRST] = "Subpartition";
+ error_messages[ER_TEMPORARY_NAME - ER_ERROR_FIRST] = "Temporary";
+ error_messages[ER_RENAMED_NAME - ER_ERROR_FIRST] = "Renamed";
+
+ my_default_lc_messages->errmsgs->errmsgs = error_messages;
+
+ return 0;
+}
+
+void test_1(const char *in, const char *exp, enum_explain_filename_mode mode)
+{
+ char out[BUFLEN];
+
+ uint len1 = explain_filename(0, in, out, BUFLEN, mode);
+
+ /* expected output and actual output must be same */
+ bool pass = (strcmp(exp, out) == 0);
+
+ /* length returned by explain_filename is fine */
+ bool length = (len1 == strlen(exp));
+
+ ok( (pass && length) , "(%d): %s => %s\n", mode, in, out);
+}
+
+int main(int argc __attribute__((unused)),char *argv[])
+{
+ MY_INIT(argv[0]);
+ setup();
+ plan(NO_PLAN);
+
+ test_1("test/t1.ibd",
+ "Database \"test\", Table \"t1.ibd\"",
+ EXPLAIN_ALL_VERBOSE);
+
+ test_1("test/t1.ibd",
+ "\"test\".\"t1.ibd\"",
+ EXPLAIN_PARTITIONS_VERBOSE);
+
+ test_1("test/t1.ibd",
+ "\"test\".\"t1.ibd\"",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("test/t1#TMP#",
+ "Database \"test\", Table \"t1#TMP#\"",
+ EXPLAIN_ALL_VERBOSE);
+
+ test_1("test/#sql-2882.ibd",
+ "Database \"test\", Table \"#sql-2882.ibd\"",
+ EXPLAIN_ALL_VERBOSE);
+
+ test_1("test/t1#REN#",
+ "Database \"test\", Table \"t1#REN#\"",
+ EXPLAIN_ALL_VERBOSE);
+
+ test_1("test/t1@0023REN@0023",
+ "Database \"test\", Table \"t1#REN#\"",
+ EXPLAIN_ALL_VERBOSE);
+
+ test_1("test/t1#p#p1",
+ "Database \"test\", Table \"t1\", Partition \"p1\"",
+ EXPLAIN_ALL_VERBOSE);
+
+ test_1("test/t1#P#p1",
+ "\"test\".\"t1\" /* Partition \"p1\" */",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("test/t1#P#p1@00231",
+ "\"test\".\"t1\" /* Partition \"p1#1\" */",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("test/t1#P#p1#SP#sp1",
+ "\"test\".\"t1\" /* Partition \"p1\", Subpartition \"sp1\" */",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("test/t1#p1#SP#sp1",
+ "\"test\".\"t1#p1#SP#sp1\"",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("test/t1#p#p1@00232#SP#sp1@00231#REN#",
+ "\"test\".\"t1\" /* Renamed Partition \"p1#2\", Subpartition \"sp1#1\" */",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("test/t1#p#p1#SP#sp1#TMP#",
+ "\"test\".\"t1\" /* Temporary Partition \"p1\", Subpartition \"sp1\" */",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("test/#sql-t1#P#p1#SP#sp1#TMP#",
+ "\"test\".\"#sql-t1#P#p1#SP#sp1#TMP#\" /* Temporary Partition \"p1\", Subpartition \"sp1\" */",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("test/#sql-t1#P#p1#SP#sp1",
+ "\"test\".\"#sql-t1#P#p1#SP#sp1\" /* Partition \"p1\", Subpartition \"sp1\" */",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("test/#sqlx-33",
+ "\"test\".\"#sqlx-33\"",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("test/#mysql50#t",
+ "\"test\".\"#mysql50#t\"",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("#mysql50#t",
+ "\"#mysql50#t\"",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("@0023t",
+ "\"#t\"",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ test_1("test/t@0023",
+ "\"test\".\"t#\"",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ /*
+ If a character not allowed in my_charset_filename is encountered,
+ then it will not be converted to system_charset_info!
+ */
+ test_1("test/t@0023#",
+ "\"test\".\"t@0023#\"",
+ EXPLAIN_PARTITIONS_AS_COMMENT);
+
+ my_end(0);
+ return 0;
+}
+
diff --git a/unittest/mysys/my_delete-t.c b/unittest/mysys/my_delete-t.c
new file mode 100644
index 00000000000..7d15f09c787
--- /dev/null
+++ b/unittest/mysys/my_delete-t.c
@@ -0,0 +1,57 @@
+/* Copyright (c) 2011, Monty Program Ab
+
+ 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 */
+
+#include <my_global.h>
+#include <my_sys.h>
+#include "tap.h"
+
+
+int main(int argc __attribute__((unused)),char *argv[])
+{
+ char tmp_dir[MAX_PATH];
+ char tmp_filename[MAX_PATH];
+ HANDLE h, h2;
+
+ MY_INIT(argv[0]);
+
+ plan(6);
+
+ GetTempPathA(MAX_PATH, tmp_dir);
+ ok(GetTempFileNameA(tmp_dir, "foo", 0, tmp_filename) != 0, "create temp file");
+ ok(my_delete(tmp_filename,MYF(0)) == 0, "Delete closed file");
+
+
+ /* Delete an open file */
+ ok(GetTempFileNameA(tmp_dir, "foo", 0, tmp_filename) != 0, "create temp file 2");
+ h = CreateFileA(tmp_filename, GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL);
+ ok (h != INVALID_HANDLE_VALUE || h != 0, "open temp file");
+ ok(my_delete(tmp_filename, MYF(0)) == 0, "Delete open file");
+
+
+ /*
+ Check if it is possible to reuse file name after delete (not all handles
+ to it are closed.
+ */
+ h2 = CreateFileA(tmp_filename, GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_DELETE, NULL, CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, NULL);
+ ok(h2 != 0 && h2 != INVALID_HANDLE_VALUE, "Reuse file name");
+ CloseHandle(h);
+ CloseHandle(h2);
+
+ my_end(0);
+ return exit_status();
+}
+
diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c
index ad08789a275..7bfc6dba8f5 100644
--- a/unittest/mytap/tap.c
+++ b/unittest/mytap/tap.c
@@ -12,7 +12,7 @@
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Library for providing TAP support for testing C and C++ was written
by Mats Kindahl <mats@mysql.com>.
diff --git a/unittest/mytap/tap.h b/unittest/mytap/tap.h
index 55f74f5fa02..834392c5fae 100644
--- a/unittest/mytap/tap.h
+++ b/unittest/mytap/tap.h
@@ -11,7 +11,7 @@
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Library for providing TAP support for testing C and C++ was written
by Mats Kindahl <mats@mysql.com>.