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