[PATCH 02/29] vbox: Add test case for vboxUniformedAPI

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The test case will make sure each API will filled
with something. So we will not to define an API,
use it, yet forgot to implement.
---
 tests/Makefile.am            |    9 +++-
 tests/vboxuniformedapitest.c |   98 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100644 tests/vboxuniformedapitest.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index bc1040a..f73d25d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -241,7 +241,7 @@ test_programs += esxutilstest
 endif WITH_ESX
 
 if WITH_VBOX
-test_programs += vboxsnapshotxmltest
+test_programs += vboxsnapshotxmltest vboxuniformedapitest
 endif WITH_VBOX
 
 if WITH_VMX
@@ -638,8 +638,13 @@ vboxsnapshotxmltest_SOURCES = \
 	testutils.c testutils.h
 vbox_LDADDS = ../src/libvirt_driver_vbox_impl.la
 vboxsnapshotxmltest_LDADD = $(LDADDS) $(vbox_LDADDS)
+
+vboxuniformedapitest_SOURCES = \
+	vboxuniformedapitest.c \
+	testutils.c testutils.h
+vboxuniformedapitest_LDADD = $(vbox_LDADDS) $(LDADDS)
 else ! WITH_VBOX
-EXTRA_DIST += vboxsnapshotxmltest.c
+EXTRA_DIST += vboxsnapshotxmltest.c vboxuniformedapitest.c
 endif ! WITH_VBOX
 
 if WITH_VMX
diff --git a/tests/vboxuniformedapitest.c b/tests/vboxuniformedapitest.c
new file mode 100644
index 0000000..933cdb7
--- /dev/null
+++ b/tests/vboxuniformedapitest.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2014, Taowei Luo (uaedante@xxxxxxxxx)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "testutils.h"
+
+#ifdef WITH_VBOX
+
+# include "datatypes.h"
+# include "domain_event.h"
+# include "vbox/vbox_common.h"
+# include "vbox/vbox_uniformed_api.h"
+
+# define VIR_FROM_THIS VIR_FROM_NONE
+
+static vboxUniformedAPI vboxAPI;
+typedef void (*installAPI_f)(vboxUniformedAPI *pVBoxAPI);
+
+/* This test make sure all APIs in vboxUniformedAPI is
+ * filled with something (say not null). It helps to
+ * make sure you will not leave an API defined (and used
+ * probably) but not implemented yet.
+ */
+
+static int testUniformedAPI(const void *args)
+{
+    installAPI_f installAPI = (installAPI_f)args;
+    void **iter;
+
+    memset(&vboxAPI, 0, sizeof(vboxUniformedAPI));
+    installAPI(&vboxAPI);
+
+    /* Assuming that the vboxUniformedAPI is in the range
+     * of [initializeFWatch, fWatchNeedInitialize).
+     */
+    for (iter = (void **)&vboxAPI.initializeFWatch;
+         iter < (void **)&vboxAPI.fWatchNeedInitialize;
+         iter ++)
+    {
+        if ((void *)(*iter) == NULL)
+            return -1;
+    }
+    return 0;
+}
+
+static int
+mymain(void)
+{
+    int ret = 0;
+
+# define TEST(version)                                                      \
+    do  {                                                                   \
+        if (virtTestRun("Test uniformedAPI " # version,                     \
+                        testUniformedAPI,                                   \
+                        vbox##version##InstallUniformedAPI) < 0)            \
+            ret = -1;                                                       \
+    } while (0)
+
+    TEST(22);
+    TEST(30);
+    TEST(31);
+    TEST(32);
+    TEST(40);
+    TEST(41);
+    TEST(42);
+    TEST(42_20);
+    TEST(43);
+    TEST(43_4);
+
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
+
+#else
+
+int main(void)
+{
+    return EXIT_AM_SKIP;
+}
+
+#endif /*WITH_VBOX*/
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]