testy - first cut

git-svn-id: svn://10.0.0.236/trunk@140995 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dougt%netscape.com
2003-04-10 19:51:25 +00:00
parent 9f18a25fd9
commit 3b2287436c
6 changed files with 273 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
LIBRARY_NAME = tstysupt
include $(DEPTH)/config/autoconf.mk
MODULE = testy
REQUIRES = \
$(NULL)
TESTCPPSRCS = Testy.cpp
CPPSRCS = \
TestySupport.cpp \
$(TESTCPPSRCS) \
$(NULL)
SIMPLE_PROGRAMS = $(TESTCPPSRCS:.cpp=$(BIN_SUFFIX))
EXTRA_DSO_LDOPTS = \
$(NSPR_LIBS) \
$(NULL)
LIBS = \
tstysupt.lib \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,112 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "prlink.h"
#include "prio.h"
#include "plstr.h"
#include "TestySupport.h"
#define LOG(args) printf args
#ifdef XP_WIN
static const char kPathSep = '\\';
#else
static const char kPathSep = '/';
#endif
static const char kTestsDirectory[] = "tch_tests";
typedef int (* EntryPoint)(void);
static const char kInitMethod[] = "Testy_Init";
static const char kTestMethod[] = "Testy_RunTest";
static const char kShutdownMethod[] = "Testy_Shutdown";
static void
ProcessModule(const char *modulesDir, const char *fileName)
{
int dLen = strlen(modulesDir);
int fLen = strlen(fileName);
char *buf = (char *) malloc(dLen + 1 + fLen + 1);
memcpy(buf, modulesDir, dLen);
buf[dLen] = kPathSep;
memcpy(buf + dLen + 1, fileName, fLen);
buf[dLen + 1 + fLen] = '\0';
PRLibrary *lib = PR_LoadLibrary(buf);
if (lib) {
EntryPoint initFunc = (EntryPoint) PR_FindFunctionSymbol(lib, kInitMethod);
EntryPoint testFunc = (EntryPoint) PR_FindFunctionSymbol(lib, kTestMethod);
EntryPoint shutdownFunc = (EntryPoint) PR_FindFunctionSymbol(lib, kShutdownMethod);
if (testFunc) {
int rv = 0;
if (initFunc)
rv = initFunc();
// don't run test case if init fails.
if (rv == 0)
testFunc();
if (shutdownFunc)
shutdownFunc();
}
PR_UnloadLibrary(lib);
}
free(buf);
}
static void
RunTests(const char *exePath)
{
if (!(exePath && *exePath))
return;
//
// load test modules
//
char *p = strrchr(exePath, kPathSep);
if (p == NULL) {
LOG(("unexpected exe path\n"));
return;
}
int baseLen = p - exePath;
int finalLen = baseLen + 1 + sizeof(kTestsDirectory);
// build full path to ipc modules
char *modulesDir = (char*) malloc(finalLen);
memcpy(modulesDir, exePath, baseLen);
modulesDir[baseLen] = kPathSep;
memcpy(modulesDir + baseLen + 1, kTestsDirectory, sizeof(kTestsDirectory));
LOG(("loading libraries in %s\n", modulesDir));
//
// scan directory for IPC modules
//
PRDir *dir = PR_OpenDir(modulesDir);
if (dir) {
PRDirEntry *ent;
while ((ent = PR_ReadDir(dir, PR_SKIP_BOTH)) != NULL) {
//
// locate extension, and check if dynamic library
//
char *p = strrchr(ent->name, '.');
if (p && PL_strcasecmp(p, MOZ_DLL_SUFFIX) == 0)
ProcessModule(modulesDir, ent->name);
}
PR_CloseDir(dir);
}
free(modulesDir);
}
int main(int argc, char **argv)
{
Testy_LogInit("tch.log");
RunTests(argv[0]);
Testy_LogShutdown();
return 0;
}

View File

@@ -0,0 +1,49 @@
#include "nspr.h"
#include "TestySupport.h"
FILE* gLogFile = NULL;
int Testy_LogInit(const char* fileName)
{
gLogFile = fopen(fileName, "r+b");
if (!gLogFile) return -1;
return 0;
}
void Testy_LogShutdown()
{
if (gLogFile)
fclose(gLogFile);
}
void Testy_LogStart(const char* name)
{
PR_ASSERT(gLogFile);
fprintf(gLogFile, "Test Case: %s", name);
fflush(gLogFile);
}
void Testy_LogComment(const char* name, const char* comment)
{
PR_ASSERT(gLogFile);
fprintf(gLogFile, "Test Case: %s\n\t%s", name, comment);
fflush(gLogFile);
}
void Testy_LogEnd(const char* name, PRBool passed)
{
PR_ASSERT(gLogFile);
fprintf(gLogFile, "Test Case: %s (%s)", name, passed ? "Passed" : "Failed");
fflush(gLogFile);
}
void Testy_GenericStartup()
{
}
void Testy_GenericShutdown()
{
}

View File

@@ -0,0 +1,10 @@
PR_BEGIN_EXTERN_C
PR_EXPORT(int) Testy_LogInit(const char* fileName);
PR_EXPORT(void) Testy_LogShutdown();
PR_EXPORT(void) Testy_LogStart(const char* name);
PR_EXPORT(void) Testy_LogComment(const char* name, const char* comment);
PR_EXPORT(void) Testy_LogEnd(const char* name, PRBool passed);
PR_END_EXTERN_C

View File

@@ -0,0 +1,28 @@
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
LIBRARY_NAME = SimpleTest
include $(DEPTH)/config/autoconf.mk
MODULE = testy
REQUIRES = \
$(NULL)
LOCAL_INCLUDES = \
-I$(srcdir)/.. \
$(NULL)
CPPSRCS = \
SimpleTest.cpp \
$(NULL)
EXTRA_DSO_LDOPTS = \
../tstysupt.lib \
$(NSPR_LIBS) \
$(NULL)
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,39 @@
#include "nspr.h"
#include "TestySupport.h"
PR_BEGIN_EXTERN_C
PR_EXPORT(int) Testy_Init();
PR_EXPORT(int) Testy_RunTest();
PR_EXPORT(int) Testy_Shutdown();
PR_END_EXTERN_C
int Testy_Init()
{
return 0;
}
int Testy_RunTest()
{
const char* testCaseName1 = "Simple Test 1";
Testy_LogStart(testCaseName1);
Testy_LogComment(testCaseName1, "Comment 1");
Testy_LogEnd(testCaseName1, true);
const char* testCaseName2 = "Simple Test 2";
Testy_LogStart(testCaseName2);
Testy_LogComment(testCaseName2, "Comment 2");
Testy_LogEnd(testCaseName2, false);
return 0;
}
int Testy_Shutdown()
{
return 0;
}