source: Sophya/trunk/SophyaProg/Tests/tdynl.cc@ 2609

Last change on this file since 2609 was 2499, checked in by ansari, 22 years ago

Ajout programme test classe PDynMgr suite adaptation a l'API OSX-Darwin (NSModule ...) - Reza 23/02/2004

File size: 2.1 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <math.h>
4#include <iostream>
5#include <fstream>
6
7#include "tarrinit.h"
8#include "array.h"
9
10#include "pdlmgr.h"
11#include "pexceptions.h"
12#include "timing.h"
13
14// Fonction de test qu'on reproduit dans le fichier CTestFileName
15double testfunc_dynl(double x, double y)
16{
17 return (exp(-x)+sin(y)*x);
18}
19
20typedef double (* MyDlFunctionOfXY) (double x, double y);
21
22int main(int narg, char *arg[])
23{
24 SophyaInit();
25 InitTim();
26
27 if (narg < 3) {
28 cout << " --- tdynl -- test de la classe PDynLinkMgr --- \n "
29 << " Usage: tdynl TmpDirName/ CTestFileName\n"
30 << " Exemple: tdynl /tmp/ toto.c \n" << endl;
31 return(0);
32 }
33
34 try {
35 string TmpDirName = arg[1];
36 string CTestFileName = arg[2];
37 string cfilename = TmpDirName + CTestFileName;
38 {
39 ofstream of(cfilename.c_str());
40 of << "#include <math.h> \n "
41 << "double myf_dyl(double x, double y) \n"
42 << "{ \n"
43 << " return (exp(-x)+sin(y)*x); \n"
44 << "} \n" << endl;
45 cout << " File " << cfilename << "created ... " << endl;
46 }
47
48 cout << " Calling PDynLinkMgr::BuildFromCFile(" << cfilename << ")" << endl;
49 PDynLinkMgr::SetTmpDir(TmpDirName);
50 PDynLinkMgr * dyl = PDynLinkMgr::BuildFromCFile(cfilename);
51 PrtTim(" End of Compile-Link ");
52
53 MyDlFunctionOfXY f = (MyDlFunctionOfXY)dyl->GetFunction("myf_dyl");
54 if (f != NULL) {
55 cout << " DlFunction f dyl.GetFunction(myf_dyl) linked OK - calling f() " << endl;
56 cout << "f(0,1)= " << f(0.,1.) << " ?= testfunc_dynl(0,1)= " << testfunc_dynl(0.,1.) << endl;
57 cout << "f(1,1)= " << f(1.,1.) << " ?= testfunc_dynl(1,1)= " << testfunc_dynl(1.,1.) << endl;
58 cout << "f(-1,2.5)= " << f(-1.,2.5) << " ?= testfunc_dynl(-1,2.5)= " << testfunc_dynl(-1.,2.5) << endl;
59 }
60 else {
61 cout << " ERROR linking DlFunction f !!! " << endl;
62 }
63 delete dyl;
64 }
65
66 catch (PThrowable & exc) {
67 cerr << " Catched Exception " << (string)typeid(exc).name()
68 << " - Msg= " << exc.Msg() << endl;
69 }
70 catch (...) {
71 cerr << " some other exception was caught ! " << endl;
72 }
73
74 PrtTim(" End of tdynl ");
75}
Note: See TracBrowser for help on using the repository browser.