1 : /*
2 : * This file is part of MIN Test Framework. Copyright © 2008 Nokia Corporation
3 : * and/or its subsidiary(-ies).
4 : * Contact: Konrad Marek Zapalowicz
5 : * Contact e-mail: DG.MIN-Support@nokia.com
6 : *
7 : * This program is free software: you can redistribute it and/or modify it
8 : * under the terms of the GNU General Public License as published by the Free
9 : * Software Foundation, version 2 of the License.
10 : *
11 : * This program is distributed in the hope that it will be useful, but WITHOUT
12 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 : * more details. You should have received a copy of the GNU General Public
15 : * License along with this program. If not, see
16 : * <http://www.gnu.org/licenses/>.
17 : */
18 :
19 :
20 : /**
21 : * @file test_module_api.c
22 : * @version 0.1
23 : * @brief This file contains implementation of Test Module API
24 : */
25 :
26 : /* ------------------------------------------------------------------------- */
27 : /* INCLUDE FILES */
28 : #include <test_module_api.h>
29 : #include <min_test_event_if.h>
30 :
31 : /* ------------------------------------------------------------------------- */
32 : /* EXTERNAL DATA STRUCTURES */
33 : /* None */
34 :
35 : /* ------------------------------------------------------------------------- */
36 : /* EXTERNAL GLOBAL VARIABLES */
37 : /* None */
38 :
39 : /* ------------------------------------------------------------------------- */
40 : /* EXTERNAL FUNCTION PROTOTYPES */
41 :
42 : /* ------------------------------------------------------------------------- */
43 : /* GLOBAL VARIABLES */
44 :
45 : /* ------------------------------------------------------------------------- */
46 : /* CONSTANTS */
47 : /* None */
48 :
49 : /* ------------------------------------------------------------------------- */
50 : /* MACROS */
51 :
52 : /* ------------------------------------------------------------------------- */
53 : /* LOCAL GLOBAL VARIABLES */
54 : /* None */
55 :
56 : /* ------------------------------------------------------------------------- */
57 : /* LOCAL CONSTANTS AND MACROS */
58 : /* None */
59 :
60 : /* ------------------------------------------------------------------------- */
61 : /* MODULE DATA STRUCTURES */
62 : /* None */
63 :
64 : /* ------------------------------------------------------------------------- */
65 : /* LOCAL FUNCTION PROTOTYPES */
66 : /* ------------------------------------------------------------------------- */
67 : /* FORWARD DECLARATIONS */
68 : /* None */
69 :
70 : /* ==================== LOCAL FUNCTIONS ==================================== */
71 : /* None */
72 :
73 : /* ======================== FUNCTIONS ====================================== */
74 :
75 : /* ------------------------------------------------------------------------- */
76 : int compare_id (const void *a, const void *b)
77 0 : {
78 0 : TestCaseInfo *tci = (TestCaseInfo *) a;
79 0 : int *id = (int *)b;
80 :
81 0 : if (tci->id_ == *id)
82 0 : return 0;
83 : else
84 0 : return -1;
85 : }
86 :
87 : /* ------------------------------------------------------------------------- */
88 : int tm_printf (int priority, char *desc, char *format, ...)
89 72 : {
90 72 : int retval = -1;
91 72 : int mqid = -1;
92 : va_list ap;
93 : MsgBuffer buff;
94 : char tmp_msg[MaxUsrMessage];
95 :
96 72 : if (strlen (desc) > (MaxUsrMessage - 1))
97 0 : desc[MaxUsrMessage - 1] = '\0';
98 72 : if (strlen (format) > (MaxUsrMessage - 1))
99 0 : format[MaxUsrMessage - 1] = '\0';
100 :
101 72 : va_start (ap, format);
102 72 : vsnprintf (tmp_msg, MaxUsrMessage, format, ap);
103 :
104 72 : buff.receiver_ = getppid ();
105 72 : buff.sender_ = getpid ();
106 72 : buff.type_ = MSG_USR;
107 72 : buff.param_ = priority;
108 72 : STRCPY (buff.desc_, desc, MaxUsrMessage);
109 72 : STRCPY (buff.message_, tmp_msg, MaxUsrMessage);
110 :
111 72 : mqid = mq_open_queue ('a');
112 :
113 72 : if (mqid != -1) {
114 72 : retval = 0;
115 72 : retval = mq_send_message (mqid, &buff);
116 : }
117 :
118 72 : va_end (ap);
119 72 : return retval;
120 : }
121 :
122 : /* ------------------------------------------------------------------------- */
123 : int tm_print_err (char *format, ...)
124 76 : {
125 76 : int retval = -1;
126 76 : int mqid = -1;
127 : va_list ap;
128 : MsgBuffer buff;
129 : char tmp_msg[MaxUsrMessage];
130 :
131 76 : if (strlen (format) > (MaxUsrMessage - 1))
132 0 : format[MaxUsrMessage - 1] = '\0';
133 :
134 76 : va_start (ap, format);
135 76 : vsnprintf (tmp_msg, MaxUsrMessage, format, ap);
136 :
137 76 : buff.receiver_ = getppid ();
138 76 : buff.sender_ = getpid ();
139 76 : buff.type_ = MSG_USR;
140 76 : buff.param_ = 0;
141 76 : STRCPY (buff.desc_, "__error_console__", MaxUsrMessage);
142 76 : STRCPY (buff.message_, tmp_msg, MaxUsrMessage);
143 :
144 76 : mqid = mq_open_queue ('a');
145 :
146 76 : if (mqid != -1) {
147 76 : retval = 0;
148 76 : retval = mq_send_message (mqid, &buff);
149 : }
150 :
151 76 : va_end (ap);
152 76 : return retval;
153 : }
154 :
155 :
156 : /* ------------------------------------------------------------------------- */
157 : void tm_macro_error (unsigned int macro_type,
158 : const char *file,
159 : const char *function,
160 : unsigned int line,
161 : int result,
162 : int expected1,
163 : int expected2,
164 : int expected3, int expected4, int expected5)
165 0 : {
166 :
167 0 : switch (macro_type) {
168 : case 0: /* TL */
169 0 : MIN_INFO ("FAIL: MIN TF's macro. FILE[%s], "
170 : "FUNCTION[%s], LINE[%d]", file, function, line);
171 0 : break;
172 :
173 : case 1: /* T1L */
174 0 : MIN_INFO ("FAIL: MIN TF's macro. RECEIVED[%d], "
175 : "EXPECTED[%d], FILE[%s], FUNCTION[%s], LINE[%d]",
176 : result, expected1, file, function, line);
177 0 : break;
178 :
179 : case 2: /* T2L */
180 0 : MIN_INFO ("FAIL: MIN TF's macro. RECEIVED[%d], "
181 : "EXPECTED[%d], EXPECTED[%d], FILE[%s], "
182 : "FUNCTION[%s], LINE[%d]",
183 : result, expected1, expected2,
184 : file, function, line);
185 0 : break;
186 :
187 : case 3: /* T3L */
188 0 : MIN_INFO ("FAIL: MIN TF's macro. RECEIVED[%d], "
189 : "EXPECTED[%d], EXPECTED[%d], EXPECTED[%d], "
190 : "FILE[%s], FUNCTION[%s], LINE[%d]",
191 : result, expected1, expected2, expected3,
192 : file, function, line);
193 0 : break;
194 :
195 : case 4: /* T4L */
196 0 : MIN_INFO ("FAIL: MIN TF's macro. RECEIVED[%d], "
197 : "EXPECTED[%d], EXPECTED[%d], EXPECTED[%d], "
198 : "EXPECTED[%d], FILE[%s], FUNCTION[%s], LINE[%d]",
199 : result, expected1, expected2, expected3,
200 : expected4, file, function, line);
201 0 : break;
202 :
203 : case 5: /* T5L */
204 0 : MIN_INFO ("FAIL: MIN TF's macro. RECEIVED[%d], "
205 : "EXPECTED[%d], EXPECTED[%d], EXPECTED[%d], "
206 : "EXPECTED[%d], EXPECTED[%d], FILE[%s], "
207 : "FUNCTION[%s], LINE[%d]",
208 : result, expected1, expected2, expected3,
209 : expected4, expected5, file, function, line);
210 : break;
211 : }
212 0 : }
213 :
214 : /* ------------------------------------------------------------------------- */
215 : /* ================= OTHER EXPORTED FUNCTIONS ============================== */
216 : /* None */
217 :
218 : /* ================= TESTS FOR LOCAL FUNCTIONS ============================= */
219 : #ifdef MIN_UNIT_TEST
220 : #include <check.h>
221 : #include "test_module_api.tests"
222 : #endif /* MIN_UNIT_TEST */
223 : /* ------------------------------------------------------------------------- */
224 : /* End of file */
|