• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include "MockAndroidAgentFactory.h"
15 
16 #include <stdio.h>
17 
18 #include "gtest/gtest.h"
19 
20 #ifdef _WIN32
21 using android::emulation::WindowsFlags;
22 bool WindowsFlags::sIsParentProcess = true;
23 HANDLE WindowsFlags::sChildRead = nullptr;
24 HANDLE WindowsFlags::sChildWrite = nullptr;
25 char WindowsFlags::sFileLockPath[MAX_PATH] = {};
26 #endif
27 
28 extern "C" const QAndroidVmOperations* const gMockQAndroidVmOperations;
29 extern "C" const QAndroidEmulatorWindowAgent* const
30         gMockQAndroidEmulatorWindowAgent;
31 extern "C" const QAndroidMultiDisplayAgent* const
32         gMockQAndroidMultiDisplayAgent;
33 
34 namespace android {
35 namespace emulation {
36 
37 const QAndroidVmOperations* const
android_get_QAndroidVmOperations() const38 MockAndroidConsoleFactory::android_get_QAndroidVmOperations() const {
39     return gMockQAndroidVmOperations;
40 }
41 
42 const QAndroidMultiDisplayAgent* const
android_get_QAndroidMultiDisplayAgent() const43 MockAndroidConsoleFactory::android_get_QAndroidMultiDisplayAgent() const {
44     return gMockQAndroidMultiDisplayAgent;
45 }
46 
47 const QAndroidEmulatorWindowAgent* const
android_get_QAndroidEmulatorWindowAgent() const48 MockAndroidConsoleFactory::android_get_QAndroidEmulatorWindowAgent() const {
49     return gMockQAndroidEmulatorWindowAgent;
50 }
51 }  // namespace emulation
52 }  // namespace android
53 
54 
55 // The gtest entry point that will configure the mock agents.
main(int argc,char ** argv)56 int main(int argc, char** argv) {
57 #ifdef _WIN32
58 #define _READ_STR "--read"
59 #define _WRITE_STR "--write"
60 #define _FILE_PATH_STR "--file-lock-path"
61     for (int i = 1; i < argc; i++) {
62         if (!strcmp("--child", argv[i])) {
63             WindowsFlags::sIsParentProcess = false;
64         } else if (!strncmp(_READ_STR, argv[i], strlen(_READ_STR))) {
65             sscanf(argv[i], _READ_STR "=%p", &WindowsFlags::sChildRead);
66         } else if (!strncmp(_WRITE_STR, argv[i], strlen(_WRITE_STR))) {
67             sscanf(argv[i], _WRITE_STR "=%p", &WindowsFlags::sChildWrite);
68         } else if (!strncmp(_FILE_PATH_STR, argv[i], strlen(_FILE_PATH_STR))) {
69             sscanf(argv[i], _FILE_PATH_STR "=%s",
70                    WindowsFlags::sFileLockPath);
71         }
72     }
73 #endif
74     ::testing::InitGoogleTest(&argc, argv);
75     fprintf(stderr, " -- Injecting mock agents. -- \n");
76     android::emulation::injectConsoleAgents(
77             android::emulation::MockAndroidConsoleFactory());
78     return RUN_ALL_TESTS();
79 }
80