gcapi_test.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <stdio.h>
6
7#include "base/command_line.h"
8#include "chrome/installer/gcapi/gcapi.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11void call_statically() {
12  DWORD reason = 0;
13  BOOL result_flag_on = FALSE;
14  BOOL result_flag_off = FALSE;
15
16  // running this twice verifies that the first call does not set
17  // a flag that would make the second fail.  Thus, the results
18  // of the two calls should be the same (no state should have changed)
19  result_flag_off = GoogleChromeCompatibilityCheck(
20      FALSE, GCAPI_INVOKED_STANDARD_SHELL, &reason);
21  result_flag_on = GoogleChromeCompatibilityCheck(
22      TRUE, GCAPI_INVOKED_STANDARD_SHELL, &reason);
23
24  if (result_flag_off != result_flag_on)
25      printf("Registry key flag is not being set properly.");
26
27  printf("Static call returned result as %d and reason as %d.\n",
28         result_flag_on, reason);
29}
30
31void call_dynamically() {
32  HMODULE module = LoadLibrary(L"gcapi_dll.dll");
33  if (module == NULL) {
34    printf("Couldn't load gcapi_dll.dll.\n");
35    return;
36  }
37
38  GCCC_CompatibilityCheck gccfn = (GCCC_CompatibilityCheck) GetProcAddress(
39      module, "GoogleChromeCompatibilityCheck");
40  if (gccfn != NULL) {
41    DWORD reason = 0;
42
43    // running this twice verifies that the first call does not set
44    // a flag that would make the second fail.  Thus, the results
45    // of the two calls should be the same (no state should have changed)
46    BOOL result_flag_off = gccfn(FALSE, GCAPI_INVOKED_STANDARD_SHELL, &reason);
47    BOOL result_flag_on = gccfn(TRUE, GCAPI_INVOKED_STANDARD_SHELL, &reason);
48
49    if (result_flag_off != result_flag_on)
50      printf("Registry key flag is not being set properly.");
51
52    printf("Dynamic call returned result as %d and reason as %d.\n",
53           result_flag_on, reason);
54  } else {
55    printf("Couldn't find GoogleChromeCompatibilityCheck() in gcapi_dll.\n");
56  }
57  FreeLibrary(module);
58}
59
60const char kManualLaunchTests[] = "launch-chrome";
61
62int main(int argc, char* argv[]) {
63  CommandLine::Init(argc, argv);
64
65  testing::InitGoogleTest(&argc, argv);
66  RUN_ALL_TESTS();
67
68  if (CommandLine::ForCurrentProcess()->HasSwitch(kManualLaunchTests)) {
69    call_dynamically();
70    call_statically();
71    printf("LaunchChrome returned %d.\n", LaunchGoogleChrome());
72  }
73}
74