[SCM] Development fot GoFind! branch, master, updated. 689a513482a20575fed2a51f62f835fed5dcca3b

Miriam Ruiz miriam at debian.org
Sat Nov 22 08:57:53 UTC 2008


The following commit has been merged in the master branch:
commit 689a513482a20575fed2a51f62f835fed5dcca3b
Author: Miriam Ruiz <miriam at debian.org>
Date:   Sat Nov 22 02:10:29 2008 +0100

    Add unit tests for plugins

diff --git a/Makefile b/Makefile
index cd4104e..74ff962 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ OBJS= Engine.o Environment.o filter.o field.o gofind.o \
 	taghandler.o cfgmanager.o boolparser.o \
 	utf8.o dll.o guiplugin.o
 
-PLUGINS=gui_cli.so
+PLUGINS= gui_cli.so
 
 all: gofind $(PLUGINS)
 
@@ -48,10 +48,11 @@ gui_cli.so: gui_cli.o slre.o
 %.so : %.o
 	g++ $(CFLAGS) -shared $^ -o $@
 
-TEST_OBJS=  filter.test.o taghandler.test.o cfgmanager.test.o boolparser.test.o slre.test.o utf8.test.o CuTest.o test.o
+TEST_OBJS=  filter.test.o taghandler.test.o cfgmanager.test.o boolparser.test.o slre.test.o utf8.test.o CuTest.o dll.test.o test.o
+TEST_PLUGINS= testplugin.test.so
 
-test: $(TEST_OBJS)
-	g++ -o $@ $+ -rdynamic $(LDFLAGS) $(LIBS)
+test: $(TEST_OBJS) $(TEST_PLUGINS)
+	g++ -o $@ $+ -rdynamic -Wl,-rpath,. $(LDFLAGS) $(LIBS)
 
 test.c:
 	sh CuTest.sh > $@
@@ -65,5 +66,8 @@ test.o: test.c
 %.test.o: %.c
 	gcc -o $@ -DUNIT_TEST -c $+ $(CFLAGS)
 
+%.test.so : %.test.o
+	g++ $(CFLAGS)  -DUNIT_TEST -shared $^ -o $@
+
 clean:
 	rm -f gofind test test.c *.o *.so
diff --git a/dll.cpp b/dll.cpp
index ba3209a..9be10f5 100644
--- a/dll.cpp
+++ b/dll.cpp
@@ -30,6 +30,7 @@ DLLManager::DLLManager( const char *fname )
 {
     // Try to open the library now and get any error message.
 	
+	dlerror(); // Clean previous errors, if any
 	h=dlopen( fname, RTLD_NOW );
 	err=dlerror();
 }
@@ -85,5 +86,27 @@ DLLFactoryBase::~DLLFactoryBase()
 {
 }
 
+#ifdef UNIT_TEST
 
+#include "testplugin.h"
+#include "CuTest.h"
 
+TEST_FUNCTION TestCuTestPlugIn(CuTest* tc)
+{
+	std::cout << "Loading Test Plugin: \"testplugin.test.so\"" << std::endl;
+	DLLFactory<TestPlugInFactory> factory( "testplugin.test.so" );
+	CuAssertTrue(tc, factory.LastError() == NULL );
+	if (factory.LastError() != NULL) return;
+	TestPlugIn *plugin=factory.factory->CreatePlugIn();
+	CuAssertTrue(tc, plugin != NULL );
+	if (!plugin) return;
+	CuAssertTrue(tc, plugin->GetTrue() == true );
+	CuAssertTrue(tc, plugin->GetFalse() == false );
+	CuAssertTrue(tc, plugin->GetSame(true) == true );
+	CuAssertTrue(tc, plugin->GetSame(false) != true );
+	CuAssertTrue(tc, plugin->GetOther(true) == false );
+	CuAssertTrue(tc, plugin->GetOther(false) != false );
+	delete plugin;
+}
+
+#endif
diff --git a/guiplugin.cpp b/guiplugin.cpp
index f03b3fd..1786050 100644
--- a/guiplugin.cpp
+++ b/guiplugin.cpp
@@ -19,11 +19,12 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include "common.h"
+#include "guiplugin.h"
+
 #include <typeinfo>
 #include <iostream>
 
-#include "guiplugin.h"
-
 #ifdef GUIPLUGIN_VERSION
 	const unsigned int GUIPlugInFactory::version = GUIPLUGIN_VERSION;
 #endif
