[sheepdog] [PATCH 3/4] tests/unit: use MOCK_METHOD when define mock method

Kai Zhang kyle at zelin.io
Wed Jul 10 12:23:16 CEST 2013


Signed-off-by: Kai Zhang <kyle at zelin.io>
---
 tests/unit/collie/Makefile.am   |    3 ++-
 tests/unit/collie/mock_collie.c |   12 +++---------
 tests/unit/sheep/Makefile.am    |    4 +++-
 tests/unit/sheep/mock_request.c |   12 +++---------
 tests/unit/sheep/mock_store.c   |   32 ++++++++++----------------------
 5 files changed, 21 insertions(+), 42 deletions(-)

diff --git a/tests/unit/collie/Makefile.am b/tests/unit/collie/Makefile.am
index 2471aa1..404bc66 100644
--- a/tests/unit/collie/Makefile.am
+++ b/tests/unit/collie/Makefile.am
@@ -7,10 +7,11 @@ check_PROGRAMS		= ${TESTS}
 INCLUDES		= -I$(top_srcdir)/include			\
 			  -I$(top_srcdir)/collie			\
 			  -I$(top_srcdir)/collie/farm			\
+			  -I../mock					\
 			  @CHECK_CFLAGS@
 
 LIBS			= $(top_srcdir)/lib/libsheepdog.a -lpthread	\
-			  @CHECK_LIBS@
+			  ../mock/libmock.a @CHECK_LIBS@
 
 test_common_SOURCES	= test_common.c mock_collie.c			\
 			  $(top_srcdir)/collie/common.c
diff --git a/tests/unit/collie/mock_collie.c b/tests/unit/collie/mock_collie.c
index 1f9ce35..c66d730 100644
--- a/tests/unit/collie/mock_collie.c
+++ b/tests/unit/collie/mock_collie.c
@@ -12,6 +12,7 @@
  */
 
 #include "collie.h"
+#include "mock.h"
 
 /* collie mock */
 const char *sdhost = "127.0.0.1";
@@ -20,12 +21,5 @@ bool highlight = true;
 bool raw_output;
 struct sd_vnode sd_vnodes[SD_MAX_VNODES];
 
-int update_node_list(int max_nodes)
-{
-	return 0;
-}
-
-void subcommand_usage(char *cmd, char *subcmd, int status)
-{
-	return;
-}
+MOCK_METHOD(update_node_list, int, 0, int max_nodes)
+MOCK_VOID_METHOD(subcommand_usage, char *cmd, char *subcmd, int status)
diff --git a/tests/unit/sheep/Makefile.am b/tests/unit/sheep/Makefile.am
index 651470a..1cc3988 100644
--- a/tests/unit/sheep/Makefile.am
+++ b/tests/unit/sheep/Makefile.am
@@ -6,9 +6,11 @@ check_PROGRAMS		= ${TESTS}
 
 INCLUDES		= -I$(top_srcdir)/include			\
 			  -I$(top_srcdir)/sheep				\
+			  -I../mock					\
 			  @CHECK_CFLAGS@
 
-LIBS			= $(top_srcdir)/lib/libsheepdog.a -lpthread	\
+LIBS			= $(top_srcdir)/lib/libsheepdog.a		\
+			  ../mock/libmock.a -lpthread			\
 			  @CHECK_LIBS@
 
 test_vdi_SOURCES	= test_vdi.c mock_sheep.c mock_store.c		\
diff --git a/tests/unit/sheep/mock_request.c b/tests/unit/sheep/mock_request.c
index c37ab30..bd7c2b7 100644
--- a/tests/unit/sheep/mock_request.c
+++ b/tests/unit/sheep/mock_request.c
@@ -11,14 +11,8 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "mock.h"
 #include "sheep_priv.h"
 
-int exec_local_req(struct sd_req *rq, void *data)
-{
-	return 0;
-}
-
-void put_request(struct request *req)
-{
-	return;
-}
+MOCK_METHOD(exec_local_req, int, 0, struct sd_req *rq, void *data)
+MOCK_VOID_METHOD(put_request, struct request *req)
diff --git a/tests/unit/sheep/mock_store.c b/tests/unit/sheep/mock_store.c
index e9a2901..fe6c0d9 100644
--- a/tests/unit/sheep/mock_store.c
+++ b/tests/unit/sheep/mock_store.c
@@ -11,27 +11,15 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "mock.h"
 #include "sheep_priv.h"
 
-int read_object(uint64_t oid, char *data, unsigned int datalen,
-		uint64_t offset)
-{
-	return 0;
-}
-
-int write_object(uint64_t oid, char *data, unsigned int datalen,
-		 uint64_t offset, bool create)
-{
-	return 0;
-}
-
-int read_backend_object(uint64_t oid, char *data, unsigned int datalen,
-			uint64_t offset)
-{
-	return 0;
-}
-
-int remove_object(uint64_t oid)
-{
-	return 0;
-}
+MOCK_METHOD(read_object, int, 0,
+	    uint64_t oid, char *data, unsigned int datalen, uint64_t offset)
+MOCK_METHOD(write_object, int, 0,
+	    uint64_t oid, char *data, unsigned int datalen, uint64_t offset,
+	    bool create)
+MOCK_METHOD(read_backend_object, int, 0,
+	    uint64_t oid, char *data, unsigned int datalen, uint64_t offset)
+MOCK_METHOD(remove_object, int, 0,
+	    uint64_t oid)
-- 
1.7.9.5




More information about the sheepdog mailing list