]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
pluginlib: Add smartptr template unittest.
authorRadosław Korzeniewski <radekk@inteos.pl>
Wed, 23 Dec 2020 12:00:57 +0000 (13:00 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:00 +0000 (09:03 +0100)
bacula/src/plugins/fd/pluginlib/Makefile.in
bacula/src/plugins/fd/pluginlib/smartptr_test.cpp [new file with mode: 0644]

index 1cc68b6946d38564b8cbba266bce744537f85a15..caed27e15d85d21a908924f4916776a841eaa465 100644 (file)
@@ -30,6 +30,7 @@ EXECPROGOBJ = $(filter %.lo,$(EXECPROGSRC:.cpp=.lo))
 PTCOMMSRC = ptcomm.cpp ptcomm.h
 PTCOMMOBJ = $(filter %.lo,$(PTCOMMSRC:.cpp=.lo))
 SMARTALISTSRC = smartalist.h
+SMARTPTRSRC = smartalist.h
 
 PLUGINLIBSTEST = pluginlib_test.cpp $(PLUGINLIBSSRC) $(UNITTESTSOBJ)
 PLUGINLIBSTESTOBJ = $(filter %.lo,$(PLUGINLIBSTEST:.cpp=.lo))
@@ -37,6 +38,8 @@ ISO8601TEST = iso8601_test.cpp $(ISO8601SRC) $(UNITTESTSOBJ)
 ISO8601TESTOBJ = $(filter %.lo,$(ISO8601TEST:.cpp=.lo))
 SMARTALISTTEST = smartalist_test.cpp $(SMARTALISTSRC) $(PLUGINLIBSOBJ) $(UNITTESTSOBJ)
 SMARTALISTTESTOBJ = $(filter %.lo,$(SMARTALISTTEST:.cpp=.lo))
+SMARTPTRTEST = smartptr_test.cpp $(SMARTPTRSRC) $(PLUGINLIBSOBJ) $(UNITTESTSOBJ)
+SMARTPTRTESTOBJ = $(filter %.lo,$(SMARTPTRTEST:.cpp=.lo))
 
 TESTMETAPLUGINBACKENDSRC = test_metaplugin_backend.c
 TESTMETAPLUGINBACKENDOBJ = $(TESTMETAPLUGINBACKENDSRC:.c=.lo)
@@ -44,7 +47,7 @@ TESTMETAPLUGINBACKENDOBJ = $(TESTMETAPLUGINBACKENDSRC:.c=.lo)
 # COMMONPLUGINOBJ = $(PLUGINLIBSOBJ) $(ISO8601OBJ) $(EXECPROGOBJ)
 COMMONPLUGINOBJ = $(PLUGINLIBSOBJ) $(PTCOMMOBJ)
 # COMMONPLUGINTESTS = pluginlib_test iso8601_test
-COMMONPLUGINTESTS = pluginlib_test smartalist_test
+COMMONPLUGINTESTS = pluginlib_test smartalist_test smartptr_test
 
 .SUFFIXES:    .c .cpp .lo
 
@@ -79,6 +82,10 @@ smartalist_test: Makefile $(SMARTALISTTESTOBJ) $(SMARTALISTTESTOBJ)
        @echo "Building $@ ..."
        $(NO_ECHO)$(LIBTOOL_LINK) --silent $(CXX) $(LDFLAGS) $(LIBCURL) $(LIBBAC) $(SMARTALISTTESTOBJ) -o $@
 
+smartptr_test: Makefile $(SMARTPTRTESTOBJ) $(SMARTPTRTESTOBJ)
+       @echo "Building $@ ..."
+       $(NO_ECHO)$(LIBTOOL_LINK) --silent $(CXX) $(LDFLAGS) $(LIBCURL) $(LIBBAC) $(SMARTPTRTESTOBJ) -o $@
+
 iso8601_test: Makefile $(ISO8601TESTOBJ) $(ISO8601SRC)
        @echo "Building $@ ..."
        $(NO_ECHO)$(LIBTOOL_LINK) --silent $(CXX) $(LDFLAGS) $(LIBCURL) $(LIBBAC) $(PLUGINLIBSTESTOBJ) -o $@
diff --git a/bacula/src/plugins/fd/pluginlib/smartptr_test.cpp b/bacula/src/plugins/fd/pluginlib/smartptr_test.cpp
new file mode 100644 (file)
index 0000000..a052035
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2007-2017 Bacula Systems SA
+   All rights reserved.
+
+   The main author of Bacula is Kern Sibbald, with contributions from many
+   others, a complete list can be found in the file AUTHORS.
+
+   Licensees holding a valid Bacula Systems SA license may use this file
+   and others of this release in accordance with the proprietary license
+   agreement provided in the LICENSE file.  Redistribution of any part of
+   this release is not permitted.
+
+   Bacula® is a registered trademark of Kern Sibbald.
+*/
+/**
+ * @file smartptr_test.cpp
+ * @author Radosław Korzeniewski (radoslaw@korzeniewski.net)
+ * @brief Common definitions and utility functions for Inteos plugins - unittest.
+ * @version 1.1.0
+ * @date 2020-12-23
+ *
+ * @copyright Copyright (c) 2020 All rights reserved. IP transferred to Bacula Systems according to agreement.
+ */
+
+#include "pluginlib.h"
+#include "smartptr.h"
+#include "unittests.h"
+
+bFuncs *bfuncs;
+bInfo *binfo;
+
+static int referencenumber = 0;
+
+struct testclass
+{
+   testclass() { referencenumber++; };
+   ~testclass() { referencenumber--; };
+};
+
+int main()
+{
+   Unittests pluglib_test("smartalist_test");
+
+   // Pmsg0(0, "Initialize tests ...\n");
+
+   {
+      smart_ptr<testclass> ptr(new testclass);
+      ok(referencenumber == 1, "check smart allocation");
+   }
+
+   ok(referencenumber == 0, "check smart free");
+
+   return report();
+}