summaryrefslogtreecommitdiffstats
path: root/unittest/examples
diff options
context:
space:
mode:
Diffstat (limited to 'unittest/examples')
-rw-r--r--unittest/examples/CMakeLists.txt16
-rw-r--r--unittest/examples/core-t.c34
-rw-r--r--unittest/examples/no_plan-t.c40
-rw-r--r--unittest/examples/simple-t.c53
-rw-r--r--unittest/examples/skip-t.c29
-rw-r--r--unittest/examples/skip_all-t.c40
-rw-r--r--unittest/examples/todo-t.c36
7 files changed, 248 insertions, 0 deletions
diff --git a/unittest/examples/CMakeLists.txt b/unittest/examples/CMakeLists.txt
new file mode 100644
index 00000000..cba7db5b
--- /dev/null
+++ b/unittest/examples/CMakeLists.txt
@@ -0,0 +1,16 @@
+# Copyright (c) 2006, 2010, 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-1335 USA
+
+MY_ADD_TESTS(simple skip todo skip_all no_plan)
diff --git a/unittest/examples/core-t.c b/unittest/examples/core-t.c
new file mode 100644
index 00000000..12d9fe5c
--- /dev/null
+++ b/unittest/examples/core-t.c
@@ -0,0 +1,34 @@
+/* Copyright (c) 2006 MySQL AB, 2009 Sun Microsystems, Inc.
+ Use is subject to license terms.
+
+ 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-1335 USA */
+
+#include <my_global.h>
+
+#include <stdlib.h>
+#include <tap.h>
+
+/*
+ This is a simple test to demonstrate what happens if a signal that
+ generates a core is raised.
+
+ Note that this test will stop all further testing!
+ */
+
+int main() {
+ plan(3);
+ ok(1, "First test");
+ abort();
+ return exit_status();
+}
diff --git a/unittest/examples/no_plan-t.c b/unittest/examples/no_plan-t.c
new file mode 100644
index 00000000..80a56970
--- /dev/null
+++ b/unittest/examples/no_plan-t.c
@@ -0,0 +1,40 @@
+/* Copyright (c) 2006, 2010, 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-1335 USA */
+
+#include <my_global.h>
+
+#include <stdlib.h>
+#include <tap.h>
+
+/*
+ Sometimes, the number of tests is not known beforehand. In those
+ cases, you should invoke plan(NO_PLAN).
+ The plan will be printed at the end of the test (inside exit_status()).
+
+ Use this sparingly, it is a last resort: planning how many tests you
+ are going to run will help you catch that offending case when some
+ tests are skipped for an unknown reason.
+*/
+int main() {
+ /*
+ We recommend calling plan(NO_PLAN), but want to verify that
+ omitting the call works as well.
+ plan(NO_PLAN);
+ */
+ ok(1, " ");
+ ok(1, " ");
+ ok(1, " ");
+ return exit_status();
+}
diff --git a/unittest/examples/simple-t.c b/unittest/examples/simple-t.c
new file mode 100644
index 00000000..ea64696c
--- /dev/null
+++ b/unittest/examples/simple-t.c
@@ -0,0 +1,53 @@
+/* Copyright (C) 2006 MySQL AB
+ Use is subject to license terms
+
+ 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-1335 USA */
+
+#include <tap.h>
+
+unsigned int gcs(unsigned int a, unsigned int b)
+{
+ if (b > a) {
+ unsigned int t = a;
+ a = b;
+ b = t;
+ }
+
+ while (b != 0) {
+ unsigned int m = a % b;
+ a = b;
+ b = m;
+ }
+ return a;
+}
+
+int main() {
+ unsigned int a,b;
+ unsigned int failed;
+ plan(1);
+ diag("Testing basic functions");
+ failed = 0;
+ for (a = 1 ; a < 2000 ; ++a)
+ for (b = 1 ; b < 2000 ; ++b)
+ {
+ unsigned int d = gcs(a, b);
+ if (a % d != 0 || b % d != 0) {
+ ++failed;
+ diag("Failed for gcs(%4u,%4u)", a, b);
+ }
+ }
+ ok(failed == 0, "Testing gcs()");
+ return exit_status();
+}
+
diff --git a/unittest/examples/skip-t.c b/unittest/examples/skip-t.c
new file mode 100644
index 00000000..a8ca43f6
--- /dev/null
+++ b/unittest/examples/skip-t.c
@@ -0,0 +1,29 @@
+/*
+ Copyright (c) 2006, 2010, 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-1335 USA */
+
+#include <tap.h>
+#include <stdlib.h>
+
+int main() {
+ plan(4);
+ ok1(1);
+ ok1(1);
+ SKIP_BLOCK_IF(1, 2, "Example of skipping a few test points in a test") {
+ ok1(1);
+ ok1(1);
+ }
+ return exit_status();
+}
diff --git a/unittest/examples/skip_all-t.c b/unittest/examples/skip_all-t.c
new file mode 100644
index 00000000..cfe6432b
--- /dev/null
+++ b/unittest/examples/skip_all-t.c
@@ -0,0 +1,40 @@
+/*
+ Copyright (c) 2006, 2010, 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-1335 USA */
+
+#include <my_global.h>
+
+#include <stdlib.h>
+#include <tap.h>
+
+int has_feature() {
+ return 0;
+}
+
+/*
+ In some cases, an entire test file does not make sense because there
+ some feature is missing. In that case, the entire test case can be
+ skipped in the following manner.
+ */
+int main() {
+ if (!has_feature())
+ skip_all("Example of skipping an entire test");
+ plan(4);
+ ok1(1);
+ ok1(1);
+ ok1(1);
+ ok1(1);
+ return exit_status();
+}
diff --git a/unittest/examples/todo-t.c b/unittest/examples/todo-t.c
new file mode 100644
index 00000000..91720b30
--- /dev/null
+++ b/unittest/examples/todo-t.c
@@ -0,0 +1,36 @@
+/*
+ Copyright (c) 2006, 2010, 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-1335 USA */
+
+#include <my_global.h>
+
+#include <stdlib.h>
+#include <tap.h>
+
+int main()
+{
+ plan(4);
+ ok1(1);
+ ok1(1);
+ /*
+ Tests in the todo region is expected to fail. If they don't,
+ something is strange.
+ */
+ todo_start("Need to fix these");
+ ok1(0);
+ ok1(0);
+ todo_end();
+ return exit_status();
+}