1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
10 #include "CommonStuff.hh"
16 #define MAXLINELENGTH (8 * 1024)
18 StrList
readlogfile(const CHARSTRING
& filename
)
20 StrList
str_list(NULL_VALUE
);
22 fp
= fopen(filename
, "r");
23 if (!fp
) return str_list
;
24 char line
[MAXLINELENGTH
];
25 while (fgets(line
, MAXLINELENGTH
, fp
))
27 size_t str_len
= strlen(line
);
28 if (line
[str_len
- 1] == '\n') line
[str_len
- 1] = '\0';
29 str_list
[str_list
.size_of()] = CHARSTRING(line
);
40 namespace CommonStuff
{
43 EPTF__CharstringList
v__EPTF__Common__errorMsgs(NULL_VALUE
);
45 void f__EPTF__Common__initErrorMsgs(void) {
46 v__EPTF__Common__errorMsgs
= NULL_VALUE
;
49 void f__EPTF__Common__addErrorMsg(const CHARSTRING
& pl__newMsg
)
51 v__EPTF__Common__errorMsgs
[v__EPTF__Common__errorMsgs
.size_of()] = pl__newMsg
;
54 INTEGER
f__EPTF__Common__nofErrorMsgs()
56 return v__EPTF__Common__errorMsgs
.size_of();
59 CHARSTRING
f__EPTF__Common__getErrorMsg(const INTEGER
& pl__errorNum
)
61 if (v__EPTF__Common__errorMsgs
.size_of() == 0) {
62 return CHARSTRING("");
65 tmp_16
= (v__EPTF__Common__errorMsgs
.size_of() <= pl__errorNum
);
66 if (!tmp_16
) tmp_16
= (pl__errorNum
< 0);
68 return CHARSTRING("");
70 return v__EPTF__Common__errorMsgs
[pl__errorNum
];
73 void f__EPTF__Common__error(const CHARSTRING
& pl__message
)
75 f__EPTF__Common__addErrorMsg(pl__message
);
76 TTCN_Logger::log_str(TTCN_Logger::ERROR_UNQUALIFIED
, pl__message
);
79 void f__EPTF__Common__warning(const CHARSTRING
& pl__message
)
81 TTCN_Logger::log_str(TTCN_Logger::WARNING_UNQUALIFIED
, pl__message
);
84 void f__EPTF__Common__user(const CHARSTRING
& pl__message
)
86 TTCN_Logger::log_str(TTCN_Logger::USER_UNQUALIFIED
, pl__message
);
89 INTEGER
f__EPTF__Base__upcast(const EPTF__Base__CT
& pl__compRef
) {
90 return INTEGER((component
)pl__compRef
);
93 EPTF__Base__CT
f__EPTF__Base__downcast(const INTEGER
& pl__baseCompRef
) {
94 return EPTF__Base__CT(pl__baseCompRef
);
97 void f__EPTF__Base__assert(const CHARSTRING
& pl__assertMessage
, const BOOLEAN
& pl__predicate
)
100 if (!(pl__predicate
)) {
101 f__EPTF__Base__addAssertMsg(pl__assertMessage
);
102 TTCN_Logger::log_str(TTCN_Logger::ERROR_UNQUALIFIED
, CHARSTRING("f_EPTF_Base_assert: Assertion failed! ") + pl__assertMessage
);
103 if (EPTF__CommonStuff::EPTF__Base__CT__private_component_v__EPTF__Base__negativeTestMode
== true) {
104 f__EPTF__Base__stop(NONE
);
106 f__EPTF__Base__stop(FAIL
);
112 FLOAT
f__EPTF__Base__getTimeOfDay()
115 gettimeofday(&tv
, NULL
);
116 return tv
.tv_sec
+ tv
.tv_usec
/ 1000000.0;