-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbaseclasses.h
160 lines (138 loc) · 5.58 KB
/
baseclasses.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#ifndef REFPROP_TESTS_BASECLASSES
#define REFPROP_TESTS_BASECLASSES
#include "REFPROP_lib.h"
#include "manyso/native.h"
#include "manyso/exceptions.h"
#include "REFPROPtests/utils.h"
#include <string>
#include <cstring>
struct REFPROPResult {
std::vector<double> Output;
std::string hUnits;
int iUnit;
std::vector<double> x, y, x3;
double q;
int ierr;
std::string herr;
};
class REFPROPDLLFixture
{
private:
std::unique_ptr<NativeSharedLibraryWrapper> RP;
public:
REFPROPDLLFixture(){ reload(); }
void reload(){
char* RPPREFIX = std::getenv("RPPREFIX");
REQUIRE(RPPREFIX != nullptr);
REQUIRE(strlen(RPPREFIX) != 0);
#if defined(__MANYSOISWINDOWS__)
#if defined(IS_32_BIT)
std::string shared_library_filename = "REFPROP.DLL";
#else
std::string shared_library_filename = "REFPRP64.DLL";
#endif
#else
std::string shared_library_filename = "librefprop.so";
#endif
std::string shared_library_path = path_join_and_norm(std::string(RPPREFIX), shared_library_filename);
CAPTURE(shared_library_path);
#if defined(__MANYSOISWINDOWS__)
#if defined(IS_32_BIT)
auto load_method = AbstractSharedLibraryWrapper::load_method::LOAD_LIBRARY;
#else
auto load_method = AbstractSharedLibraryWrapper::load_method::FROM_FILE;
#endif
#else
auto load_method = AbstractSharedLibraryWrapper::load_method::LOAD_LIBRARY;
#endif
RP.reset(new NativeSharedLibraryWrapper(shared_library_path, load_method));
// Check that the load was a success
bool loaded_properly = std::get<0>(RP->is_locked());
REQUIRE(loaded_properly);
// Set the path in REFPROP
std::string path(RPPREFIX);
char hpth[256] = "";
strcpy(hpth, (path + std::string(255-path.size(), ' ')).c_str());
SETPATHdll(hpth, 255);
}
virtual ~REFPROPDLLFixture(){
RP.reset(nullptr);
}
// And now, totally magical, the use of variadic function arguments in concert with type macros
// Add many methods, each corresponding to a 1-to-1 wrapper of a function from the shared library
#define X(name) template<class ...Args> void name(Args&&... args){ return RP->getAddress<name ## _POINTER>(#name)(std::forward<Args>(args)...); };
LIST_OF_REFPROP_FUNCTION_NAMES
#undef X
int get_enum(const std::string &key) {
char henum[256]="", herr[256]="";
int ienum = 0, ierr = 0;
REQUIRE(key.size() < 254);
strcpy(henum, (key + std::string(255-key.size(), ' ')).c_str());
int ii = 0;
GETENUMdll(ii, henum, ienum, ierr, herr, 255, 255);
CAPTURE(key);
CAPTURE(herr);
REQUIRE(ierr==0);
return ienum;
}
REFPROPResult REFPROP(const std::string &_hFld, const std::string &_hIn, const std::string &_hOut, int unit_system, int iMass, int iFlag, double a, double b, std::vector<double> &z) {
char hFld[10001], hIn[256], hOut[256];
REQUIRE(_hFld.size() < 9999);
REQUIRE(_hIn.size() < 254);
REQUIRE(_hOut.size() < 254);
strcpy(hFld, (_hFld + std::string(10000-_hFld.size(),' ')).c_str());
strcpy(hIn, (_hIn + std::string(255-_hIn.size(), ' ')).c_str());
strcpy(hOut, (_hOut + std::string(255-_hOut.size(), ' ')).c_str());
std::vector<double> Output(200), x(20), y(20), x3(20);
double q;
int iUnit = 0, ierr = 0;
char herr[256] = "", hUnits[256] = "";
REFPROPdll(hFld, hIn, hOut, unit_system, iMass, iFlag, a, b, &(z[0]), &(Output[0]), hUnits, iUnit, &(x[0]), &(y[0]), &(x3[0]), q, ierr, herr, 10000, 255, 255, 255, 255);
REFPROPResult res = {Output, std::string(hUnits), iUnit, x, y, x3, q, ierr, std::string(herr) };
return res;
}
void FLAGS(const std::string &_hFlag, int jflag, int &kflag){
char hFlag[256] = "";
REQUIRE(_hFlag.size() <= 255);
strcpy(hFlag, (_hFlag.c_str() + std::string(255 - _hFlag.size(), ' ')).c_str());
char herr[256] = "";
int ierr = 0;
FLAGSdll(hFlag, jflag, kflag, ierr, herr, 255, 255);
CAPTURE(herr);
REQUIRE(ierr == 0);
if (jflag != -999){
REQUIRE(kflag == jflag);
}
}
void SETFLUIDS(const std::string &flds, int &ierr, std::string &herr) {
char hFlds[10001] = "";
REQUIRE(flds.size() <= 10000);
strcpy(hFlds, (flds.c_str() + std::string(10000 - flds.size(), ' ')).c_str());
ierr = 0;
SETFLUIDSdll(hFlds, ierr, 10000);
char herrsetup[255] = "";
if (ierr != 0) {
ERRMSGdll(ierr, herrsetup, 255);
}
herr = std::string(herrsetup);
}
std::pair<int, std::string> SETMOD(int Ncomp, const std::string &type, const std::string &mix, const std::string &model) {
char htype[4] = "", hmix[4] = "", hmodel[4] = "";
REQUIRE(type.size() == 3);
REQUIRE(mix.size() == 3);
REQUIRE(model.size() == 3);
strcpy(htype, type.c_str());
strcpy(hmix, mix.c_str());
strcpy(hmodel, model.c_str());
int ierr = 0; char herr[256] = ""; memset(herr,' ',255);
SETMODdll(Ncomp, htype, hmix, hmodel, ierr, herr, 3, 3, 3, 255);
return std::make_pair(ierr, std::string(herr));
}
std::tuple<std::string, std::string> GETMOD(int Ncomp, const std::string &type) {
char htype[4] = "", hcode[4] = " ", hcite[256] = ""; memset(hcite, ' ', 255);
strcpy(htype, type.c_str());
GETMODdll(Ncomp, htype, hcode, hcite, 3, 3, 255);
return std::make_tuple(std::string(hcode), std::string(hcite));
}
};
#endif