73590577639d666eee7c4e12e2629ea938dcb05a
[platform/core/api/context.git] / testsuite / src / shared.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __CONTEXT_TEST_SHARED_H__
18 #define __CONTEXT_TEST_SHARED_H__
19
20 #include <cstdlib>
21 #include <iostream>
22 #include <string>
23 #include <glib.h>
24 #include <ContextTypes.h>
25 #include <SharedUtil.h>
26
27 #define ASSERT_RETURN(condition, ret) \
28         do { \
29                 if (!(condition)) { \
30                         g_print("\n>> " RED("FAIL") ": %s(%d) > %s\n", __FUNCTION__, __LINE__, #condition); \
31                         return ret; \
32                 } \
33         } while (0)
34
35 #define ASSERT(condition) ASSERT_RETURN(condition, false)
36
37 #define ASSERT_CMPINT(left, comp, right) \
38         do { \
39                 if (!((left) comp (right))) { \
40                         g_print("\n>> " RED("FAIL") ": %s(%d) > %s(%d) %s %s(%d)\n", __FUNCTION__, __LINE__, #left, (left), #comp, #right, (right)); \
41                         return false; \
42                 } \
43         } while (0)
44
45 namespace test {
46         void start_mainloop();
47         void stop_mainloop();
48         bool is_mainloop_running();
49
50         int read_int();
51         int read_int(const std::string& msg);
52         std::string read_str();
53         std::string read_str(const std::string& msg);
54
55         void run_test_case(const char *tcName, bool (*tcFunc)(void));
56 }
57
58 #endif