diff --git a/guiplugin.h b/testplugin.cpp
similarity index 53%
copy from guiplugin.h
copy to testplugin.cpp
index 6d0f4b9..a3b0cad 100644
--- a/guiplugin.h
+++ b/testplugin.cpp
@@ -19,53 +19,69 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef _GOFIND_GUIPLUGIN_H
-#define _GOFIND_GUIPLUGIN_H
+#include "common.h"
+#include "testplugin.h"
 
-#include "dll.h"
-#include "Engine.h"
-
-#include <iostream>
+class MyTestPlugIn : public TestPlugIn
+{
+ public:
+	MyTestPlugIn(TestPlugInFactory *f) : TestPlugIn(f)
+	{
+	}
 
-#define GUIPLUGIN_VERSION 0x0001
+	virtual ~MyTestPlugIn()
+	{
+	}
 
-using namespace ept;
+	virtual bool GetTrue();
+	virtual bool GetFalse();
+	virtual bool GetSame(bool p);
+	virtual bool GetOther(bool p);
+};
 
-class GUIPlugInFactory;
+bool MyTestPlugIn::GetTrue()
+{
+	return true;
+}
 
-class GUIPlugIn
+bool MyTestPlugIn::GetFalse()
 {
- public:
-	GUIPlugIn(GUIPlugInFactory *f);
+	return false;
+}
 
-	virtual ~GUIPlugIn();
+bool MyTestPlugIn::GetSame(bool p)
+{
+	return p;
+}
 
-	virtual void Comment(const char *szFormat, ...) = 0;
-	virtual bool Go(Engine &engine) = 0;
- 
- protected:
-	 GUIPlugInFactory *factory;
-};
+bool MyTestPlugIn::GetOther(bool p)
+{
+	return !p;
+}
 
-class GUIPlugInFactory
+class MyTestPlugInFactory : public TestPlugInFactory
 {
  public:
-	GUIPlugInFactory() 
+	MyTestPlugInFactory()
 	{
-		std::cout << "GUIPlugInFactory Created" << std::endl;
 	}
-	
-	virtual ~GUIPlugInFactory()
+
+	~MyTestPlugInFactory()
 	{
-		std::cout << "GUIPlugInFactory Destroy" << std::endl;
 	}
-	
-	virtual GUIPlugIn * CreatePlugIn() = 0;
 
- protected:
-#ifdef GUIPLUGIN_VERSION
-	const static unsigned int version;
-#endif
+	virtual TestPlugIn * CreatePlugIn()
+	{
+		return new MyTestPlugIn(this);
+	}
 };
 
-#endif // _GOFIND_GUIPLUGIN_H
+//
+// The "C" linkage factory0() function creates the PlugIn Factory
+// class for this library
+//
+
+extern "C" void * factory0( void )
+{
+	return new MyTestPlugInFactory;
+}
diff --git a/guiplugin.cpp b/testplugin.h
similarity index 63%
copy from guiplugin.cpp
copy to testplugin.h
index f03b3fd..afcfe23 100644
--- a/guiplugin.cpp
+++ b/testplugin.h
@@ -19,27 +19,43 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include <typeinfo>
-#include <iostream>
+#ifndef _GOFIND_TESTPLUGIN_H
+#define _GOFIND_TESTPLUGIN_H
 
-#include "guiplugin.h"
+class TestPlugInFactory;
 
-#ifdef GUIPLUGIN_VERSION
-	const unsigned int GUIPlugInFactory::version = GUIPLUGIN_VERSION;
-#endif
+class TestPlugIn
+{
+ public:
+	TestPlugIn(TestPlugInFactory *f) : factory(f)
+	{
+	}
 
-//
-// Announce to the world that the PlugIn base
-// class has been created or destroyed
-//
+	virtual ~TestPlugIn()
+	{
+	}
 
-GUIPlugIn::GUIPlugIn(GUIPlugInFactory *f) : factory(f)
-{
-	std::cout << "GUIPlugIn Created" << std::endl;
-}
+	virtual bool GetTrue() = 0;
+	virtual bool GetFalse() = 0;
+	virtual bool GetSame(bool p) = 0;
+	virtual bool GetOther(bool p) = 0;
+ 
+ protected:
+	 TestPlugInFactory *factory;
+};
 
-GUIPlugIn::~GUIPlugIn()
+class TestPlugInFactory
 {
-	std::cout << "GUIPlugIn Destroyed" << std::endl;
-}
+ public:
+	TestPlugInFactory() 
+	{
+	}
+	
+	virtual ~TestPlugInFactory()
+	{
+	}
+	
+	virtual TestPlugIn * CreatePlugIn() = 0;
+};
 
+#endif // _GOFIND_TESTPLUGIN_H

-- 
Development fot GoFind!



More information about the Pkg-games-commits mailing list