Commit | Line | Data |
---|---|---|
970ed795 EL |
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 | /////////////////////////////////////////////////////////////////////////////// | |
8 | #include <stdio.h> | |
9 | #include "LogFiles.hh" | |
10 | #include "CommonStuff.hh" | |
11 | ||
12 | #ifndef OLD_NAMES | |
13 | namespace LogFiles { | |
14 | #endif | |
15 | ||
16 | #define MAXLINELENGTH (8 * 1024) | |
17 | ||
18 | StrList readlogfile(const CHARSTRING& filename) | |
19 | { | |
20 | StrList str_list(NULL_VALUE); | |
21 | FILE *fp; | |
22 | fp = fopen(filename, "r"); | |
23 | if (!fp) return str_list; | |
24 | char line[MAXLINELENGTH]; | |
25 | while (fgets(line, MAXLINELENGTH, fp)) | |
26 | { | |
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); | |
30 | } | |
31 | fclose(fp); | |
32 | return str_list; | |
33 | } | |
34 | ||
35 | #ifndef OLD_NAMES | |
36 | } | |
37 | #endif | |
38 | ||
39 | #ifndef OLD_NAMES | |
40 | namespace CommonStuff { | |
41 | #endif | |
42 | ||
43 | EPTF__CharstringList v__EPTF__Common__errorMsgs(NULL_VALUE); | |
44 | ||
45 | void f__EPTF__Common__initErrorMsgs(void) { | |
46 | v__EPTF__Common__errorMsgs = NULL_VALUE; | |
47 | } | |
48 | ||
49 | void f__EPTF__Common__addErrorMsg(const CHARSTRING& pl__newMsg) | |
50 | { | |
51 | v__EPTF__Common__errorMsgs[v__EPTF__Common__errorMsgs.size_of()] = pl__newMsg; | |
52 | } | |
53 | ||
54 | INTEGER f__EPTF__Common__nofErrorMsgs() | |
55 | { | |
56 | return v__EPTF__Common__errorMsgs.size_of(); | |
57 | } | |
58 | ||
59 | CHARSTRING f__EPTF__Common__getErrorMsg(const INTEGER& pl__errorNum) | |
60 | { | |
61 | if (v__EPTF__Common__errorMsgs.size_of() == 0) { | |
62 | return CHARSTRING(""); | |
63 | } | |
64 | boolean tmp_16; | |
65 | tmp_16 = (v__EPTF__Common__errorMsgs.size_of() <= pl__errorNum); | |
66 | if (!tmp_16) tmp_16 = (pl__errorNum < 0); | |
67 | if (tmp_16) { | |
68 | return CHARSTRING(""); | |
69 | } | |
70 | return v__EPTF__Common__errorMsgs[pl__errorNum]; | |
71 | } | |
72 | ||
73 | void f__EPTF__Common__error(const CHARSTRING& pl__message) | |
74 | { | |
75 | f__EPTF__Common__addErrorMsg(pl__message); | |
76 | TTCN_Logger::log_str(TTCN_Logger::ERROR_UNQUALIFIED, pl__message); | |
77 | } | |
78 | ||
79 | void f__EPTF__Common__warning(const CHARSTRING& pl__message) | |
80 | { | |
81 | TTCN_Logger::log_str(TTCN_Logger::WARNING_UNQUALIFIED, pl__message); | |
82 | } | |
83 | ||
84 | void f__EPTF__Common__user(const CHARSTRING& pl__message) | |
85 | { | |
86 | TTCN_Logger::log_str(TTCN_Logger::USER_UNQUALIFIED, pl__message); | |
87 | } | |
88 | ||
89 | INTEGER f__EPTF__Base__upcast(const EPTF__Base__CT& pl__compRef) { | |
90 | return INTEGER((component)pl__compRef); | |
91 | } | |
92 | ||
93 | EPTF__Base__CT f__EPTF__Base__downcast(const INTEGER& pl__baseCompRef) { | |
94 | return EPTF__Base__CT(pl__baseCompRef); | |
95 | } | |
96 | ||
97 | void f__EPTF__Base__assert(const CHARSTRING& pl__assertMessage, const BOOLEAN& pl__predicate) | |
98 | { | |
99 | #ifdef EPTF_DEBUG | |
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); | |
105 | } else { | |
106 | f__EPTF__Base__stop(FAIL); | |
107 | } | |
108 | } | |
109 | #endif | |
110 | } | |
111 | ||
112 | FLOAT f__EPTF__Base__getTimeOfDay() | |
113 | { | |
114 | struct timeval tv; | |
115 | gettimeofday(&tv, NULL); | |
116 | return tv.tv_sec + tv.tv_usec / 1000000.0; | |
117 | } | |
118 | ||
119 | #ifndef OLD_NAMES | |
120 | } | |
121 | #endif |