9 #include "TestySupport.h"
11 #define LOG(args) printf args
14 static const char kPathSep
= '\\';
16 static const char kPathSep
= '/';
18 static const char kTestsDirectory
[] = "tch_tests";
20 typedef int (* EntryPoint
)(void);
21 static const char kInitMethod
[] = "Testy_Init";
22 static const char kTestMethod
[] = "Testy_RunTest";
23 static const char kShutdownMethod
[] = "Testy_Shutdown";
26 ProcessModule(const char *modulesDir
, const char *fileName
)
28 int dLen
= strlen(modulesDir
);
29 int fLen
= strlen(fileName
);
31 char *buf
= (char *) malloc(dLen
+ 1 + fLen
+ 1);
32 memcpy(buf
, modulesDir
, dLen
);
34 memcpy(buf
+ dLen
+ 1, fileName
, fLen
);
35 buf
[dLen
+ 1 + fLen
] = '\0';
37 PRLibrary
*lib
= PR_LoadLibrary(buf
);
39 EntryPoint initFunc
= (EntryPoint
) PR_FindFunctionSymbol(lib
, kInitMethod
);
40 EntryPoint testFunc
= (EntryPoint
) PR_FindFunctionSymbol(lib
, kTestMethod
);
41 EntryPoint shutdownFunc
= (EntryPoint
) PR_FindFunctionSymbol(lib
, kShutdownMethod
);
47 // don't run test case if init fails.
53 PR_UnloadLibrary(lib
);
60 RunTests(const char *exePath
)
62 if (!(exePath
&& *exePath
))
68 char *p
= strrchr(exePath
, kPathSep
);
70 LOG(("unexpected exe path\n"));
74 int baseLen
= p
- exePath
;
75 int finalLen
= baseLen
+ 1 + sizeof(kTestsDirectory
);
77 // build full path to ipc modules
78 char *modulesDir
= (char*) malloc(finalLen
);
79 memcpy(modulesDir
, exePath
, baseLen
);
80 modulesDir
[baseLen
] = kPathSep
;
81 memcpy(modulesDir
+ baseLen
+ 1, kTestsDirectory
, sizeof(kTestsDirectory
));
83 LOG(("loading libraries in %s\n", modulesDir
));
85 // scan directory for IPC modules
87 PRDir
*dir
= PR_OpenDir(modulesDir
);
90 while ((ent
= PR_ReadDir(dir
, PR_SKIP_BOTH
)) != NULL
) {
92 // locate extension, and check if dynamic library
94 char *p
= strrchr(ent
->name
, '.');
95 if (p
&& PL_strcasecmp(p
, MOZ_DLL_SUFFIX
) == 0)
96 ProcessModule(modulesDir
, ent
->name
);
104 int main(int argc
, char **argv
)
106 Testy_LogInit("tch.log");